Skip to content

Commit 1a1ea50

Browse files
committed
Add more vulnerabilities
1 parent d35a5a5 commit 1a1ea50

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

main.go

+36
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package main
22

33
import (
4+
"compress/gzip"
45
"crypto/des"
56
"crypto/md5"
7+
"crypto/rc4"
68
"crypto/tls"
79
"database/sql"
810
"fmt"
11+
"io"
912
"log"
1013
"math/rand"
1114
"net/http"
1215
"os"
1316
"os/exec"
17+
"strconv"
1418
)
1519

1620
func main() {
@@ -50,6 +54,7 @@ func main() {
5054
defer f.Close()
5155

5256
// Gosec G201: SQL query construction using format string
57+
// CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
5358
username := "admin"
5459
pass := "' OR 1=1--"
5560
query := fmt.Sprintf("SELECT * FROM users WHERE username='%s' AND password='%s'", username, pass)
@@ -74,5 +79,36 @@ func main() {
7479
token := rand.Int()
7580
fmt.Println("Random token:", token)
7681

82+
// Gosec G501: Blacklisted import crypto/rc4
83+
// CWE-327: Use of a Broken or Risky Cryptographic Algorithm
84+
cipher, _ := rc4.NewCipher([]byte("secret"))
85+
fmt.Printf("%x", cipher)
86+
87+
resp, err := http.Get("http://127.0.0.1")
88+
if err != nil {
89+
log.Fatal(err)
90+
}
91+
defer resp.Body.Close()
92+
93+
// Gosec G107: Potential HTTP request made with variable url
94+
// CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')
95+
url := resp.Request.URL.Query().Get("url")
96+
http.Get(url)
97+
98+
// Gosec G109: Potential Integer overflow made by strconv.Atoi result conversion to int16/32
99+
// CWE-190: Integer Overflow or Wraparound
100+
val := resp.Request.URL.Query().Get("val")
101+
num, _ := strconv.Atoi(val)
102+
var intVal int16 = int16(num)
103+
fmt.Println(intVal)
104+
105+
// Gosec G110: Potential DoS vulnerability via decompression bomb
106+
// CWE-409: Improper Handling of Highly Compressed Data (Data Amplification)
107+
http.HandleFunc("/decompress", func(w http.ResponseWriter, r *http.Request) {
108+
r.Body = http.MaxBytesReader(w, r.Body, 1<<30) // 1GB
109+
gzr, _ := gzip.NewReader(r.Body)
110+
_, _ = io.Copy(os.Stdout, gzr)
111+
})
112+
77113
log.Fatal(http.ListenAndServe(":8080", nil))
78114
}

0 commit comments

Comments
 (0)