6
6
require 'msf/core'
7
7
8
8
class Metasploit3 < Msf ::Auxiliary
9
-
10
9
include Msf ::Auxiliary ::Report
11
10
include Msf ::Auxiliary ::UDPScanner
12
11
13
12
def initialize
14
13
super (
14
+ # TODO: fill in all of this
15
15
'Name' => 'UDP Scanner Example' ,
16
16
'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.
18
21
) ,
19
22
'Author' => 'Joe Contributor <joe_contributor[at]example.com>' ,
20
23
'References' =>
@@ -38,53 +41,77 @@ def initialize
38
41
] , self . class )
39
42
end
40
43
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.
42
62
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
47
64
end
48
65
49
66
# 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
51
75
@results [ src_host ] ||= [ ]
52
- @results [ src_host ] << data . inspect
53
- end
54
76
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
60
83
end
61
84
62
85
# 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 |
65
88
peer = "#{ host } :#{ rport } "
66
89
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
70
94
report_service (
71
95
host : host ,
72
- proto :'udp' ,
96
+ proto : 'udp' ,
73
97
port : rport ,
74
- name : 'example'
98
+ name : 'example' ,
99
+ # show at most 4 relevant responses
100
+ info : relevant_responses [ 0 , 4 ] . join ( ',' )
75
101
)
76
102
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!" )
79
107
report_vuln (
80
108
host : host ,
81
109
port : rport ,
82
110
proto : 'udp' ,
83
111
name : 'something!' ,
112
+ info : "Got #{ relevant_responses . size } response(s)" ,
84
113
refs : references
85
114
)
86
- else
87
- vprint_status ( "#{ peer } - Not vulnerable to something" )
88
115
end
89
116
end
90
117
end
0 commit comments