/
dllmgt.asm
156 lines (118 loc) · 3.18 KB
/
dllmgt.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
.code
;align 16
; ###################################################
; trouve un offset de dll by hash,
; return 0 si pas trouvé
; In stack : Hash DLL name
; Out eax : DLL Base address
_getdll:
; mov eax,[fs:0x30] ; To BE REMOVED
; int 3
;; mov dword [PEB],eax
push ebp
mov ebp,esp
mov ebx, [fs:0x30] ; pointer sur PEB fs:0x30
mov ebx, [ebx+0x0C] ; pointeur sur PEB->Ldr
mov ebx, [ebx+0x14] ; flink premier module de la liste InMemoryOrder
mov edx, [ebx+4] ; blink... alias le point de sortie..
xor ecx,ecx
xor eax,eax
jmp .startlist
.nextmod:
cmp ebx,edx
je .tfini
.startlist:
mov esi, [ebx+0x28] ; pointeur sur la liste (unicode)
.readchar:
lodsw ; lis un Word
test al,al ; Fin de la string ?
jz .stopreadchar
cmp al,0x60 ; Si misuscule convert to Majuscule,
jbe .stoschar
sub al,0x20 ; pass en majuscule
.stoschar
xor cl,al ; Hash du pauvre, rolxor
rol ecx,HASH_SFT
jmp .readchar
.stopreadchar:
cmp ecx,[ebp+0x8] ; Parametre 1, Hash DLL Name
je .tfinifound
mov ecx,0 ; Reset the hash
mov ebx, [ebx] ; choppe le module suivant
mov esi, [ebx+0x4] ; module base address
jmp .nextmod
.tfinifound
mov eax, [ebx+0x10] ; module base address
jmp .tgohome
.tfini:
mov eax,0 ; pas trouvé l'offset return 0
.tgohome:
mov esp,ebp
pop ebp
retn 4
; ###################################################
; trouve un offset de fonction by hash
; return 0 si pas trouvé... erratum crash si pas trouvé
; In stack : Hash Fonction
; In stack : Offset DLL name
; Out eax : Fonction Base address
; trouve une fonction dans kernel32.dll
_getfunction:
push ebp
mov ebp,esp
sub eax,eax
mov eax,[ebp+0x8]
mov ebx, eax
mov edx,[eax+60] ; PE base loCATION
add eax, edx
mov edx,[eax] ; PE base dans EDX
add eax, 0x78
mov edx,[eax] ; Export Table offset
add ebx,edx ; edx = iat export table
mov [ExpTable],ebx
mov edx,[ebp+0xC]
ExpTable equ ebp-0x8
mov esi, [ExpTable]
mov esi, [esi+0x20] ;RVA
add esi, [ebp+0x8] ;VA
xor ebx,ebx
cld
myloop:
inc ebx
lodsd
add eax , [ebp+0x8] ;eax sur les string des fonctions
push esi ; save pour la prochane loop
mov esi,eax
mov edi,edx
cld
; push ecx
xor ecx,ecx
.readcharf:
lodsb ; lis un Word
test al,al ; Fin de la string ?
jz .stopreadcharf
cmp al,0x60 ; Si misuscule convert to Majuscule,
jbe .stoscharf
sub al,0x20 ; pass en majuscule
.stoscharf
xor cl,al ; Hash du pauvre, rolxor
rol ecx,HASH_SFT
jmp .readcharf
.stopreadcharf
pop esi
cmp ecx,[ebp+0xc] ; Hash Match ??
jne myloop
dec ebx
mov eax,[ExpTable]
mov eax,[eax+0x24] ;RVA EOT
add eax,[ebp+0x8] ;VA EOT
movzx eax , word [ebx*2+eax] ;eax offset de la fonction
mov ebx,[ExpTable]
mov ebx,[ebx+0x1C] ;RVA EAT
add ebx,[ebp+0x8] ;VA EAT
mov ebx,[eax*4+ebx]
add ebx,[ebp+0x8]
mov eax,ebx
mov esp,ebp
pop ebp
retn 8