[asm] modul base

05/28/2012 16:58 Tyrar#1
ich versuche grade, an die base adresse einer dll zur kommen!
ich kann allerdings kein GetModuleHandle verwenden, da das ganze mit meinem crypter zu tun hat. strings sind auch schlecht möglich zu verwenden.

ich bräuchte etwas in die richtung, wie es auch mit der process base geht:
Code:
mov eax, fs:[0x30]
mov eax, [eax+8] ; process base
so könnte ich dann zur runtime die ganzen adressen berechnen, relocations kann ich leider auch nicht verwenden, da die auch (möglichst) entfernt werden sollen

jemand ne idee wie ich das anstellen kann?

oder gibt es eine möglichkeit an das eip register zu kommen?
damit könnte ich immerhin auch was anfangen!

edit:
mir kam grad nach dem absenden des posts ne passende idee:
Code:
GetEIP:
pop eax
jmp eax
Code:
call GetEIP
05/28/2012 17:30 Ende!#2
Code:
; ------------------------------------------------------------------------------
; Name: sc_FindGPA
; Return:	eax = Address of GetProcAddress
;		edx = Module handle of Kernel32.dll
; ------------------------------------------------------------------------------
sc_FindGPA Macro
	Local _no_match
	Local _walk_export_list
	Local _leave_loop
		
		push			ebp
		mov			ebp, esp					; Create stack frame
		sub			esp, 20
		
		push			ecx
		push			ebx
		push			edi
		push			esi
		
		sc_FindKernel32		edx
		
		mov			eax, [edx+3Ch] 		; PE Header
		add			eax, edx		; Add VMA
		mov			esi, [eax+78h] 		; Export table ptr
		add			esi, edx		; Add VMA
		add			esi, 18h		; Number of names
		
		lodsd
		mov			[ebp-4], eax
		
		lodsd
		add			eax, edx
		mov			[ebp-8], eax
		
		lodsd
		add			eax, edx
		mov			[ebp-12], eax
		
		lodsd
		add			eax, edx
		mov			[ebp-16], eax
				
		mov			ecx, [ebp-4]
		xor			ebx, ebx

	; Search export list for GetProcAddress
	_walk_export_list:
		lea			eax, [ebx*4]
		add			eax, [ebp-12]
		mov			eax, [eax]
		add			eax, edx
		
		mov			edi, [eax]
		cmp			edi, 'PteG'
		jne short		_no_match
		mov			edi, [eax+4]
		cmp			edi, 'Acor'
		jne short		_no_match
		
		jmp short		_leave_loop
	_no_match:
		
		inc			ebx
		loop 			_walk_export_list
		
	_leave_loop:
	
		; Ordinal is in ebx nao
		
		lea			eax, [ebx*2]
		add			eax, [ebp-16]
		lea			eax, [eax]
		
		; Get function address using ordinal as index
		xor 			ebx, ebx
		mov 			bx, word ptr[eax]
		shl			ebx, 2  			; * 4
		add			ebx, [ebp-8]
		mov			eax, [ebx]
		add			eax, edx
		
		pop			esi
		pop			edi
		pop			ebx
		pop			ecx
		
		leave
		
EndM
Code:
; ------------------------------------------------------------------------------
; Name: sc_FindKernel32
; Parameters: reg = register to store ptr to Kernel32.dll
; ------------------------------------------------------------------------------
sc_FindKernel32 Macro reg:REQ
	Local _next_module

		push	esi
		push	edi

		mov	esi, fs:[30h]
		mov	esi, [esi+0Ch]
		mov	esi, [esi+1Ch]
		
	_next_module:
		mov	reg, [esi+08h]
		mov	edi, [esi+20h]
		mov	esi, [esi]
		cmp	byte ptr[edi+12*2], 0
		jne	_next_module
		
		pop	edi
		pop	esi
EndM
Copy pasta aus einem alten Projekt von mir, welches exzessiven Gebrauch von Shellcode machte. Um das Ganze zu verstehen, solltest du mit dem MASM Syntax vertraut sein.

Edit:
Quote:
oder gibt es eine möglichkeit an das eip register zu kommen?
damit könnte ich immerhin auch was anfangen!
Um auch diese Frage zu beantworten:
Code:
GetEIP proc
    pop eax
    push eax
    ret
GetEIP endp
So mach ich's immer, deine Variante ist aber selbstredend auch möglich.