Skip to content

Commit

Permalink
started on feature request #5 by adding job control support
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Aug 31, 2018
1 parent 74782da commit ff833c0
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 61 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -4,7 +4,7 @@ Thank you for considering making contributions to Amass! Start by taking a look

Please follow standard github best practices: fork the repo, branch from the tip of develop, make some commits, and submit a pull request to develop.

Please make sure to use `gofmt` before every commit - the easiest way to do this is have your editor run it for you upon saving a file.
Please make sure to use `gofmt` before every commit - the easiest way to do this is have your editor run it for you upon saving a file. Otherwise, run the following command in the project root directory: `go fmt ./...`

## Forking

Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -46,6 +46,11 @@ If you would like snap to get you the latest unstable build of OWASP Amass, type
$ sudo snap install --edge amass
```

Periodically, execute the following command to update all your snap packages:
```
$ sudo snap refresh
```

#### From Source

If you would prefer to build your own binary from the latest version of the source code, make sure you have a correctly configured **Go >= 1.10** environment. More information about how to achieve this can be found [on the golang website.](https://golang.org/doc/install) Then, take the following steps:
Expand Down
14 changes: 13 additions & 1 deletion amass/alteration.go
Expand Up @@ -34,6 +34,14 @@ func (as *AlterationService) OnStart() error {
return nil
}

func (as *AlterationService) OnPause() error {
return nil
}

func (as *AlterationService) OnResume() error {
return nil
}

func (as *AlterationService) OnStop() error {
as.BaseAmassService.OnStop()

Expand All @@ -43,16 +51,20 @@ func (as *AlterationService) OnStop() error {

func (as *AlterationService) processRequests() {
t := time.NewTicker(as.Config().Frequency)
defer t.Stop()
loop:
for {
select {
case <-t.C:
go as.executeAlterations()
case <-as.PauseChan():
t.Stop()
case <-as.ResumeChan():
t = time.NewTicker(as.Config().Frequency)
case <-as.Quit():
break loop
}
}
t.Stop()
}

// executeAlterations - Runs all the DNS name alteration methods as goroutines
Expand Down
66 changes: 50 additions & 16 deletions amass/amass.go
Expand Up @@ -40,7 +40,7 @@ var Banner string = `
`

const (
Version = "v2.6.1"
Version = "v2.6.2"
Author = "Jeff Foley (@jeff_foley)"

DefaultFrequency = 10 * time.Millisecond
Expand Down Expand Up @@ -123,6 +123,13 @@ type Enumeration struct {

// The root domain names that the enumeration will target
domains []string

// Pause/Resume channels for halting the enumeration
pause chan struct{}
resume chan struct{}

// Broadcast channel that indicates no further writes to the output channel
done chan struct{}
}

func NewEnumeration() *Enumeration {
Expand All @@ -134,6 +141,9 @@ func NewEnumeration() *Enumeration {
Alterations: true,
Frequency: 10 * time.Millisecond,
MinForRecursive: 1,
pause: make(chan struct{}),
resume: make(chan struct{}),
done: make(chan struct{}),
}
}

Expand Down Expand Up @@ -234,37 +244,61 @@ func (e *Enumeration) Start() error {
if data != nil {
e.Graph = data.Graph
}

// Periodically check if all the services have finished
t := time.NewTicker(1 * time.Second)
defer t.Stop()
for range t.C {
done := true

for _, service := range services {
if service.IsActive() {
done = false
break
t := time.NewTicker(time.Second)
loop:
for {
select {
case <-e.pause:
t.Stop()
case <-e.resume:
t = time.NewTicker(time.Second)
case <-t.C:
done := true

for _, service := range services {
if service.IsActive() {
done = false
break
}
}
}

if done {
break
if done {
break loop
}
}

}
t.Stop()
// Stop all the services
for _, service := range services {
service.Stop()
}

// Wait for output to finish being handled
bus.Unsubscribe(core.OUTPUT, e.sendOutput)
bus.WaitAsync()
close(e.done)
time.Sleep(2 * time.Second)
close(e.Output)
return nil
}

func (e *Enumeration) Pause() {
e.pause <- struct{}{}
}

func (e *Enumeration) Resume() {
e.resume <- struct{}{}
}

func (e *Enumeration) sendOutput(out *AmassOutput) {
e.Output <- out
// Check if the output channel has been closed
select {
case <-e.done:
return
default:
e.Output <- out
}
}

func (e *Enumeration) WriteVisjsFile(path string) {
Expand Down
14 changes: 13 additions & 1 deletion amass/brute.go
Expand Up @@ -39,6 +39,14 @@ func (bfs *BruteForceService) OnStart() error {
return nil
}

func (bfs *BruteForceService) OnPause() error {
return nil
}

func (bfs *BruteForceService) OnResume() error {
return nil
}

func (bfs *BruteForceService) OnStop() error {
bfs.BaseAmassService.OnStop()

Expand All @@ -48,16 +56,20 @@ func (bfs *BruteForceService) OnStop() error {

func (bfs *BruteForceService) processRequests() {
t := time.NewTicker(bfs.Config().Frequency)
defer t.Stop()
loop:
for {
select {
case <-t.C:
go bfs.checkForNewSubdomain()
case <-bfs.PauseChan():
t.Stop()
case <-bfs.ResumeChan():
t = time.NewTicker(bfs.Config().Frequency)
case <-bfs.Quit():
break loop
}
}
t.Stop()
}

// Returns true if the subdomain name is a duplicate entry in the filter.
Expand Down
40 changes: 40 additions & 0 deletions amass/core/service.go
Expand Up @@ -17,6 +17,14 @@ type AmassService interface {
// OPSEC for the service
List() string

// Pause the service
Pause() error
OnPause() error

// Resume the service
Resume() error
OnResume() error

// Stop the service
Stop() error
OnStop() error
Expand All @@ -27,6 +35,10 @@ type AmassService interface {
IsActive() bool
SetActive()

// Returns channels that fire during Pause/Resume operations
PauseChan() <-chan struct{}
ResumeChan() <-chan struct{}

// Returns a channel that is closed when the service is stopped
Quit() <-chan struct{}

Expand All @@ -41,6 +53,8 @@ type BaseAmassService struct {
stopped bool
queue []*AmassRequest
active time.Time
pause chan struct{}
resume chan struct{}
quit chan struct{}
config *AmassConfig

Expand All @@ -52,6 +66,8 @@ func NewBaseAmassService(name string, config *AmassConfig, service AmassService)
return &BaseAmassService{
name: name,
queue: make([]*AmassRequest, 0, 50),
pause: make(chan struct{}),
resume: make(chan struct{}),
quit: make(chan struct{}),
config: config,
service: service,
Expand All @@ -75,6 +91,22 @@ func (bas *BaseAmassService) List() string {
return "N/A"
}

func (bas *BaseAmassService) Pause() error {
return bas.service.OnPause()
}

func (bas *BaseAmassService) OnPause() error {
return nil
}

func (bas *BaseAmassService) Resume() error {
return bas.service.OnResume()
}

func (bas *BaseAmassService) OnResume() error {
return nil
}

func (bas *BaseAmassService) Stop() error {
if bas.IsStopped() {
return errors.New(bas.name + " service has already been stopped")
Expand Down Expand Up @@ -141,6 +173,14 @@ func (bas *BaseAmassService) SetActive() {
bas.active = time.Now()
}

func (bas *BaseAmassService) PauseChan() <-chan struct{} {
return bas.pause
}

func (bas *BaseAmassService) ResumeChan() <-chan struct{} {
return bas.resume
}

func (bas *BaseAmassService) Quit() <-chan struct{} {
return bas.quit
}
Expand Down
20 changes: 18 additions & 2 deletions amass/datamgmtsrv.go
Expand Up @@ -59,6 +59,14 @@ func (dms *DataManagerService) OnStart() error {
return nil
}

func (dms *DataManagerService) OnPause() error {
return nil
}

func (dms *DataManagerService) OnResume() error {
return nil
}

func (dms *DataManagerService) OnStop() error {
dms.BaseAmassService.OnStop()

Expand All @@ -72,32 +80,40 @@ func (dms *DataManagerService) OnStop() error {

func (dms *DataManagerService) processRequests() {
t := time.NewTicker(dms.Config().Frequency)
defer t.Stop()
loop:
for {
select {
case <-t.C:
dms.manageData()
case <-dms.PauseChan():
t.Stop()
case <-dms.ResumeChan():
t = time.NewTicker(dms.Config().Frequency)
case <-dms.Quit():
break loop
}
}
t.Stop()
}

func (dms *DataManagerService) processOutput() {
t := time.NewTicker(2 * time.Second)
defer t.Stop()
loop:
for {
select {
case <-t.C:
if dms.NumOfRequests() < 25 {
dms.discoverOutput()
}
case <-dms.PauseChan():
t.Stop()
case <-dms.ResumeChan():
t = time.NewTicker(dms.Config().Frequency)
case <-dms.Quit():
break loop
}
}
t.Stop()
dms.discoverOutput()
}

Expand Down
14 changes: 13 additions & 1 deletion amass/dnssrv/dnssrv.go
Expand Up @@ -62,6 +62,14 @@ func (ds *DNSService) OnStart() error {
return nil
}

func (ds *DNSService) OnPause() error {
return nil
}

func (ds *DNSService) OnResume() error {
return nil
}

func (ds *DNSService) OnStop() error {
ds.BaseAmassService.OnStop()

Expand All @@ -71,16 +79,20 @@ func (ds *DNSService) OnStop() error {

func (ds *DNSService) processRequests() {
t := time.NewTicker(ds.Config().Frequency)
defer t.Stop()
loop:
for {
select {
case <-t.C:
ds.performRequest()
case <-ds.PauseChan():
t.Stop()
case <-ds.ResumeChan():
t = time.NewTicker(ds.Config().Frequency)
case <-ds.Quit():
break loop
}
}
t.Stop()
}

func (ds *DNSService) duplicate(name string) bool {
Expand Down

0 comments on commit ff833c0

Please sign in to comment.