Skip to content

Commit e008120

Browse files
author
HD Moore
committed
Bug fixes to the SSDP discovery module
1 parent aa8549f commit e008120

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed

modules/auxiliary/scanner/upnp/ssdp_msearch.rb

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,58 +51,77 @@ def scan_host(ip)
5151
scanner_send(@msearch_probe, ip, datastore['RPORT'])
5252
end
5353

54+
def scanner_postscan(batch)
55+
@results.each_pair do |skey,res|
56+
sinfo = res[:service]
57+
next unless sinfo
58+
59+
bits = []
60+
61+
[ :server, :location, :usn ].each do |k|
62+
bits << res[:info][k] if res[:info][k]
63+
end
64+
65+
desc = bits.join(" | ")
66+
sinfo[:info] = desc
67+
68+
print_status("#{skey} SSDP #{desc}")
69+
report_service( sinfo )
70+
71+
if res[:info][:ssdp_host]
72+
report_service(
73+
:host => res[:info][:ssdp_host],
74+
:port => res[:info][:ssdp_port],
75+
:proto => 'tcp',
76+
:name => 'upnp',
77+
:info => res[:info][:location].to_s
78+
) if datastore['REPORT_LOCATION']
79+
end
80+
end
81+
end
82+
5483
def scanner_process(data, shost, sport)
5584

5685
skey = "#{shost}:#{datastore['RPORT']}"
57-
return if @results[skey]
5886

59-
info = []
60-
if data =~ /^Server:[\s]*(.*)/
61-
info << $1.strip
87+
@results[skey] ||= {
88+
:info => { },
89+
:service => {
90+
:host => shost,
91+
:port => datastore['RPORT'],
92+
:proto => 'udp',
93+
:name => 'ssdp'
94+
}
95+
}
96+
97+
if data =~ /^Server:[\s]*(.*)/i
98+
@results[skey][:info][:server] = $1.strip
6299
end
63100

64101
ssdp_host = nil
65102
ssdp_port = 80
66103
location_string = ''
67-
if data =~ /^Location:[\s]*(.*)/
104+
if data =~ /^Location:[\s]*(.*)/i
68105
location_string = $1
69-
info << location_string.to_s.strip
106+
@results[skey][:info][:location] = $1.strip
70107
if location_string[/(https?):\x2f\x2f([^\x5c\x2f]+)/]
71108
ssdp_host,ssdp_port = $2.split(":") if $2.respond_to?(:split)
72109
if ssdp_port.nil?
73110
ssdp_port = ($1 == "http" ? 80 : 443)
74111
end
112+
113+
if ssdp_host and ssdp_port
114+
@results[skey][:info][:ssdp_host] = ssdp_host
115+
@results[skey][:info][:ssdp_port] = ssdp_port.to_i
116+
end
117+
75118
end
76119
end
77120

78-
if data =~ /^USN:[\s]*(.*)/
79-
info << $1.strip
121+
if data =~ /^USN:[\s]*(.*)/i
122+
@results[skey][:info][:usn] = $1.strip
80123
end
81124

82-
return unless info.length > 0
83-
84-
desc = info.join(" | ")
85-
86-
@results[skey] = {
87-
:host => shost,
88-
:port => datastore['RPORT'],
89-
:proto => 'udp',
90-
:name => 'ssdp',
91-
:info => desc
92-
}
93-
94-
print_status("#{shost}:#{sport} SSDP #{desc}")
95-
report_service( @results[skey] )
96-
97-
if ssdp_host
98-
report_service(
99-
:host => ssdp_host,
100-
:port => ssdp_port,
101-
:proto => 'tcp',
102-
:name => 'upnp',
103-
:info => location_string
104-
) if datastore['REPORT_LOCATION']
105-
end
106125
end
107126

108127

0 commit comments

Comments
 (0)