Skip to content

Commit

Permalink
Merge pull request #52 from projectdiscovery/40-feature-output-filters
Browse files Browse the repository at this point in the history
Using new dns-only/http-only flags for regular output
  • Loading branch information
ehsandeep authored Jul 23, 2021
2 parents 6073c43 + e4e29da commit 1549bb9
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions cmd/interactsh-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ var (
verbose = flag.Bool("v", false, "Show verbose output")
pollInterval = flag.Int("poll-interval", 5, "Number of seconds between each poll request")
persistent = flag.Bool("persist", false, "Enables persistent interactsh sessions")
dnsOnly = flag.Bool("dns-only", false, "Display only dns requests in verbose output")
httpOnly = flag.Bool("http-only", false, "Display only http requests in verbose output")
dnsOnly = flag.Bool("dns-only", false, "Display dns interactions")
httpOnly = flag.Bool("http-only", false, "Display http interactions")
smtpOnly = flag.Bool("smtp-only", false, "Display smtp interactions")
)

const banner = `
Expand Down Expand Up @@ -69,32 +70,39 @@ func main() {
gologger.Info().Msgf("%s\n", client.URL())
}

// show all interactions
noFilter := !*dnsOnly && !*httpOnly && !*smtpOnly

client.StartPolling(time.Duration(*pollInterval)*time.Second, func(interaction *server.Interaction) {
if !*json {
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")))
if *verbose && !*httpOnly {
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))
if noFilter || *dnsOnly {
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")))
if *verbose {
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))
}
writeOutput(outputFile, builder)
}
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")))
if *verbose && !*dnsOnly {
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))
if noFilter || *httpOnly {
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")))
if *verbose {
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))
}
writeOutput(outputFile, builder)
}
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")))
if *verbose {
builder.WriteString(fmt.Sprintf("\n------------\nSMTP Interaction\n------------\n\n%s\n\n", interaction.RawRequest))
if noFilter || *smtpOnly {
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")))
if *verbose {
builder.WriteString(fmt.Sprintf("\n------------\nSMTP Interaction\n------------\n\n%s\n\n", interaction.RawRequest))
}
writeOutput(outputFile, builder)
}
}
if outputFile != nil {
_, _ = outputFile.Write(builder.Bytes())
_, _ = outputFile.Write([]byte("\n"))
}
gologger.Silent().Msgf("%s", builder.String())
} else {
b, err := jsonpkg.MarshalIndent(interaction, "", "\t")
if err != nil {
Expand All @@ -118,3 +126,11 @@ func main() {
os.Exit(1)
}
}

func writeOutput(outputFile *os.File, builder *bytes.Buffer) {
if outputFile != nil {
_, _ = outputFile.Write(builder.Bytes())
_, _ = outputFile.Write([]byte("\n"))
}
gologger.Silent().Msgf("%s", builder.String())
}

0 comments on commit 1549bb9

Please sign in to comment.