lightning-bolt 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lightning/bolt/cli.rb +2 -1
- data/lib/lightning/bolt/fuzzer.rb +19 -17
- data/lib/lightning/bolt/templates/payload.yml +115 -66
- data/lib/lightning/bolt/version.rb +1 -1
- data/lib/lightning/bolt.rb +292 -2
- metadata +2 -4
- data/lib/lightning/bolt/codex.rb +0 -302
- data/lib/lightning/bolt/encoding.yml +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14a570b0301f4b6762152de51c14bde142aa8758
|
4
|
+
data.tar.gz: 1635e9d632ba71791d6217758c6b81cdaeb515c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f88dc2d733b77040763b93c9a98460b7a598890d2fe6da34adb2a3c516d614c5e093b765ae2fe2621008096c55129a18f9fdc203a3e237650688e25ed521d4f7
|
7
|
+
data.tar.gz: 28a41fd9d4e93076228360f7ddbe24e74e5ca9ac11e10ca8bf334050f63dd60d22fc74796459049493d7a4beb560e331c135c6b614fe3ffc391205277e0015a2
|
data/lib/lightning/bolt/cli.rb
CHANGED
@@ -5,35 +5,37 @@ module Lightning
|
|
5
5
|
|
6
6
|
def initialize(encoder)
|
7
7
|
@encoder = encoder
|
8
|
-
@
|
9
|
-
@warp = Time.new.to_i
|
8
|
+
@alphabet = alphabet()
|
10
9
|
end
|
11
10
|
|
12
11
|
def random_number(min,max)
|
13
12
|
return SecureRandom.random_number(max-min)+min
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
17
|
-
randomizer = seeder(seed)
|
18
|
-
addable = true
|
15
|
+
def random_character(seed, size, flags)
|
19
16
|
enigma = ""
|
20
|
-
|
21
|
-
|
22
|
-
if encodable?(rotar)
|
23
|
-
enigma += rotar
|
24
|
-
end
|
17
|
+
(0..size).each do | index |
|
18
|
+
engima += random_number(0,@alphabet.size)
|
25
19
|
end
|
26
|
-
return enigma.encode(@encoder)
|
27
20
|
end
|
28
21
|
|
29
22
|
private
|
30
23
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
24
|
+
def alphabet
|
25
|
+
charset = []
|
26
|
+
0.upto(1112064) do |i|
|
27
|
+
char = nil
|
28
|
+
begin
|
29
|
+
char = "" << i
|
30
|
+
rescue
|
31
|
+
end
|
32
|
+
if !char.eql?(nil)
|
33
|
+
if encodable?(char)
|
34
|
+
charset.push(char.encode(@encoder))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
return charset
|
37
39
|
end
|
38
40
|
|
39
41
|
def encodable?(rotar)
|
@@ -1,67 +1,116 @@
|
|
1
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
|
-
|
2
|
+
theorems:
|
3
|
+
- name: "birth_date"
|
4
|
+
path: "#:identification-birth-date"
|
5
|
+
path: "#:identification-birth-date-range|#:identification-birth-date-norange"
|
6
|
+
- name: "birth_date_range"
|
7
|
+
path: "#:identification-birth-date-range"
|
8
|
+
rule: "#:birth-date-month&#:identification-birth-date-delimiter&#:identification-birth-year"
|
9
|
+
- name: "birth_date_month"
|
10
|
+
path: "#:birth-date-month"
|
11
|
+
rule: "(#:birth-date-feburary|#:birth-date-days-thirty-even|#:birth-date-days-thirty-odd)"
|
12
|
+
- name: "birth_date_feburary"
|
13
|
+
path: "#:birth-date-feburary"
|
14
|
+
rule: "(2#:identification-birth-date-delimiter[0..29])"
|
15
|
+
- name: "birth_date_days_thirty_even"
|
16
|
+
path: "#:birth-date-days-thirty-even"
|
17
|
+
rule: "((4|6|9|11)#:identification-birth-date-delimiter[0..30])"
|
18
|
+
- name: "birth_date_days_thirty_odd"
|
19
|
+
path: "#:birth-date-days-thirty-odd"
|
20
|
+
rule: "((1|3|5|7|8|10|12)#:identification-birth-date-delimiter[0..31])"
|
21
|
+
- name: "birth_date_norange"
|
22
|
+
path: "#:identification-birth-date-norange"
|
23
|
+
rule: "((2(([0-1][0-9])|(2[0-9])))|((1|3|5|7|8|10|12)&(([0-2])|([0-2][0-9])))|((4|6|9|11)[0..30]))"
|
24
|
+
- name: "birth_date_delimiter"
|
25
|
+
path: "#:identification-birth-date-delimiter"
|
26
|
+
rule: "/"
|
27
|
+
- name: "birth_year"
|
28
|
+
path: "#:identification-birth-year"
|
29
|
+
rule: "(19[0-9][0-9])|(20[0-1][0-9])|(20[0-1][6])"
|
30
|
+
- name: "time_year"
|
31
|
+
path: "#:time-year"
|
32
|
+
rule: "[0-9]{4:4}"
|
33
|
+
- name: "us_dollar"
|
34
|
+
path: "#:en-us-dollar"
|
35
|
+
rule: "$([0-9]{0:2}),([1-9]{3:3})\\.[0-9][0-9]"
|
36
|
+
- name: "time_month_numeric"
|
37
|
+
path: "#:time-month-numeric"
|
38
|
+
rule: "([1..12])|((0[0-9])|1(0-2))"
|
39
|
+
- name: "time_day_numeric"
|
40
|
+
path: "#:time-day-numeric"
|
41
|
+
rule: "([1..31])|(([0-2][0-9])|(3[01]))"
|
42
|
+
- name: "identification-email"
|
43
|
+
path: "#:profile-email"
|
44
|
+
rule: "#:name-dot@#:organization-website"
|
45
|
+
- name: "identification-website"
|
46
|
+
path: "#:organization-website"
|
47
|
+
rule: "@:en-organizations\\.#:names-domain"
|
48
|
+
- name: "website_domain"
|
49
|
+
path: "#:names-domain"
|
50
|
+
rule: "(org|com|net|)"
|
51
|
+
- name: "dot_name"
|
52
|
+
path: "#:name-dot"
|
53
|
+
rule: "((#:en-first-name)&(\\.)&(#:en-last-name)|(#:fr-first-name)&(\\.)&(#:fr-last-name)|(#:it-first-name)&(\\.)&(#:it-last-name))"
|
54
|
+
- name: "dash_name"
|
55
|
+
path: "#:name-dash"
|
56
|
+
rule: "((#:en-first-name\\-#:en-last-name)|(#:fr-first-name\\-#:fr-last-name)|(#:it-first-name\\-#:it-last-name))"
|
57
|
+
- name: "full_name"
|
58
|
+
path: "#:name-full"
|
59
|
+
rule: "((#:en-first-name #:en-last-name)|(#:fr-first-name #:fr-last-name)|(#:it-first-name #:it-last-name))"
|
60
|
+
- name: "english_first_name"
|
61
|
+
path: "#:en-first-name"
|
62
|
+
rule: "@:en-names-first"
|
63
|
+
- name: "english_last_name"
|
64
|
+
path: "#:en-last-name"
|
65
|
+
rule: "@:en-names-last"
|
66
|
+
- name: "french_first_name"
|
67
|
+
path: "#:fr-first-name"
|
68
|
+
rule: "@:fr-names-first"
|
69
|
+
- name: "french_last_name"
|
70
|
+
path: "#:fr-last-name"
|
71
|
+
rule: "@:fr-names-last"
|
72
|
+
- name: "italian_first_name"
|
73
|
+
path: "#:it-first-name"
|
74
|
+
rule: "@:it-names-first"
|
75
|
+
- name: "italian_last_name"
|
76
|
+
path: "#:it-last-name"
|
77
|
+
rule: "@:it-names-last"
|
78
|
+
- name: "hexadecimal"
|
79
|
+
path: "#:numeric-base-sixteen"
|
80
|
+
rule: "[0-9a-f]"
|
81
|
+
- name: "ipv4"
|
82
|
+
path: "#:technology-internet-ipv4"
|
83
|
+
rule: "(((([0-1][0-9][0-9])|(2([0-4][0-9]|5[0-5])))|(2[0..55]))\\.{3:3})&((([0-1][0-9][0-9])|(2([0-4][0-9]|5[0-5])))|(2[0..55]))"
|
84
|
+
- name: "ipv6"
|
85
|
+
path: "#:technology-internet-ipv6"
|
86
|
+
rule: "((#:numeric-base-sixteen{4:4}):{7:7})(#:numeric-base-sixteen{4:4})"
|
87
|
+
- name: "social_security_number"
|
88
|
+
path: "#:identification-socialsecuritynumber"
|
89
|
+
rule: "([0-9]{3:3})\\-([0-9]{2:2})\\-([0-9]{4:4})"
|
90
|
+
- name: "geolocation_latitude"
|
91
|
+
path: "#:geolocation-latitude"
|
92
|
+
rule: "#:numeric-float-signed"
|
93
|
+
- name: "geolocation_longitude"
|
94
|
+
path: "#:geolocation-longitude"
|
95
|
+
rule: "#:numeric-float-signed"
|
96
|
+
- name: "numeric_float_signed"
|
97
|
+
path: "#:numeric-float-signed"
|
98
|
+
rule: "(\\+|\\-)[0..65536]\\.[0..65536]"
|
99
|
+
- name: "us_address"
|
100
|
+
path: "#:identification-us-address"
|
101
|
+
rule: "[0..99999] @:"
|
102
|
+
- name: "us_city"
|
103
|
+
path: "#:identification-us-city"
|
104
|
+
rule: "@:en-us-cities"
|
105
|
+
- name: "us_state"
|
106
|
+
path: "#:identification-us-state"
|
107
|
+
rule: "@:en-us-states"
|
108
|
+
- name: "us_zipcode"
|
109
|
+
path: "#:identification-us-zipcode"
|
110
|
+
rule: "[0-9]{5:5}"
|
111
|
+
- name: "us_phone_number"
|
112
|
+
path: "#:identification-us-phonenumber"
|
113
|
+
rule: "[1-9][1-9][1-9]\\-[1-9][1-9][1-9]\\-[1-9][1-9][1-9][1-9]"
|
114
|
+
- name: "international_phone_number"
|
115
|
+
path: "#:identification-international-phonenumber"
|
116
|
+
rule: "hi"
|
data/lib/lightning/bolt.rb
CHANGED
@@ -1,8 +1,298 @@
|
|
1
|
+
require "lightning/bolt/cypher"
|
2
|
+
require "lightning/bolt/fuzzer"
|
1
3
|
require "lightning/bolt/version"
|
2
|
-
|
4
|
+
|
5
|
+
require 'yaml'
|
6
|
+
require 'json'
|
7
|
+
require 'digest'
|
3
8
|
|
4
9
|
module Lightning
|
5
10
|
module Bolt
|
6
|
-
|
11
|
+
class Codex
|
12
|
+
def initialize(bookstore, theorems, memories)
|
13
|
+
@cypher = Lightning::Bolt::Cypher.new(bookstore)
|
14
|
+
@fuzzer = Lightning::Bolt::Fuzzer.new('UTF-8')
|
15
|
+
@keys = YAML.load_file("#{File.dirname(__FILE__)}/keys.yml")
|
16
|
+
@passable = true
|
17
|
+
@theorems = theorems
|
18
|
+
@memory = memories
|
19
|
+
end
|
20
|
+
|
21
|
+
def signal(passable, unique, name)
|
22
|
+
@passable = passable.eql?(nil) ? true : passable
|
23
|
+
unique = unique.eql?(nil) ? false : unique
|
24
|
+
path = nil
|
25
|
+
@theorems.each do | theorem |
|
26
|
+
if theorem["name"].eql?(name)
|
27
|
+
path = theorem["path"]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
if path
|
31
|
+
data = decrypt(path)
|
32
|
+
if unique
|
33
|
+
hash = Digest::SHA256.hexdigest(path)
|
34
|
+
@memory[hash] = data
|
35
|
+
end
|
36
|
+
return path
|
37
|
+
else
|
38
|
+
return ""
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def archive
|
43
|
+
return @memory
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def decrypt(rule)
|
49
|
+
rule = rotar(rule, @keys["keys"]["reference"]) ? references(rule) : rule
|
50
|
+
rule = rotar(rule, @keys["keys"]["data"]) ? datum(rule) : rule
|
51
|
+
rule = rotar(rule, @keys["keys"]["group"]) ? group(rule) : rule
|
52
|
+
rule = rotar(rule, @keys["keys"]["repeat"]) ? repeat(rule) : rule
|
53
|
+
rule = rotar(rule, @keys["keys"]["set"]) ? set(rule) : rule
|
54
|
+
rule = rotar(rule, @keys["keys"]["not"]) ? exclude(rule) : rule
|
55
|
+
rule = rotar(rule, @keys["keys"]["or"]) ? either(rule) : rule
|
56
|
+
rule = rotar(rule, @keys["keys"]["and"]) ? concat(rule) : rule
|
57
|
+
rule = rotar(rule, @keys["keys"]["exist"]) ? exist(rule) : rule
|
58
|
+
rule = rotar(rule, @keys["keys"]["escapable"]) ? escapable(rule) : rule
|
59
|
+
rule = rotar(rule, @keys["keys"]["remember"]) ? remember(rule) : rule
|
60
|
+
return rule
|
61
|
+
end
|
62
|
+
|
63
|
+
def rotar(rule, expr)
|
64
|
+
return (rule.scan(Regexp.new(expr)).size > 0)
|
65
|
+
end
|
66
|
+
|
67
|
+
def references(rule)
|
68
|
+
vars = rule.scan(Regexp.new(@keys["keys"]["reference"]))
|
69
|
+
lock = false
|
70
|
+
vars.each do | var |
|
71
|
+
scan = radar(var)
|
72
|
+
if scan.eql?("")
|
73
|
+
lock = true
|
74
|
+
else
|
75
|
+
rule = rule.sub(var, radar(var))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
if lock
|
79
|
+
return rule
|
80
|
+
else
|
81
|
+
return decrypt(rule)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def radar(map)
|
86
|
+
rule = ""
|
87
|
+
if @passable
|
88
|
+
@theorems.each do | theorem |
|
89
|
+
if theorem["path"].eql?(map)
|
90
|
+
rule = theorem["rule"]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
else
|
94
|
+
rule = @theorems[@fuzzer.random_number(0, @theorems.size)]
|
95
|
+
end
|
96
|
+
return rule
|
97
|
+
end
|
98
|
+
|
99
|
+
def datum(rule)
|
100
|
+
datum = rule.scan(Regexp.new(@keys["keys"]["data"]))
|
101
|
+
datum.each do | data |
|
102
|
+
if @passable
|
103
|
+
rule = rule.sub(data, @cypher.arc(data))
|
104
|
+
else
|
105
|
+
rule = rule.sub(data, @fuzzer.random_character(64, ''))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
return rule
|
109
|
+
end
|
110
|
+
|
111
|
+
def group(rule)
|
112
|
+
groups = rule.scan(Regexp.new(@keys["keys"]["group"]))
|
113
|
+
groups.each do | group |
|
114
|
+
group = group.join("")
|
115
|
+
rule = rule.sub(group, decrypt(group[1..-2]))
|
116
|
+
end
|
117
|
+
return rule
|
118
|
+
end
|
119
|
+
|
120
|
+
def set(rule)
|
121
|
+
sets = rule.scan(Regexp.new(@keys["keys"]["set"]))
|
122
|
+
if sets
|
123
|
+
sets.each do | set |
|
124
|
+
rangesets = set[0].scan(Regexp.new(@keys["keys"]["range"]))
|
125
|
+
subsets = set[0].scan(Regexp.new(@keys["keys"]["subsets"]))
|
126
|
+
if rangesets.size > 0
|
127
|
+
rangesets.each do | rangeset |
|
128
|
+
subranges = []
|
129
|
+
subrangeset = rangeset[1..-2].split("..")
|
130
|
+
(subrangeset[0]..subrangeset[1]).each do | x |
|
131
|
+
subranges.push(x)
|
132
|
+
end
|
133
|
+
swap = subranges[@fuzzer.random_number(0,subranges.size)]
|
134
|
+
rule = rule.sub(rangeset, swap)
|
135
|
+
end
|
136
|
+
elsif subsets.size > 0
|
137
|
+
charset = []
|
138
|
+
subsets.each do | subset |
|
139
|
+
if subset
|
140
|
+
if @passable
|
141
|
+
charset += ruleset(subset[0])
|
142
|
+
else
|
143
|
+
charset += @fuzzer.random_character(1, '')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
if charset.size > 0
|
148
|
+
char = charset[@fuzzer.random_number(0,charset.size)]
|
149
|
+
rule = rule.sub(set[0], char)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
return (rule)
|
155
|
+
end
|
156
|
+
|
157
|
+
def ruleset(subset)
|
158
|
+
charset = []
|
159
|
+
if subset
|
160
|
+
if subset.size == 3
|
161
|
+
set_range = subset.split("-")
|
162
|
+
if set_range.size == 2
|
163
|
+
min = set_range[0]
|
164
|
+
max = set_range[1]
|
165
|
+
range_set = []
|
166
|
+
(min..max).each do | range |
|
167
|
+
range_set.push(range)
|
168
|
+
end
|
169
|
+
charset += range_set
|
170
|
+
end
|
171
|
+
elsif subset.size == 2 && subset[0].eql?("\\")
|
172
|
+
charset.push(subset[1])
|
173
|
+
else
|
174
|
+
charset.push(subset)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
return charset
|
178
|
+
end
|
179
|
+
|
180
|
+
def either(rule)
|
181
|
+
if !@passable
|
182
|
+
rule = charflip(rule, "|", "&")
|
183
|
+
end
|
184
|
+
subrules = rule.split(Regexp.new(@keys["keys"]["or"]))
|
185
|
+
subrule = subrules[@fuzzer.random_number(0,subrules.length)]
|
186
|
+
rule = rule.sub(rule, decrypt(subrule))
|
187
|
+
end
|
188
|
+
|
189
|
+
def concat(rule)
|
190
|
+
if !@passable
|
191
|
+
rule = charflip(rule, "&", "|")
|
192
|
+
end
|
193
|
+
combinator = ""
|
194
|
+
subrules = rule.split(Regexp.new(@keys["keys"]["and"]))
|
195
|
+
subrules.each do | subrule |
|
196
|
+
combinator += decrypt(subrule)
|
197
|
+
end
|
198
|
+
return rule.sub(rule, combinator)
|
199
|
+
end
|
200
|
+
|
201
|
+
def charflip(str, a, b)
|
202
|
+
charset = str.split("")
|
203
|
+
charset.each_with_index do | set, index |
|
204
|
+
if set.eql?(a)
|
205
|
+
charset[index] = b
|
206
|
+
elsif set.eql?(b)
|
207
|
+
charset[index] = a
|
208
|
+
else
|
209
|
+
end
|
210
|
+
end
|
211
|
+
return charset.join("")
|
212
|
+
end
|
213
|
+
|
214
|
+
def exists(rule)
|
215
|
+
group_ranges = rule.match(Regexp.new(@keys["keys"]["group"] + @keys["keys"]["exist"]))
|
216
|
+
set_ranges = rule.match(Regexp.new(@keys["keys"]["set"] + @keys["keys"]["exist"]))
|
217
|
+
ranges = []
|
218
|
+
ranges += group_ranges.eql?(nil) ? [] : group_ranges[0..-1]
|
219
|
+
ranges += set_ranges.eql?(nil) ? [] : set_ranges[0..-1]
|
220
|
+
if ranges
|
221
|
+
ranges.each do | range |
|
222
|
+
range_set = range.match(Regexp.new(@keys["keys"]["exist"]))
|
223
|
+
if range_set
|
224
|
+
subrule = ""
|
225
|
+
if @fuzzer.random_number(0,1).eql(1)
|
226
|
+
subrule = rule[0..rule.size-2]
|
227
|
+
end
|
228
|
+
rule = rule.sub(rule, decrypt(subrule))
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
return rule
|
233
|
+
end
|
234
|
+
|
235
|
+
def exclude(rule)
|
236
|
+
rule.scan(Regexp.new(@keys["keys"]["exclude"]))
|
237
|
+
violated = true
|
238
|
+
while violated.eql?(true) do
|
239
|
+
violated = false
|
240
|
+
decrypt(rule)
|
241
|
+
end
|
242
|
+
return rule
|
243
|
+
end
|
244
|
+
|
245
|
+
def repeat(rule)
|
246
|
+
combinator = ""
|
247
|
+
min = max = 0
|
248
|
+
repeater = rule.scan(Regexp.new(@keys["keys"]["repeat"]))[0]
|
249
|
+
if repeater
|
250
|
+
rule = rule.sub(repeater, "")
|
251
|
+
range = repeater.to_s[1..-2].split(":")
|
252
|
+
min = @passable ? range[0].to_i() : @fuzzer.random_number(0,min)
|
253
|
+
max = @passable ? range[1].to_i() : @fuzzer.random_number(min, rand(max + 9))
|
254
|
+
if min.eql?(max)
|
255
|
+
(0..max-1).each do | i |
|
256
|
+
combinator += decrypt(rule)
|
257
|
+
end
|
258
|
+
else
|
259
|
+
(0..min-1).each do | i |
|
260
|
+
combinator += decrypt(rule)
|
261
|
+
end
|
262
|
+
(min..max-min).each do | i |
|
263
|
+
combinator += decrypt(rule)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
return rule.sub(rule, combinator)
|
268
|
+
end
|
269
|
+
|
270
|
+
def escapable(rule)
|
271
|
+
escapes = rule.scan(Regexp.new(@keys["keys"]["escapable"]))
|
272
|
+
escapes.each do | escape |
|
273
|
+
if @passable
|
274
|
+
rule = rule.sub(escape, escape[1..-1])
|
275
|
+
else
|
276
|
+
rule = rule.sub(escape, @fuzzer.random_character(1, ''))
|
277
|
+
end
|
278
|
+
end
|
279
|
+
return decrypt(rule)
|
280
|
+
end
|
281
|
+
|
282
|
+
def remember(rule)
|
283
|
+
cortex = rule.scan(Regexp.new(@keys["keys"]["memorize"]))
|
284
|
+
bank = rule.split("+:")
|
285
|
+
memory = @memory[bank[1]]
|
286
|
+
if memory
|
287
|
+
return memory
|
288
|
+
else
|
289
|
+
bank = rule.split("+:")
|
290
|
+
rule = decrypt(bank[0])
|
291
|
+
memory = decrypt(bank[0])
|
292
|
+
return memory
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
7
297
|
end
|
8
298
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightning-bolt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Austin Vecchio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -96,9 +96,7 @@ files:
|
|
96
96
|
- bin/lightningbolt
|
97
97
|
- lib/lightning/bolt.rb
|
98
98
|
- lib/lightning/bolt/cli.rb
|
99
|
-
- lib/lightning/bolt/codex.rb
|
100
99
|
- lib/lightning/bolt/cypher.rb
|
101
|
-
- lib/lightning/bolt/encoding.yml
|
102
100
|
- lib/lightning/bolt/fuzzer.rb
|
103
101
|
- lib/lightning/bolt/keys.yml
|
104
102
|
- lib/lightning/bolt/templates/codex/en/colors.yml
|
data/lib/lightning/bolt/codex.rb
DELETED
@@ -1,302 +0,0 @@
|
|
1
|
-
require "lightning/bolt/cypher"
|
2
|
-
require "lightning/bolt/fuzzer"
|
3
|
-
|
4
|
-
require 'yaml'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
module Lightning
|
8
|
-
module Bolt
|
9
|
-
class Codex
|
10
|
-
def initialize(bookstore, theorems, memory)
|
11
|
-
@cypher = Lightning::Bolt::Cypher.new(bookstore)
|
12
|
-
@fuzzer = Lightning::Bolt::Fuzzer.new('UTF-8')
|
13
|
-
@keys = YAML.load_file("#{File.dirname(__FILE__)}/keys.yml")
|
14
|
-
@passable = true
|
15
|
-
@unique = false
|
16
|
-
@theorems = theorems
|
17
|
-
@memory = memory
|
18
|
-
end
|
19
|
-
|
20
|
-
def signal(passable, unique, name)
|
21
|
-
@passable = passable.eql?(nil) ? true : passable
|
22
|
-
@unique = unique.eql?(nil) ? false : unique
|
23
|
-
path = nil
|
24
|
-
@theorems.each do | theorem |
|
25
|
-
if theorem["name"].eql?(name)
|
26
|
-
path = theorem["path"]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
if path
|
30
|
-
path = decrypt(path)
|
31
|
-
path = rotar(path, @keys["keys"]["escapable"]) ? escapable(path) : path
|
32
|
-
return path
|
33
|
-
else
|
34
|
-
return ""
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def decrypt(rule)
|
41
|
-
rule = rotar(rule, @keys["keys"]["reference"]) ? references(rule) : rule
|
42
|
-
rule = rotar(rule, @keys["keys"]["data"]) ? datum(rule) : rule
|
43
|
-
rule = rotar(rule, @keys["keys"]["group"]) ? group(rule) : rule
|
44
|
-
rule = rotar(rule, @keys["keys"]["repeat"]) ? repeat(rule) : rule
|
45
|
-
rule = rotar(rule, @keys["keys"]["set"]) ? set(rule) : rule
|
46
|
-
#rule = rotar(rule, @keys["keys"]["not"]) ? exclude(rule) : rule
|
47
|
-
rule = rotar(rule, @keys["keys"]["or"]) ? either(rule) : rule
|
48
|
-
rule = rotar(rule, @keys["keys"]["and"]) ? concat(rule) : rule
|
49
|
-
rule = rotar(rule, @keys["keys"]["exist"]) ? exist(rule) : rule
|
50
|
-
rule = rotar(rule, @keys["keys"]["escapable"]) ? escapable(rule) : rule
|
51
|
-
rule = rotar(rule, @keys["keys"]["remember"]) ? remember(rule) : rule
|
52
|
-
return rule
|
53
|
-
end
|
54
|
-
|
55
|
-
def rotar(rule, expr)
|
56
|
-
return (rule.scan(Regexp.new(expr)).size > 0)
|
57
|
-
end
|
58
|
-
|
59
|
-
def references(rule)
|
60
|
-
vars = rule.scan(Regexp.new(@keys["keys"]["reference"]))
|
61
|
-
lock = false
|
62
|
-
vars.each do | var |
|
63
|
-
scan = radar(var)
|
64
|
-
if scan.eql?("")
|
65
|
-
lock = true
|
66
|
-
else
|
67
|
-
rule = rule.sub(var, radar(var))
|
68
|
-
end
|
69
|
-
end
|
70
|
-
if lock
|
71
|
-
return rule
|
72
|
-
else
|
73
|
-
return decrypt(rule)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def radar(map)
|
78
|
-
rule = ""
|
79
|
-
if @passable
|
80
|
-
@theorems.each do | theorem |
|
81
|
-
if theorem["path"].eql?(map)
|
82
|
-
rule = theorem["rule"]
|
83
|
-
end
|
84
|
-
end
|
85
|
-
else
|
86
|
-
rule = @theorems[@fuzzer.random_number(0, @theorems.size)]
|
87
|
-
end
|
88
|
-
return rule
|
89
|
-
end
|
90
|
-
|
91
|
-
def datum(rule)
|
92
|
-
datum = rule.scan(Regexp.new(@keys["keys"]["data"]))
|
93
|
-
datum.each do | data |
|
94
|
-
if @passable
|
95
|
-
rule = rule.sub(data, @cypher.arc(data))
|
96
|
-
else
|
97
|
-
rule = rule.sub(data, @fuzzer.launch(nil, 64, true))
|
98
|
-
end
|
99
|
-
end
|
100
|
-
return rule
|
101
|
-
end
|
102
|
-
|
103
|
-
def group(rule)
|
104
|
-
groups = rule.scan(Regexp.new(@keys["keys"]["group"]))
|
105
|
-
groups.each do | group |
|
106
|
-
group = group.join("")
|
107
|
-
rule = rule.sub(group, decrypt(group[1..-2]))
|
108
|
-
end
|
109
|
-
return rule
|
110
|
-
end
|
111
|
-
|
112
|
-
def set(rule)
|
113
|
-
sets = rule.scan(Regexp.new(@keys["keys"]["set"]))
|
114
|
-
if sets
|
115
|
-
sets.each do | set |
|
116
|
-
rangesets = set[0].scan(Regexp.new(@keys["keys"]["range"]))
|
117
|
-
subsets = set[0].scan(Regexp.new(@keys["keys"]["subsets"]))
|
118
|
-
if rangesets.size > 0
|
119
|
-
rangesets.each do | rangeset |
|
120
|
-
subranges = []
|
121
|
-
subrangeset = rangeset[1..-2].split("..")
|
122
|
-
(subrangeset[0]..subrangeset[1]).each do | x |
|
123
|
-
subranges.push(x)
|
124
|
-
end
|
125
|
-
swap = subranges[@fuzzer.random_number(0,subranges.size)]
|
126
|
-
rule = rule.sub(rangeset, swap)
|
127
|
-
end
|
128
|
-
elsif subsets.size > 0
|
129
|
-
charset = []
|
130
|
-
subsets.each do | subset |
|
131
|
-
if subset
|
132
|
-
if @passable
|
133
|
-
charset += ruleset(subset[0])
|
134
|
-
else
|
135
|
-
charset += glyph
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
if charset.size > 0
|
140
|
-
char = charset[@fuzzer.random_number(0,charset.size)]
|
141
|
-
rule = rule.sub(set[0], char)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
return (rule)
|
147
|
-
end
|
148
|
-
|
149
|
-
def ruleset(subset)
|
150
|
-
charset = []
|
151
|
-
if subset
|
152
|
-
if subset.size == 3
|
153
|
-
set_range = subset.split("-")
|
154
|
-
if set_range.size == 2
|
155
|
-
min = set_range[0]
|
156
|
-
max = set_range[1]
|
157
|
-
range_set = []
|
158
|
-
(min..max).each do | range |
|
159
|
-
range_set.push(range)
|
160
|
-
end
|
161
|
-
charset += range_set
|
162
|
-
end
|
163
|
-
elsif subset.size == 2 && subset[0].eql?("\\")
|
164
|
-
charset.push(subset[1])
|
165
|
-
else
|
166
|
-
charset.push(subset)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
return charset
|
170
|
-
end
|
171
|
-
|
172
|
-
def glyph()
|
173
|
-
range_set = []
|
174
|
-
min = rand(65)
|
175
|
-
max = rand(129)
|
176
|
-
(min..@fuzzer.random_number(min,max)).each do | range |
|
177
|
-
range_set.push(range.to_s(2).to_i(2))
|
178
|
-
end
|
179
|
-
return charsets
|
180
|
-
end
|
181
|
-
|
182
|
-
def either(rule)
|
183
|
-
if !@passable
|
184
|
-
rule = charflip(rule, "|", "&")
|
185
|
-
end
|
186
|
-
subrules = rule.split(Regexp.new(@keys["keys"]["or"]))
|
187
|
-
subrule = subrules[@fuzzer.random_number(0,subrules.length)]
|
188
|
-
rule = rule.sub(rule, decrypt(subrule))
|
189
|
-
end
|
190
|
-
|
191
|
-
def concat(rule)
|
192
|
-
if !@passable
|
193
|
-
rule = charflip(rule, "&", "|")
|
194
|
-
end
|
195
|
-
combinator = ""
|
196
|
-
subrules = rule.split(Regexp.new(@keys["keys"]["and"]))
|
197
|
-
subrules.each do | subrule |
|
198
|
-
combinator += decrypt(subrule)
|
199
|
-
end
|
200
|
-
return rule.sub(rule, combinator)
|
201
|
-
end
|
202
|
-
|
203
|
-
def charflip(str, a, b)
|
204
|
-
charset = str.split("")
|
205
|
-
charset.each_with_index do | set, index |
|
206
|
-
if set.eql?(a)
|
207
|
-
charset[index] = b
|
208
|
-
elsif set.eql?(b)
|
209
|
-
charset[index] = a
|
210
|
-
else
|
211
|
-
end
|
212
|
-
end
|
213
|
-
return charset.join("")
|
214
|
-
end
|
215
|
-
|
216
|
-
def exists(rule)
|
217
|
-
group_ranges = rule.match(Regexp.new(@keys["keys"]["group"] + @keys["keys"]["exist"]))
|
218
|
-
set_ranges = rule.match(Regexp.new(@keys["keys"]["set"] + @keys["keys"]["exist"]))
|
219
|
-
ranges = []
|
220
|
-
ranges += group_ranges.eql?(nil) ? [] : group_ranges[0..-1]
|
221
|
-
ranges += set_ranges.eql?(nil) ? [] : set_ranges[0..-1]
|
222
|
-
if ranges
|
223
|
-
ranges.each do | range |
|
224
|
-
range_set = range.match(Regexp.new(@keys["keys"]["exist"]))
|
225
|
-
if range_set
|
226
|
-
subrule = ""
|
227
|
-
if @fuzzer.random_number(0,1).eql(1)
|
228
|
-
subrule = rule[0..rule.size-2]
|
229
|
-
end
|
230
|
-
rule = rule.sub(rule, decrypt(subrule))
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
return rule
|
235
|
-
end
|
236
|
-
|
237
|
-
def exclude(rule)
|
238
|
-
=begin
|
239
|
-
violated = true
|
240
|
-
rule = switch(rule)
|
241
|
-
while violated.eql?(true) do
|
242
|
-
violated = false
|
243
|
-
rule = decrypt(rule)
|
244
|
-
end
|
245
|
-
=end
|
246
|
-
return rule
|
247
|
-
end
|
248
|
-
|
249
|
-
def repeat(rule)
|
250
|
-
combinator = ""
|
251
|
-
min = max = 0
|
252
|
-
repeater = rule.scan(Regexp.new(@keys["keys"]["repeat"]))[0]
|
253
|
-
if repeater
|
254
|
-
rule = rule.sub(repeater, "")
|
255
|
-
range = repeater.to_s[1..-2].split(":")
|
256
|
-
min = @passable ? range[0].to_i() : @fuzzer.random_number(0,min)
|
257
|
-
max = @passable ? range[1].to_i() : @fuzzer.random_number(min, rand(max + 9))
|
258
|
-
if min.eql?(max)
|
259
|
-
(0..max-1).each do | i |
|
260
|
-
combinator += decrypt(rule)
|
261
|
-
end
|
262
|
-
else
|
263
|
-
(0..min-1).each do | i |
|
264
|
-
combinator += decrypt(rule)
|
265
|
-
end
|
266
|
-
(min..max-min).each do | i |
|
267
|
-
combinator += decrypt(rule)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
return rule.sub(rule, combinator)
|
272
|
-
end
|
273
|
-
|
274
|
-
def escapable(rule)
|
275
|
-
escapes = rule.scan(Regexp.new(@keys["keys"]["escapable"]))
|
276
|
-
escapes.each do | escape |
|
277
|
-
if @passable
|
278
|
-
rule = rule.sub(escape, escape[1..-1])
|
279
|
-
else
|
280
|
-
rule = rule.sub(escape, @fuzzer.launch(nil, 1, false))
|
281
|
-
end
|
282
|
-
end
|
283
|
-
return decrypt(rule)
|
284
|
-
end
|
285
|
-
|
286
|
-
def remember(rule)
|
287
|
-
cortex = rule.scan(Regexp.new(@keys["keys"]["memorize"]))
|
288
|
-
bank = rule.split("+:")
|
289
|
-
memory = @memory[bank[1]]
|
290
|
-
if memory
|
291
|
-
return memory
|
292
|
-
else
|
293
|
-
bank = rule.split("+:")
|
294
|
-
rule = decrypt(bank[0])
|
295
|
-
memory = decrypt(bank[0])
|
296
|
-
return memory
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
encoding: "UTF-8"
|
2
|
-
#encodable:
|
3
|
-
#
|
4
|
-
non-encodable:
|
5
|
-
start: 55296
|
6
|
-
end: 57343
|
7
|
-
non-printable:
|
8
|
-
- code: 0
|
9
|
-
char: NUL
|
10
|
-
- code: 1
|
11
|
-
char: SOH
|
12
|
-
- code: 2
|
13
|
-
char: STX
|
14
|
-
- code: 3
|
15
|
-
char: ETX
|
16
|
-
- code: 4
|
17
|
-
char: EOT
|
18
|
-
- code: 5
|
19
|
-
char: ENQ
|
20
|
-
- code: 6
|
21
|
-
char: ACK
|
22
|
-
- code: 7
|
23
|
-
char: BEL
|
24
|
-
- code: 8
|
25
|
-
char: BS
|
26
|
-
- code: 9
|
27
|
-
char: TAB
|
28
|
-
- code: A
|
29
|
-
char: LF
|
30
|
-
- code: B
|
31
|
-
char: VT
|
32
|
-
- code: C
|
33
|
-
char: FF
|
34
|
-
- code: D
|
35
|
-
char: CR
|
36
|
-
- code: E
|
37
|
-
char: SO
|
38
|
-
- code: F
|
39
|
-
char: SI
|
40
|
-
- code: 10
|
41
|
-
char: DLE
|
42
|
-
- code: 11
|
43
|
-
char: DC1
|
44
|
-
- code: 12
|
45
|
-
char: DC2
|
46
|
-
- code: 13
|
47
|
-
char: DC3
|
48
|
-
- code: 14
|
49
|
-
char: DC4
|
50
|
-
- code: 15
|
51
|
-
char: NAK
|
52
|
-
- code: 16
|
53
|
-
char: SYN
|
54
|
-
- code: 17
|
55
|
-
char: ETB
|
56
|
-
- code: 18
|
57
|
-
char: CAN
|
58
|
-
- code: 19
|
59
|
-
char: EM
|
60
|
-
- code: 1A
|
61
|
-
char: SUB
|
62
|
-
- code: 1B
|
63
|
-
char: ESC
|
64
|
-
- code: 1C
|
65
|
-
char: FS
|
66
|
-
- code: 1D
|
67
|
-
char: GS
|
68
|
-
- code: 1E
|
69
|
-
char: RS
|
70
|
-
- code: 1F
|
71
|
-
char: US
|
72
|
-
- code: 7F
|
73
|
-
char: DEL
|