-
Notifications
You must be signed in to change notification settings - Fork 7
/
rand.rb
75 lines (60 loc) · 1.81 KB
/
rand.rb
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
class Random
def rand_val(rng)
begin
self.rand(rng)
rescue
rng.first + Kernel.rand(rng.last)
end
end
def rnd_bytes(size)
begin
self.bytes(size)
rescue
x = ''
size.times { x << rand_val(0..0xff).chr }
end
end
end
class FuzzLib
def initialize
@maxlibSize = 5000 #Max of 30000 bytes of fuzzing data
@commonDelimiters = ["\x0a", "\x0d", ",", ".", ":", ";",
"&", "%", "\$", "\x20", "\x00", "#",
"(", ")", "{", "}", "<", ">", "\"",
"'", "\\", "|", "@", "*", "-"]
@commonStrings = [ "\x41"*500, "\x41"*1000, "\x41"*2000,
"\x41"*3000, "\x41"*4000, "\x41"*5000,
"\x41"*6000, "\x41"*7000, "\x41"*8000,
"\x41"*10000,"\x41"*11000,"\x41"*12000,
"~!@#\$^&"*1000, "~!@#\$^&"*2000,
"~!@#\$^&"*3000, "~!@#\$^&"*4000,
"~!@#\$^&"*5000, "%n%n%n%n%n", "%p%p%p%p",
"%s"*500, "%x"*1000, "../"*1000,
"../"*5000, "%%20x", "%2e%2e/"*1000,
"16777215", "0x99999999", "0xffffffff",
"%u000", "AAAA"+"../"+"A"*300, "%"+"A"*3000]
@prng = ::Random.new
end
def __rndSize
@prng.rand_val(1...@maxlibSize)
end
def __rndList(list)
i = @prng.rand_val(0...list.size)
list.at(i)
end
def rndBinary
@prng.rnd_bytes(__rndSize)
end
def rndAscii
(1..__rndSize).map{|i| @prng.rand_val(65..90).chr}.join
end
def rndDelimiter
common + __rndList(@commonDelimiters) + common
end
def common
__rndList(@commonStrings)
end
def rndFunc
__rndList([lambda{common}, lambda{rndDelimiter}, lambda {rndAscii}, lambda { rndBinary }])
end
end