-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregex2.js
77 lines (72 loc) · 1.69 KB
/
regex2.js
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
// testfile for testing some things
const avro = require('avsc');
const path = 'test.txt';
const type = avro.parse({
type : 'array',
items : {
type : 'record',
name : 'rules',
fields : [ {
name : 'id',
type : ['null', 'long'],
default: null,
}, {
name : 'why',
type : ['null', 'string'],
default: null,
}, {
name : 'level',
type : ['null', 'long'],
default: null,
}, {
name : 'enable',
type : ['null', 'boolean'],
default: null,
}, {
name : 'chain',
type : {
type : 'array',
items : {
type : 'record',
name : 'chain',
fields : [ {
name : 'where',
type : ['null', 'string'],
default: null,
},
{
name : 'what',
type : ['null', 'string'],
default: null,
},
{
name : 'operator',
type : ['null', 'long'],
default: null,
}]
}
},
} ]
}
});
console.time("RegEx test");
const fs = require('fs');
console.time("loadrules2 test");
fs.readFile(path, function (err, data ) {
console.timeEnd("loadrules2 test");
const attack_string = 'localHost';
const rules = type.fromBuffer(data);
for (const rule in rules) {
// @todo: testing, testing, testing
const current_rule = rules[rule];
if(
current_rule.enable &&
current_rule.chain[0].where.split('|').indexOf('GET') !== -1 &&
attack_string.match(new RegExp(current_rule.chain[0].what, current_rule.chain[0].what_flags!==undefined? current_rule.chain[0].what_flags : "")) !== null
){
// console.log(current_rule.why);
break;
}
}
console.timeEnd("RegEx test");
});