-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
223 lines (168 loc) · 7.93 KB
/
request.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package lualib
import (
"net/http"
"strings"
"github.com/croessner/nauthilus/server/global"
lua "github.com/yuin/gopher-lua"
)
// CommonRequest represents a common request object with various properties used in different functionalities.
type CommonRequest struct {
// Debug is a flag indicating if the action is executed in debug mode.
Debug bool
// Repeating is a flag indicating if the action would be repeated.
Repeating bool
// UserFound is a flag indicating if the user executing the action was found in the system.
UserFound bool
// Authenticated is a flag indicating if the user is authenticated.
Authenticated bool
// NoAuth is a flag indicating if the action requires no authentication.
NoAuth bool
// BruteForceCounter keeps track of unsuccessful login attempts for the user.
BruteForceCounter uint
// Service is the http routers endpoint name.
Service string
// Session stores the unique session identifier.
Session string // GUID
// ClientIP stores the IP address of the client.
ClientIP string
// ClientPort stores the port number used by the client.
ClientPort string
// ClientNet stores the network used by the client.
ClientNet string
// ClientHost stores the hostname of the client.
ClientHost string
// ClientID stores the unique identifier for the client.
ClientID string
// UserAgent stores toe User-Agent of the client.
UserAgent string
// LocalIP stores the IP address of the local machine.
LocalIP string
// LocalPort stores the port number used by the local machine.
LocalPort string
// Username stores the username of the user that was used to authenticate.
Username string
// Account stores the user's account information.
Account string
// UniqueUserID stores the unique user identifier.
UniqueUserID string
// DisplayName stores the user's display name.
DisplayName string
// Password stores the user's password.
Password string
// Protocol stores the protocol that the user used to authenticate.
Protocol string
// BruteForceName stores the name of the brute force protection mechanism.
BruteForceName string
// FeatureName is a feature that triggered the action.
FeatureName string
// StatusMessage is a configurable message that is returned to the client upon errors (not tempfail).
StatusMessage *string
// XSSL contains SSL information.
XSSL string
// XSSLSessionID is the SSL session identifier.
XSSLSessionID string
// XSSLClientVerify indicates whether SSL client is verified.
XSSLClientVerify string
// XSSLClientDN is the client's Distinguished Name in the SSL certificate.
XSSLClientDN string
// XSSLClientCN is the client's Common Name in the SSL certificate.
XSSLClientCN string
// XSSLIssuer is the issuer of the SSL certificate.
XSSLIssuer string
// XSSLClientNotBefore is the date before which the SSL certificate is not valid.
XSSLClientNotBefore string
// XSSLClientNotAfter is the date after which the SSL certificate is not valid.
XSSLClientNotAfter string
// XSSLSubjectDN is the Subject's Distinguished Name in the SSL certificate.
XSSLSubjectDN string
// XSSLIssuerDN is the Issuer's Distinguished Name in the SSL certificate.
XSSLIssuerDN string
// XSSLClientSubjectDN is the client's Subject Distinguished Name in the SSL certificate.
XSSLClientSubjectDN string
// XSSLClientIssuerDN is the client's Issuer Distinguished Name in the SSL certificate.
XSSLClientIssuerDN string
// XSSLProtocol is the SSL protocol used.
XSSLProtocol string
// XSSLCipher is the encryption cipher used in the SSL protocol.
XSSLCipher string
}
// SetupRequest sets up the request object with the common request properties
func (c *CommonRequest) SetupRequest(request *lua.LTable) *lua.LTable {
request.RawSet(lua.LString(global.LuaRequestDebug), lua.LBool(c.Debug))
request.RawSet(lua.LString(global.LuaRequestRepeating), lua.LBool(c.Repeating))
request.RawSet(lua.LString(global.LuaRequestUserFound), lua.LBool(c.UserFound))
request.RawSet(lua.LString(global.LuaRequestAuthenticated), lua.LBool(c.Authenticated))
request.RawSet(lua.LString(global.LuaRequestNoAuth), lua.LBool(c.NoAuth))
request.RawSet(lua.LString(global.LuaRequestBruteForceCounter), lua.LNumber(c.BruteForceCounter))
request.RawSetString(global.LuaRequestService, lua.LString(c.Service))
request.RawSetString(global.LuaRequestSession, lua.LString(c.Session))
request.RawSetString(global.LuaRequestClientIP, lua.LString(c.ClientIP))
request.RawSetString(global.LuaRequestClientPort, lua.LString(c.ClientPort))
request.RawSetString(global.LuaRequestClientNet, lua.LString(c.ClientNet))
request.RawSetString(global.LuaRequestClientHost, lua.LString(c.ClientHost))
request.RawSetString(global.LuaRequestClientID, lua.LString(c.ClientID))
request.RawSetString(global.LuaRequestUserAgent, lua.LString(c.UserAgent))
request.RawSetString(global.LuaRequestLocalIP, lua.LString(c.LocalIP))
request.RawSetString(global.LuaRequestLocalPort, lua.LString(c.LocalPort))
request.RawSetString(global.LuaRequestUsername, lua.LString(c.Username))
request.RawSetString(global.LuaRequestAccount, lua.LString(c.Account))
request.RawSetString(global.LuaRequestUniqueUserID, lua.LString(c.UniqueUserID))
request.RawSetString(global.LuaRequestDisplayName, lua.LString(c.DisplayName))
request.RawSetString(global.LuaRequestPassword, lua.LString(c.Password))
request.RawSetString(global.LuaRequestProtocol, lua.LString(c.Protocol))
request.RawSetString(global.LuaRequestBruteForceBucket, lua.LString(c.BruteForceName))
request.RawSetString(global.LuaRequestFeature, lua.LString(c.FeatureName))
request.RawSetString(global.LuaRequestStatusMessage, lua.LString(*c.StatusMessage))
request.RawSetString(global.LuaRequestXSSL, lua.LString(c.XSSL))
request.RawSetString(global.LuaRequestXSSSLSessionID, lua.LString(c.XSSLSessionID))
request.RawSetString(global.LuaRequestXSSLClientVerify, lua.LString(c.XSSLClientVerify))
request.RawSetString(global.LuaRequestXSSLClientDN, lua.LString(c.XSSLClientDN))
request.RawSetString(global.LuaRequestXSSLClientCN, lua.LString(c.XSSLClientCN))
request.RawSetString(global.LuaRequestXSSLIssuer, lua.LString(c.XSSLIssuer))
request.RawSetString(global.LuaRequestXSSLClientNotBefore, lua.LString(c.XSSLClientNotBefore))
request.RawSetString(global.LuaRequestXSSLClientNotAfter, lua.LString(c.XSSLClientNotAfter))
request.RawSetString(global.LuaRequestXSSLSubjectDN, lua.LString(c.XSSLSubjectDN))
request.RawSetString(global.LuaRequestXSSLIssuerDN, lua.LString(c.XSSLIssuerDN))
request.RawSetString(global.LuaRequestXSSLClientSubjectDN, lua.LString(c.XSSLClientSubjectDN))
request.RawSetString(global.LuaRequestXSSLClientIssuerDN, lua.LString(c.XSSLClientIssuerDN))
request.RawSetString(global.LuaRequestXSSLProtocol, lua.LString(c.XSSLProtocol))
request.RawSetString(global.LuaRequestXSSLCipher, lua.LString(c.XSSLCipher))
return request
}
func SetStatusMessage(status **string) lua.LGFunction {
return func(L *lua.LState) int {
newStatus := L.CheckString(1)
*status = &newStatus
return 0
}
}
// GetAllHTTPRequestHeaders returns a LGFunction that creates a Lua table containing all headers from the http.Request object
// The table is indexed by the lowercase header name and each header's value is a list of strings
// The function expects a *http.Request object as its parameter
//
// Example usage:
//
// headers := getAllHeaders(request)
// L.SetGlobal("getAllHeaders", L.NewClosure(headers))
// result := L.DoString(`
// local headers = getAllHeaders()
// print(headers["content-type"][1]) -- print the first value of the "content-type" header
// `)
// if result != nil {
// fmt.Println("Error:", result)
// }
func GetAllHTTPRequestHeaders(httpRequest *http.Request) lua.LGFunction {
return func(L *lua.LState) int {
headerTable := L.NewTable()
for name, headers := range httpRequest.Header {
name = strings.ToLower(name)
headerList := L.NewTable()
for _, h := range headers {
headerList.Append(lua.LString(h))
}
headerTable.RawSetString(name, headerList)
}
L.Push(headerTable)
return 1
}
}