-
Notifications
You must be signed in to change notification settings - Fork 2
/
skeleton.aslan++
387 lines (334 loc) · 9.2 KB
/
skeleton.aslan++
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
specification @filename
channel_model CCM
entity Environment {
types
cookie < text;
param < text;
fnode < param;
page < fnode;
sess < text;
nonce < text;
symbols
sqli_bypass, sqli, sqli_write, sqli_read, sqli_insert: param; %sql injection payload
path_injection: param; %valid file
xss: param; % XSS payload
evil_file: fnode; %valid file
honest, webapplication : agent;
% Honest entity
nonpublic hknows : message set;
eq, emp : text; % used as separator
nonpublic sanitized(message) : message;
nonpublic client_xss(message) : fact;
%DBMS
nonpublic db: message set;
nonpublic query(message set,message): fact;
nonpublic query_read(message) : fact;
nonpublic query_write(message) : fact;
nonpublic insert(message set,message): fact;
nonpublic update(message set, message, message) : fact;
nonpublic delete(message set, message) : fact;
nonpublic inDB(message): fact;
nonpublic inDB_write(message): fact;
nonpublic inDB_read(message): fact;
nonpublic inDB_bypass(message): fact;
nonpublic inDB_insert(message) : fact;
% database structure
@databasestructure
%Filesystem
nonpublic fs: message set;
nonpublic file(message) : message;
nonpublic writeFile(message): fact;
nonpublic readFile(message): fact;
nonpublic inFS(message): fact;
Result : message;
% request
% page, parameters, cookie
http_request(message, message, message): message;
% response
% page, result
http_response(message, message, message): message;
% none parameter
none : text;
@pages
@params
% messages tagss
@tags
clauses
% database vulns
db_hc_ev(M) : inDB(M) :- M=sqli.?;
db_hc_ev_write(M) : inDB_write(M) :- M=sqli_write.?;
db_hc_ev_read(M) : inDB_read(M) :- M=sqli_read.?;
db_hc_ev_bypass(M) : inDB_bypass(M) :- M=sqli_bypass.?;
db_hc_ev_insert(M) : inDB_insert(M) :- M=sqli_insert.?;
% client side vulns
db_hc_ev_xss(M) : client_xss(M) :- M=xss.?;
% file-system vulns
fs_hc_ev(M) : inFS(M) :- M=path_injection.?;
entity Session(Webapplication, Honest: agent) {
entity Webapplication(Actor, Honest: agent) {
symbols
WebNonce : nonce;
Entity : agent;
@webappsymbols
body{
while(true){
select{
@webappbody
}
}%end while
}%end body
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HONEST ENTITY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
entity Honest(Actor, Webapplication : agent){
symbols
WebNonce : nonce;
Page : page;
Cookie : cookie;
Params, Body : message;
Tag : text;
@webappsymbols
body{
while(true){
select{
@honestbody
% This represent the intruder that sent a link to
% the honest agent used for Reflected XSS but also for CSRF
on( i *->* Actor : ?Page.?Params.?Tag ):{
%assert o: Page != index | Params != u.s.xss.?.s.p.s.none | !hknows->contains(?) | Tag != tag1;
%assert o: Page != insertPage | Params != comment.s.xss.insertPage | Tag != tag1;
%assert h: exists M. hknows->contains(M) & cookieUsed(M);
Cookie := ?;
WebNonce := fresh();
Actor *->* Webapplication : http_request(Page,Params,Cookie).Tag.WebNonce;
Webapplication *->* Actor : http_response(?Page, ?Body, ?Cookie).Tag.WebNonce;
hknows->add(Cookie);
if(client_xss(Body)){
Actor -> i : hknows;
}
}
} %end select
} %end while
} % end body
} % end entity
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% END HONEST ENTITY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DATABASE ENTITY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%TODO: fix SQLquery is just one message
entity Database{
symbols
SQLquery, Key: message;
File : fnode;
Page : page;
Sql, Val : message;
Table : message set;
body{
while(true){
select{
% query behavior
on(query(?Table, ?SQLquery)):{
select{
on(Table->contains(SQLquery) | (SQLquery=sanitized(?Sql) & Table->contains(?Sql))):{
Result := SQLquery;
}
% malicious behavior
on(inDB_bypass(SQLquery) & Table->contains(?Sql)):{
Result := Sql;
}
on(inDB_read(SQLquery) & fs->contains(file(?File))):{
Result := file(File);
}
on(inDB_write(SQLquery) & SQLquery = sqli_write.?File.?):{
fs->add(file(File));
}
on(inDB_insert(SQLquery)):{
Table->add(SQLquery);
}
on(inDB(SQLquery)):{
Result := db;
}
}
retract query(Table, SQLquery);
}
% query read behavior
on(query_read(?SQLquery)):{
select{
on(fs->contains(file(SQLquery))):{
Result := file(SQLquery);
}
% malicious behavior
on(inDB_bypass(SQLquery) & Table->contains(?Sql)):{
Result := Sql;
}
on(inDB_read(SQLquery) & fs->contains(file(?File))):{
Result := file(File);
}
on(inDB_write(SQLquery) & SQLquery = sqli_write.?File.?):{
fs->add(file(File));
}
on(inDB_insert(SQLquery)):{
Table->add(SQLquery);
}
on(inDB(SQLquery)):{
Result := db;
}
}
retract query(Table, SQLquery);
}
% query write behavior
on(query_write(?SQLquery)):{
select{
on(true):{
fs->add(file(SQLquery));
}
% malicious behavior
on(inDB_bypass(SQLquery) & Table->contains(?Sql)):{
Result := Sql;
}
on(inDB_read(SQLquery) & fs->contains(file(?File))):{
Result := file(File);
}
on(inDB_write(SQLquery) & SQLquery = sqli_write.?File.?):{
fs->add(file(File));
}
on(inDB_insert(SQLquery)):{
Table->add(SQLquery);
}
on(inDB(SQLquery)):{
Result := db;
}
}
retract query_write(SQLquery);
}
% query insert behavior
on(insert(?Table, ?SQLquery)):{
select{
on(true):{
Table->add(SQLquery);
}
% malicious behavior
on(inDB_bypass(SQLquery) & Table->contains(?Sql)):{
Result := Sql;
}
on(inDB_read(SQLquery) & fs->contains(file(?File))):{
Result := file(File);
}
on(inDB_write(SQLquery) & SQLquery = sqli_write.?File.?):{
fs->add(file(File));
}
on(inDB_insert(SQLquery)):{
Table->add(SQLquery);
}
on(inDB(SQLquery)):{
Result := db;
}
}
retract insert(Table, SQLquery);
}
% query delete behavior
on(delete(?Table, ?SQLquery)):{
select{
on(true):{
Table->remove(SQLquery);
}
% malicious behavior
on(inDB_bypass(SQLquery) & Table->contains(?Sql)):{
Result := Sql;
}
on(inDB_read(SQLquery) & fs->contains(file(?File))):{
Result := file(File);
}
on(inDB_write(SQLquery) & SQLquery = sqli_write.?File.?):{
fs->add(file(File));
}
on(inDB_insert(SQLquery)):{
Table->add(SQLquery);
}
on(inDB(SQLquery)):{
Result := db;
}
}
retract insert(Table, SQLquery);
}
% query update behavior
on(update(?Table, ?Key, ?SQLquery)):{
select{
on(true):{
Table->remove(Key);
Table->add(SQLquery);
Result := SQLquery;
}
% malicious behavior
on(inDB_bypass(SQLquery) & Table->contains(?Sql)):{
Result := Sql;
}
on(inDB_read(SQLquery) & fs->contains(file(?File))):{
Result := file(File);
}
on(inDB_write(SQLquery) & SQLquery = sqli_write.?File.?):{
fs->add(file(File));
}
on(inDB_insert(SQLquery)):{
Table->add(SQLquery);
}
on(inDB(SQLquery)):{
Result := db;
}
}
retract update(Table, Key, SQLquery);
}
} %behavior select
} %while
} %body
}%dbEntity
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FILESYSTEM ENTITY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
entity Filesystem{
symbols
Path ; message;
Val: fnode;
body{
while(true){
select{
% begin honest behavior
on(readFile(?Path) & fs->contains(file(?Path))):{
Result := file(Path);
retract readFile(Path);
}
on(writeFile(?Path)):{
fs->add(file(Path));
retract writeFile(Path);
}
% end honest behavior
% begin dishonest behavior
on(readFile(?Path) & inFS(?Path) & fs->contains(file(?Val))):{
Result := file(Val);
retract readFile(Path);
}
% end dishonest behavior
} % select
}%while
}%body
}%fs_entity
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
body{ %of session
@databaseinit
new Webapplication(webapplication, honest); %, webapplication, database, filesystem);
new Database;
new Filesystem;
new Honest(honest, webapplication);
}
goals %of session
security_goal:
[](!iknows(db));
}
body{ %of Environment
new Session(webapplication, honest);
}
}