Skip to content

Commit b99e71d

Browse files
committed
Example UDPScanner style cleanup, move most to UDPScanner
1 parent c921611 commit b99e71d

File tree

1 file changed

+53
-26
lines changed

1 file changed

+53
-26
lines changed

modules/auxiliary/scanner/udp_scanner_template.rb

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
require 'msf/core'
77

88
class Metasploit3 < Msf::Auxiliary
9-
109
include Msf::Auxiliary::Report
1110
include Msf::Auxiliary::UDPScanner
1211

1312
def initialize
1413
super(
14+
# TODO: fill in all of this
1515
'Name' => 'UDP Scanner Example',
1616
'Description' => %q(
17-
This module does stuff
17+
This module is an example of how to send probes to UDP services
18+
en-masse, analyze any responses, and then report on any discovered
19+
hosts, services, vulnerabilities or otherwise noteworthy things.
20+
Simply address any of the TODOs.
1821
),
1922
'Author' => 'Joe Contributor <joe_contributor[at]example.com>',
2023
'References' =>
@@ -38,53 +41,77 @@ def initialize
3841
], self.class)
3942
end
4043

41-
# Called for each IP in the batch
44+
def setup
45+
super
46+
# TODO: do any sort of preliminary sanity checking, like perhaps validating some options
47+
# in the datastore, etc.
48+
49+
# TODO: build the appropriate probe here
50+
@probe = 'abracadabra!'
51+
end
52+
53+
# TODO: this is called before the scan block for each batch of hosts. Do any
54+
# per-batch setup here, otherwise remove it.
55+
def scanner_prescan(batch)
56+
super
57+
end
58+
59+
# TODO: this is called for each IP in the batch. This will send all of the
60+
# necessary probes. If something different must be done for each IP, do it
61+
# here, otherwise remove it.
4262
def scan_host(ip)
43-
if datastore['SPECIAL']
44-
@probe = "Please and thank you, #{ip}!"
45-
end
46-
scanner_send(@probe, ip, datastore['RPORT'])
63+
super
4764
end
4865

4966
# Called for each response packet
50-
def scanner_process(data, src_host, src_port)
67+
def scanner_process(response, src_host, _src_port)
68+
# TODO: inspect each response, perhaps confirming that it is a valid
69+
# response for the service/protocol in question and/or analyzing it more
70+
# closely. In this case, we simply check to see that it is of reasonable
71+
# size and storing a result for this host iff so. Note that src_port may
72+
# not actually be the same as the original RPORT for some services if they
73+
# respond back from different ports
74+
return unless response.size >= 42
5175
@results[src_host] ||= []
52-
@results[src_host] << data.inspect
53-
end
5476

55-
# Called before the scan block
56-
def scanner_prescan(batch)
57-
vprint_status("Sending probes to #{batch[0]}->#{batch[-1]} (#{batch.length} hosts)")
58-
@results = {}
59-
@probe = "abracadabra!"
77+
# TODO: store something about this response, perhaps the response itself,
78+
# some metadata obtained by analyzing it, the proof that it is vulnerable
79+
# to something, etc. In this example, we simply look for any response
80+
# with a sequence of 5 useful ASCII characters and, iff found, we store
81+
# that sequence
82+
/(?<relevant>[\x20-\x7E]{5})/ =~ response && @results[src_host] << relevant
6083
end
6184

6285
# Called after the scan block
63-
def scanner_postscan(batch)
64-
@results.each_pair do |host, responses|
86+
def scanner_postscan(_batch)
87+
@results.each_pair do |host, relevant_responses|
6588
peer = "#{host}:#{rport}"
6689

67-
# consider confirming that any of the responses are actually
68-
# valid responses for this service before reporing it or
69-
# examining the responses for signs of a vulnerability
90+
# report on the host
91+
report_host(host: host)
92+
93+
# report on the service, since it responded
7094
report_service(
7195
host: host,
72-
proto:'udp',
96+
proto: 'udp',
7397
port: rport,
74-
name: 'example'
98+
name: 'example',
99+
# show at most 4 relevant responses
100+
info: relevant_responses[0, 4].join(',')
75101
)
76102

77-
if responses.any? { |response| response =~ /[a-z0-9]{5}/i }
78-
print_good("#{peer} - Vulnerable to something!")
103+
if relevant_responses.empty?
104+
vprint_status("#{peer} Not vulnerable to something")
105+
else
106+
print_good("#{peer} Vulnerable to something!")
79107
report_vuln(
80108
host: host,
81109
port: rport,
82110
proto: 'udp',
83111
name: 'something!',
112+
info: "Got #{relevant_responses.size} response(s)",
84113
refs: references
85114
)
86-
else
87-
vprint_status("#{peer} - Not vulnerable to something")
88115
end
89116
end
90117
end

0 commit comments

Comments
 (0)