In order to have listeners always ready on the C&C and have access easily through SSH we will use Tmux.
Tmux is a powerful alternative to the Screen command, included in multiple Linux distributions like Kali.
Requirements:
– Detachable from the console.
– Always up.
– Logging all the connection.
Create a script called tmux_listener.sh
1 2 |
name="windows" tmux new-session -d -s $name 'msfconsole -r rcscripts/'$name'.rc' 2>&1 | if grep -q duplicate; then echo "Duplicated session bro: "$name; else echo "Created and loggin: "$name; tmux pipe-pane -o -t $name "cat > /root/logs/"$name"_`date +%F_%T`.log";fi |
As you can see here we create a new detached session, then we check if there is another active session, if there is no we create another loggin file.
Finally execute this script to add the script to the Cron job scheduler
1 |
(crontab -l ; echo \"*/2 * * * * /root/whse/tmux_listener.sh\") | sort | uniq | crontab |
If for any reason it dies, the Cron job will trigger another one automatically and another logging file.
Just with we don’t need to worry about it, as it will always be a listener active.
Listing all the Tmux sessions:
1 |
tmux ls |
Attaching to a session (“windows” is how we named the session before):
1 |
tmux attach -t windows |
Detach from the session:
1 |
Control + B + D |