Class: Rex::PeScan::Analyze::Fingerprint

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/pescan/analyze.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pe) ⇒ Fingerprint

Returns a new instance of Fingerprint.



10
11
12
# File 'lib/rex/pescan/analyze.rb', line 10

def initialize(pe)
	self.pe = pe
end

Instance Attribute Details

#peObject

Returns the value of attribute pe.



8
9
10
# File 'lib/rex/pescan/analyze.rb', line 8

def pe
  @pe
end

Instance Method Details

#config(param) ⇒ Object



14
15
16
17
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
# File 'lib/rex/pescan/analyze.rb', line 14

def config(param)
	@sigs = {}

	name = nil
	regx = ''
	epon = 0
	sidx = 0

	fd = File.open(param['database'], 'rb')
	fd.each_line do |line|
		case line
		when /^\s*#/
			next
		when /\[\s*(.*)\s*\]/
			if (name)
				@sigs[ name ] = [regx, epon]
			end
			name = $1 + " [#{ sidx+=1 }]"
			epon = 0
			next
		when /signature\s*=\s*(.*)/
			pat = $1.strip
			regx = ''
			pat.split(/\s+/).each do |c|
				next if c.length != 2
				regx << (c.index('?') ? '.' : "\\x#{c}")
			end
		when /ep_only\s*=\s*(.*)/
			epon = ($1 =~ /^T/i) ? 1 : 0
		end
	end

	if (name and ! @sigs[name])
		@sigs[ name ] = [regx, epon]
	end

	fd.close
end

#scan(param) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rex/pescan/analyze.rb', line 53

def scan(param)
	config(param)

	epa = pe.hdr.opt.AddressOfEntryPoint
	buf = pe.read_rva(epa, 256)

	@sigs.each_pair do |name, data|
		begin
		if (buf.match(Regexp.new('^' + data[0], nil, 'n')))
			$stdout.puts param['file'] + ": " + name
		end
		rescue RegexpError
			$stderr.puts "Invalid signature: #{name} #{data[0]}"
		end
	end
end