Sqlmap+本地代理池
在使用sqlmap测试时候,容易因为请求过快,次数过多的原因而被ban掉ip的情况,所以使用一下的方法可以实现自动切换ip
流程
- 爬虫程序爬取到可用ip写入.txt文档中 写入格式每一行为 192.168.10.1:9999
- 使用下面的脚本程序读取.txt文件中的ip 挂到本地服务中的 127.0.0.1:50007
- sqlmap中设置代理 --proxy=“127.0.0.1:50007” 相当于在本地中搭建了一个临时的pool
- sqlmap语句:python sqlmap.py -u “192.168.100.1/www” --proxy=“127.0.0.1:50007”
- 爬虫程序自备
# -*- coding: utf-8 -*-
# from hutaow
import sys
import socket
import logging
import threading
import random
local_ip = '127.0.0.1'
local_port = 50007
PKT_BUFF_SIZE = 2048
logger = logging.getLogger("Proxy Logging")
formatter = logging.Formatter('%(name)-12s %(asctime)s %(levelname)-8s %(lineno)-4d %(message)s', '%Y %b %d %a %H:%M:%S',)
stream_handler = logging.StreamHandler(sys.stderr)
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
logger.setLevel(logging.DEBUG)
def tcp_mapping_worker(conn_receiver, conn_sender):
while True:
try:
data = conn_receiver.recv(PKT_BUFF_SIZE)
except Exception:
logger.debug('Connection closed.')
break
if not data:
logger.info('No more data is received.')
break
try:
conn_sender.sendall(data)
except Exception:
logger.error('Failed sending data.')
break
logger.info('Mapping > %s -> %s > %d bytes.' % (conn_receiver.getpeername(), conn_sender.getpeername(), len(data)))
conn_receiver.close()
conn_sender.close()
return
def tcp_mapping_request(local_conn, remote_ip, remote_port):
while True:
remote_conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
remote_conn.settimeout(3)
remote_conn.connect((remote_ip, remote_port))
except Exception:
logger.error('Unable to connect to the remote server.')
continue
threading.Thread(target=tcp_mapping_worker, args=(local_conn, remote_conn)).start()
threading.Thread(target=tcp_mapping_worker, args=(remote_conn, local_conn)).start()
return
def Loadips():
ip_list = []
ip = ['ip','port']
with open('D:/Project/PythonProject/ip.txt') as ips:
lines = ips.readlines()
for line in lines:
ip[0],ip[1] = line.strip().split(":")
ip[1] = eval(ip[1])
nip = tuple(ip)
ip_list.append(nip)
return ip_list
if __name__ == '__main__':
a = Loadips()
print(a)
local_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
local_server.bind((local_ip, local_port))
local_server.listen(5)
logger.debug('Starting mapping service on ' + local_ip + ':' + str(local_port) + ' ...')
while True:
try:
(local_conn, local_addr) = local_server.accept()
proxyip = random.choice(a)
print("[!]Now proxy ip:"+str(proxyip))
prip = proxyip[0]
prpo= proxyip[1]
except KeyboardInterrupt as Exception:
local_server.close()
logger.debug('Stop mapping service.')
break
threading.Thread(target=tcp_mapping_request, args=(local_conn, prip, prpo)).start()
logger.debug('Receive mapping request from %s:%d.' % local_addr)
产靠地址:
o)).start()
logger.debug(‘Receive mapping request from %s:%d.’ % local_addr)
参考:
https://cloud.tencent.com/developer/article/1535219