bp驗證碼爆破外掛二改
這不315晚會burp都上了嘛,蹭蹭時事熱點。
0x01 背景
最近遇到了很多驗證碼登入口,驗證碼識別專案github上找了幾個,但是不是裝不上就是準確率不高的問題,後續也是慢慢修改出來了還算滿意的識別驗證碼外掛。
原外掛專案地址為:
https://github.com/c0ny1/captcha-killer
修改後的專案地址為:
https://github.com/f0ng/captcha-killer-modified
已徵得原作者同意進行二開
0x02外掛二次修改
直接下載原專案的jar包,按照專案說明進行使用,發現intruder無法進行爆破,有些情況也滿足不了需求,後面優化了一下,總共修改了兩處地方
修改點1
發現使用過程中出現了報錯
後面查了一下,原因是sun.misc.BASE64Encoder
類不在jdk8+支援了,因為都在用新版burp了,而新版burp啟動需要高版本的jdk,這裡我是jdk10啟動的burp,所以沒有sun.misc.BASE64Encoder
類
下載原始碼,修改java.utils.Util裡的原始碼如下:
// FileName: Util.java public static String base64Encode(byte[] byteArray){ byte[] res = Base64.getEncoder().encode(byteArray); String res2 = new String(res); res2 = res2.replace(System.lineSeparator(),""); return res2; } public static String base64Encode(String str){ byte[] b = new byte[]{}; try { b = str.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } byte[] res = Base64.getEncoder().encode(b); String res2 = new String(res); //去除base64結果中的換行符,java base64編碼預設會76個字母換行一次 res2 = res2.replace(System.lineSeparator(),""); return res2; } public static byte[] base64Decode(String str){ byte[] byteRes = new byte[]{}; byteRes = Base64.getDecoder().decode(str); return byteRes; }
再匯入依賴
import java.util.Base64;
修改點2
這裡還有個不是很完美的地方,只能識別響應包為圖片的驗證碼,但是遇到的真實環境中,也有一種data:image
這種格式的驗證碼,這個外掛就無法識別了,如下:
這裡我也進行了一點修改,主要是響應包圖片的提取,主要修改如下:
在java.utils.Util包中增加函式
public static byte[] dataimgToimg(String str_img) throws IOException { String pattern = "(data:image.*?)[\"|&]|(data%2Aimage.*?)[\"|&]"; Pattern r = Pattern.compile(pattern); Matcher m = r.matcher(str_img); if (m.find( )) { str_img = m.group(0).replace("\"","").replace("&","") ; } byte[] img = DatatypeConverter.parseBase64Binary(str_img.substring(str_img.indexOf(",") + 1)); InputStream buffin = new ByteArrayInputStream(img); return img; } public static boolean isImage(String str_img) throws IOException { String pattern = "(data:image.*?)[\"|&]|(data%2Aimage.*?)[\"|&]"; Pattern r = Pattern.compile(pattern); Matcher m = r.matcher(str_img); if (m.find( )) { str_img = m.group(0).replace("\"","").replace("&","") ; } byte[] img = DatatypeConverter.parseBase64Binary(str_img.substring(str_img.indexOf(",") + 1)); boolean isImg = false; InputStream buffin = new ByteArrayInputStream(img); BufferedImage image = ImageIO.read(buffin); if(image == null){ isImg = false; }else { isImg = true; } return isImg; }
修改後對專案進行編譯:
$ mvn package
識別的效果如下:
0x03 外掛驗證碼識別庫的選擇
這裡的介面大部分都需要付費,如baidu的介面每天只有300次,還有其他平臺的,每天有限制次數,不利於咱們測試呀
於是在我的不懈努力下,找到了一個開源識別驗證碼的專案,專案地址為:
https://github.com/sml2h3/ddddocr
所需要的環境支援如下:
python <= 3.9
Windows/Linux/Macos..
暫時不支援Macbook M1(X),M1(X)使用者需要自己編譯onnxruntime才可以使用
0x04 實際效果
安裝好ocr庫以後直接執行程式碼:
# -*- coding:utf-8 -*-
# author:f0ngf0ng
import argparse
import ddddocr # 匯入 ddddocr
from aiohttp import web
parser = argparse.ArgumentParser()
parser.add_argument("-p", help="http port",default="8888")
args = parser.parse_args()
ocr = ddddocr.DdddOcr()
port = args.p
async def handle_cb(request):
return web.Response(text=ocr.classification(img_base64=await request.text()))
app = web.Application()
app.add_routes([
web.post('/reg', handle_cb),
])
if __name__ == '__main__':
web.run_app(app, port=port)
$ python3 codereg.py
執行程式碼介面
識別模板如下:
POST /reg HTTP/1.1
Host: 127.0.0.1:8888
Connection: close
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Sec-Fetch-Site: none
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Content-Type: application/x-www-form-urlencoded
Content-Length: 55
<@BASE64><@IMG_RAW></@IMG_RAW></@BASE64>
記得設定介面地址為:http://127.0.0.1:8888
點選識別
即可識別出來驗證碼,準確率還不錯,在85%以上,重要的是免費,無限使用
關於captcha-killer的用法可以參考c0ny1師傅的文章
注:
- intruder的cookie要和captcha-killer的cookie一致
- intruder的執行緒調為1,最好加時間延遲引數
0x05 總結
- 最近一直在寫、改一些外掛,發現burp對jdk版本高低太敏感了,有些時候特定的jdk版本會造成外掛之間的衝突
- 修改外掛感覺就像是站在巨人的肩膀上,不得不說c0ny1師傅的這個外掛GUI頁面用起來都很舒服
- 學會開發很重要,可以自己進行自定義修改,不做百分百的指令碼小子
0x06 附錄
https://github.com/c0ny1/captcha-killer [外掛源專案]
https://gv7.me/articles/2019/burp-captcha-killer-usage/ [外掛用法]
https://github.com/sml2h3/ddddocr [驗證碼識別專案]
https://github.com/PoJun-Lab/blaster [驗證碼登入爆破]
https://github.com/f0ng/captcha-killer-modified [修改後的burp驗證碼識別外掛]