fix panic in interactsh process interaction ( nil check on compiled operators) (#4511)

* nil check

* misc updates

---------

Co-authored-by: Tarun Koyalwar <tarun@projectdiscovery.io>
dev
Dogan Can Bakir 2024-01-13 00:54:52 +03:00 committed by GitHub
parent 39d25c3d4f
commit 76f7c0c903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -151,6 +151,13 @@ func requestShouldStopAtFirstMatch(request *RequestData) bool {
// processInteractionForRequest processes an interaction for a request // processInteractionForRequest processes an interaction for a request
func (c *Client) processInteractionForRequest(interaction *server.Interaction, data *RequestData) bool { func (c *Client) processInteractionForRequest(interaction *server.Interaction, data *RequestData) bool {
var result *operators.Result
var matched bool
defer func() {
if r := recover(); r != nil {
gologger.Error().Msgf("panic occurred while processing interaction with result=%v matched=%v err=%v", result, matched, r)
}
}()
data.Event.Lock() data.Event.Lock()
data.Event.InternalEvent["interactsh_protocol"] = interaction.Protocol data.Event.InternalEvent["interactsh_protocol"] = interaction.Protocol
data.Event.InternalEvent["interactsh_request"] = interaction.RawRequest data.Event.InternalEvent["interactsh_request"] = interaction.RawRequest
@ -158,7 +165,16 @@ func (c *Client) processInteractionForRequest(interaction *server.Interaction, d
data.Event.InternalEvent["interactsh_ip"] = interaction.RemoteAddress data.Event.InternalEvent["interactsh_ip"] = interaction.RemoteAddress
data.Event.Unlock() data.Event.Unlock()
result, matched := data.Operators.Execute(data.Event.InternalEvent, data.MatchFunc, data.ExtractFunc, c.options.Debug || c.options.DebugRequest || c.options.DebugResponse) if data.Operators != nil {
result, matched = data.Operators.Execute(data.Event.InternalEvent, data.MatchFunc, data.ExtractFunc, c.options.Debug || c.options.DebugRequest || c.options.DebugResponse)
} else {
// this is most likely a bug so error instead of warning
var templateID string
if data.Event.InternalEvent != nil {
templateID = fmt.Sprint(data.Event.InternalEvent[templateIdAttribute])
}
gologger.Error().Msgf("missing compiled operators for '%v' template", templateID)
}
// for more context in github actions // for more context in github actions
if strings.EqualFold(os.Getenv("GITHUB_ACTIONS"), "true") && c.options.Debug { if strings.EqualFold(os.Getenv("GITHUB_ACTIONS"), "true") && c.options.Debug {