Skip to content

Commit e55032a

Browse files
authored
Land #20238, resolves RuboCop violations in auxiliary/scanner/db2
modules/auxiliary/scanner/db2: Resolve RuboCop violations
2 parents 94b5ba5 + feebf2b commit e55032a

File tree

3 files changed

+113
-90
lines changed

3 files changed

+113
-90
lines changed

modules/auxiliary/scanner/db2/db2_auth.rb

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,48 @@ class MetasploitModule < Msf::Auxiliary
1414

1515
def initialize
1616
super(
17-
'Name' => 'DB2 Authentication Brute Force Utility',
18-
'Description' => %q{This module attempts to authenticate against a DB2
19-
instance using username and password combinations indicated by the
20-
USER_FILE, PASS_FILE, and USERPASS_FILE options.},
21-
'Author' => ['todb'],
22-
'References' =>
23-
[
24-
[ 'CVE', '1999-0502'] # Weak password
25-
],
26-
'License' => MSF_LICENSE
17+
'Name' => 'DB2 Authentication Brute Force Utility',
18+
'Description' => %q{
19+
This module attempts to authenticate against a DB2 instance
20+
using username and password combinations indicated by the
21+
USER_FILE, PASS_FILE, and USERPASS_FILE options.
22+
},
23+
'Author' => ['todb'],
24+
'References' => [
25+
[ 'CVE', '1999-0502'] # Weak password
26+
],
27+
'License' => MSF_LICENSE,
28+
'Notes' => {
29+
'Stability' => [CRASH_SAFE],
30+
'SideEffects' => [IOC_IN_LOGS, ACCOUNT_LOCKOUTS],
31+
'Reliability' => []
32+
}
2733
)
2834

2935
register_options(
3036
[
3137
Opt::Proxies,
32-
OptPath.new('USERPASS_FILE', [ false, "File containing (space-separated) users and passwords, one pair per line",
33-
File.join(Msf::Config.data_directory, "wordlists", "db2_default_userpass.txt") ]),
34-
OptPath.new('USER_FILE', [ false, "File containing users, one per line",
35-
File.join(Msf::Config.data_directory, "wordlists", "db2_default_user.txt") ]),
36-
OptPath.new('PASS_FILE', [ false, "File containing passwords, one per line",
37-
File.join(Msf::Config.data_directory, "wordlists", "db2_default_pass.txt") ]),
38-
])
38+
OptPath.new('USERPASS_FILE', [
39+
false, 'File containing (space-separated) users and passwords, one pair per line',
40+
File.join(Msf::Config.data_directory, 'wordlists', 'db2_default_userpass.txt')
41+
]),
42+
OptPath.new('USER_FILE', [
43+
false, 'File containing users, one per line',
44+
File.join(Msf::Config.data_directory, 'wordlists', 'db2_default_user.txt')
45+
]),
46+
OptPath.new('PASS_FILE', [
47+
false, 'File containing passwords, one per line',
48+
File.join(Msf::Config.data_directory, 'wordlists', 'db2_default_pass.txt')
49+
]),
50+
]
51+
)
3952
end
4053

4154
def run_host(ip)
4255
cred_collection = build_credential_collection(
43-
realm: datastore['DATABASE'],
44-
username: datastore['USERNAME'],
45-
password: datastore['PASSWORD']
56+
realm: datastore['DATABASE'],
57+
username: datastore['USERNAME'],
58+
password: datastore['PASSWORD']
4659
)
4760

4861
scanner = Metasploit::Framework::LoginScanner::DB2.new(
@@ -70,8 +83,8 @@ def run_host(ip)
7083
scanner.scan! do |result|
7184
credential_data = result.to_h
7285
credential_data.merge!(
73-
module_fullname: self.fullname,
74-
workspace_id: myworkspace_id
86+
module_fullname: fullname,
87+
workspace_id: myworkspace_id
7588
)
7689
if result.success?
7790
credential_core = create_credential(credential_data)

modules/auxiliary/scanner/db2/db2_version.rb

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,56 @@ class MetasploitModule < Msf::Auxiliary
1010

1111
def initialize
1212
super(
13-
'Name' => 'DB2 Probe Utility',
14-
'Description' => 'This module queries a DB2 instance information.',
15-
'Author' => ['todb'],
16-
'License' => MSF_LICENSE
13+
'Name' => 'DB2 Probe Utility',
14+
'Description' => 'This module queries a DB2 instance information.',
15+
'Author' => ['todb'],
16+
'License' => MSF_LICENSE,
17+
'Notes' => {
18+
'Stability' => [CRASH_SAFE],
19+
'SideEffects' => [],
20+
'Reliability' => []
21+
}
1722
)
1823
register_options(
1924
[
2025
OptInt.new('TIMEOUT', [true, 'Timeout for the DB2 probe', 5])
21-
])
26+
]
27+
)
2228

23-
deregister_options('USERNAME' , 'PASSWORD')
29+
deregister_options('USERNAME', 'PASSWORD')
2430
end
2531

2632
def to
2733
return 5 if datastore['TIMEOUT'].to_i.zero?
34+
2835
datastore['TIMEOUT'].to_i
2936
end
3037

3138
def run_host(ip)
32-
begin
33-
34-
info = db2_probe(to)
35-
if info[:excsatrd]
36-
inst,plat,ver,pta = info[:instance_name],info[:platform],info[:version],info[:plaintext_auth]
37-
report_info = "Platform: #{plat}, Version: #{ver}, Instance: #{inst}, Plain-Authentication: #{pta ? "OK" : "NO"}"
38-
print_good("#{ip}:#{rport} DB2 - #{report_info}")
39-
report_service(
40-
:host => rhost,
41-
:port => rport,
42-
:name => "db2",
43-
:info => report_info
44-
)
45-
end
46-
disconnect
47-
48-
rescue ::Rex::ConnectionRefused
49-
vprint_error("#{rhost}:#{rport} : Cannot connect to host")
50-
return :done
51-
rescue ::Rex::ConnectionError
52-
vprint_error("#{rhost}:#{rport} : Unable to attempt probe")
53-
return :done
54-
rescue ::Rex::Proto::DRDA::RespError => e
55-
vprint_error("#{rhost}:#{rport} : Error in connecting to DB2 instance: #{e}")
56-
return :error
39+
info = db2_probe(to)
40+
if info[:excsatrd]
41+
inst = info[:instance_name]
42+
plat = info[:platform]
43+
ver = info[:version]
44+
pta = info[:plaintext_auth]
45+
report_info = "Platform: #{plat}, Version: #{ver}, Instance: #{inst}, Plain-Authentication: #{pta ? 'OK' : 'NO'}"
46+
print_good("#{ip}:#{rport} DB2 - #{report_info}")
47+
report_service(
48+
host: rhost,
49+
port: rport,
50+
name: 'db2',
51+
info: report_info
52+
)
5753
end
54+
disconnect
55+
rescue ::Rex::ConnectionRefused
56+
vprint_error("#{rhost}:#{rport} : Cannot connect to host")
57+
return :done
58+
rescue ::Rex::ConnectionError
59+
vprint_error("#{rhost}:#{rport} : Unable to attempt probe")
60+
return :done
61+
rescue ::Rex::Proto::DRDA::RespError => e
62+
vprint_error("#{rhost}:#{rport} : Error in connecting to DB2 instance: #{e}")
63+
return :error
5864
end
5965
end

modules/auxiliary/scanner/db2/discovery.rb

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,59 @@ class MetasploitModule < Msf::Auxiliary
1010

1111
def initialize
1212
super(
13-
'Name' => 'DB2 Discovery Service Detection',
14-
'Description' => 'This module simply queries the DB2 discovery service for information.',
15-
'Author' => [ 'MC' ],
16-
'License' => MSF_LICENSE
13+
'Name' => 'DB2 Discovery Service Detection',
14+
'Description' => 'This module simply queries the DB2 discovery service for information.',
15+
'Author' => [ 'MC' ],
16+
'License' => MSF_LICENSE,
17+
'Notes' => {
18+
'Stability' => [CRASH_SAFE],
19+
'SideEffects' => [],
20+
'Reliability' => []
21+
}
1722
)
1823

1924
register_options([Opt::RPORT(523),])
2025
end
2126

2227
def run_host(ip)
28+
pkt = 'DB2GETADDR' + "\x00" + 'SQL05000' + "\x00"
2329

24-
pkt = "DB2GETADDR" + "\x00" + "SQL05000" + "\x00"
30+
connect_udp
31+
udp_sock.put(pkt)
32+
res = udp_sock.read(1024)
2533

26-
begin
27-
28-
connect_udp
29-
udp_sock.put(pkt)
30-
res = udp_sock.read(1024)
31-
32-
unless res
33-
print_error("Unable to determine version info for #{ip}")
34-
return
35-
end
36-
37-
res = res.split(/\x00/)
34+
unless res
35+
print_error("Unable to determine version info for #{ip}")
36+
return
37+
end
3838

39-
report_note(
40-
:host => ip,
41-
:proto => 'udp',
42-
:port => datastore['RPORT'],
43-
:type => 'SERVICE_INFO',
44-
:data => { :service_info => "#{res[2]}_#{res[1]}" }
45-
)
39+
res = res.split(/\x00/)
4640

47-
report_service(
48-
:host => ip,
49-
:port => datastore['RPORT'],
50-
:proto => 'udp',
51-
:name => "ibm-db2",
52-
:info => "#{res[2]}_#{res[1]}"
53-
)
41+
product_id = res[1]
42+
node_name = res[2]
5443

55-
print_good("Host #{ip} node name is " + res[2] + " with a product id of " + res[1] )
44+
report_note(
45+
host: ip,
46+
proto: 'udp',
47+
port: datastore['RPORT'],
48+
type: 'SERVICE_INFO',
49+
data: { service_info: "#{node_name}_#{product_id}" }
50+
)
5651

57-
rescue ::Rex::ConnectionError
58-
rescue ::Errno::EPIPE
59-
ensure
60-
disconnect_udp
61-
end
52+
report_service(
53+
host: ip,
54+
port: datastore['RPORT'],
55+
proto: 'udp',
56+
name: 'ibm-db2',
57+
info: "#{node_name}_#{product_id}"
58+
)
6259

60+
print_good("Host #{ip} node name is #{node_name} with a product id of #{product_id}")
61+
rescue ::Rex::ConnectionError => e
62+
vprint_error(e.message)
63+
rescue ::Errno::EPIPE => e
64+
vprint_error(e.message)
65+
ensure
66+
disconnect_udp
6367
end
6468
end

0 commit comments

Comments
 (0)