nuclei/v2/pkg/collaborator/collaborator.go

65 lines
1.5 KiB
Go
Raw Normal View History

2020-10-23 10:13:34 +02:00
package collaborator
import (
"strings"
2020-11-23 21:37:52 +01:00
"sync"
2020-10-23 10:13:34 +02:00
"time"
"github.com/projectdiscovery/collaborator"
)
const (
2020-10-23 12:37:30 +02:00
PollSeconds = 5
2020-10-23 10:13:34 +02:00
DefaultMaxBufferLimit = 150
)
2020-10-23 12:37:30 +02:00
var DefaultPollInterval time.Duration = time.Second * time.Duration(PollSeconds)
2020-10-23 10:13:34 +02:00
var DefaultCollaborator BurpCollaborator = BurpCollaborator{Collab: collaborator.NewBurpCollaborator()}
type BurpCollaborator struct {
2020-11-23 21:37:52 +01:00
sync.RWMutex
2020-10-23 12:37:30 +02:00
options *Options // unused
2020-10-23 10:13:34 +02:00
Collab *collaborator.BurpCollaborator
}
type Options struct {
BIID string
PollInterval time.Duration
MaxBufferLimit int
}
2020-10-23 12:37:30 +02:00
func New(options *Options) *BurpCollaborator {
2020-10-23 10:13:34 +02:00
collab := collaborator.NewBurpCollaborator()
collab.AddBIID(options.BIID)
collab.MaxBufferLimit = options.MaxBufferLimit
2020-10-23 12:37:30 +02:00
return &BurpCollaborator{Collab: collab, options: options}
2020-10-23 10:13:34 +02:00
}
func (b *BurpCollaborator) Poll() {
// if no valid biids were provided just return
if len(b.Collab.BIIDs) > 0 {
go b.Collab.PollEach(DefaultPollInterval)
}
}
2020-11-23 21:37:52 +01:00
func (b *BurpCollaborator) Has(s string) (found bool) {
foundAt := 0
2020-10-23 10:13:34 +02:00
for _, r := range b.Collab.RespBuffer {
2020-10-23 12:37:30 +02:00
for i := 0; i < len(r.Responses); i++ {
2020-11-23 21:37:52 +01:00
// search in dns - http - smtp
b.RLock()
found = strings.Contains(r.Responses[i].Data.RawRequestDecoded, s) || strings.Contains(r.Responses[i].Data.RequestDecoded, s) || strings.Contains(r.Responses[i].Data.MessageDecoded, s)
b.RUnlock()
if found {
b.Lock()
r.Responses = removeMatch(r.Responses, foundAt)
b.Unlock()
break
2020-10-23 10:13:34 +02:00
}
}
}
2020-11-23 21:37:52 +01:00
return
2020-10-23 10:13:34 +02:00
}