Scan4all provides a powerful and extensible scanning engine that allows you to create custom scan modules. The engine uses an event-driven architecture with a worker pool for efficient concurrent scanning.
The main engine object is defined in engine/engineImp.go:18:
type Engine struct { Context *context.Context // Execution context Wg *sync.WaitGroup // Wait group for goroutines Pool int // Thread pool size PoolFunc *ants.PoolWithFunc // Worker pool function EventData chan *models.EventData // Event data queue caseScanFunc sync.Map // Registered scan functions}
To create a custom scan module, you need to register it with the engine using the factory pattern:
import ( "github.com/GhostTroops/scan4all/lib/goSqlite_gorm/lib/scan/Const" "github.com/GhostTroops/scan4all/lib/goSqlite_gorm/pkg/models" "github.com/GhostTroops/scan4all/lib/util")func init() { util.RegInitFunc(func() { // Register your scan function with a unique scan type util.EngineFuncFactory(Const.ScanType_YourModule, func(evt *models.EventData, args ...interface{}) { // Your scan logic here performCustomScan(evt) }) })}
Create your scanning function that processes the event data:
func performCustomScan(evt *models.EventData) { // Get the target URL from the event targetURL := evt.Task.ScanWeb // Perform your custom scanning logic results := doYourScan(targetURL) // Send results back to the engine util.SendEngineLog(evt, Const.ScanType_YourModule, results)}func doYourScan(url string) []string { var findings []string // Your custom scan implementation // Example: Check for specific vulnerabilities if checkVulnerability(url) { findings = append(findings, "vulnerability-found") } return findings}