邪恶八进制信息安全团队技术讨论组's Archiver

金州 2005-12-16 00:36

[转载]显示指定主机的IP地址

文章作者:Betrayed<BR><BR>.386<BR>.model flat, stdcall<BR>option casemap :none<BR><BR>include /masm32/include/windows.inc<BR>include /masm32/include/user32.inc<BR>include /masm32/include/kernel32.inc<BR>include /masm32/include/wsock32.inc<BR>includelib /masm32/lib/wsock32.lib<BR>includelib /masm32/lib/user32.lib<BR>includelib /masm32/lib/kernel32.lib<BR><BR> WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD<BR> ResolveIp PROTO :DWORD           ;proto for helper thread<BR><BR>.data <BR> dlgname  db "MAIN",0 <BR> szTitle  db "Host/Ip Resolver",0<BR> wsaError  db "Error initializing winsock!",0<BR> szReady  db "Ready",0<BR> szResolving db "Resolving...",0<BR> szReverse  db "Reversing...",0<BR> unknown  db "Unknown",0<BR><BR>.data?<BR> wsa WSADATA <?>            ;winsock data<BR> hInstance  dd ?<BR> szIpaddr  db 256 dup(?)          <BR> szHostname db 256 dup(?)<BR> hMain  dd ?<BR> hResolve dd ?<BR> ThreadId dd ?              ;hold the thread id<BR> ip   dd ?<BR> <BR>.code<BR><BR>start:<BR><BR>  invoke GetModuleHandle, NULL<BR>    mov hInstance, eax<BR>  invoke WSAStartup,101h,offset wsa      ;load winsock version 1.1<BR>    .if eax != NULL          ;if we did not get a null it worked<BR>     invoke MessageBox,NULL,offset wsaError,offset szTitle,MB_OK + MB_ICONSTOP ;error handling<BR>      invoke ExitProcess,1       ;quit if no winsock<BR>    .endif<BR>     invoke DialogBoxParam,hInstance,ADDR dlgname,0,ADDR WndProc,0<BR>      invoke ExitProcess,0<BR>      <BR>WndProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD<BR><BR>  .if uMsg == WM_INITDIALOG<BR>    mov eax,hWin<BR>    mov hMain,eax<BR>    invoke GetDlgItem,hWin,2000<BR>    mov hResolve,eax<BR>  .elseif uMsg == WM_COMMAND<BR>    .if wParam == 2000<BR>     invoke CreateThread,0,0,addr ResolveIp,0,0,addr ThreadId  ;call or thread so windows does not freeze<BR>      invoke CloseHandle,eax<BR>    .endif<BR>     xor eax,eax<BR>      ret<BR>  .elseif uMsg == WM_CLOSE<BR>    invoke WSACleanup                ;free the winsock.dll<BR>     invoke EndDialog,hWin,0 <BR>      ret<BR>  .endif<BR> xor eax,eax<BR>  ret <BR>WndProc endp<BR><BR>ResolveIp proc lParam:DWORD<BR> invoke EnableWindow,hResolve,FALSE            ;disable the resolve button<BR> invoke GetDlgItemText,hMain,1001,addr szIpaddr,sizeof szIpaddr  ;get the text from the ip box<BR>   or  eax,eax                   ;check return<BR>    jz ResolveHost                 ;if 0 jump to resolve host<BR> invoke lstrcmp,addr unknown,addr szIpaddr         ;compare return with unknown string<BR>   or  eax,eax                   ;check eax<BR>    jz ResolveHost                ;jmp to resolve host if 0<BR> invoke SetDlgItemText,hMain,3000,addr szReverse       ;change the frame text<BR>   invoke inet_addr,addr szIpaddr             ;converts dotted ip to a in_addr<BR>    mov  ip,eax                 ;mov eax into ip<BR> invoke gethostbyaddr,addr ip,4,2             ;gets host info from address info<BR>   mov ebx,1000                   ;move hostbox id into ebx<BR>    or eax,eax                 ;see if gethost...worked<BR>     jz Unresolvable               ;if not jump to unresolvable<BR> mov eax,[eax]                   ;mov the pointer returnt by gethost into eax<BR>   or  eax,eax                   ;check return to see if eax contains anything<BR>    jz Unresolvable                 ;if not jump to unresolveable<BR> invoke SetDlgItemText,hMain,1000,eax           ;set the info in the host box<BR>   jmp endResolve                 ;jump to the cleanup<BR><BR>Unresolvable:                     ;label<BR> invoke SetDlgItemText,hMain,ebx,addr unknown        ;set unknown text in correct textbox<BR>   jmp endResolve                  ;jump to cleanup<BR><BR>ResolveHost:                     ;label<BR> invoke SetDlgItemText,hMain,3000,addr szResolving       ;change the frame text<BR> invoke GetDlgItemText,hMain,1000,addr szHostname,sizeof szHostname ;get the text from the host textbox<BR>   or  eax,eax                   ;see if we got something<BR>    jz endResolve                ;nothing in either box so do nothing<BR> invoke lstrcmp,addr unknown,addr szHostname         ;compare it to are unknown string<BR>   or  eax,eax                   ;check for 0<BR>    jz endResolve                 ;if so jump to cleanup<BR> invoke gethostbyname,addr szHostname           ;<BR>   mov ebx,1001                  ;mov the ip text id into ebx<BR>    or eax,eax                 ;check to see if gethost...returned something<BR>     jz Unresolvable              ;if not jmp to unresolvable<BR> mov eax,[eax+12]                  ;mov through the hosnet struct<BR> mov eax,[eax]                   ;again<BR> mov eax,[eax]                   ;finally to our wanted info<BR> invoke inet_ntoa,eax                ;convert it to a dotted ip address<BR> invoke SetDlgItemText,hMain,1001,eax           ;set the text<BR>   <BR>endResolve:                     ;label<BR> invoke EnableWindow,hResolve,TRUE            ;Re-enable the Resolve button<BR> invoke SetDlgItemText,hMain,3000,addr szReady        ;change the frame text<BR> invoke ExitThread,0                 ;exit the helper thread<BR>xor eax,eax                     <BR>ret<BR><BR>ResolveIp endp<BR>end start

页: [1]
© 1999-2008 EvilOctal Security Team