Class: Rex::ElfScan::Scanner::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/elfscan/scanner.rb

Direct Known Subclasses

JmpRegScanner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elf) ⇒ Generic

Returns a new instance of Generic


11
12
13
# File 'lib/rex/elfscan/scanner.rb', line 11

def initialize(elf)
  self.elf = elf
end

Instance Attribute Details

#elfObject

Returns the value of attribute elf


9
10
11
# File 'lib/rex/elfscan/scanner.rb', line 9

def elf
  @elf
end

#regexObject

Returns the value of attribute regex


9
10
11
# File 'lib/rex/elfscan/scanner.rb', line 9

def regex
  @regex
end

Instance Method Details

#config(param) ⇒ Object


15
16
# File 'lib/rex/elfscan/scanner.rb', line 15

def config(param)
end

#scan(param) ⇒ Object


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
# File 'lib/rex/elfscan/scanner.rb', line 18

def scan(param)
  config(param)

  $stdout.puts "[#{param['file']}]"
  elf.program_header.each do |program_header|

    # Scan only loadable segment entries in the program header table
    if program_header.p_type == Rex::ElfParsey::ElfBase::PT_LOAD
      hits = scan_segment(program_header, param)
      hits.each do |hit|
        rva  = hit[0]
        message  = hit[1].is_a?(Array) ? hit[1].join(" ") : hit[1]
        $stdout.puts elf.ptr_s(rva) + " " + message
        if(param['disasm'])
          message.gsub!("; ", "\n")
          if message.include?("retn")
            message.gsub!("retn", "ret")
          end

          begin
            d2 = Metasm::Shellcode.assemble(Metasm::Ia32.new, message).disassemble
          rescue Metasm::ParseError
            d2 = Metasm::Shellcode.disassemble(Metasm::Ia32.new, [message].pack('H*'))
          end

          addr = 0
          while ((di = d2.disassemble_instruction(addr)))
            disasm = "0x%08x\t" % (rva + addr)
            disasm << di.instruction.to_s
            $stdout.puts disasm
            addr = di.next_addr
          end
        end
      end
    end

  end
end

#scan_segment(program_header, param = {}) ⇒ Object


57
58
59
# File 'lib/rex/elfscan/scanner.rb', line 57

def scan_segment(program_header, param={})
  []
end