-
Notifications
You must be signed in to change notification settings - Fork 0
/
fires.go
161 lines (133 loc) · 3.32 KB
/
fires.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
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
package api
import (
"net/http"
"path/filepath"
"strconv"
"github.com/thomasfady/xsstower/models"
"github.com/gin-gonic/gin"
)
type APIFires struct {
Ip string
Handler string
Url string
UserAgent string
Referer string
CorrelationKey string
}
// @BasePath /api/
// @Summary Fires
// @Description Get XSS Fires
// @Produce json
// @Tags XSSFire
// @Router /fires [get]
func GetFires(c *gin.Context) {
user_id := c.GetInt("user_id")
fires := make([]APIFires, 0)
var pagination models.Pagination
c.Bind(&pagination)
hits := models.GetViewableHitPaginated(user_id, &pagination)
for _, v := range hits {
fires = append(fires, APIFires{
Ip: v.Ip,
Handler: v.Handler.Path,
Url: v.Url,
UserAgent: v.UserAgent,
Referer: v.Referer,
CorrelationKey: v.CorrelationKey,
})
}
c.JSON(http.StatusOK, gin.H{
"fires": fires,
"limit": pagination.Limit,
"page": pagination.Page,
"total_rows": pagination.TotalRows,
"total_pages": pagination.TotalPages,
})
}
// @BasePath /api/
// @Summary Fire
// @Description Get XSS Fire information
// @Produce json
// @Tags XSSFire
// @Router /fire/{fire_id} [get]
func GetFire(c *gin.Context) {
user_id := c.GetInt("user_id")
hit := models.GetHitByCorrelationKey(c.Param("key"))
if hit.CanView(user_id) {
c.JSON(http.StatusOK, hit)
} else {
c.JSON(http.StatusForbidden, nil)
}
}
// @BasePath /api/
// @Summary Fire
// @Tags XSSFire
// @Description Get XSS Fire File
// @Router /fire/{fire_id}/file/{file_id} [get]
func GetFireFile(c *gin.Context) {
user_id := c.GetInt("user_id")
hit := models.GetHitByCorrelationKey(c.Param("key"))
if hit.ID == 0 {
c.JSON(http.StatusNotFound, nil)
return
}
if hit.CanView(user_id) {
for _, cp := range hit.CollectedPages {
if strconv.FormatInt(int64(cp.ID), 10) == c.Param("id") {
c.Header("Content-Disposition", "attachment; filename=\""+filepath.Base(cp.Path)+"\"")
c.Data(http.StatusOK, "application/data", []byte(cp.Content))
return
}
}
c.JSON(http.StatusNotFound, nil)
} else {
c.JSON(http.StatusForbidden, nil)
}
}
// @BasePath /api/
// @Summary Fires
// @Description Delete Fire
// @Produce json
// @Tags XSSFire
// @Router /fire/{fire_id} [delete]
func DeleteFire(c *gin.Context) {
user_id := c.GetInt("user_id")
hit := models.GetHitByCorrelationKey(c.Param("key"))
if hit.CanDelete(user_id) {
hit.Delete()
} else {
c.JSON(http.StatusForbidden, nil)
}
c.JSON(http.StatusOK, "")
}
// @BasePath /api/
// @Summary Fires sharing
// @Description Enable fire sharing
// @Produce json
// @Tags XSSFire
// @Router /fire/{fire_id}/share [post]
func PostFireShare(c *gin.Context) {
user_id := c.GetInt("user_id")
hit := models.GetHitByCorrelationKey(c.Param("key"))
if hit.CanUpdate(user_id) {
hit.EnableSharing()
c.Status(http.StatusCreated)
} else {
c.Status(http.StatusForbidden)
}
}
// @BasePath /api/
// @Summary Fires sharing
// @Description Disable fire sharing
// @Tags XSSFire
// @Router /fire/{fire_id}/share [delete]
func DeleteFireShare(c *gin.Context) {
user_id := c.GetInt("user_id")
hit := models.GetHitByCorrelationKey(c.Param("key"))
if hit.CanUpdate(user_id) {
hit.DisableSharing()
c.Status(http.StatusOK)
} else {
c.Status(http.StatusForbidden)
}
}