This series of tutorials is aimed to share the notes taken while I was learning python for cybersecurity with the books - Black Hat Python.
這系列教學文章為學習筆記+延伸資源,旨在分享學習書籍 Black Hat Python時所思所學,也希望能幫助想了解Python和資安的大大們入門。
This tutorail has also been written in English in Medium.
Let's get started! 開始吧!
def server_loop(local_host, local_port, remote_host, remote_port, receive_first):
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
server.bind((local_host, local_port))
except Exception as e:
print("[!!] Failed to listen on %s:%d" % (local_host, local_port))
print("[!!] Check for other listening sockets or correct permissions.")
print(e)
sys.exit(0)
print("[*] Listening on %s:%d" % (local_host, local_port))
server.listen(5)
while True:
client_socket, addr = server.accept()
print("> Received incoming connection from %s:%d" % (addr[0], addr[1]))
proxy_thread = threading.Thread(
target=proxy_handler,
args=(client_socket, remote_host,
remote_port, receive_first))
proxy_thread.start()
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
建立一個socket
server.bind((local_host, local_port))
The socket binds to the local host and listens.
socket綁定在當地host並聆聽。
while True:
client_socket, addr = server.accept()
print("> Received incoming connection from %s:%d" % (addr[0], addr[1]))
proxy_thread = threading.Thread(
target=proxy_handler,
args=(client_socket, remote_host,
remote_port, receive_first))
proxy_thread.start()
In the main loop, when a fresh connection request comes in, we hand it off to the proxy_handler in a raw thread, which does all the sending and receiving of juicy bits to either side of the data stream.
Reference參考資料
推薦影片
絕讚! Youtube 教學影片 | Elevate Cyber
原始碼
Github - Python For Cybersecurity | Monles