diff --git a/lib/rex/exploitation/omelet.rb b/lib/rex/exploitation/omelet.rb index 9dc3565d5f..2044ffe263 100644 --- a/lib/rex/exploitation/omelet.rb +++ b/lib/rex/exploitation/omelet.rb @@ -84,8 +84,9 @@ class Omelet eggsize = opts[:eggsize] || 123 eggtag = opts[:eggtag] || "00w" searchforward = opts[:searchforward] || true - reset = opts[:reset] || false + reset = opts[:reset] startreg = opts[:startreg] + usechecksum = opts[:checksum] return nil if ((opts = hunter_stub) == nil) @@ -114,36 +115,39 @@ class Omelet searchstub2 = nil flipflagpre = '' flipflagpost = '' + checksum = '' if searchforward # clear direction flag - setflag = "cld\n" - searchstub1 = "dec edx\n" * 4 - searchstub2 = "inc edx\n" + setflag = "cld" + searchstub1 = "dec edx; dec edx; dec edx; dec edx" + searchstub2 = "inc edx" else # set the direction flag setflag = "std" - searchstub1 = "inc edx\n" * 4 - searchstub2 = "dec edx\n" - flipflagpre = "cld\nsub esi,-8\n" - flipflagpost = "std\n" + searchstub1 = "inc edx; inc edx; inc edx; inc edx" + searchstub2 = "dec edx" + flipflagpre = "cld; sub esi,-8" + flipflagpost = "std" end # prepare the stub that starts the search startstub = '' if startreg if startreg.downcase != 'ebp' - startstub << "mov ebp,#{startreg}\n" + startstub << "mov ebp,#{startreg}" end - startstub << "mov edx,ebp\n" + startstub << "; " if startstub.length > 0 + startstub << "mov edx,ebp" end # a register will be used as start location for the search - startstub << "push esp\n" + "pop edi\n" + "or di,0xffff\n" + startstub << "; " if startstub.length > 0 + startstub << "push esp; pop edi; or di,0xffff" # edx will be used, start at end of stack frame if not startreg - startstub << "mov edx,edi\n" + startstub << "; mov edx,edi" if reset - startstub << "push edx\n" + "pop ebp\n" + startstub << "; push edx; pop ebp" end end @@ -151,8 +155,24 @@ class Omelet # will allow to find eggs when they are out of order/sequence resetstart = '' if reset - resetstart = "push ebp\n" + "pop edx\n" - end + resetstart = "push ebp; pop edx" + end + + #checksum code by dijital1 & corelanc0d3r + if usechecksum + checksum = < 2 do egg_prep = eggcnt.chr + eggtag this_egg = fullcode[startcode, eggsize] - startcode = startcode + eggsize + if usechecksum + cksum = 0 + this_egg.each_byte { |b| + cksum += b + } + this_egg << [cksum & 0xff].pack('C') + end + this_egg = egg_prep + this_egg - eggcnt = eggcnt - 1 - eggs[arraycnt] = this_egg - arraycnt = arraycnt + 1 + eggs << this_egg + + eggcnt -= 1 + startcode += eggsize end return [ the_omelet, eggs ] diff --git a/lib/rex/exploitation/omelet.rb.ut.rb b/lib/rex/exploitation/omelet.rb.ut.rb new file mode 100644 index 0000000000..18ba2a2949 --- /dev/null +++ b/lib/rex/exploitation/omelet.rb.ut.rb @@ -0,0 +1,13 @@ +# $Id$ + +require 'omelet.rb' + +x = Rex::Exploitation::Omelet.new('win', ARCH_X86) +x.generate("\xcc" * 1024, '', { + #:eggsize => 31336, # default: 123 + #:eggtag => "b00", # default: 00w + #:searchforward => false, # default: true + #:reset => true, # default: false + #:startreg => "EBP", # default: none + :checksum => true # default: false +})