A common question that comes up with post-exploitation is the need to run multiple things when a meterpreter session is initiated.
You can easily run a single command using the ‘AutoRunScript’ option. For example:
msf (psexec) > set AutoRunScript killav
However, if you need multiple things to run, there’re a couple multi-runner scripts that you should know about: multiscript, multicommand, and multi_console_command. They can take either a -c or a -rc option, which will provide the list of items to run. These scripts were provided by dark0perator.
Sidenote: If you’re using the multi* scripts, it’s better to use the -rc option. The parsing for the multi-command scripts doesn’t handle spaces well.
msf (psexec) > set AutoRunScript multi_console_command -c ‘command, command, command’ ## Don’t do this
It’s much better to use an external rc file where commands.rc is just a list of commands one-per-line like:
Then call it like:
msf (psexec) > set AutoRunScript multi_console_command -rc commands.rc
Another (non-recommended) trick is to set the InitialAutoRunScript option ie ‘set InitialAutoRunScript killav’ if you only need two scripts to run – but generally InitialAutoRunScript shouldn’t be touched except by exploits. It’s intended for exploits that know the target process is going to die, so they can migrate. (thanks to egyp7 for the info).