Skip to content

Commit 1f35c0f

Browse files
committed
Merge rapid7#3713, @hmoore-r7's SIP cleanup of my SIP cleanup
2 parents 8d26b66 + 316a952 commit 1f35c0f

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

lib/msf/core/exploit/sip.rb

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,58 @@ def report_response(response, rhost, proto, desired_headers = %w(User-Agent Serv
1616
return false
1717
end
1818

19-
# We know it is SIP, so report
20-
report_service(
21-
host: rhost,
22-
port: rport,
23-
proto: proto.downcase,
24-
name: 'sip'
25-
)
26-
27-
# Do header extraction as necessary
19+
# Extracted headers, stored as a hash where the key is the header name
20+
# and the value is a list of all values seen for the header, covering the
21+
# case where the same header value is seen multiple times
2822
extracted_headers = {}
2923
unless desired_headers.nil? || desired_headers.empty?
3024
desired_headers.each do |desired_header|
3125
next unless (found_header = options_response.header(desired_header))
3226
extracted_headers[desired_header] ||= []
33-
extracted_headers[desired_header] |= found_header
27+
extracted_headers[desired_header] |= found_header
3428
end
29+
end
3530

36-
# report on any extracted headers
37-
extracted_headers.each do |k, v|
38-
report_note(
39-
host: rhost,
40-
port: rport,
41-
proto: proto.downcase,
42-
type: "sip_header.#{k.gsub(/-/, '_').downcase}",
43-
data: v.join(',')
44-
)
45-
end
31+
# Create a SIP OPTIONS fingerprint hash
32+
fprint = {
33+
'code' => options_response.code,
34+
'message' => options_response.message
35+
}
36+
37+
# compact the header values, append the header information to the
38+
# fingerprint hash
39+
extracted_headers.each_pair do |k,v|
40+
value = v.join(',')
41+
extracted_headers[k] = value
42+
fprint['header_' + k.gsub('-', '_').downcase] = value
43+
end
44+
45+
# Create a summary of the response
46+
status = options_response.status_line.dup
47+
unless extracted_headers.keys.empty?
48+
status << ": #{extracted_headers}"
4649
end
4750

48-
status = "#{endpoint} #{options_response.status_line}"
49-
status += ": #{extracted_headers}" unless extracted_headers.empty?
50-
print_status(status)
51+
# Report the service with the status information
52+
report_service(
53+
host: rhost,
54+
port: rport,
55+
proto: proto.downcase,
56+
name: 'sip',
57+
info: status
58+
)
59+
60+
# Report the fingerprint information
61+
report_note(
62+
host: rhost,
63+
port: rport,
64+
proto: proto.downcase,
65+
type: "sip.options.fingerprint",
66+
data: fprint
67+
)
68+
69+
# Display the actual result to the user
70+
print_status(endpoint + " " + status)
5171
true
5272
end
5373

0 commit comments

Comments
 (0)