Removed Learn Python The Hard Way (Python2)
This commit is contained in:
parent
1c9c83af91
commit
b80404e1c4
24
python/bhp/banner_grab.py
Executable file
24
python/bhp/banner_grab.py
Executable file
@ -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)
|
||||||
105
python/bhp/netcat.py
Executable file
105
python/bhp/netcat.py
Executable file
@ -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()
|
||||||
23
python/bhp/tcp_client.py
Normal file
23
python/bhp/tcp_client.py
Normal file
@ -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)
|
||||||
38
python/bhp/tcp_server.py
Normal file
38
python/bhp/tcp_server.py
Normal file
@ -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()
|
||||||
15
python/bhp/udp_client.py
Normal file
15
python/bhp/udp_client.py
Normal file
@ -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)
|
||||||
@ -1 +0,0 @@
|
|||||||
print "Hello World!"
|
|
||||||
@ -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
|
|
||||||
Loading…
x
Reference in New Issue
Block a user