-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
102 lines (93 loc) · 2.66 KB
/
Copy pathutil.go
File metadata and controls
102 lines (93 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"os"
"strings"
"time"
)
// now returns the current Unix timestamp in seconds.
func now() int64 {
return time.Now().Unix()
}
// elapsedSeconds computes int(time.time() - start_time) from a Unix ts.
func elapsedSeconds(startUnix int64) int64 {
return time.Now().Unix() - startUnix
}
// readLinesFile reads a text file and returns non-empty trimmed lines.
func readLinesFile(path string) ([]string, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
lines := strings.Split(string(data), "\n")
var result []string
for _, line := range lines {
trimmed := strings.TrimSpace(line)
if trimmed != "" {
result = append(result, trimmed)
}
}
return result, nil
}
// fileExists checks if a path is a regular file.
func fileExists(path string) bool {
info, err := os.Stat(path)
if err != nil {
return false
}
return !info.IsDir()
}
// promptForURLs reads the URL input (file or single URL) with retry.
func promptForURLs(welcomeMsg string) []string {
for {
urlInput := promptFilePath("[?] Enter the path to the input file containing the URLs (or press Enter to input a single URL): ")
if urlInput != "" {
if !fileExists(urlInput) {
fmt.Printf("%s[!] Error reading input file: %s. Exception: File not found: %s%s\n", colorRed, urlInput, urlInput, colorReset)
pausePrompt()
clearScreen()
colorPrintln(colorGreen, welcomeMsg)
continue
}
urls, err := readLinesFile(urlInput)
if err != nil {
fmt.Printf("%s[!] Error reading input file: %s. Exception: %s%s\n", colorRed, urlInput, err, colorReset)
pausePrompt()
clearScreen()
colorPrintln(colorGreen, welcomeMsg)
continue
}
return urls
}
singleURL := promptString(colorCyan + "[?] Enter a single URL to scan: ")
if singleURL != "" {
return []string{singleURL}
}
fmt.Println(colorRed + "[!] You must provide either a file with URLs or a single URL.")
pausePrompt()
clearScreen()
colorPrintln(colorGreen, welcomeMsg)
}
}
// promptForPayloads reads the payload file path with retry.
func promptForPayloads(welcomeMsg string) []string {
for {
path := promptFilePath("[?] Enter the path to the payloads file: ")
if !fileExists(path) {
fmt.Printf("%s[!] Error reading payload file: %s. Exception: File not found: %s%s\n", colorRed, path, path, colorReset)
pausePrompt()
clearScreen()
colorPrintln(colorGreen, welcomeMsg)
continue
}
payloads, err := readLinesFile(path)
if err != nil {
fmt.Printf("%s[!] Error reading payload file: %s. Exception: %s%s\n", colorRed, path, err, colorReset)
pausePrompt()
clearScreen()
colorPrintln(colorGreen, welcomeMsg)
continue
}
return payloads
}
}