1. 程式人生 > >讀書筆記 ~ Python黑帽子 黑客與滲透測試編程之道

讀書筆記 ~ Python黑帽子 黑客與滲透測試編程之道

alt nbsp too 管理 return cps 工具 transfer args

Python黑帽子 黑客與滲透測試編程之道 <<< 持續更新中>>>

第一章: 設置python 環境

1、python軟件包管理工具安裝

[email protected]:~# apt-get install python-setuptools python-pip

[email protected]:~# pip install github3.py

[註]如果在安裝的過程中出現:E: Sub-process /usr/bin/dpkg returned an error code (1), 請參考解決辦法

第二章:網絡基礎

1、簡單的python TCP客戶/服務器通信

服務器端:tcpserver.py

import socket
import threading

bind_ip = "127.0.0.1"                   # ip
bind_port = 9999                        # port

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
server.bind((bind_ip, bind_port))
server.listen(5)

print [*] Listening on %s:%d % (bind_ip, bind_port) # handle client/server data transfer def handle_client(client_socket): # recv data request = client_socket.recv(1024) print [*] Received:%s % request # send data client_socket.send("ACK!") client_socket.close()
# multithreading... while True: client, addr = server.accept() # accept a connection from client print [*] Accept connection from:%s:%d % (addr[0], addr[1]) # create a new thread to handle client connection client_handler = threading.Thread(target=handle_client, args=(client,)) client_handler.start()

客戶端:tcpclient.py

import socket

target_host = "127.0.0.1"
target_port = 9999

# construct a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# connect server
client.connect((target_host, target_port))

# send data
client.send("ABCDEFG")

# receive data  
response = client.recv(4096)

print response

技術分享

讀書筆記 ~ Python黑帽子 黑客與滲透測試編程之道