@@ -51,58 +51,77 @@ def scan_host(ip)
51
51
scanner_send ( @msearch_probe , ip , datastore [ 'RPORT' ] )
52
52
end
53
53
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
+
54
83
def scanner_process ( data , shost , sport )
55
84
56
85
skey = "#{ shost } :#{ datastore [ 'RPORT' ] } "
57
- return if @results [ skey ]
58
86
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
62
99
end
63
100
64
101
ssdp_host = nil
65
102
ssdp_port = 80
66
103
location_string = ''
67
- if data =~ /^Location:[\s ]*(.*)/
104
+ if data =~ /^Location:[\s ]*(.*)/i
68
105
location_string = $1
69
- info << location_string . to_s . strip
106
+ @results [ skey ] [ : info] [ :location ] = $1 . strip
70
107
if location_string [ /(https?):\x2f \x2f ([^\x5c \x2f ]+)/ ]
71
108
ssdp_host , ssdp_port = $2. split ( ":" ) if $2. respond_to? ( :split )
72
109
if ssdp_port . nil?
73
110
ssdp_port = ( $1 == "http" ? 80 : 443 )
74
111
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
+
75
118
end
76
119
end
77
120
78
- if data =~ /^USN:[\s ]*(.*)/
79
- info << $1. strip
121
+ if data =~ /^USN:[\s ]*(.*)/i
122
+ @results [ skey ] [ : info] [ :usn ] = $1. strip
80
123
end
81
124
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
106
125
end
107
126
108
127
0 commit comments