lifedebugger commited on
Commit
0399646
·
verified ·
1 Parent(s): ef44f53

Update main.go

Browse files
Files changed (1) hide show
  1. main.go +5 -11
main.go CHANGED
@@ -86,24 +86,19 @@ func main() {
86
  username := r.FormValue("username")
87
  password := r.FormValue("password")
88
 
89
- // --- CHALLENGE PART 1: HEADER CHECK ---
90
- // The student must read the code to realize they need to change their User-Agent.
91
  ua := r.Header.Get("User-Agent")
92
  if ua != "Secure-CTF-Browser/1.0" {
93
  http.Error(w, "Security Alert: Browser not authorized. Please use 'Secure-CTF-Browser/1.0'", http.StatusForbidden)
94
  return
95
  }
96
 
97
- // --- CHALLENGE PART 2: THE TRAP ---
98
- // We explicitly block "admin" to prevent simple brute forcing.
99
- // They must use SQL injection to select the admin row *without* sending "admin" as the username string.
100
  if username == "admin" {
101
  http.Error(w, "Direct login as 'admin' is disabled for security reasons.", http.StatusForbidden)
102
  return
103
  }
104
 
105
- // --- CHALLENGE PART 3: THE WAF (Input Filtering) ---
106
- // We block spaces. The student must use SQL comments (/**/) or tabs to bypass this.
107
  if strings.Contains(username, " ") || strings.Contains(password, " ") {
108
  http.Error(w, "WAF Detection: Spaces are not allowed in input fields.", http.StatusBadRequest)
109
  return
@@ -117,14 +112,13 @@ func main() {
117
  }
118
  defer db.Close()
119
 
120
- // --- THE VULNERABILITY ---
121
- // Still using fmt.Sprintf, but now the input is heavily restricted by the checks above.
122
  query := fmt.Sprintf("SELECT id, username, flag FROM users WHERE username = '%s' AND password = '%s'", username, password)
123
 
124
  log.Printf("Executing Query: %s\n", query)
125
 
126
  var user User
127
- // QueryRow returns the first matching row. If they inject ' OR '1'='1, it will return the first user in the DB (Admin).
128
  err = db.QueryRow(query).Scan(&user.ID, &user.Username, &user.Flag)
129
 
130
  if err != nil {
@@ -137,7 +131,7 @@ func main() {
137
  return
138
  }
139
 
140
- // Success
141
  w.WriteHeader(http.StatusOK)
142
  fmt.Fprintf(w, `
143
  <div style="font-family: monospace; background: #111; color: #4ade80; padding: 20px; text-align: center;">
 
86
  username := r.FormValue("username")
87
  password := r.FormValue("password")
88
 
89
+
 
90
  ua := r.Header.Get("User-Agent")
91
  if ua != "Secure-CTF-Browser/1.0" {
92
  http.Error(w, "Security Alert: Browser not authorized. Please use 'Secure-CTF-Browser/1.0'", http.StatusForbidden)
93
  return
94
  }
95
 
96
+
 
 
97
  if username == "admin" {
98
  http.Error(w, "Direct login as 'admin' is disabled for security reasons.", http.StatusForbidden)
99
  return
100
  }
101
 
 
 
102
  if strings.Contains(username, " ") || strings.Contains(password, " ") {
103
  http.Error(w, "WAF Detection: Spaces are not allowed in input fields.", http.StatusBadRequest)
104
  return
 
112
  }
113
  defer db.Close()
114
 
115
+
 
116
  query := fmt.Sprintf("SELECT id, username, flag FROM users WHERE username = '%s' AND password = '%s'", username, password)
117
 
118
  log.Printf("Executing Query: %s\n", query)
119
 
120
  var user User
121
+
122
  err = db.QueryRow(query).Scan(&user.ID, &user.Username, &user.Flag)
123
 
124
  if err != nil {
 
131
  return
132
  }
133
 
134
+
135
  w.WriteHeader(http.StatusOK)
136
  fmt.Fprintf(w, `
137
  <div style="font-family: monospace; background: #111; color: #4ade80; padding: 20px; text-align: center;">