1. 程式人生 > >python爬蟲--自動獲取seebug的poc

python爬蟲--自動獲取seebug的poc

nowait 位數 完成 再次 問題 reading use odi html

簡單的寫了一個爬取www.seebug.org上poc的小玩意兒~

首先我們進行一定的抓包分析

我們遇到的第一個問題就是seebug需要登錄才能進行下載,這個很好處理,只需要抓取返回值200的頁面,將我們的headers信息復制下來就行了

(這裏我就不放上我的headers信息了,不過headers裏需要修改和註意的內容會在下文講清楚)

headers = {
    Host:******,
    Connection:close,
    Accept:******,
    User-Agent:******,
    Referer:https://www.seebug.org/vuldb/ssvid-
, Accept-Language:zh-CN,zh;q=0.8, Cookie:*********** }

由上所知,我們的中點就是referer這一項,是我們後面要進行修改的

那麽怎麽去修改這個呢

我先進行點擊下載鏈接抓包發現,seebug的poc下載鏈接特別的整齊:

‘https://www.seebug.org/vuldb/downloadPoc/xxxxx‘,

後面只需要加上一個五位數就行,而且五位數是連號的哦!

這就一目了然,我更改了五位數再次進行請求時發現,並沒有返回美麗的200狀態碼,瞄了一眼header,發現了referer這一項:

‘Referer‘:‘https://www.seebug.org/vuldb/ssvid-xxxxx‘

也就是說referer這一項的五位數字也要隨之變化,這樣我們的get請求頭部就完成了

接下來是線程的問題

使用了queue和threading進行多線程處理,發現我們不能圖快,不然會被反爬蟲發現

於是導入time增加time.sleep(1),能有一秒的休眠就行了,線程數給了2個(這樣看來好像線程的意義並不大,不過也就這麽寫啦)

# coding=utf-8

import requests
import threading
import Queueimport time 

headers = {
            ******
        }
url_download 
= https://www.seebug.org/vuldb/downloadPoc/ class SeeBugPoc(threading.Thread): def __init__(self,queue): threading.Thread.__init__(self) self._queue = queue def run(self): while not self._queue.empty(): url_download = self._queue.get_nowait() self.download_file(url_download) def download_file(self,url_download): r = requests.get(url = url_download,headers = headers) print r.status_code name = url_download.split(/)[-1] print name if r.status_code == 200: f = open(E:/poc/+name+.txt,w) f.write(r.content) f.close() print it ok! else: print what fuck ! time.sleep(1) ‘‘‘ def get_html(self,url): r = requests.get(url = url,headers = headers) print r.status_code print time.time() ‘‘‘ def main(): queue = Queue.Queue() for i in range(93000,93236): headers[Referer] = https://www.seebug.org/vuldb/ssvid-+str(i) queue.put(https://www.seebug.org/vuldb/downloadPoc/+str(i)) #queue用來存放設計好的url,將他們放入一個隊列中,以便後面取用 threads = [] thread_count = 2 for i in range(thread_count): threads.append(SeeBugPoc(queue)) for i in threads: i.start() for i in threads: i.join() if __name__ == __main__: main()

代碼如上

控制下載的range()中的兩個五位數,大家只要去seebug庫中找一找想要掃描的庫的開頭和結尾編碼的五位數就行了(也就是他們的編號)

關於返回的狀態碼,如果項目不提供poc下載、poc下載不存在、poc需要兌換幣才能下載,就不能夠返回正常的200啦(非正常:404/403/521等)

當然,如果一直出現521,可以考慮刷新網頁重新獲取header並修改代碼

最後進行一個狀態碼的判斷,並且將200的文件寫出來就好了

  表示慚愧感覺自己寫的很簡單

  如果大家發現錯誤或者有疑惑可以留言討論哦

python爬蟲--自動獲取seebug的poc