-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie-decode
executable file
·122 lines (98 loc) · 2.43 KB
/
cookie-decode
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
#!/usr/bin/env ruby
# coding: utf-8
#
# Decode cookies that string encodings are detected for
#
require 'base16'
require 'base62'
require 'base64'
require 'htmlentities'
require 'rbkb'
require 'zap_attack'
include ZapAttack::API
output, params = Array.new, Params.new
cookies = params.select { |h| h['type'] == 'cookie' }
cookies.each do |c|
values = c['Values']
values.each do |v|
s, acnt, aflag = v.dup, 0, true
loop do
break if acnt >= 2
if v.is_base16?
begin
s = Base16.decode16(s)
aflag = false
rescue Exception => e
STDERR.puts('Cookie value appears to be Base16 (hexadecimal), but could not decode!')
end
end
if v.is_base64?
begin
s = Base64.urlsafe_decode64(s)
aflag = false
rescue Exception => e1
begin
s = Base64.strict_decode64(s)
aflag = false
rescue Exception => e2
begin
s = Base64.decode64(s)
aflag = false
rescue Exception => e3
STDERR.puts("#{e1} #{e2} #{e3}")
end # e3
end # e2
end # e1
if s.empty?
STDERR.print('Cookie value appears to be Base64, but could not decode!')
STDERR.puts(v)
break
end
end
if v.match(%r{&[^&]+;})
b = true
begin
if b
s = CGI.unescapeHTML(s)
else
s = HTMLEntities.new.decode(s)
end
aflag = false
rescue Exception => e
if b
b = false
retry
else
STDERR.puts('Cookie value appears to have HTML entities, but could not decode!')
end # if b
end # begin
end # if v.match
if aflag
iflag = false
output.each do |i|
if i[:name].eql?(c['name'])
iflag = true
break
end
end
if iflag
output.map do |w|
if w[:name].eql?(c['name'])
w[:value] << s
break
end
end
else
output << { :name => c['name'], :value => [ s ] }
end # if output.include?
end # if aflag
acnt += 1
end # loop do
end # values.each
end # cookies.each
output.each do |o|
o[:value].sort!
o[:value].uniq!
STDOUT.puts("#{o[:name]} => #{o[:value]}")
end # output.each
exit 0