MCPcopy
hub / github.com/projectdiscovery/katana / storeFields

Function storeFields

pkg/output/fields.go:63–84  ·  view source on GitHub ↗

storeFields stores fields for a result into individual files based on name.

(output *Result, storeFields []string)

Source from the content-addressed store, hash-verified

61// storeFields stores fields for a result into individual files
62// based on name.
63func storeFields(output *Result, storeFields []string) {
64 parsed, err := urlutil.Parse(output.Request.URL)
65 if err != nil {
66 gologger.Warning().Msgf("storeFields: failed to parse url %v got %v", output.Request.URL, err)
67 return
68 }
69
70 hostname := parsed.Hostname()
71 etld, _ := publicsuffix.EffectiveTLDPlusOne(hostname)
72 rootURL := fmt.Sprintf("%s://%s", parsed.Scheme, parsed.Host)
73 for _, field := range storeFields {
74 if result := getValueForField(output, parsed.URL, hostname, etld, rootURL, field); result != "" {
75 appendToFileField(parsed.URL, field, result)
76 }
77 if _, ok := CustomFieldsMap[field]; ok {
78 results := getValueForCustomField(output)
79 for _, result := range results {
80 appendToFileField(parsed.URL, result.field, result.value)
81 }
82 }
83 }
84}
85
86func appendToFileField(parsed *url.URL, field, data string) {
87 file, err := os.OpenFile(path.Join(storeFieldDir, fmt.Sprintf("%s_%s_%s.txt", parsed.Scheme, parsed.Hostname(), field)), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)

Callers 1

WriteMethod · 0.85

Calls 3

getValueForFieldFunction · 0.85
appendToFileFieldFunction · 0.85
getValueForCustomFieldFunction · 0.85

Tested by

no test coverage detected