-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (76 loc) · 1.99 KB
/
main.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
package main
import (
"io/ioutil"
"net/http"
)
func main() {
http.HandleFunc("/file", func(w http.ResponseWriter, r *http.Request) {
fileName := r.URL.Query().Get("name")
// 漏洞:直接使用用户输入的文件路径,存在路径遍历风险
data, err := ioutil.ReadFile("/var/www/" + fileName)
if err != nil {
http.Error(w, "File not found", http.StatusNotFound)
return
}
w.Write(data)
// 漏洞:直接使用用户输入的文件路径,存在路径遍历风险
data, err = ioutil.ReadFile("/var/www/" + fileName)
if err != nil {
http.Error(w, "File not found", http.StatusNotFound)
return
}
w.Write(data)
data, err = ioutil.ReadFile("/var/www1111/" + fileName)
if err != nil {
http.Error(w, "File not found", http.StatusNotFound)
return
}
data, err = ioutil.ReadFile("/var/www111222/" + fileName)
if err != nil {
http.Error(w, "File not found", http.StatusNotFound)
return
}
data, err = ioutil.ReadFile("/var/www111333/" + fileName)
if err != nil {
http.Error(w, "File not found", http.StatusNotFound)
return
}
w.Write(data)
})
abs(2)
http.ListenAndServe(":8080", nil)
}
func abs(x int) int {
if x >= 0 {
return x
} else {
return x
}
}
// package main
// import (
// "flag"
// "github.com/nrbackback/a-dog-a-day/config"
// "github.com/nrbackback/a-dog-a-day/email"
// "github.com/nrbackback/a-dog-a-day/log"
// "github.com/nrbackback/a-dog-a-day/picture"
// "github.com/nrbackback/a-dog-a-day/runner"
// "github.com/nrbackback/a-dog-a-day/title"
// )
// func main() {
// log.Init()
// var configFile string
// flag.StringVar(&configFile, "config", "config.yml", "load config")
// flag.Parse()
// if err := config.Load(configFile); err != nil {
// panic(err)
// }
// if err := picture.Init(config.Config.Picture); err != nil {
// panic(err)
// }
// email.WeiboSender = email.EmailSender{
// Conf: config.Config.Email,
// }
// title.Init(config.Config.Title)
// runner.Start(config.Config.Runner)
// }