-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add additional json fields: port,ip,scheme,url (#4417)
* add additional json fields: port,ip,scheme,url * include host field in case of ip input
- Loading branch information
1 parent
ce5df9c
commit 6e969cb
Showing
10 changed files
with
183 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package utils | ||
|
||
import ( | ||
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/contextargs" | ||
iputil "github.com/projectdiscovery/utils/ip" | ||
urlutil "github.com/projectdiscovery/utils/url" | ||
) | ||
|
||
// JsonFields contains additional metadata fields for JSON output | ||
type JsonFields struct { | ||
Host string `json:"host,omitempty"` | ||
Path string `json:"path,omitempty"` | ||
Port string `json:"port,omitempty"` | ||
Ip string `json:"ip,omitempty"` | ||
Scheme string `json:"scheme,omitempty"` | ||
URL string `json:"url,omitempty"` | ||
} | ||
|
||
// GetJsonFields returns the json fields for the request | ||
func GetJsonFieldsFromURL(URL string) JsonFields { | ||
parsed, err := urlutil.Parse(URL) | ||
if err != nil { | ||
return JsonFields{} | ||
} | ||
fields := JsonFields{ | ||
Port: parsed.Port(), | ||
Scheme: parsed.Scheme, | ||
URL: parsed.String(), | ||
Path: parsed.Path, | ||
} | ||
if fields.Port == "" { | ||
fields.Port = "80" | ||
if fields.Scheme == "https" { | ||
fields.Port = "443" | ||
} | ||
} | ||
if iputil.IsIP(parsed.Host) { | ||
fields.Ip = parsed.Host | ||
} | ||
|
||
fields.Host = parsed.Host | ||
return fields | ||
} | ||
|
||
// GetJsonFieldsFromMetaInput returns the json fields for the request | ||
func GetJsonFieldsFromMetaInput(ctx *contextargs.MetaInput) JsonFields { | ||
input := ctx.Input | ||
fields := JsonFields{ | ||
Ip: ctx.CustomIP, | ||
} | ||
parsed, err := urlutil.Parse(input) | ||
if err != nil { | ||
return fields | ||
} | ||
fields.Port = parsed.Port() | ||
fields.Scheme = parsed.Scheme | ||
fields.URL = parsed.String() | ||
fields.Path = parsed.Path | ||
if fields.Port == "" { | ||
fields.Port = "80" | ||
if fields.Scheme == "https" { | ||
fields.Port = "443" | ||
} | ||
} | ||
if iputil.IsIP(parsed.Host) { | ||
fields.Ip = parsed.Host | ||
} | ||
|
||
fields.Host = parsed.Host | ||
return fields | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters