forked from owasp-amass/amass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.go
83 lines (70 loc) · 1.77 KB
/
monitor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright © by Jeff Foley 2017-2023. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0
package enum
import (
"net/netip"
"strings"
"github.com/owasp-amass/asset-db/types"
"github.com/owasp-amass/open-asset-model/domain"
"github.com/owasp-amass/open-asset-model/network"
)
const falsePositiveThreshold int = 100
func (e *Enumeration) checkForMissedWildcards(addr string) {
ip, err := netip.ParseAddr(addr)
if err != nil {
return
}
var t string
if ip.Is4() {
t = "IPv4"
} else if ip.Is6() {
t = "IPv6"
} else {
return
}
results, err := e.graph.DB.FindByContent(&network.IPAddress{
Address: ip,
Type: t,
}, e.Config.CollectionStartTime.UTC())
if err != nil {
return
}
var asset *types.Asset
for _, res := range results {
if i, ok := res.Asset.(network.IPAddress); ok && i.Address.String() == addr {
asset = res
break
}
}
if asset == nil {
return
}
in, err := e.graph.DB.IncomingRelations(asset, e.Config.CollectionStartTime.UTC(), "a_record", "aaaa_record")
if err != nil {
return
}
if len(in) < falsePositiveThreshold {
return
}
subsToAssets := make(map[string][]string)
for _, rel := range in {
n, err := e.graph.DB.FindById(rel.FromAsset.ID, e.Config.CollectionStartTime.UTC())
if err != nil {
continue
} else if fqdn, ok := n.Asset.(domain.FQDN); ok {
parts := strings.Split(fqdn.Name, ".")
sub := strings.Join(parts[1:], ".")
subsToAssets[sub] = append(subsToAssets[sub], rel.FromAsset.ID)
}
}
for sub, assets := range subsToAssets {
if len(assets) < falsePositiveThreshold {
continue
}
e.Config.BlacklistSubdomain(sub)
for _, id := range assets {
_ = e.graph.DB.DeleteAsset(id)
}
}
}