SqlMap代理池


獲取代理池

獲取代理池使用了GIthub上的項目:https://github.com/jhao104/proxy_pool ,並利用REDIS存儲獲取到的代理地址

啟動項目

cli目錄下通過ProxyPool.py啟動

# 首先啟動調度程序
>>>python proxyPool.py schedule

# 然后啟動webApi服務
>>>python proxyPool.py webserver

Api

啟動過幾分鍾后就能看到抓取到的代理IP,可以直接到數據庫中查看,也可以通過api訪問http://127.0.0.1:5010 查看。

api method Description arg
/ GET api介紹 None
/get GET 隨機獲取一個代理 None
/get_all GET 獲取所有代理 None
/get_status GET 查看代理數量 None
/delete GET 刪除代理 proxy=host:ip

保存代理

自己編寫了個小腳本將ProxyPool.py獲取到的代理保存在ips.txt
get_proxy.py

import requests

def get_proxy():
    return requests.get("http://127.0.0.1:5010/get_all/").json()

def delete_proxy(proxy):
    requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))

res = requests.get("http://127.0.0.1:5010/get_status").json()
count = res.get("useful_proxy")
print("目前代理池中共計:%s個代理." % count)

f = open("ips.txt", "w")
for i in range(count):
    b = get_proxy()[i]["proxy"]
f.write(b + "\n")
f.close()

本地代理轉發

借用前人的成果,實現的效果是啟用本地127.0.0.1:9999服務,將ips.txt內的代理轉發給本地客戶端
ips.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket
from socket import error
import threading
import random
import time

localtime = time.asctime(time.localtime(time.time()))

class ProxyServerTest:
    def __init__(self, proxyip):
        # 本地socket服務
        self.ser = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.proxyip = proxyip

    def run(self):
        try:
            # 本地服務IP和端口
            self.ser.bind(('127.0.0.1', 9999))
            # 最大連接數
            self.ser.listen(5)
        except error as e:
            print("[-]The local service : " + str(e))
            return "[-]The local service : " + str(e)

        while True:
            try:
                # 接收客戶端數據
                client, addr = self.ser.accept()
                print('[*]accept %s connect' % (addr,))
                data = client.recv(1024)
                if not data:
                    break
                print('[*' + localtime + ']: Accept data...')
            except error as e:
                print("[-]Local receiving client : " + str(e))
                return "[-]Local receiving client : " + str(e)

            while True:
                # 目標代理服務器,將客戶端接收數據轉發給代理服務器
                mbsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                iplen = len(self.proxyip)
                proxyip = self.proxyip[random.randint(0, iplen - 1)]
                print("[!]Now proxy ip:" + str(proxyip))
                prip = proxyip[0]
                prpo = proxyip[1
                try:
                    mbsocket.settimeout(3)
                    mbsocket.connect((prip, prpo))
                except:
                    print("[-]RE_Connect...")
                    continue
                break

            #                   except :
            #                       print("[-]Connect failed,change proxy ip now...")
            #                      pass

            try:
                mbsocket.send(data)
            except error as e:
                print("[-]Sent to the proxy server : " + str(e))
                return "[-]Sent to the proxy server : " + str(e)
                               
            while True:
                try:
                    # 從代理服務器接收數據,然后轉發回客戶端
                    data_1 = mbsocket.recv(1024)
                    if not data_1:
                        break
                    print('[*' + localtime + ']: Send data...')
                    client.send(data_1)
                except socket.timeout as e:
                    print(proxyip)
                    print("[-]Back to the client : " + str(e))
                    continue

            # 關閉連接

            client.close()
            mbsocket.close()


def Loadips():
    print("[*]Loading proxy ips..")
    ip_list = []
    ip = ['ip', 'port']
    with open("ips.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

def main():
    print('''*Atuhor : V@1n3R.

*Blog :http://www.Lz1y.cn
*date: 2017.7.17
*http://www.Lz1y.cn/wordpress/?p=643





                         __     __    _       _____ ____    

                         \ \   / /_ _/ |_ __ |___ /|  _ \   

                          \ \ / / _` | | '_ \  |_ \| |_) |  

                           \ V / (_| | | | | |___) |  _ < _ 

                            \_/ \__,_|_|_| |_|____/|_| \_(_) 






    ''')

    ip_list = Loadips()
    #   ip_list = [('118.89.148.92',8088)]
    #   ip_list = tuple(ip_list)
    try:
        pst = ProxyServerTest(ip_list)
        # 多線程
        t = threading.Thread(target=pst.run, name='LoopThread')
        print('[*]Waiting for connection...')
        # 關閉多線程
        t.start()
        t.join()
    except Exception as e:
        print("[-]main : " + str(e))
        return "[-]main : " + str(e)

if __name__ == '__main__':
    main()

SqlMap使用代理池

sqlmap加上代理 "–proxy=http://127.0.0.1:9999" 即可使用

使用之前建議先檢測一下代理的有效性:http://h.jiguangdaili.com/check/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM