Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 29b712c

Browse files
committed
修复:因处理 IHttpService 实例不当,导致的 'java.lang.IllegalArgumentException: Invalid service' 异常
1 parent b9bc68c commit 29b712c

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

extender/src/main/java/burp/hae/montoya/http/HttpServiceImpl.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import burp.IHttpService;
44
import burp.api.montoya.http.HttpService;
5+
import burp.vaycore.common.utils.IPUtils;
6+
import burp.vaycore.common.utils.StringUtils;
57

68
import java.net.InetAddress;
7-
import java.net.UnknownHostException;
89

910
/**
1011
* <p>
@@ -20,26 +21,50 @@ public HttpServiceImpl(IHttpService httpService) {
2021

2122
@Override
2223
public String host() {
23-
return this.httpService.getHost();
24+
if (this.httpService == null) {
25+
return "0.0.0.0";
26+
}
27+
String host = this.httpService.getHost();
28+
if (StringUtils.isEmpty(host)) {
29+
return "0.0.0.0";
30+
}
31+
return host;
2432
}
2533

34+
/**
35+
* @return 范围(1-65535)
36+
*/
2637
@Override
2738
public int port() {
28-
return this.httpService.getPort();
39+
if (this.httpService == null) {
40+
return 80;
41+
}
42+
int port = this.httpService.getPort();
43+
if (port <= 0 || port > 65535) {
44+
return 80;
45+
}
46+
return port;
2947
}
3048

3149
@Override
3250
public boolean secure() {
33-
return "https".equals(httpService.getProtocol());
51+
if (this.httpService == null) {
52+
return false;
53+
}
54+
return "https".equalsIgnoreCase(this.httpService.getProtocol());
3455
}
3556

3657
@Override
3758
public String ipAddress() {
38-
String host = httpService.getHost();
59+
String host = this.host();
60+
// 如果是 IPv4 地址,直接返回
61+
if (IPUtils.hasIPv4(host)) {
62+
return host;
63+
}
3964
try {
4065
InetAddress ip = InetAddress.getByName(host);
4166
return ip.getHostAddress();
42-
} catch (UnknownHostException e) {
67+
} catch (Exception e) {
4368
return "0.0.0.0";
4469
}
4570
}

0 commit comments

Comments
 (0)