Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce visual recon clusters #1372

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ OUTPUT:
-irrb, -include-response-base64 include base64 encoded http request/response in JSON output (-json only)
-include-chain include redirect http chain in JSON output (-json only)
-store-chain include http redirect chain in responses (-sr only)
-svrc, -store-vision-recon-cluster include visual recon clusters (-ss and -sr only)

CONFIGURATIONS:
-config string path to the httpx configuration file (default $HOME/.config/httpx/config.yaml)
Expand Down
3 changes: 3 additions & 0 deletions runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type ScanOptions struct {
NoFallbackScheme bool
TechDetect bool
StoreChain bool
StoreVisionReconClusters bool
MaxResponseBodySizeToSave int
MaxResponseBodySizeToRead int
OutputExtractRegex string
Expand Down Expand Up @@ -228,6 +229,7 @@ type Options struct {
StatsInterval int
RandomAgent bool
StoreChain bool
StoreVisionReconClusters bool
Deny customlist.CustomList
Allow customlist.CustomList
MaxResponseBodySizeToSave int
Expand Down Expand Up @@ -402,6 +404,7 @@ func ParseOptions() *Options {
flagSet.BoolVarP(&options.Base64ResponseInStdout, "include-response-base64", "irrb", false, "include base64 encoded http request/response in JSON output (-json only)"),
flagSet.BoolVar(&options.chainInStdout, "include-chain", false, "include redirect http chain in JSON output (-json only)"),
flagSet.BoolVar(&options.StoreChain, "store-chain", false, "include http redirect chain in responses (-sr only)"),
flagSet.BoolVarP(&options.StoreVisionReconClusters, "store-vision-recon-cluster", "svrc", false, "include visual recon clusters (-ss and -sr only)"),
)

flagSet.CreateGroup("configs", "Configurations",
Expand Down
53 changes: 53 additions & 0 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ type Runner struct {
HostErrorsCache gcache.Cache[string, int]
browser *Browser
errorPageClassifier *errorpageclassifier.ErrorPageClassifier
pHashClusters []pHashCluster
}

// picked based on try-fail but it seems to close to one it's used https://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html#c1992
var hammingDistanceThreshold int = 22

type pHashCluster struct {
BasePHash uint64 `json:"base_phash,omitempty" csv:"base_phash"`
Hashes []pHashUrl `json:"hashes,omitempty" csv:"hashes"`
}
type pHashUrl struct {
PHash uint64 `json:"phash,omitempty" csv:"phash"`
Url string `json:"url,omitempty" csv:"url"`
}

// New creates a new client for running enumeration process.
Expand Down Expand Up @@ -237,6 +250,7 @@ func New(options *Options) (*Runner, error) {
scanopts.NoFallbackScheme = options.NoFallbackScheme
scanopts.TechDetect = options.TechDetect
scanopts.StoreChain = options.StoreChain
scanopts.StoreVisionReconClusters = options.StoreVisionReconClusters
scanopts.MaxResponseBodySizeToSave = options.MaxResponseBodySizeToSave
scanopts.MaxResponseBodySizeToRead = options.MaxResponseBodySizeToRead
scanopts.extractRegexps = make(map[string]*regexp.Regexp)
Expand Down Expand Up @@ -881,6 +895,27 @@ func (r *Runner) RunEnumeration() {
}
}

if r.scanopts.StoreVisionReconClusters {
foundCluster := false
pHash, _ := resp.KnowledgeBase["pHash"].(uint64)
for i, cluster := range r.pHashClusters {
distance, _ := goimagehash.NewImageHash(pHash, goimagehash.PHash).Distance(goimagehash.NewImageHash(cluster.BasePHash, goimagehash.PHash))
if distance <= hammingDistanceThreshold {
r.pHashClusters[i].Hashes = append(r.pHashClusters[i].Hashes, pHashUrl{PHash: pHash, Url: resp.URL})
foundCluster = true
break
}
}

if !foundCluster {
newCluster := pHashCluster{
BasePHash: pHash,
Hashes: []pHashUrl{{PHash: pHash, Url: resp.URL}},
}
r.pHashClusters = append(r.pHashClusters, newCluster)
}
}

if !jsonOrCsv || jsonAndCsv || r.options.OutputAll {
gologger.Silent().Msgf("%s\n", resp.str)
}
Expand Down Expand Up @@ -1016,6 +1051,24 @@ func (r *Runner) RunEnumeration() {
close(output)

wgoutput.Wait()

if r.scanopts.StoreVisionReconClusters {
visionReconClusters := filepath.Join(r.options.StoreResponseDir, "vision_recon_clusters.json")
clusterReportJSON, err := json.Marshal(r.pHashClusters)
if err != nil {
gologger.Fatal().Msgf("Failed to marshal report to JSON: %v", err)
}
file, err := os.Create(visionReconClusters)
if err != nil {
gologger.Fatal().Msgf("Failed to create JSON file: %v", err)
}
defer file.Close()

_, err = file.Write(clusterReportJSON)
if err != nil {
gologger.Fatal().Msgf("Failed to write to JSON file: %v", err)
}
}
}

func logFilteredErrorPage(url string) {
Expand Down