|
3 | 3 |
|
4 | 4 | import burp.BurpExtender; |
5 | 5 | import burp.IHttpRequestResponse; |
| 6 | +import utils.UrlUtils; |
| 7 | + |
| 8 | +import java.io.IOException; |
6 | 9 | import java.net.MalformedURLException; |
| 10 | +import java.net.URL; |
| 11 | +import java.util.HashMap; |
| 12 | +import java.util.Map; |
| 13 | +import java.util.regex.Pattern; |
7 | 14 |
|
8 | | -import static burp.BurpExtender.stdout; |
| 15 | +import static burp.BurpExtender.stderr; |
9 | 16 |
|
10 | 17 | public class Detector { |
11 | | - private static String[] staticRegex = { |
12 | | - // ".*?", |
13 | | - "root:x:\\d*:\\d*:root" |
14 | | - }; |
| 18 | + private static String[] staticRegex; |
15 | 19 |
|
| 20 | + static { |
| 21 | + try { |
| 22 | + staticRegex = UrlUtils.getHTTPContent("https://raw.githubusercontent.com/BitTheByte/BitTraversal/master/list/regex.list").split("\n"); |
| 23 | + Logger.info(staticRegex); |
| 24 | + } catch (IOException e) { |
| 25 | + stderr.println(e); |
| 26 | + } |
| 27 | + } |
16 | 28 |
|
17 | | - public static String staticDetection(String content){ |
18 | | - stdout.println(content); |
19 | | - for(String match: staticRegex){ |
20 | | - if(content.replaceAll("\n","").replaceAll("\r","").matches(match)) |
| 29 | + public static String staticDetection(String content) { |
| 30 | + for (String match : staticRegex) { |
| 31 | + if (Pattern.compile(match).matcher(content).find()) |
21 | 32 | return String.format(Template.static_match_template, match); |
22 | 33 | } |
23 | 34 | return null; |
24 | 35 | } |
25 | 36 |
|
26 | | - public static String dynamicDetection(String content){ |
| 37 | + |
| 38 | + private static Map<String, String> responseMap = new HashMap<>(); |
| 39 | + |
| 40 | + public static String dynamicDetection(String url, String content) throws MalformedURLException { |
| 41 | + for (Map.Entry<String, String> entry : responseMap.entrySet()) { |
| 42 | + if (entry.getValue().equals(content) && |
| 43 | + new URL(url).getHost().equals(new URL(entry.getKey()).getHost())) { |
| 44 | + return String.format(Template.dynamic_match_template, url, entry.getKey()); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + if (!responseMap.containsKey(url)) |
| 49 | + responseMap.put(url, content); |
| 50 | + |
27 | 51 | return null; |
28 | 52 | } |
29 | 53 |
|
| 54 | + |
30 | 55 | public static void report(IHttpRequestResponse messageInfo, String match) throws MalformedURLException { |
31 | 56 | BurpExtender.callbacks.addScanIssue(new Reporter( |
32 | 57 | messageInfo, |
|
0 commit comments