forked from S4NJ4Y-KUMAR/Go-Thr0ugh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.go
94 lines (83 loc) · 2.37 KB
/
input.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
92
93
94
package main
import (
"fmt"
"html/template"
"net/http"
)
var users = map[string]string{
"Sanjay": "Sanjaypass",
"Jei": "Jeipass",
"Sugash": "Sugashpass",
}
func main() {
http.HandleFunc("/", indexHandler)
http.HandleFunc("/login", loginHandler)
http.HandleFunc("/welcome", welcomeHandler)
http.ListenAndServe(":8080", nil)
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Welcome to the vulnerable web app!<br>")
fmt.Fprint(w, `<a href="/login">Login</a>`)
}
func loginHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost {
username := r.FormValue("username")
password := r.FormValue("password")
// Simulate SQL Injection (Vulnerable Code)
query := fmt.Sprintf("SELECT * FROM users WHERE username='%s' AND password='%s'", username, password)
fmt.Println("Executing SQL Query:", query)
// Authenticate user
if storedPassword, ok := users[username]; ok && storedPassword == password {
fmt.Fprintf(w, "Welcome, %s!<br>", username)
// Simulate XSS (Vulnerable Code)
fmt.Fprintf(w, "Your password is: %s<br>", password)
fmt.Fprint(w, "Logout: <a href='/'>Logout</a>")
} else {
fmt.Fprint(w, "Invalid login. <a href='/login'>Try again</a>")
}
} else {
loginTemplate.Execute(w, nil)
}
}
func welcomeHandler(w http.ResponseWriter, r *http.Request) {
// Simulate CSRF (Vulnerable Code)
if r.Method == http.MethodPost {
fmt.Fprint(w, "Money transferred successfully!")
} else {
welcomeTemplate.Execute(w, nil)
}
}
var loginTemplate = template.Must(template.New("").Parse(`
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form method="post">
<label for="username">Username:</label>
<input type="text" name="username"><br>
<label for="password">Password:</label>
<input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
`))
var welcomeTemplate = template.Must(template.New("").Parse(`
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome to the vulnerable web app!</h1>
<form method="post" action="/welcome">
<input type="hidden" name="amount" value="1000">
<input type="hidden" name="to" value="attacker">
<input type="submit" value="Transfer Money">
</form>
</body>
</html>
`))