Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using new dns-only/http-only flags for regular output #52

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
}