mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-01-31 15:53:10 +08:00
Added debug-req/resp support for interactsh interactions (#1491)
* Added debug-req/resp support for interactsh interactions * Added format function for interact debug logs + misc fixes * Added function for interact debug header * Typo fix * Enable debug logging for req/resp debug flag
This commit is contained in:
@@ -152,7 +152,7 @@ func configureOutput(options *types.Options) {
|
||||
if options.Verbose || options.Validate {
|
||||
gologger.DefaultLogger.SetMaxLevel(levels.LevelVerbose)
|
||||
}
|
||||
if options.Debug {
|
||||
if options.Debug || options.DebugRequests || options.DebugResponse {
|
||||
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
|
||||
}
|
||||
if options.NoColor {
|
||||
|
||||
@@ -183,6 +183,9 @@ func New(options *types.Options) (*Runner, error) {
|
||||
opts.PollDuration = time.Duration(options.InteractionsPollDuration) * time.Second
|
||||
opts.NoInteractsh = runner.options.NoInteractsh
|
||||
opts.StopAtFirstMatch = runner.options.StopAtFirstMatch
|
||||
opts.Debug = runner.options.Debug
|
||||
opts.DebugRequest = runner.options.DebugRequests
|
||||
opts.DebugResponse = runner.options.DebugResponse
|
||||
interactshClient, err := interactsh.New(opts)
|
||||
if err != nil {
|
||||
gologger.Error().Msgf("Could not create interactsh client: %s", err)
|
||||
|
||||
@@ -75,7 +75,9 @@ type Options struct {
|
||||
// Progress is the nuclei progress bar implementation.
|
||||
Progress progress.Progress
|
||||
// Debug specifies whether debugging output should be shown for interactsh-client
|
||||
Debug bool
|
||||
Debug bool
|
||||
DebugRequest bool
|
||||
DebugResponse bool
|
||||
// DisableHttpFallback controls http retry in case of https failure for server url
|
||||
DisableHttpFallback bool
|
||||
// NoInteractsh disables the engine
|
||||
@@ -146,8 +148,8 @@ func (c *Client) firstTimeInitializeClient() error {
|
||||
c.hostname = interactDomain
|
||||
|
||||
interactsh.StartPolling(c.pollDuration, func(interaction *server.Interaction) {
|
||||
if c.options.Debug {
|
||||
debugPrintInteraction(interaction)
|
||||
if c.options.Debug || c.options.DebugRequest || c.options.DebugResponse {
|
||||
c.debugPrintInteraction(interaction)
|
||||
}
|
||||
item := c.requests.Get(interaction.UniqueID)
|
||||
|
||||
@@ -343,26 +345,48 @@ func HasMatchers(op *operators.Operators) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func debugPrintInteraction(interaction *server.Interaction) {
|
||||
func (c *Client) debugPrintInteraction(interaction *server.Interaction) {
|
||||
builder := &bytes.Buffer{}
|
||||
|
||||
switch interaction.Protocol {
|
||||
case "dns":
|
||||
builder.WriteString(fmt.Sprintf("[%s] Received DNS interaction (%s) from %s at %s", interaction.FullId, interaction.QType, interaction.RemoteAddress, interaction.Timestamp.Format("2006-01-02 15:04:05")))
|
||||
builder.WriteString(fmt.Sprintf("\n-----------\nDNS Request\n-----------\n\n%s\n\n------------\nDNS Response\n------------\n\n%s\n\n", interaction.RawRequest, interaction.RawResponse))
|
||||
builder.WriteString(formatInteractionHeader("DNS", interaction.FullId, interaction.RemoteAddress, interaction.Timestamp))
|
||||
if c.options.DebugRequest || c.options.Debug {
|
||||
builder.WriteString(formatInteractionMessage("DNS Request", interaction.RawRequest))
|
||||
}
|
||||
if c.options.DebugResponse || c.options.Debug {
|
||||
builder.WriteString(formatInteractionMessage("DNS Response", interaction.RawResponse))
|
||||
}
|
||||
case "http":
|
||||
builder.WriteString(fmt.Sprintf("[%s] Received HTTP interaction from %s at %s", interaction.FullId, interaction.RemoteAddress, interaction.Timestamp.Format("2006-01-02 15:04:05")))
|
||||
builder.WriteString(fmt.Sprintf("\n------------\nHTTP Request\n------------\n\n%s\n\n-------------\nHTTP Response\n-------------\n\n%s\n\n", interaction.RawRequest, interaction.RawResponse))
|
||||
builder.WriteString(formatInteractionHeader("HTTP", interaction.FullId, interaction.RemoteAddress, interaction.Timestamp))
|
||||
if c.options.DebugRequest || c.options.Debug {
|
||||
builder.WriteString(formatInteractionMessage("HTTP Request", interaction.RawRequest))
|
||||
}
|
||||
if c.options.DebugResponse || c.options.Debug {
|
||||
builder.WriteString(formatInteractionMessage("HTTP Response", interaction.RawResponse))
|
||||
}
|
||||
case "smtp":
|
||||
builder.WriteString(fmt.Sprintf("[%s] Received SMTP interaction from %s at %s", interaction.FullId, interaction.RemoteAddress, interaction.Timestamp.Format("2006-01-02 15:04:05")))
|
||||
builder.WriteString(fmt.Sprintf("\n------------\nSMTP Interaction\n------------\n\n%s\n\n", interaction.RawRequest))
|
||||
builder.WriteString(formatInteractionHeader("SMTP", interaction.FullId, interaction.RemoteAddress, interaction.Timestamp))
|
||||
if c.options.DebugRequest || c.options.Debug || c.options.DebugResponse {
|
||||
builder.WriteString(formatInteractionMessage("SMTP Interaction", interaction.RawRequest))
|
||||
}
|
||||
case "ldap":
|
||||
builder.WriteString(fmt.Sprintf("[%s] Received LDAP interaction from %s at %s", interaction.FullId, interaction.RemoteAddress, interaction.Timestamp.Format("2006-01-02 15:04:05")))
|
||||
builder.WriteString(fmt.Sprintf("\n------------\nLDAP Interaction\n------------\n\n%s\n\n", interaction.RawRequest))
|
||||
builder.WriteString(formatInteractionHeader("LDAP", interaction.FullId, interaction.RemoteAddress, interaction.Timestamp))
|
||||
if c.options.DebugRequest || c.options.Debug || c.options.DebugResponse {
|
||||
builder.WriteString(formatInteractionMessage("LDAP Interaction", interaction.RawRequest))
|
||||
}
|
||||
}
|
||||
fmt.Fprint(os.Stderr, builder.String())
|
||||
}
|
||||
|
||||
func formatInteractionHeader(protocol, ID, address string, at time.Time) string {
|
||||
return fmt.Sprintf("[%s] Received %s interaction from %s at %s", ID, protocol, address, at.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
|
||||
func formatInteractionMessage(key, value string) string {
|
||||
return fmt.Sprintf("\n------------\n%s\n------------\n\n%s\n\n", key, value)
|
||||
}
|
||||
|
||||
func hash(templateID, host string) string {
|
||||
h := sha1.New()
|
||||
h.Write([]byte(templateID))
|
||||
|
||||
Reference in New Issue
Block a user