diff --git a/python/bhp/banner_grab.py b/python/bhp/banner_grab.py new file mode 100755 index 0000000..5cebe6c --- /dev/null +++ b/python/bhp/banner_grab.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 +import socket + +targetHost = "127.0.0.1" +targetPort = 22 +print(targetHost) + +#create a socket object +client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +#connect the client +client.connect((targetHost, targetPort)) + +#send some data +message = "GET / HTTP/1.1\r\nHost: google.com\r\n\r\n" +#we have to encode our string using UTF-8 +#client.send(message.encode("utf-8")) + + +#receive some data +response = client.recv(4096) #This is the amount of bytes you want to read!! + +#print the response +print(response) \ No newline at end of file diff --git a/python/bhp/netcat.py b/python/bhp/netcat.py new file mode 100755 index 0000000..49dda52 --- /dev/null +++ b/python/bhp/netcat.py @@ -0,0 +1,105 @@ +#!/usr/bin/python3 +import sys +import socket +import getopt +import threading +import subprocess + +#define global variables +listen = False +command = False +upload = False +execute = "" +target = "" +uploadDestination = "" +port = 0 + +def usage(): + print ("BlackHat Python Net Tool") + print("Usage: netcat.py -t target_host -p port") + print("-l --listen\t - Listen on [host]:[port] for incoming connections") + print("-e --execute=file_to_run\t - Execute the given file open receiving connection") + print("-c --command\t - initialize a command shell") + print("-u --upload=destination\t - Upon receiving a connection, upload file to [destination]") + print("\n\nExamples:") + print(""" + netcat.py -t 192.168.1.100 -p 5555 -l -c + netcat.py -t 192.168.1.100 -p 5555 -l -u=c:\\target.exe + netcat.py -t 192.168.1.100 -p 5555 -l -e=\"cat /etc/passwd\" + Echo 'ABCDEFGHI' | ./netcat.py -t 192.168.1.100 -p 5555 + """) + sys.exit(0) + +def clientSender(buffer): + client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + try: + client.connect((target,port)) + + if len(buffer): + client.send(buffer) + while True: + recvLen = 1 + response = "" + + while recvLen: + data = client.recv(4096) + recvLen = len(data) + response += data + + if recvLen < 4096: + break + print(response) + + buffer = rawInput("") + buffer += "\n" + + client.send(buffer) + except: + print("[*] Exception!! Exiting.") + client.close() + +def main(): + global listen + global port + global execute + global command + global uploadDestination + global target + + if not len(sys.argv[1:]): + usage() + + #read command line arguments + try: + opts, args = getopt.getopt(sys.argv[1:],"hle:t:cu:",["help", "listen", "execute", "target", "port", "command", "upload"]) + except getopt.GetoptError as err: + print(err) + usage() + + for o,a in opts: + if o in ("-h","--help"): + usage() + elif o in ("-l","--listen"): + listen = True + elif o in ("-e","--execute"): + execute = True + elif o in ("-c","--command"): + command = True + elif o in ("-u","--upload"): + uploadDestination = a + elif o in ("-t","--target"): + target = a + elif o in ("-p","--port"): + port = (int)a + else: + assert False,"Unhandled Option" + if not listen and len(target) and port > 0: + + buffer = sys.stdin.read() + clientSener(buffer) + + if listen: + serverLoop() + +main() \ No newline at end of file diff --git a/python/bhp/tcp_client.py b/python/bhp/tcp_client.py new file mode 100644 index 0000000..025ebf0 --- /dev/null +++ b/python/bhp/tcp_client.py @@ -0,0 +1,23 @@ +import socket + +targetHost = "127.0.0.1" +targetPort = 80 +print(targetHost) + +#create a socket object +client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +#connect the client +client.connect((targetHost, targetPort)) + +#send some data +message = "GET / HTTP/1.1\r\nHost: google.com\r\n\r\n" +#we have to encode our string using UTF-8 +#client.send(message.encode("utf-8")) + + +#receive some data +response = client.recv(4096) #This is the amount of bytes you want to read!! + +#print the response +print(response) \ No newline at end of file diff --git a/python/bhp/tcp_server.py b/python/bhp/tcp_server.py new file mode 100644 index 0000000..b406bfe --- /dev/null +++ b/python/bhp/tcp_server.py @@ -0,0 +1,38 @@ +import socket +import threading + +bindIP = "0.0.0.0" +bindPort = 9999 + +#create the socket +server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +#Open the sever +server.bind((bindIP, bindPort)) + +#Listen for connections +server.listen(5) +print("Listening on %s:%d" %(bindIP,bindPort)) + +#This is the client handling thread +def handleClient(clientSocket): + #print out what the client saends + request = clientSocket.recv(1024) + + print(f"[*] Received: ${request}") + + #send back data + quitMSG = "ACK!" + clientSocket.send(quitMSG.encode("utf-8")) + + #Close the connection + clientSocket.close() + +while True: + + clientAddr = server.accept() + + print (f"[*] Accepted connecction from {clientAddr}") + + clientHandler = threading.Thread(target=handleClient,args=(clientAddr,)) + clientHandler.start() \ No newline at end of file diff --git a/python/bhp/udp_client.py b/python/bhp/udp_client.py new file mode 100644 index 0000000..5dd8e9e --- /dev/null +++ b/python/bhp/udp_client.py @@ -0,0 +1,15 @@ +import socket +targetHost = "127.0.0.1" +targetPort = 80 + +#create a UDP socket +client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + +#send some data +message = "AAAABBBBCCCCDDDD" +client.sendto(message.encode("utf-8"), (targetHost, targetPort)) + +#receive data +data, addr = client.recvfrom(4096) + +ptint(data) \ No newline at end of file diff --git a/python/lpthw/Exercise-1/helloworld.py b/python/lpthw/Exercise-1/helloworld.py deleted file mode 100644 index f4da9af..0000000 --- a/python/lpthw/Exercise-1/helloworld.py +++ /dev/null @@ -1 +0,0 @@ -print "Hello World!" diff --git a/python/lpthw/README.md b/python/lpthw/README.md deleted file mode 100644 index 787a4b2..0000000 --- a/python/lpthw/README.md +++ /dev/null @@ -1,7 +0,0 @@ -Learn Python the Hard Way - -https://itbook.store/books/9780134123486 - -This is not any kind of official advertisement or endorsement. This is merely the link provided from within the book itself. - -I just realized this is a python 2 tutorial, I may come back to this =(. Moving onto Python3