|
本帖最后由 gto250 于 2010-9-8 21:43 编辑
今天利用P版的RTApiHook32.au3实验了一下hook api。实现对ie浏览器的抓包。
Hook的api是 ws2_32.dll中的send,recv,WSASend,recvfrom,WSARecv,还有一个
Sendto没有hook。
函数的原型如下:
send(SOCKET s, const char FAR * buf, int len, int flags);
sendto( SOCKET s,
const char FAR * buf,
int len,
int flags,
const struct sockaddr FAR * to,
int tolen);
WSASend(
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesSent,
DWORD dwFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
recv( SOCKET s, char FAR * buf, int len, int flags);
recvfrom(
SOCKET s,
char FAR * buf,
int len,
int flags,
struct sockaddr FAR * from,
int FAR * fromlen
);
WSARecv(
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesRecvd,
LPDWORD lpFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
代码如下:#include <RTApiHook32.au3>
$hCallBack = DllCallBackRegister("_ApiHookCallBack", "dword", "handle;ptr")
$pCallBack = DllCallBackGetPtr($hCallBack)
$hProcess = _RTOpenProcess("iexplore.exe")
$psend = _RTGetProcAddress("ws2_32.dll", "send")
$precv = _RTGetProcAddress("ws2_32.dll", "recv")
$pWSASend = _RTGetProcAddress("ws2_32.dll", "WSASend")
$precvfrom = _RTGetProcAddress("ws2_32.dll", "recvfrom")
$pWSARecv = _RTGetProcAddress("ws2_32.dll", "WSARecv")
$tHooksend = _RTApiHookEx($hProcess,$psend,4,$pCallBack,$APIHOOK_Flags_Default)
$tHookrecv = _RTApiHookEx($hProcess,$precv,4,$pCallBack,$APIHOOK_Flags_Default)
$tHookwsasend = _RTApiHookEx($hProcess, $pWSASend, 7, $pCallBack, $APIHOOK_Flags_Default)
$tHookrecvfrom = _RTApiHookEx($hProcess,$precvfrom,6,$pCallBack,$APIHOOK_Flags_Default)
$tHookwsaRecv = _RTApiHookEx($hProcess, $pWSARecv, 7, $pCallBack, $APIHOOK_Flags_Default)
; 用于程序在退出时,恢复目标进程的系统函数。
HotKeySet("^{f5}", "_Close")
OnAutoItExitRegister("_Close")
While 1
Sleep(100)
WEnd
Func _ApiHookCallBack($hProcess, $pCallInfo)
Switch _RTApiHookReadProcedure($hProcess, $pCallInfo)
Case $psend
$pFileName = _RTApiHookReadParam($hProcess, $pCallInfo, 2) ;获取sendto中第二个参数 const char FAR*buf的指针
$sFileName = _RTReadProcessMemory($hProcess, $pFileName, "", 1024, "str")
MsgBox(48 + 4, "send", "发送内容:" & $sFileName )
Case $pWSASend
$pFileName2 = _RTApiHookReadParam($hProcess, $pCallInfo, 2)
$sFileName2= _RTReadProcessMemory($hProcess, $pFileName2, "", 1024, "str")
MsgBox(48 + 4, "WSAsend", "发送内容:" & $sFileName2 )
Case $precv
$pFileName3 = _RTApiHookReadParam($hProcess, $pCallInfo, 2)
$sFileName3= _RTReadProcessMemory($hProcess, $pFileName3, "", 1024, "str")
MsgBox(48 + 4, "recv", "接收内容:" & $sFileName3 )
Case $precvfrom
$pFileName4 = _RTApiHookReadParam($hProcess, $pCallInfo, 2)
$sFileName4= _RTReadProcessMemory($hProcess, $pFileName4, "", 1024, "str")
MsgBox(48 + 4, "recvfrom", "接收内容:" & $sFileName4 )
Case $pWSARecv
$pFileName5 = _RTApiHookReadParam($hProcess, $pCallInfo, 2)
$sFileName5= _RTReadProcessMemory($hProcess, DllStructGetData($pFileName5,2), "", 1024, "str")
MsgBox(48 + 4, "pWSARecv", "接收内容:" & $sFileName5 )
EndSwitch
EndFunc ;==>_ApiHookCallBack
Func _Close()
_RTApiUnhook($hProcess, $psend, DllStructGetData($tHooksend, 6))
_RTApiUnhook($hProcess, $pWSASend, DllStructGetData($tHookwsasend, 6))
_RTApiUnhook($hProcess, $precv, DllStructGetData($tHookrecv, 6))
_RTApiUnhook($hProcess, $precvfrom, DllStructGetData($tHookrecv, 6))
_RTApiUnhook($hProcess, $pWSARecv, DllStructGetData($tHookrecv, 6))
exit
EndFunc ;==>_Close
运行的结果是:ie中发送包是用send函数,接收包是WSARecv函数。
但是这个程序可以截获send中的数据包,对WSARecv中的数据包却无法获得。
现在需要寻求帮助的是
1、 怎么获得WSARecv中的数据包
2、 怎么获得数据包是从哪个ip地址哪个端口发送或接收的
(虽然还没有解决,但是还是先好好消化一下) |
评分
-
查看全部评分
|