1
1
package main
2
2
3
3
import (
4
+ "compress/gzip"
4
5
"crypto/des"
5
6
"crypto/md5"
7
+ "crypto/rc4"
6
8
"crypto/tls"
7
9
"database/sql"
8
10
"fmt"
11
+ "io"
9
12
"log"
10
13
"math/rand"
11
14
"net/http"
12
15
"os"
13
16
"os/exec"
17
+ "strconv"
14
18
)
15
19
16
20
func main () {
@@ -50,6 +54,7 @@ func main() {
50
54
defer f .Close ()
51
55
52
56
// Gosec G201: SQL query construction using format string
57
+ // CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
53
58
username := "admin"
54
59
pass := "' OR 1=1--"
55
60
query := fmt .Sprintf ("SELECT * FROM users WHERE username='%s' AND password='%s'" , username , pass )
@@ -74,5 +79,36 @@ func main() {
74
79
token := rand .Int ()
75
80
fmt .Println ("Random token:" , token )
76
81
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
+
77
113
log .Fatal (http .ListenAndServe (":8080" , nil ))
78
114
}
0 commit comments