@@ -21,12 +21,35 @@ package cmd
2121
2222import (
2323 "os"
24+ "strings"
2425
2526 "github.com/Chocapikk/wpprobe/internal/scanner"
2627 "github.com/Chocapikk/wpprobe/internal/utils"
2728 "github.com/spf13/cobra"
2829)
2930
31+ func getProxyFromEnv () (string , string ) {
32+ if v := firstNonEmpty (os .Getenv ("HTTPS_PROXY" ), os .Getenv ("https_proxy" )); v != "" {
33+ return v , "HTTPS_PROXY"
34+ }
35+ if v := firstNonEmpty (os .Getenv ("HTTP_PROXY" ), os .Getenv ("http_proxy" )); v != "" {
36+ return v , "HTTP_PROXY"
37+ }
38+ if v := firstNonEmpty (os .Getenv ("ALL_PROXY" ), os .Getenv ("all_proxy" )); v != "" {
39+ return v , "ALL_PROXY"
40+ }
41+ return "" , ""
42+ }
43+
44+ func firstNonEmpty (vals ... string ) string {
45+ for _ , v := range vals {
46+ if strings .TrimSpace (v ) != "" {
47+ return v
48+ }
49+ }
50+ return ""
51+ }
52+
3053var scanCmd = & cobra.Command {
3154 Use : "scan" ,
3255 Short : "Scan a WordPress site for installed plugins and vulnerabilities" ,
@@ -37,6 +60,25 @@ var scanCmd = &cobra.Command{
3760
3861 headers , _ := cmd .Flags ().GetStringArray ("header" )
3962
63+ proxyURL := cmd .Flag ("proxy" ).Value .String ()
64+
65+ if strings .TrimSpace (proxyURL ) != "" {
66+ utils .DefaultLogger .Info ("Using given proxy: " + proxyURL )
67+ } else {
68+ utils .DefaultLogger .Info ("No proxy URL provided, checking environment variables" )
69+ if envProxy , from := getProxyFromEnv (); envProxy != "" {
70+ proxyURL = envProxy
71+ utils .DefaultLogger .Info ("Using proxy from " + from + ": " + proxyURL )
72+ } else {
73+ noProxy := firstNonEmpty (os .Getenv ("NO_PROXY" ), os .Getenv ("no_proxy" ))
74+ if noProxy != "" {
75+ utils .DefaultLogger .Info ("No explicit proxy; NO_PROXY is set: " + noProxy )
76+ } else {
77+ utils .DefaultLogger .Info ("No proxy configured; using direct connection" )
78+ }
79+ }
80+ }
81+
4082 opts := scanner.ScanOptions {
4183 URL : cmd .Flag ("url" ).Value .String (),
4284 File : cmd .Flag ("file" ).Value .String (),
@@ -48,6 +90,7 @@ var scanCmd = &cobra.Command{
4890 ScanMode : cmd .Flag ("mode" ).Value .String (),
4991 PluginList : cmd .Flag ("plugin-list" ).Value .String (),
5092 Headers : headers ,
93+ Proxy : proxyURL ,
5194 }
5295
5396 if opts .URL == "" && opts .File == "" {
@@ -71,6 +114,7 @@ func init() {
71114 StringP ("plugin-list" , "p" , "" , "Path to a custom plugin list file for bruteforce mode" )
72115 scanCmd .Flags ().
73116 StringArrayP ("header" , "H" , []string {}, "HTTP header to include in requests. Can be specified multiple times." )
117+ scanCmd .Flags ().String ("proxy" , "" , "HTTP/HTTPS proxy URL (e.g., http://127.0.0.1:8080)" )
74118}
75119
76120func mustBool (value bool , err error ) bool {
0 commit comments