CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/parser/ip360_xml.rb
Views: 11780
1
# -*- coding: binary -*-
2
require 'rexml/document'
3
4
module Rex
5
module Parser
6
7
8
class IP360XMLStreamParser
9
10
attr_accessor :on_found_host
11
12
def initialize(&block)
13
reset_state
14
on_found_host = block if block
15
end
16
17
def reset_state
18
@host = {'hname' => nil, 'hid' => nil, 'addr' => nil, 'mac' => nil, 'os' => nil,
19
'vulns' => ['vuln' => {'vulnid' => nil, 'port' => nil, 'proto' => nil} ],
20
'apps' => ['app' => {'appid' => nil, 'svcid' => nil, 'port' => nil, 'proto' => nil } ],
21
}
22
@state = :generic_state
23
end
24
25
def tag_start(name, attributes)
26
case name
27
when "host"
28
@host['hid'] = attributes['persistent_id']
29
when "ip"
30
@state = :is_ip
31
when "dnsName"
32
@state = :is_fqdn
33
when "macAddress"
34
@state = :is_mac
35
when "os"
36
@host['os'] = attributes['id']
37
when "vulnerability"
38
@x = Hash.new
39
@x['vulnid'] = attributes['id']
40
when "port"
41
@state = :is_port
42
when "protocol"
43
@state = :is_proto
44
when "application"
45
@y = Hash.new
46
@y['appid'] = attributes['application_id']
47
@y['svcid'] = attributes['svcid']
48
@y['port'] = attributes['port']
49
@y['proto'] = attributes['protocol']
50
@host['apps'].push @y
51
end
52
end
53
54
def text(str)
55
case @state
56
when :is_fqdn
57
@host['hname'] = str
58
when :is_ip
59
@host['addr'] = str
60
when :is_mac
61
@host['mac'] = str
62
when :is_port
63
@x['port'] = str
64
when :is_proto
65
@x['proto'] = str
66
end
67
end
68
69
def tag_end(name)
70
case name
71
when "host"
72
on_found_host.call(@host) if on_found_host
73
reset_state
74
when "vulnerability"
75
@host['vulns'].push @x
76
end
77
@state = :generic_state
78
end
79
80
def cdata(d)
81
#do nothing
82
end
83
84
# We don't need these methods, but they're necessary to keep REXML happy
85
#
86
def xmldecl(version, encoding, standalone) # :nodoc:
87
end
88
def comment(str) # :nodoc:
89
end
90
def instruction(name, instruction) # :nodoc:
91
end
92
def attlist # :nodoc:
93
end
94
end
95
96
end
97
end
98
99