Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"database/sql"
"fmt"
"log"
"net/http"
"strings"

_ "github.com/mattn/go-sqlite3"
)

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
username := r.URL.Query().Get("username")
password := r.URL.Query().Get("password")

// SQL Injection vulnerability
db, err := sql.Open("sqlite3", "./example.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()

var user string
err = db.QueryRow("SELECT username FROM users WHERE username = '" + username + "' AND password = '" + password + "'").Scan(&user)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// Command Injection vulnerability
cmd := fmt.Sprintf("echo 'Hello, %s!'", username)
output, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "%s", output)

// Path Traversal vulnerability
filePath := r.URL.Query().Get("file")
if filePath != "" {
http.ServeFile(w, r, "./"+filePath)
}
})

// Cross-Site Scripting (XSS) vulnerability
http.HandleFunc("/xss", func(w http.ResponseWriter, r *http.Request) {
input := r.URL.Query().Get("input")
fmt.Fprintf(w, "<h1>%s</h1>", input)
})

log.Fatal(http.ListenAndServe(":8080", nil))
}