Skip to content

Commit

Permalink
fixed #439 to add filtering to names discovered within ADS scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Jul 28, 2020
1 parent 73d0a96 commit d7d484a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
15 changes: 13 additions & 2 deletions datasrcs/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"regexp"

"github.com/OWASP/Amass/v3/config"
"github.com/OWASP/Amass/v3/eventbus"
Expand Down Expand Up @@ -34,16 +35,26 @@ type Script struct {
asn lua.LValue
resolved lua.LValue
subdomain lua.LValue
// Regexp to match any subdomain name
subre *regexp.Regexp
}

// NewScript returns he object initialized, but not yet started.
func NewScript(script string, sys systems.System) *Script {
s := &Script{sys: sys}
re, err := regexp.Compile(dns.AnySubdomainRegexString())
if err != nil {
return nil
}

s := &Script{
sys: sys,
subre: re,
}
L := s.newLuaState(sys.Config())
s.luaState = L

// Load the script
err := L.DoString(script)
err = L.DoString(script)
if err != nil {
msg := fmt.Sprintf("Script: Failed to load script: %v", err)

Expand Down
27 changes: 17 additions & 10 deletions datasrcs/script_exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,24 @@ func (s *Script) newName(L *lua.LState) int {
}

lv := L.Get(2)
if n, ok := lv.(lua.LString); ok {
name := string(n)
n, ok := lv.(lua.LString)
if !ok {
return 0
}

if domain := cfg.WhichDomain(name); domain != "" {
bus.Publish(requests.NewNameTopic, eventbus.PriorityHigh, &requests.DNSRequest{
Name: cleanName(name),
Domain: domain,
Tag: s.SourceType,
Source: s.String(),
})
}
name := s.subre.FindString(string(n))
if name == "" {
return 0
}
cleaned := cleanName(name)

if domain := cfg.WhichDomain(cleaned); domain != "" {
bus.Publish(requests.NewNameTopic, eventbus.PriorityHigh, &requests.DNSRequest{
Name: cleaned,
Domain: domain,
Tag: s.SourceType,
Source: s.String(),
})
}
return 0
}
Expand Down

0 comments on commit d7d484a

Please sign in to comment.