Skip to content

Commit

Permalink
many various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Feb 23, 2025
1 parent d1ea873 commit 951f1ff
Show file tree
Hide file tree
Showing 24 changed files with 520 additions and 379 deletions.
2 changes: 1 addition & 1 deletion engine/plugins/api/gleif/fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (fc *fuzzyCompletions) query(e *et.Event, orgent *dbt.Entity) *dbt.Entity {

leiList = append(leiList, &general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", general.LEICode, id),
EntityID: id,
ID: id,
Type: general.LEICode,
})
}
Expand Down
10 changes: 5 additions & 5 deletions engine/plugins/api/gleif/lei_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func (g *gleif) getLEIRecord(id *general.Identifier) (*leiRecord, error) {
g.rlimit.Take()

u := "https://api.gleif.org/api/v1/lei-records/" + id.EntityID
u := "https://api.gleif.org/api/v1/lei-records/" + id.ID
resp, err := http.RequestWebPage(context.TODO(), &http.Request{URL: u})
if err != nil || resp.StatusCode != 200 || resp.Body == "" {
return nil, err
Expand All @@ -29,7 +29,7 @@ func (g *gleif) getLEIRecord(id *general.Identifier) (*leiRecord, error) {
var result singleResponse
if err := json.Unmarshal([]byte(resp.Body), &result); err != nil {
return nil, err
} else if result.Data.Type != "lei-records" || result.Data.ID != id.EntityID {
} else if result.Data.Type != "lei-records" || result.Data.ID != id.ID {
return nil, errors.New("failed to find the LEI record")
}
return &result.Data, nil
Expand All @@ -38,7 +38,7 @@ func (g *gleif) getLEIRecord(id *general.Identifier) (*leiRecord, error) {
func (g *gleif) getDirectParentRecord(id *general.Identifier) (*leiRecord, error) {
g.rlimit.Take()

u := "https://api.gleif.org/api/v1/lei-records/" + id.EntityID + "/direct-parent"
u := "https://api.gleif.org/api/v1/lei-records/" + id.ID + "/direct-parent"
resp, err := http.RequestWebPage(context.TODO(), &http.Request{URL: u})
if err != nil || resp.StatusCode != 200 || resp.Body == "" {
return nil, err
Expand All @@ -57,7 +57,7 @@ func (g *gleif) getDirectChildrenRecords(id *general.Identifier) ([]*leiRecord,
var children []*leiRecord

last := 1
link := "https://api.gleif.org/api/v1/lei-records/" + id.EntityID + "/direct-children"
link := "https://api.gleif.org/api/v1/lei-records/" + id.ID + "/direct-children"
for i := 1; i <= last && link != ""; i++ {
g.rlimit.Take()

Expand Down Expand Up @@ -106,7 +106,7 @@ func (g *gleif) createLEIIdentifier(session et.Session, orgent *dbt.Entity, lei
func (g *gleif) createLEIFromRecord(e *et.Event, orgent *dbt.Entity, lei *leiRecord) (*dbt.Entity, error) {
return g.createLEIIdentifier(e.Session, orgent, &general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", general.LEICode, lei.ID),
EntityID: lei.ID,
ID: lei.ID,
Type: general.LEICode,
Status: lei.Attributes.Registration.Status,
CreationDate: lei.Attributes.Registration.InitialRegistrationDate,
Expand Down
6 changes: 3 additions & 3 deletions engine/plugins/api/gleif/lei_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGetLEIRecord(t *testing.T) {
lei := "ZXTILKJKG63JELOEG630"
id := &general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", general.LEICode, lei),
EntityID: lei,
ID: lei,
Type: general.LEICode,
}

Expand All @@ -36,7 +36,7 @@ func TestGetDirectParentRecord(t *testing.T) {
lei := "25490065U2GR0UPXFY63"
id := &general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", general.LEICode, lei),
EntityID: lei,
ID: lei,
Type: general.LEICode,
}

Expand All @@ -53,7 +53,7 @@ func TestGetDirectChildrenRecord(t *testing.T) {
lei := "ZXTILKJKG63JELOEG630"
id := &general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", general.LEICode, lei),
EntityID: lei,
ID: lei,
Type: general.LEICode,
}

Expand Down
4 changes: 2 additions & 2 deletions engine/plugins/api/gleif/org_lei.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (g *gleif) updateOrgFromLEIRecord(e *et.Event, orgent *dbt.Entity, lei *lei
// check if the org entity already has a LEI identifier
if leient := g.orgEntityToLEI(e, orgent); leient != nil {
// check if the LEI identifier is the same as the one we are processing
if id, ok := leient.Asset.(*general.Identifier); ok && id.EntityID != lei.ID {
if id, ok := leient.Asset.(*general.Identifier); ok && id.ID != lei.ID {
return
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func (g *gleif) addIdentifiersToOrg(e *et.Event, orgent *dbt.Entity, idtype stri

oamid := &general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", idtype, id),
EntityID: id,
ID: id,
Type: idtype,
}

Expand Down
16 changes: 10 additions & 6 deletions engine/plugins/api/rdap/netblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ func (nb *netblock) lookup(e *et.Event, cidr string, since time.Time) *dbt.Entit
func (nb *netblock) query(e *et.Event, asset *dbt.Entity) (*dbt.Entity, *rdap.IPNetwork) {
n := asset.Asset.(*network.Netblock)

var req *rdap.Request
_, ipnet, err := net.ParseCIDR(n.CIDR.String())
if err != nil {
return nil, nil
}
req = rdap.NewIPNetRequest(ipnet)
req := rdap.NewIPNetRequest(ipnet)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand All @@ -89,10 +88,10 @@ func (nb *netblock) query(e *et.Event, asset *dbt.Entity) (*dbt.Entity, *rdap.IP
if !ok {
return nil, nil
}
return nb.store(e, record, asset, nb.plugin.source), record
return nb.store(e, record, asset), record
}

func (nb *netblock) store(e *et.Event, resp *rdap.IPNetwork, asset *dbt.Entity, src *et.Source) *dbt.Entity {
func (nb *netblock) store(e *et.Event, resp *rdap.IPNetwork, asset *dbt.Entity) *dbt.Entity {
n := asset.Asset.(*network.Netblock)
ipnetrec := &oamreg.IPNetRecord{
CIDR: n.CIDR,
Expand Down Expand Up @@ -128,14 +127,19 @@ func (nb *netblock) store(e *et.Event, resp *rdap.IPNetwork, asset *dbt.Entity,

record, err := e.Session.Cache().CreateAsset(ipnetrec)
if err == nil && record != nil {
_, _ = e.Session.Cache().CreateEntityProperty(record, &general.SourceProperty{
Source: nb.plugin.source.Name,
Confidence: nb.plugin.source.Confidence,
})

if edge, err := e.Session.Cache().CreateEdge(&dbt.Edge{
Relation: &general.SimpleRelation{Name: "registration"},
FromEntity: asset,
ToEntity: record,
}); err == nil && edge != nil {
_, _ = e.Session.Cache().CreateEdgeProperty(edge, &general.SourceProperty{
Source: src.Name,
Confidence: src.Confidence,
Source: nb.plugin.source.Name,
Confidence: nb.plugin.source.Confidence,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine/plugins/api/rdap/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (rd *rdapPlugin) storeEntity(e *et.Event, level int, entity *rdap.Entity, a
if email := strings.ToLower(v.Email()); m.IsMatch(string(oam.Identifier)) && email != "" {
if a, err := e.Session.Cache().CreateAsset(&general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", general.EmailAddress, email),
EntityID: email,
ID: email,
Type: general.EmailAddress,
}); err == nil && a != nil {
_ = rd.createContactEdge(e.Session, cr, a, &general.SimpleRelation{Name: "id"}, src)
Expand Down
21 changes: 18 additions & 3 deletions engine/plugins/enrich/banner_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ package enrich
import (
"errors"
"log/slog"
"net/netip"

"github.com/owasp-amass/amass/v4/engine/plugins/support"
et "github.com/owasp-amass/amass/v4/engine/types"
dbt "github.com/owasp-amass/asset-db/types"
oam "github.com/owasp-amass/open-asset-model"
oamdns "github.com/owasp-amass/open-asset-model/dns"
"github.com/owasp-amass/open-asset-model/general"
oamnet "github.com/owasp-amass/open-asset-model/network"
"github.com/owasp-amass/open-asset-model/platform"
oamurl "github.com/owasp-amass/open-asset-model/url"
)
Expand Down Expand Up @@ -89,11 +92,23 @@ func (bu *bannerURLs) query(e *et.Event, asset *dbt.Entity) []*dbt.Entity {
return nil
}

var results []*dbt.Entity
var results []*oamurl.URL
// TODO: in the future, further investigation of out of scope URLs may be needed
if urls := support.ExtractURLsFromString(serv.Output); len(urls) > 0 {
results = append(results, bu.store(e, urls)...)
for _, u := range urls {
if addr, err := netip.ParseAddr(u.Host); err == nil {
if _, conf := e.Session.Scope().IsAssetInScope(&oamnet.IPAddress{Address: addr}, 0); conf > 0 {
results = append(results, u)
}
} else {
if _, conf := e.Session.Scope().IsAssetInScope(&oamdns.FQDN{Name: u.Host}, 0); conf > 0 {
results = append(results, u)
}
}
}
}
return results

return bu.store(e, results)
}

func (bu *bannerURLs) store(e *et.Event, urls []*oamurl.URL) []*dbt.Entity {
Expand Down
4 changes: 2 additions & 2 deletions engine/plugins/enrich/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (ee *emailexpand) Stop() {

func (ee *emailexpand) check(e *et.Event) error {
if id, ok := e.Entity.Asset.(*general.Identifier); !ok ||
id == nil || id.Type != general.EmailAddress || id.EntityID == "" {
id == nil || id.Type != general.EmailAddress || id.ID == "" {
return nil
}

Expand All @@ -74,7 +74,7 @@ func (ee *emailexpand) store(e *et.Event, asset *dbt.Entity) []*support.Finding
var findings []*support.Finding
oame := asset.Asset.(*general.Identifier)

parts := strings.Split(oame.EntityID, "@")
parts := strings.Split(oame.ID, "@")
if len(parts) != 2 {
return findings
}
Expand Down
2 changes: 1 addition & 1 deletion engine/plugins/enrich/tls_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (te *tlsexpand) store(e *et.Event, cert *x509.Certificate, asset *dbt.Entit

if a, err := e.Session.Cache().CreateAsset(&general.Identifier{
UniqueID: fmt.Sprintf("%s:%s", general.EmailAddress, email),
EntityID: email,
ID: email,
Type: general.EmailAddress,
}); err == nil && a != nil {
findings = append(findings, &support.Finding{
Expand Down
Loading

0 comments on commit 951f1ff

Please sign in to comment.