diff --git a/README.md b/README.md index 3db9db6..e9c02e4 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ ressrf -h | **`-o`** | `--outdir` | `vulns` | Output directory path for log captures and finding summaries. | | **`-s`** | `--silent` | `false` | Suppress text banners, informational stats, and milestone lines. | | **`-b`** | `--color-blind` | `false` | Strip ANSI terminal color sequences from stdout streams. | +| **`-v`** | `--verbose` | `false` | Show livestream of active connection updates and status codes | ### Operational Examples @@ -106,6 +107,21 @@ Quiet fuzz execution routed to custom output storage destinations: ressrf -l targets.txt -s -o ssrf_audit ``` +You can it pipe with other tools: + +```bash +subfinder -d target.com -all -silent | httpx -silent | katana -silent | gf ssrf | ressrf +``` + +To watch connection status modifications or debugging logs in real-time, add the verbose flag. It streams active network interactions, status codes, and connection failures straight to your terminal screen: + +```bash +cat targets.txt | ressrf -v +``` + +> [!NOTE] +> The silent flag (`-s`) will completely suppress console output. If you want to see live verbose updates on your screen, ensure that you do not pass `-s` in your command chain. + ## Custom Payloads The underlying validation rules utilize embedded engine tracking. Default vectors located at `~/.config/ressrf/payloads.cfg` incorporate structural placeholder tags: diff --git a/lib/header.go b/lib/header.go index b351e6d..8367843 100644 --- a/lib/header.go +++ b/lib/header.go @@ -7,6 +7,11 @@ import ( "github.com/R0X4R/ressrf/pkg" ) +// ExecuteHeaderPhase enqueues header-injection jobs for each target URL and header vector using both payload formats (with and without an HTTP scheme). +// +// For each generated payload an identifier is allocated (incrementing trackCounter) and corresponding metadata is stored in requestTracker. Each job, when executed, will wait on rl, set the specified header to the payload, send the request, and invoke logActivity with either "ERROR" (on send failure) or "SENT" (on success) including the target URL, status code, and a short detail string. +// +// ExecuteHeaderPhase schedules work onto the provided jobs channel and increments wg for each scheduled job; it does not block waiting for job completion. func ExecuteHeaderPhase( urls []string, collab string, @@ -16,7 +21,7 @@ func ExecuteHeaderPhase( trackMutex *sync.Mutex, trackCounter *int, requestTracker map[string]pkg.VulnerabilityMetadata, - logActivity func(string, ...interface{}), + logActivity func(string, string, int, string), ) { for _, rawURL := range urls { for _, header := range pkg.HeadersInject { @@ -47,10 +52,12 @@ func ExecuteHeaderPhase( hdrs[hdrKey] = payloadStr status, _, err := pkg.SendRequest(targetURL, hdrs) if err != nil { - logActivity("REQUEST ERROR - Header Target: %s [%s: %s] | Err: %v", targetURL, hdrKey, payloadStr, err) + + logActivity("ERROR", targetURL, 0, fmt.Sprintf("Header Key [%s] - %s", hdrKey, err.Error())) return } - logActivity("REQUEST SENT - Status: [%d] | Header: [%s: %s] | Target URL: %s", status, hdrKey, payloadStr, targetURL) + + logActivity("SENT", targetURL, status, fmt.Sprintf("Header Vector [%s]", hdrKey)) } }(u, h, p) } diff --git a/lib/parameter.go b/lib/parameter.go index 1893ecf..0d69502 100644 --- a/lib/parameter.go +++ b/lib/parameter.go @@ -7,6 +7,17 @@ import ( "github.com/R0X4R/ressrf/pkg" ) +// ExecuteParameterPhase constructs and enqueues URL-parameter injection test requests for each input URL. +// +// For each URL this function creates two test variants (one with an explicit "http://" scheme and one without), +// reserves a unique tracking id while holding trackMutex, records metadata in requestTracker[id] with InjectType +// "URL Parameter Injection", and increments the provided WaitGroup for each enqueued job. Each job sent to the +// jobs channel waits on rl before issuing the HTTP request and reports results through logActivity: an "ERROR" +// entry with status 0 and the error message on failure, or a "SENT" entry with the response status and the +// message "URL Parameter Phase Vector" on success. +// +// This function does not return a value; it performs side effects on the WaitGroup, trackCounter, requestTracker, +// and by sending closures to the jobs channel. func ExecuteParameterPhase( urls []string, collab string, @@ -16,7 +27,7 @@ func ExecuteParameterPhase( trackMutex *sync.Mutex, trackCounter *int, requestTracker map[string]pkg.VulnerabilityMetadata, - logActivity func(string, ...interface{}), + logActivity func(string, string, int, string), ) { for _, rawURL := range urls { for _, useScheme := range []bool{false, true} { @@ -43,10 +54,10 @@ func ExecuteParameterPhase( rl.Wait() status, _, err := pkg.SendRequest(targetURL, pkg.BaseHeaders()) if err != nil { - logActivity("REQUEST ERROR - URL Param Target: %s | Err: %v", targetURL, err) + logActivity("ERROR", targetURL, 0, err.Error()) return } - logActivity("REQUEST SENT - Status: [%d] | Target URL: %s", status, targetURL) + logActivity("SENT", targetURL, status, "URL Parameter Phase Vector") } }(u) } diff --git a/lib/protocol.go b/lib/protocol.go index b144f37..083e0d1 100644 --- a/lib/protocol.go +++ b/lib/protocol.go @@ -9,13 +9,18 @@ import ( "github.com/fatih/color" ) +// ExecuteProtocolPhase schedules protocol-bypass HTTP request jobs for every combination of the provided URLs and protocol payload templates. +// +// ExecuteProtocolPhase reads payload templates from pkg.PayloadsFile, substitutes `{COLLAB}` and `{COLLAB_URL}` with the provided collab value, and for each resulting payload–URL pair enqueues a job on the provided jobs channel. Each job waits on rl, sends the HTTP request, and reports activity via logActivity. If a request fails it is logged with an "ERROR" activity and not further processed; successful requests are logged as "SENT". When the response body matches pkg.AltProtoRegex the function prints a hit line, appends a findings entry to the file at *pkg.OutDir+"/findings.txt", and logs a vulnerability-identification activity. +// +// If reading pkg.PayloadsFile fails, the function optionally prints a skip message and returns without scheduling any jobs. The function increments wg for each scheduled job and ensures wg.Done() is called when a job completes. func ExecuteProtocolPhase( urls []string, collab string, rl *pkg.RateLimiter, jobs chan<- func(), wg *sync.WaitGroup, - logActivity func(string, ...interface{}), + logActivity func(string, string, int, string), ) { payloads, err := pkg.ReadLines(pkg.PayloadsFile) if err != nil { @@ -36,11 +41,13 @@ func ExecuteProtocolPhase( defer wg.Done() rl.Wait() status, body, err := pkg.SendRequest(targetURL, pkg.BaseHeaders()) + if err != nil { - logActivity("REQUEST ERROR - Alt Proto Target: %s | Err: %v", targetURL, err) + logActivity("ERROR", targetURL, 0, err.Error()) return } - logActivity("REQUEST SENT - Status: [%d] | Alt Proto Payload URL: %s", status, targetURL) + + logActivity("SENT", targetURL, status, "Protocol Bypass Vector") if pkg.AltProtoRegex.MatchString(body) { displayLine := fmt.Sprintf("%s [%s] [%s]", @@ -49,7 +56,8 @@ func ExecuteProtocolPhase( fmt.Println(displayLine) pkg.AppendLine(*pkg.OutDir+"/findings.txt", logStorageLine) - logActivity("VULNERABILITY IDENTIFIED - %s", logStorageLine) + + logActivity("SENT", targetURL, status, "VULNERABILITY IDENTIFIED: ALT-PROTO HIT Local Content Leak") } } }(u) diff --git a/main.go b/main.go index bb9cafb..6efa00e 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "fmt" "os" "os/signal" @@ -17,18 +18,73 @@ import ( "github.com/projectdiscovery/interactsh/pkg/server" ) -func logActivity(format string, args ...interface{}) { +// logActivity writes a timestamped activity entry to the activity.log file and, when verbose and not silent, prints a colored console message. +// For evtType == "ERROR", it records an "UNABLE TO CONNECT" entry including details; otherwise it records a "REQ SENT" entry including status, target, and optional details. +// The console output colorizes the status (green for 2xx, cyan for 3xx, yellow for others) and the log is appended to (*pkg.OutDir)/activity.log. +func logActivity(evtType string, target string, status int, details string) { timestamp := time.Now().Format("2006-01-02 15:04:05") - msg := fmt.Sprintf("[%s] ", timestamp) + fmt.Sprintf(format, args...) + var msg, consoleMsg string + + if evtType == "ERROR" { + msg = fmt.Sprintf("[%s] [UNABLE TO CONNECT] Target: %s | Details: %s", timestamp, target, details) + consoleMsg = fmt.Sprintf("[%s] %s Target: %s", timestamp, color.RedString("[UNABLE TO CONNECT]"), target) + } else { + msg = fmt.Sprintf("[%s] [REQ SENT] Status: [%d] | Target: %s", timestamp, status, target) + if details != "" { + msg += " | " + details + } + + statusStr := fmt.Sprintf("[%d]", status) + if status >= 200 && status < 300 { + statusStr = color.GreenString("[%d]", status) + } else if status >= 300 && status < 400 { + statusStr = color.CyanString("[%d]", status) + } else { + statusStr = color.YellowString("[%d]", status) + } + consoleMsg = fmt.Sprintf("[%s] %s STATUS %s == %s", timestamp, color.BlueString("[REQ SENT]"), statusStr, target) + } + pkg.AppendLine(*pkg.OutDir+"/activity.log", msg) + + if *pkg.Verbose && !*pkg.Silent { + fmt.Println(consoleMsg) + } } +// logCallback appends a timestamped log line, formatted with the provided printf-style +// format and arguments, to the callback.log file in the configured output directory. func logCallback(format string, args ...interface{}) { timestamp := time.Now().Format("2006-01-02 15:04:05") msg := fmt.Sprintf("[%s] ", timestamp) + fmt.Sprintf(format, args...) pkg.AppendLine(*pkg.OutDir+"/callback.log", msg) } +// hasStdinData reports whether standard input has data available (i.e., stdin is not a terminal). +// It returns true when stdin is not a character device, and false if stdin is a terminal or if Stat() fails. +func hasStdinData() bool { + stat, err := os.Stdin.Stat() + if err != nil { + return false + } + return (stat.Mode() & os.ModeCharDevice) == 0 +} + +// main is the program entry point that orchestrates configuration parsing, target collection, +// collaboration session initialization, concurrent scanning phases, out-of-band callback polling, +// and final result reporting. +// +// It parses CLI options and prepares the output directory, sources target URLs from stdin +// when available or from the configured input file, and either starts an Interactsh client +// or normalizes a provided collab server string. It launches worker goroutines, installs an +// interrupt handler that cleans up and logs a termination event, and starts a poller to +// process out-of-band interactions which are recorded to findings and activity logs. +// The function executes header, parameter, and protocol scan phases, waits for completion, +// keeps the session open for a short grace period to collect late callbacks, and then +// prints and stores summarized OOB results. +// +// The function terminates the process on fatal configuration or runtime errors (printing +// an error message before exiting). func main() { _, err := pkg.ParseOptions() if err != nil { @@ -42,17 +98,39 @@ func main() { os.MkdirAll(*pkg.OutDir, 0755) - urls, err := pkg.ReadLines(*pkg.InputFile) - if err != nil || len(urls) == 0 { - fmt.Printf("[-] Cannot read input file or file is empty: %s\n", *pkg.InputFile) - os.Exit(1) + var urls []string + + if hasStdinData() { + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if line != "" { + urls = append(urls, line) + } + } + + if err := scanner.Err(); err != nil { + fmt.Printf("[!] ERROR READING STANDARD INPUT STREAM: %v\n", err) + os.Exit(1) + } + + } else { + if *pkg.InputFile == "" { + fmt.Println("[!] ERROR: No targets provided. Pipeline urls via stdin or specify an input file using -l ") + os.Exit(1) + } + urls, err = pkg.ReadLines(*pkg.InputFile) + if err != nil || len(urls) == 0 { + fmt.Printf("[!] ERROR: Cannot read input file or file is empty: %s\n", *pkg.InputFile) + os.Exit(1) + } } var collab string if *pkg.CollabServer == "" { collab, err = pkg.StartInteractsh() if err != nil { - fmt.Printf("[-] %v\n", err) + fmt.Printf("[!] ERROR: FAILED TO START INTERACTSH CLIENT: %v\n", err) os.Exit(1) } defer pkg.ClientInstance.Close() @@ -87,13 +165,12 @@ func main() { go func() { <-sigChan if !*pkg.Silent { - fmt.Println(color.RedString("\n[!] INTERRUPT SIGNAL RECEIVED! FLUSING LOGS AND SHUTTING DOWN GRACEFULLY...")) + fmt.Println(color.RedString("\n[!] INTERRUPT SIGNAL RECEIVED! FLUSHING LOGS AND SHUTTING DOWN GRACEFULLY...")) } if pkg.ClientInstance != nil { pkg.ClientInstance.Close() } - logActivity("SCAN TERMINATED - User aborted scan via Interrupt signal.") - logCallback("SCAN TERMINATED - User aborted scan via Interrupt signal.") + logActivity("SCAN TERMINATED", "USER ABORTED SCAN VIA INTERRUPT SIGNAL", 0, "") os.Exit(0) }() @@ -128,7 +205,11 @@ func main() { if _, alreadyHit := uniqueHits[logStorageLine]; !alreadyHit { uniqueHits[logStorageLine] = displayLine - fmt.Println(displayLine) + if *pkg.Verbose { + fmt.Print("\n" + displayLine + "\n\n") + } else { + fmt.Println(displayLine) + } pkg.AppendLine(*pkg.OutDir+"/findings.txt", logStorageLine) } } @@ -136,7 +217,7 @@ func main() { hitsMutex.Unlock() }) if err != nil && !*pkg.Silent { - fmt.Printf("[-] FAILED TO LAUNCH LIVE TRANSACTION POLLER: %v\n", err) + fmt.Printf("[!] FAILED TO LAUNCH LIVE TRANSACTION POLLER: %v\n", err) } } diff --git a/pkg/config.go b/pkg/config.go index 81521bc..71de4aa 100644 --- a/pkg/config.go +++ b/pkg/config.go @@ -1,7 +1,7 @@ package pkg import ( - _ "embed" // Required for compile-time asset embedding + _ "embed" "fmt" "os" "path/filepath" @@ -23,6 +23,7 @@ type Options struct { ExtraHeader string Silent bool ColorBlind bool + Verbose bool } type VulnerabilityMetadata struct { @@ -40,6 +41,7 @@ var ( ExtraHeader *string Silent *bool ColorBlind *bool + Verbose *bool PayloadsFile = filepath.Join(os.Getenv("HOME"), ".config", "ressrf", "payloads.cfg") HeadersInject = []string{ @@ -58,7 +60,13 @@ var ( QsReplaceRegex = regexp.MustCompile(`=([^?|&]*)`) ) -// EnsurePayloadsConfig initializes or appends default vectors safely on the host system +// EnsurePayloadsConfig ensures the payloads configuration file exists and contains the embedded default vectors. +// +// If the configured payload file does not exist, it will be created containing the embedded defaults. +// If the file exists, any default vectors not already present will be appended (with a separator) so existing +// user content is preserved. When `silent` is false a brief status message is printed. +// +// Errors are returned for filesystem failures such as directory creation, file reads, or writes. func EnsurePayloadsConfig(silent bool) error { configDir := filepath.Dir(PayloadsFile) @@ -68,9 +76,6 @@ func EnsurePayloadsConfig(silent bool) error { } if _, err := os.Stat(PayloadsFile); os.IsNotExist(err) { - if !silent { - fmt.Printf("[*] First-time initialization: Writing default payloads to %s\n", PayloadsFile) - } return os.WriteFile(PayloadsFile, []byte(strings.TrimSpace(defaultPayloads)+"\n"), 0644) } @@ -96,7 +101,7 @@ func EnsurePayloadsConfig(silent bool) error { if len(linesToAppend) > 0 { if !silent { - fmt.Printf("[*] Syncing workspace: Appending %d new default payloads to %s\n", len(linesToAppend), PayloadsFile) + fmt.Printf("[*] SYNCING WORKSPACE: Appending %d new default payloads to %s\n", len(linesToAppend), PayloadsFile) } f, err := os.OpenFile(PayloadsFile, os.O_APPEND|os.O_WRONLY, 0644) @@ -121,6 +126,11 @@ func EnsurePayloadsConfig(silent bool) error { return nil } +// ParseOptions parses command-line flags into an Options value and initializes package-level option pointers. +// +// It validates the optional InputFile when provided (must exist, must not be a directory, must be non-empty). +// It also ensures the payloads configuration is present by running the sync routine and will return an error if that setup fails. +// Returns the populated *Options on success or a non-nil error if flag parsing, input validation, or config setup fails. func ParseOptions() (*Options, error) { os.Args[0] = "ressrf" @@ -129,7 +139,7 @@ func ParseOptions() (*Options, error) { flagSet.SetDescription(`ReSSRF - An advanced Out-of-Band and In-Band SSRF fuzzing scanner with dynamic request tracking.`) flagSet.CreateGroup("input", "Input Target Options", - flagSet.StringVarP(&options.InputFile, "list", "l", "", "\tInput file containing target URLs (Required)"), + flagSet.StringVarP(&options.InputFile, "list", "l", "", "\tInput file containing target URLs (Optional if using stdin pipeline)"), flagSet.StringVarP(&options.CollabServer, "collab", "c", "", "\tCustom Interactsh/OAST collaboration server domain"), ) @@ -142,6 +152,7 @@ func ParseOptions() (*Options, error) { flagSet.CreateGroup("optimization", "Display Options", flagSet.BoolVarP(&options.Silent, "silent", "s", false, "\tSuppress banner, phase notifications and summary stats"), flagSet.BoolVarP(&options.ColorBlind, "color-blind", "b", false, "\tDisable colored terminal output sequences completely"), + flagSet.BoolVarP(&options.Verbose, "verbose", "v", false, "\tShow livestream of active connection updates and status codes"), ) flagSet.CreateGroup("output", "Output Directories", @@ -152,24 +163,22 @@ func ParseOptions() (*Options, error) { return nil, err } - if options.InputFile == "" { - return nil, fmt.Errorf("[!] RESSRF Error: Input target list file is required. Use -l ") - } - - fileInfo, err := os.Stat(options.InputFile) - if os.IsNotExist(err) { - return nil, fmt.Errorf("[!] RESSRF Error: Specified input file '%s' does not exist", options.InputFile) - } - if fileInfo.IsDir() { - return nil, fmt.Errorf("[!] RESSRF Error: '%s' is a directory, expected a regular file", options.InputFile) - } - if fileInfo.Size() == 0 { - return nil, fmt.Errorf("[!] RESSRF Error: Specified input file '%s' is empty", options.InputFile) + if options.InputFile != "" { + fileInfo, err := os.Stat(options.InputFile) + if os.IsNotExist(err) { + return nil, fmt.Errorf("[!] RESSRF Error: Specified input file '%s' does not exist", options.InputFile) + } + if fileInfo.IsDir() { + return nil, fmt.Errorf("[!] RESSRF Error: '%s' is a directory, expected a regular file", options.InputFile) + } + if fileInfo.Size() == 0 { + return nil, fmt.Errorf("[!] RESSRF Error: Specified input file '%s' is empty", options.InputFile) + } } // Automatically run the sync configuration pipeline seamlessly if err := EnsurePayloadsConfig(options.Silent); err != nil { - return nil, fmt.Errorf("[!] Config Setup Error: %v", err) + return nil, fmt.Errorf("[!] CONFIG SETUP ERROR: %v", err) } InputFile = &options.InputFile @@ -180,6 +189,7 @@ func ParseOptions() (*Options, error) { ExtraHeader = &options.ExtraHeader Silent = &options.Silent ColorBlind = &options.ColorBlind - + Verbose = &options.Verbose + return options, nil } diff --git a/static/image.png b/static/image.png index 74ead41..3fcef4f 100644 Binary files a/static/image.png and b/static/image.png differ