22
33import burp .IHttpService ;
44import burp .api .montoya .http .HttpService ;
5+ import burp .vaycore .common .utils .IPUtils ;
6+ import burp .vaycore .common .utils .StringUtils ;
57
68import 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