11package burp ;
22
33import burp .vaycore .common .helper .DomainHelper ;
4+ import burp .vaycore .common .helper .QpsLimiter ;
45import burp .vaycore .common .log .Logger ;
56import burp .vaycore .common .utils .*;
67import burp .vaycore .hae .HaE ;
78import burp .vaycore .onescan .OneScan ;
89import burp .vaycore .onescan .bean .TaskData ;
910import burp .vaycore .onescan .common .Config ;
1011import burp .vaycore .onescan .common .Constants ;
12+ import burp .vaycore .onescan .common .OnTabEventListener ;
1113import burp .vaycore .onescan .ui .payloadlist .PayloadItem ;
1214import burp .vaycore .onescan .ui .payloadlist .PayloadRule ;
15+ import burp .vaycore .onescan .ui .tab .ConfigPanel ;
1316import burp .vaycore .onescan .ui .tab .DataBoardTab ;
17+ import burp .vaycore .onescan .ui .tab .config .OtherTab ;
1418import burp .vaycore .onescan .ui .widget .TaskTable ;
19+ import org .json .HTTP ;
1520import org .json .JSONArray ;
1621import org .json .JSONObject ;
1722
3237 * Created by vaycore on 2022-08-07.
3338 */
3439public class BurpExtender implements IBurpExtender , IProxyListener , IMessageEditorController ,
35- TaskTable .OnTaskTableEventListener , ITab {
40+ TaskTable .OnTaskTableEventListener , ITab , OnTabEventListener {
3641
3742 private IBurpExtenderCallbacks mCallbacks ;
3843 private OneScan mOneScan ;
3944 private DataBoardTab mDataBoardTab ;
45+ private ConfigPanel mConfigTab ;
4046 private IMessageEditor mRequestTextEditor ;
4147 private IMessageEditor mResponseTextEditor ;
4248 private ExecutorService mThreadPool ;
4349 private IHttpRequestResponse mCurrentReqResp ;
4450 private static final Vector <String > sRepeatFilter = new Vector <>();
51+ private QpsLimiter mQpsLimit ;
4552
4653 @ Override
4754 public void registerExtenderCallbacks (IBurpExtenderCallbacks callbacks ) {
4855 initData (callbacks );
4956 initView ();
5057 initEvent ();
51- Logger .debug ("register Extender ok! Log: " + Constants .PLUGIN_VERSION . contains ( "debug" ) );
58+ Logger .debug ("register Extender ok! Log: " + Constants .DEBUG );
5259 // 加载HaE插件
5360 HaE .loadPlugin (Config .getFilePath (Config .KEY_HAE_PLUGIN_PATH ));
5461 }
@@ -58,24 +65,37 @@ private void initData(IBurpExtenderCallbacks callbacks) {
5865 this .mThreadPool = Executors .newFixedThreadPool (50 );
5966 this .mCallbacks .setExtensionName (Constants .PLUGIN_NAME + " v" + Constants .PLUGIN_VERSION );
6067 // 初始化日志打印
61- Logger .init (Constants .PLUGIN_VERSION . contains ( "debug" ) , mCallbacks .getStdout (), mCallbacks .getStderr ());
68+ Logger .init (Constants .DEBUG , mCallbacks .getStdout (), mCallbacks .getStderr ());
6269 // 初始化默认配置
6370 Config .init ();
6471 // 初始化域名辅助类
6572 DomainHelper .init ("public_suffix_list.json" );
6673 // 初始化HaE插件
6774 HaE .init (this );
75+ // 初始化QPS限制器
76+ initQpsLimiter ();
77+ }
78+
79+ private void initQpsLimiter () {
80+ // 检测范围,如果不符合条件,不创建限制器
81+ int limit = StringUtils .parseInt (Config .get (Config .KEY_QPS_LIMIT ));
82+ if (limit > 0 && limit <= 9999 ) {
83+ this .mQpsLimit = new QpsLimiter (limit );
84+ }
6885 }
6986
7087 private void initView () {
7188 mOneScan = new OneScan ();
7289 mDataBoardTab = mOneScan .getDataBoardTab ();
90+ mConfigTab = mOneScan .getConfigPanel ();
7391 mCallbacks .addSuiteTab (this );
7492 // 创建请求和响应控件
7593 mRequestTextEditor = mCallbacks .createMessageEditor (this , false );
7694 mResponseTextEditor = mCallbacks .createMessageEditor (this , false );
7795 mDataBoardTab .init (mRequestTextEditor .getComponent (), mResponseTextEditor .getComponent ());
7896 mDataBoardTab .getTaskTable ().setOnTaskTableEventListener (this );
97+ // 注册事件
98+ mConfigTab .getOtherTab ().setOnTabEventListener (this );
7999 }
80100
81101 private void initEvent () {
@@ -301,6 +321,10 @@ private void doBurpRequest(IHttpRequestResponse httpReqResp, byte[] request) {
301321 sRepeatFilter .add (url );
302322 // 给每个任务创建线程
303323 mThreadPool .execute (() -> {
324+ // 限制QPS
325+ if (mQpsLimit != null ) {
326+ mQpsLimit .limit ();
327+ }
304328 Logger .debug ("Do Send Request url: " + url );
305329 // 发起请求
306330 IHttpRequestResponse newReqResp = mCallbacks .makeHttpRequest (service , requestBytes );
@@ -322,7 +346,7 @@ private String buildRequestHeader(IHttpService service, String urlPath) {
322346 ArrayList <String > headerList = getHeaderList ();
323347 StringBuilder request = new StringBuilder ();
324348 // 请求头构造
325- request .append ("GET " ).append (urlPath ).append (" HTTP/1.1" ).append (" \r \n " );
349+ request .append ("GET " ).append (urlPath ).append (" HTTP/1.1" ).append (HTTP . CRLF );
326350 // 如果存在配置,直接加载配置的值,否则使用默认值
327351 if (headerList .size () > 0 ) {
328352 for (String headerItem : headerList ) {
@@ -332,20 +356,20 @@ private String buildRequestHeader(IHttpService service, String urlPath) {
332356 }
333357 String headerKey = headerItem .substring (0 , splitIndex );
334358 String headerValue = headerItem .substring (splitIndex + 2 );
335- request .append (headerKey ).append (": " ).append (headerValue ).append (" \r \n " );
359+ request .append (headerKey ).append (": " ).append (headerValue ).append (HTTP . CRLF );
336360 }
337361 } else {
338362 String referer = getHostByIHttpService (service ) + "/" ;
339- request .append ("Host: {{host}}" ).append (" \r \n " );
340- request .append ("User-Agent: " ).append ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4495.0 Safari/537.36" ).append (" \r \n " );
341- request .append ("Referer: " ).append (referer ).append (" \r \n " );
342- request .append ("Accept: " ).append ("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ).append (" \r \n " );
343- request .append ("Accept-Language: " ).append ("zh-CN,zh;q=0.9,en;q=0.8" ).append (" \r \n " );
344- request .append ("Accept-Encoding: " ).append ("gzip, deflate" ).append (" \r \n " );
345- request .append ("Origin: " ).append ("https://www.baidu.com" ).append (" \r \n " );
346- request .append ("Cache-Control: " ).append ("max-age=0" ).append (" \r \n " );
347- }
348- request .append (" \r \n " );
363+ request .append ("Host: {{host}}" ).append (HTTP . CRLF );
364+ request .append ("User-Agent: " ).append ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4495.0 Safari/537.36" ).append (HTTP . CRLF );
365+ request .append ("Referer: " ).append (referer ).append (HTTP . CRLF );
366+ request .append ("Accept: " ).append ("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ).append (HTTP . CRLF );
367+ request .append ("Accept-Language: " ).append ("zh-CN,zh;q=0.9,en;q=0.8" ).append (HTTP . CRLF );
368+ request .append ("Accept-Encoding: " ).append ("gzip, deflate" ).append (HTTP . CRLF );
369+ request .append ("Origin: " ).append ("https://www.baidu.com" ).append (HTTP . CRLF );
370+ request .append ("Cache-Control: " ).append ("max-age=0" ).append (HTTP . CRLF );
371+ }
372+ request .append (HTTP . CRLF );
349373 // 请求头构建完成后,设置里面包含的变量
350374 return setupVariable (service , request .toString ());
351375 }
@@ -360,9 +384,11 @@ private String setupVariable(IHttpService service, String request) {
360384 String timestamp = String .valueOf (DateUtils .getTimestamp ());
361385 String randomIP = IPUtils .randomIPv4 ();
362386 String randomUA = Utils .getRandomItem (Config .getList (Config .KEY_UA_LIST ));
387+ String mainDomain = DomainHelper .getDomain (domain );
363388 // 替换变量
364389 request = request .replace ("{{host}}" , host );
365390 request = request .replace ("{{domain}}" , domain );
391+ request = request .replace ("{{mdomain}}" , mainDomain );
366392 request = request .replace ("{{protocol}}" , protocol );
367393 request = request .replace ("{{timestamp}}" , timestamp );
368394 request = request .replace ("{{random.ip}}" , randomIP );
@@ -641,4 +667,15 @@ public void onSendToRepeater(ArrayList<TaskData> list) {
641667 }
642668 }
643669 }
670+
671+ @ Override
672+ public void onTabEventMethod (String action , Object ... params ) {
673+ switch (action ) {
674+ case OtherTab .EVENT_QPS_LIMIT :
675+ String limit = (String ) params [0 ];
676+ mQpsLimit = new QpsLimiter (StringUtils .parseInt (limit ));
677+ Logger .debug ("Event: change qps limit: " + limit );
678+ break ;
679+ }
680+ }
644681}
0 commit comments