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

Changes made with the refactoring. #1047

Merged
merged 1 commit into from
Nov 25, 2024
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
29 changes: 12 additions & 17 deletions engine/plugins/api/binaryedge.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,27 @@ func (be *binaryEdge) check(e *et.Event) error {
return nil
}

src := support.GetSource(e.Session, be.source)
if src == nil {
return errors.New("failed to obtain the plugin source information")
}

since, err := support.TTLStartTime(e.Session.Config(), string(oam.FQDN), string(oam.FQDN), be.name)
if err != nil {
return err
}

var names []*dbt.Entity
if support.AssetMonitoredWithinTTL(e.Session, e.Asset, src, since) {
names = append(names, be.lookup(e, fqdn.Name, src, since)...)
if support.AssetMonitoredWithinTTL(e.Session, e.Entity, be.source, since) {
names = append(names, be.lookup(e, fqdn.Name, since)...)
} else {
names = append(names, be.query(e, fqdn.Name, src, keys)...)
support.MarkAssetMonitored(e.Session, e.Asset, src)
names = append(names, be.query(e, fqdn.Name, be.source, keys)...)
support.MarkAssetMonitored(e.Session, e.Entity, be.source)
}

if len(names) > 0 {
be.process(e, names, src)
be.process(e, names)
}
return nil
}

func (be *binaryEdge) lookup(e *et.Event, name string, src *dbt.Entity, since time.Time) []*dbt.Entity {
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), src, since)
func (be *binaryEdge) lookup(e *et.Event, name string, since time.Time) []*dbt.Entity {
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), be.source, since)
}

func (be *binaryEdge) query(e *et.Event, name string, src *et.Source, keys []string) []*dbt.Entity {
Expand Down Expand Up @@ -166,13 +161,13 @@ loop:
}
}

return be.store(e, subs.Slice(), src)
return be.store(e, subs.Slice())
}

func (be *binaryEdge) store(e *et.Event, names []string, src *et.Source) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, src, be.name, be.name+"-Handler")
func (be *binaryEdge) store(e *et.Event, names []string) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, be.source, be.name, be.name+"-Handler")
}

func (be *binaryEdge) process(e *et.Event, assets []*dbt.Entity, src *et.Source) {
support.ProcessFQDNsWithSource(e, assets, src)
func (be *binaryEdge) process(e *et.Event, assets []*dbt.Entity) {
support.ProcessFQDNsWithSource(e, assets, be.source)
}
31 changes: 13 additions & 18 deletions engine/plugins/api/chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,30 @@ func (c *chaos) check(e *et.Event) error {
return nil
}

src := support.GetSource(e.Session, c.source)
if src == nil {
return errors.New("failed to obtain the plugin source information")
}

since, err := support.TTLStartTime(e.Session.Config(), string(oam.FQDN), string(oam.FQDN), c.name)
if err != nil {
return err
}

var names []*dbt.Entity
if support.AssetMonitoredWithinTTL(e.Session, e.Asset, src, since) {
names = append(names, c.lookup(e, fqdn.Name, src, since)...)
if support.AssetMonitoredWithinTTL(e.Session, e.Entity, c.source, since) {
names = append(names, c.lookup(e, fqdn.Name, since)...)
} else {
names = append(names, c.query(e, fqdn.Name, src, keys)...)
support.MarkAssetMonitored(e.Session, e.Asset, src)
names = append(names, c.query(e, fqdn.Name, keys)...)
support.MarkAssetMonitored(e.Session, e.Entity, c.source)
}

if len(names) > 0 {
c.process(e, names, src)
c.process(e, names)
}
return nil
}

func (c *chaos) lookup(e *et.Event, name string, src *dbt.Entity, since time.Time) []*dbt.Entity {
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), src, since)
func (c *chaos) lookup(e *et.Event, name string, since time.Time) []*dbt.Entity {
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), c.source, since)
}

func (c *chaos) query(e *et.Event, name string, src *dbt.Entity, keys []string) []*dbt.Entity {
func (c *chaos) query(e *et.Event, name string, keys []string) []*dbt.Entity {
var names []string

for _, key := range keys {
Expand Down Expand Up @@ -148,13 +143,13 @@ func (c *chaos) query(e *et.Event, name string, src *dbt.Entity, keys []string)
}
}

return c.store(e, names, src)
return c.store(e, names)
}

func (c *chaos) store(e *et.Event, names []string, src *dbt.Entity) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, src, c.name, c.name+"-Handler")
func (c *chaos) store(e *et.Event, names []string) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, c.source, c.name, c.name+"-Handler")
}

func (c *chaos) process(e *et.Event, assets []*dbt.Entity, src *dbt.Entity) {
support.ProcessFQDNsWithSource(e, assets, src)
func (c *chaos) process(e *et.Event, assets []*dbt.Entity) {
support.ProcessFQDNsWithSource(e, assets, c.source)
}
27 changes: 11 additions & 16 deletions engine/plugins/api/crtsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,27 @@ func (c *crtsh) check(e *et.Event) error {
return nil
}

src := support.GetSource(e.Session, c.source)
if src == nil {
return errors.New("failed to obtain the plugin source information")
}

since, err := support.TTLStartTime(e.Session.Config(), string(oam.FQDN), string(oam.FQDN), c.name)
if err != nil {
return err
}

var names []*dbt.Entity
if support.AssetMonitoredWithinTTL(e.Session, e.Asset, src, since) {
names = append(names, c.lookup(e, fqdn.Name, src, since)...)
if support.AssetMonitoredWithinTTL(e.Session, e.Entity, c.source, since) {
names = append(names, c.lookup(e, fqdn.Name, c.source, since)...)
} else {
names = append(names, c.query(e, fqdn.Name, src)...)
support.MarkAssetMonitored(e.Session, e.Asset, src)
names = append(names, c.query(e, fqdn.Name, c.source)...)
support.MarkAssetMonitored(e.Session, e.Entity, c.source)
}

if len(names) > 0 {
c.process(e, names, src)
c.process(e, names)
}
return nil
}

func (c *crtsh) lookup(e *et.Event, name string, src *et.Source, since time.Time) []*dbt.Entity {
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), src, since)
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), c.source, since)
}

func (c *crtsh) query(e *et.Event, name string, src *et.Source) []*dbt.Entity {
Expand Down Expand Up @@ -136,13 +131,13 @@ func (c *crtsh) query(e *et.Event, name string, src *et.Source) []*dbt.Entity {
}
}

return c.store(e, names, src)
return c.store(e, names)
}

func (c *crtsh) store(e *et.Event, names []string, src *et.Source) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, src, c.name, c.name+"-Handler")
func (c *crtsh) store(e *et.Event, names []string) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, c.source, c.name, c.name+"-Handler")
}

func (c *crtsh) process(e *et.Event, assets []*dbt.Entity, src *et.Source) {
support.ProcessFQDNsWithSource(e, assets, src)
func (c *crtsh) process(e *et.Event, assets []*dbt.Entity) {
support.ProcessFQDNsWithSource(e, assets, c.source)
}
27 changes: 11 additions & 16 deletions engine/plugins/api/dnsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,27 @@ func (d *dnsrepo) check(e *et.Event) error {
return nil
}

src := support.GetSource(e.Session, d.source)
if src == nil {
return errors.New("failed to obtain the plugin source information")
}

since, err := support.TTLStartTime(e.Session.Config(), string(oam.FQDN), string(oam.FQDN), d.name)
if err != nil {
return err
}

var names []*dbt.Entity
if support.AssetMonitoredWithinTTL(e.Session, e.Asset, src, since) {
names = append(names, d.lookup(e, fqdn.Name, src, since)...)
if support.AssetMonitoredWithinTTL(e.Session, e.Entity, d.source, since) {
names = append(names, d.lookup(e, fqdn.Name, d.source, since)...)
} else {
names = append(names, d.query(e, fqdn.Name, src, keys)...)
support.MarkAssetMonitored(e.Session, e.Asset, src)
names = append(names, d.query(e, fqdn.Name, d.source, keys)...)
support.MarkAssetMonitored(e.Session, e.Entity, d.source)
}

if len(names) > 0 {
d.process(e, names, src)
d.process(e, names)
}
return nil
}

func (d *dnsrepo) lookup(e *et.Event, name string, src *et.Source, since time.Time) []*dbt.Entity {
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), src, since)
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), d.source, since)
}

func (d *dnsrepo) query(e *et.Event, name string, src *et.Source, keys []string) []*dbt.Entity {
Expand Down Expand Up @@ -146,7 +141,7 @@ func (d *dnsrepo) query(e *et.Event, name string, src *et.Source, keys []string)
}
}

return d.store(e, names, src)
return d.store(e, names)
}

func (d *dnsrepo) parseHTML(e *et.Event, body string) []string {
Expand Down Expand Up @@ -201,10 +196,10 @@ func (d *dnsrepo) parseJSON(e *et.Event, body string) []string {
return set.Slice()
}

func (d *dnsrepo) store(e *et.Event, names []string, src *et.Source) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, src, d.name, d.name+"-Handler")
func (d *dnsrepo) store(e *et.Event, names []string) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, d.source, d.name, d.name+"-Handler")
}

func (d *dnsrepo) process(e *et.Event, assets []*dbt.Entity, src *et.Source) {
support.ProcessFQDNsWithSource(e, assets, src)
func (d *dnsrepo) process(e *et.Event, assets []*dbt.Entity) {
support.ProcessFQDNsWithSource(e, assets, d.source)
}
24 changes: 10 additions & 14 deletions engine/plugins/api/grepapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (g *grepApp) Stop() {
}

func (g *grepApp) check(e *et.Event) error {
fqdn, ok := e.Asset.Asset.(*domain.FQDN)
fqdn, ok := e.Entity.Asset.(*domain.FQDN)
if !ok {
return errors.New("failed to extract the FQDN asset")
}
Expand All @@ -84,31 +84,27 @@ func (g *grepApp) check(e *et.Event) error {
return nil
}

src := support.GetSource(e.Session, g.source)
if src == nil {
return errors.New("failed to obtain the plugin source information")
}

since, err := support.TTLStartTime(e.Session.Config(), string(oam.FQDN), string(oam.EmailAddress), g.name)
if err != nil {
return err
}

var names []*dbt.Entity
if support.AssetMonitoredWithinTTL(e.Session, e.Asset, src, since) {
names = append(names, g.lookup(e, fqdn.Name, src, since)...)
if support.AssetMonitoredWithinTTL(e.Session, e.Entity, g.source, since) {
names = append(names, g.lookup(e, fqdn.Name, g.source, since)...)
} else {
names = append(names, g.query(e, fqdn.Name, src)...)
support.MarkAssetMonitored(e.Session, e.Asset, src)
names = append(names, g.query(e, fqdn.Name, g.source)...)
support.MarkAssetMonitored(e.Session, e.Entity, g.source)
}

if len(names) > 0 {
g.process(e, names, src)
g.process(e, names, g.source)
}
return nil
}
func (g *grepApp) lookup(e *et.Event, name string, src *et.Source, since time.Time) []*dbt.Entity {
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.EmailAddress), src, since)
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.EmailAddress), g.source, since)
}

func (g *grepApp) query(e *et.Event, name string, src *et.Source) []*dbt.Entity {
Expand Down Expand Up @@ -153,13 +149,13 @@ func (g *grepApp) query(e *et.Event, name string, src *et.Source) []*dbt.Entity
}
}

return g.store(e, emails.Slice(), src)
return g.store(e, emails.Slice(), g.source)
}

func (g *grepApp) store(e *et.Event, emails []string, src *et.Source) []*dbt.Entity {
return support.StoreEmailsWithSource(e.Session, emails, src, g.name, g.name+"-Handler")
return support.StoreEmailsWithSource(e.Session, emails, g.source, g.name, g.name+"-Handler")
}

func (g *grepApp) process(e *et.Event, assets []*dbt.Entity, src *et.Source) {
support.ProcessEmailsWithSource(e, assets, src)
support.ProcessEmailsWithSource(e, assets, g.source)
}
29 changes: 12 additions & 17 deletions engine/plugins/api/hackertarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (ht *hackerTarget) Stop() {
}

func (ht *hackerTarget) check(e *et.Event) error {
fqdn, ok := e.Asset.Asset.(*domain.FQDN)
fqdn, ok := e.Entity.Asset.(*domain.FQDN)
if !ok {
return errors.New("failed to extract the FQDN asset")
}
Expand All @@ -80,32 +80,27 @@ func (ht *hackerTarget) check(e *et.Event) error {
return nil
}

src := support.GetSource(e.Session, ht.source)
if src == nil {
return errors.New("failed to obtain the plugin source information")
}

since, err := support.TTLStartTime(e.Session.Config(), string(oam.FQDN), string(oam.FQDN), ht.name)
if err != nil {
return err
}

var names []*dbt.Entity
if support.AssetMonitoredWithinTTL(e.Session, e.Asset, src, since) {
names = append(names, ht.lookup(e, fqdn.Name, src, since)...)
if support.AssetMonitoredWithinTTL(e.Session, e.Entity, ht.source, since) {
names = append(names, ht.lookup(e, fqdn.Name, ht.source, since)...)
} else {
names = append(names, ht.query(e, fqdn.Name, src)...)
support.MarkAssetMonitored(e.Session, e.Asset, src)
names = append(names, ht.query(e, fqdn.Name, ht.source)...)
support.MarkAssetMonitored(e.Session, e.Entity, ht.source)
}

if len(names) > 0 {
ht.process(e, names, src)
ht.process(e, names)
}
return nil
}

func (ht *hackerTarget) lookup(e *et.Event, name string, src *et.Source, since time.Time) []*dbt.Entity {
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), src, since)
return support.SourceToAssetsWithinTTL(e.Session, name, string(oam.FQDN), ht.source, since)
}

func (ht *hackerTarget) query(e *et.Event, name string, src *et.Source) []*dbt.Entity {
Expand All @@ -129,13 +124,13 @@ func (ht *hackerTarget) query(e *et.Event, name string, src *et.Source) []*dbt.E
}
}

return ht.store(e, names, src)
return ht.store(e, names)
}

func (ht *hackerTarget) store(e *et.Event, names []string, src *et.Source) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, src, ht.name, ht.name+"-Handler")
func (ht *hackerTarget) store(e *et.Event, names []string) []*dbt.Entity {
return support.StoreFQDNsWithSource(e.Session, names, ht.source, ht.name, ht.name+"-Handler")
}

func (ht *hackerTarget) process(e *et.Event, assets []*dbt.Entity, src *et.Source) {
support.ProcessFQDNsWithSource(e, assets, src)
func (ht *hackerTarget) process(e *et.Event, assets []*dbt.Entity) {
support.ProcessFQDNsWithSource(e, assets, ht.source)
}
Loading
Loading