Last active
May 23, 2017 21:59
-
-
Save WolfangAukang/e3d4df89c0b5bea41cd48d0f36309100 to your computer and use it in GitHub Desktop.
Black Hat Python book Netcat with Argparse
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
from argparse import ArgumentParser | |
import sys | |
import socket | |
import getopt | |
import threading | |
import subprocess | |
upload = False | |
def generate_argument_parser(): | |
parser = ArgumentParser(description='BHP Net Tool') | |
parser.add_argument('-t', help='target to listen', type=str, required=True,dest="target") | |
parser.add_argument('-p', help='port to listen', type=int, required=True,dest="port") | |
parser.add_argument('-l', '--listen', nargs='?', help='listen to [host]:[port] for incoming connections',default=False,const=True) | |
parser.add_argument('-e', '--execute', metavar='file_to_run', type=str, help='execute the given file upon receiving a connection', default="") | |
parser.add_argument('-c', '--command', nargs='?', help='initialize a command shell',default=False,const=True) | |
parser.add_argument('-u', '--upload', metavar="destination", type=str, help='listen op [host]:[port] for incoming connections',default="") | |
return parser | |
def get_arguments(): | |
parser = generate_argument_parser() | |
args = parser.parse_args() | |
return args | |
if __name__=="__main__": | |
args = get_arguments() | |
print(args) | |
if not args.listen and len(args.target) and args.port > 0: | |
buffer = sys.stdin.read() | |
print("client_sender(buffer)") | |
if args.listen: | |
print("server_loop()") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment