读书笔记 ~ Python黑帽子 黑客与渗透测试编程之道

时间:2022-07-08 18:11:51

Python黑帽子  黑客与渗透测试编程之道   <<< 持续更新中>>>

第一章: 设置python 环境

1、python软件包管理工具安装

root@starnight:~# apt-get install python-setuptools python-pip

root@starnight:~# 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黑帽子  黑客与渗透测试编程之道