-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathidor.go
More file actions
167 lines (125 loc) · 3.9 KB
/
Copy pathidor.go
File metadata and controls
167 lines (125 loc) · 3.9 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package idor
import (
"log"
"strconv"
"net/http"
"crypto/md5"
"encoding/hex"
"github.com/julienschmidt/httprouter"
"github.com/govwa/user/session"
"github.com/govwa/util"
"github.com/govwa/util/middleware"
)
type IDOR struct{}
func New() IDOR {
return IDOR{}
}
func (self IDOR) SetRouter(r *httprouter.Router) {
mw := middleware.New()
r.GET("/idor1", mw.LoggingMiddleware(mw.CapturePanic(mw.AuthCheck(idor1Handler))))
r.POST("/idor1action", mw.LoggingMiddleware(mw.CapturePanic(mw.AuthCheck(idor1ActionHandler))))
r.GET("/idor2", mw.LoggingMiddleware(mw.CapturePanic(mw.AuthCheck(idor2Handler))))
r.POST("/idor2action", mw.LoggingMiddleware(mw.CapturePanic(mw.AuthCheck(idor2ActionHandler))))
}
type DataResponse struct {
Status string `json:"status"`
Message string `json:"message"`
}
func idor1Handler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
session := session.New()
sid := session.GetSession(r, "id")
p := NewProfile()
p.GetData(sid)
data := make(map[string]interface{})
data["title"] = "Insecure Direc Object References"
data["uid"] = strconv.Itoa(p.Uid)
data["name"] = p.Name
data["city"] = p.City
data["number"] = p.PhoneNumber
util.SafeRender(w, r, "template.idor1", data)
}
func idor2Handler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
session := session.New()
sid := session.GetSession(r, "id")
p := NewProfile()
p.GetData(sid)
data := make(map[string]interface{})
signature := Md5Sum(sid)
data["signature"] = signature
data["title"] = "Insecure Direc Object References"
data["uid"] = strconv.Itoa(p.Uid)
data["name"] = p.Name
data["city"] = p.City
data["number"] = p.PhoneNumber
util.SafeRender(w, r, "template.idor2", data)
}
func idor1ActionHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
session := session.New()
sid := session.GetSession(r, "id")
p := NewProfile()
p.GetData(sid)
/* handle request response with json */
if r.Method == "POST" {
cid := util.GetCookie(r, "Uid")
uid := HTMLEscapeString(r.FormValue("uid"))
name := HTMLEscapeString(r.FormValue("name"))
city := HTMLEscapeString(r.FormValue("city"))
number := HTMLEscapeString(r.FormValue("number"))
res := &DataResponse{}
if uid != cid || uid == "" || cid == "" {
res.Status = "0"
res.Message = "Missing User Id"
log.Println("Update Error")
} else {
if util.CheckLevel(r) { //level == high
uid = sid //set uid that fetch from session this use to prevent unauthorize users force update other user profile
}
err = p.UpdateProfile(name, city, number, uid)
if err != nil {
log.Println(err.Error())
}
res.Status = "1"
res.Message = "Update Success"
log.Println("Update Success")
}
util.RenderAsJson(w, res)
}
}
func idor2ActionHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
session := session.New()
sid := session.GetSession(r, "id")
p := NewProfile()
p.GetData(sid)
/* handle request response with json */
if r.Method == "POST" {
sign := HTMLEscapeString(r.FormValue("signature"))
uid := HTMLEscapeString(r.FormValue("uid"))
name := HTMLEscapeString(r.FormValue("name"))
city := HTMLEscapeString(r.FormValue("city"))
number := HTMLEscapeString(r.FormValue("number"))
signature := Md5Sum(uid)
res := &DataResponse{}
if sign != signature{
res.Status = "0"
res.Message = "Integrity Error"
log.Println("Update Error")
} else {
if util.CheckLevel(r) { //level == high
uid = sid //set uid that fetch from session this use to prevent unauthorize users force update other user profile
}
err = p.UpdateProfile(name, city, number, uid)
if err != nil {
log.Println(err.Error())
}
res.Status = "1"
res.Message = "Update Success"
log.Println("Update Success")
}
util.RenderAsJson(w, res)
}
}
func Md5Sum(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}