ctf-party 1.3.0 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ctf_party.rb +4 -0
- data/lib/ctf_party/binary.rb +77 -0
- data/lib/ctf_party/cgi.rb +58 -0
- data/lib/ctf_party/dec.rb +49 -0
- data/lib/ctf_party/hex.rb +84 -0
- data/lib/ctf_party/leet.rb +29 -0
- data/lib/ctf_party/version.rb +1 -1
- metadata +25 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f09406956f91fdbe561c73f343efc68e28ad20c774370053e88472ebb1bb5098
|
4
|
+
data.tar.gz: 8bf8dfddfdbb4780578216b022d4815778f6f79d489506a2dba9fa0355bc8f90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40adf3307a9e8b99ccda9af3d1ab063413433998455cf92c292eb9b6e8d3deb754280673e796d7d980e22c87c222b7eb07c1fd7a6434d4597c186857ea973937
|
7
|
+
data.tar.gz: e3d1bbf14cf1dd05112833a7fa8096acaf0ee6065a266990fa56a71c30415f504a83255c8ae835188dfbd25593e37b983d06b7c137ed5e3d0598ebd3dcc83edd
|
data/lib/ctf_party.rb
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class String
|
4
|
+
# Encode a string into binary
|
5
|
+
# @param opts [Hash] optional parameters
|
6
|
+
# @option opts [Symbol] :bitnumbering Display output with most significant bit
|
7
|
+
# first (+:MSB+ default) or least significant bit first (+:LSB+).
|
8
|
+
# @return [String] the binary encoded string
|
9
|
+
# @example
|
10
|
+
# 'binary'.to_bin # => "011000100110100101101110011000010111001001111001"
|
11
|
+
# 'binary'.to_bin(bitnumbering: :LSB) # => "010001101001011001110110100001100100111010011110"
|
12
|
+
def to_bin(opts = {})
|
13
|
+
opts[:bitnumbering] ||= :MSB
|
14
|
+
# convert
|
15
|
+
return unpack1('B*') if opts[:bitnumbering] == :MSB
|
16
|
+
return unpack1('b*') if opts[:bitnumbering] == :LSB
|
17
|
+
|
18
|
+
raise ArgumentError ':bitnumbering expects :MSB or :LSB'
|
19
|
+
end
|
20
|
+
|
21
|
+
# Alias for {String#to_bin}.
|
22
|
+
def str2bin(opts = {})
|
23
|
+
to_bin(opts)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Encode a string into binary in place as described
|
27
|
+
# for {String#to_bin}.
|
28
|
+
# @example
|
29
|
+
# a = 'binary'
|
30
|
+
# a.to_bin!
|
31
|
+
# a # => "011000100110100101101110011000010111001001111001"
|
32
|
+
def to_bin!(opts = {})
|
33
|
+
replace(to_bin(opts))
|
34
|
+
end
|
35
|
+
|
36
|
+
# Alias for {String#to_bin!}.
|
37
|
+
def str2bin!(opts = {})
|
38
|
+
to_bin!(opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Decode a binary string
|
42
|
+
# @param opts [Hash] optional parameters
|
43
|
+
# @option opts [Symbol] :bitnumbering Display input with most significant bit
|
44
|
+
# first (+:MSB+ default) or least significant bit first (+:LSB+).
|
45
|
+
# @return [String] the binary decoded string
|
46
|
+
# @example
|
47
|
+
# '011000100110100101101110011000010111001001111001'.from_bin # => "binary"
|
48
|
+
# '010001101001011001110110100001100100111010011110'.from_bin(bitnumbering: :LSB) # => "binary"
|
49
|
+
def from_bin(opts = {})
|
50
|
+
opts[:bitnumbering] ||= :MSB
|
51
|
+
# convert
|
52
|
+
return Array(self).pack('B*') if opts[:bitnumbering] == :MSB
|
53
|
+
return Array(self).pack('b*') if opts[:bitnumbering] == :LSB
|
54
|
+
|
55
|
+
raise ArgumentError ':bitnumbering expects :MSB or :LSB'
|
56
|
+
end
|
57
|
+
|
58
|
+
# Alias for {String#from_bin}.
|
59
|
+
def bin2str(opts = {})
|
60
|
+
from_bin(opts)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Decode a binary string in place as described
|
64
|
+
# for {String#from_bin}.
|
65
|
+
# @example
|
66
|
+
# a = "011000100110100101101110011000010111001001111001"
|
67
|
+
# a.from_bin!
|
68
|
+
# a # => "binary"
|
69
|
+
def from_bin!(opts = {})
|
70
|
+
replace(from_bin(opts))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Alias for {String#from_bin!}.
|
74
|
+
def bin2str!(opts = {})
|
75
|
+
from_bin!(opts)
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Ruby standard library
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
class String
|
7
|
+
# URL-encode the string
|
8
|
+
# @return [String] the URL-encoded string
|
9
|
+
# @example
|
10
|
+
# "'Stop!' said Fred".urlencode # => "%27Stop%21%27+said+Fred"
|
11
|
+
def urlencode
|
12
|
+
CGI.escape self
|
13
|
+
end
|
14
|
+
|
15
|
+
# URL-encode the string in place as described for {String#urlencode}.
|
16
|
+
def urlencode!
|
17
|
+
replace(urlencode)
|
18
|
+
end
|
19
|
+
|
20
|
+
# URL-decode the string
|
21
|
+
# @return [String] the URL-decoded string
|
22
|
+
# @example
|
23
|
+
# "%27Stop%21%27+said+Fred".urldecode # => "'Stop!' said Fred"
|
24
|
+
def urldecode
|
25
|
+
CGI.unescape self
|
26
|
+
end
|
27
|
+
|
28
|
+
# URL-decode the string in place as described for {String#urldecode}.
|
29
|
+
def urldecode!
|
30
|
+
replace(urldecode)
|
31
|
+
end
|
32
|
+
|
33
|
+
# HTML escape the string
|
34
|
+
# @return [String] the HTML escaped string
|
35
|
+
# @example
|
36
|
+
# 'Usage: foo "bar" <baz>'.htmlescape # => "Usage: foo "bar" <baz>"
|
37
|
+
def htmlescape
|
38
|
+
CGI.escapeHTML self
|
39
|
+
end
|
40
|
+
|
41
|
+
# HTML escape the string in place as described for {String#htmlescape}.
|
42
|
+
def htmlescape!
|
43
|
+
replace(htmlescape)
|
44
|
+
end
|
45
|
+
|
46
|
+
# HTML unescape the string
|
47
|
+
# @return [String] the HTML unescaped string
|
48
|
+
# @example
|
49
|
+
# "Usage: foo "bar" <baz>".htmlunescape # => "Usage: foo \"bar\" <baz>"
|
50
|
+
def htmlunescape
|
51
|
+
CGI.unescapeHTML self
|
52
|
+
end
|
53
|
+
|
54
|
+
# HTML unescape the string in place as described for {String#htmlunescape}.
|
55
|
+
def htmlunescape!
|
56
|
+
replace(htmlunescape)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class String
|
4
|
+
# Encode a string into decimal (string to hexadecimal then hexadecimal to decimal)
|
5
|
+
# @return [String] the decimal encoded string
|
6
|
+
# @example
|
7
|
+
# 'noraj'.to_dec # => "474316169578"
|
8
|
+
def to_dec
|
9
|
+
str2hex.hex2dec
|
10
|
+
end
|
11
|
+
|
12
|
+
# Encode a string into decimal in place as described for {String#to_dec}.
|
13
|
+
def to_dec!
|
14
|
+
replace(to_dec)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Decode a decimal string (decimal to hexadecimal then hexadecimal to string)
|
18
|
+
# @return [String] the decimal decoded string
|
19
|
+
# @example
|
20
|
+
# '1834615104613964215417'.from_dec # => "ctf-party"
|
21
|
+
def from_dec
|
22
|
+
dec2hex.hex2str
|
23
|
+
end
|
24
|
+
|
25
|
+
# Decode a decimal string in place as described for {String#from_dec}.
|
26
|
+
def from_dec!
|
27
|
+
replace(from_dec)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Alias for {String#to_dec}.
|
31
|
+
def str2dec
|
32
|
+
to_dec
|
33
|
+
end
|
34
|
+
|
35
|
+
# Alias for {String#to_dec!}.
|
36
|
+
def str2dec!
|
37
|
+
replace(str2dec)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Alias for {String#from_dec}.
|
41
|
+
def dec2str
|
42
|
+
from_dec
|
43
|
+
end
|
44
|
+
|
45
|
+
# Alias for {String#from_dec!}.
|
46
|
+
def dec2str!
|
47
|
+
replace(dec2str)
|
48
|
+
end
|
49
|
+
end
|
data/lib/ctf_party/hex.rb
CHANGED
@@ -33,6 +33,8 @@ class String
|
|
33
33
|
# string. Example of values: +0x+, +\x+.
|
34
34
|
# @option opts [Symbol] :case Char case of the ouput. Default value +:lower+.
|
35
35
|
# Other valid value +:upper+.
|
36
|
+
# @option opts [Symbol] :padding Minimum size of the hexadecimal display
|
37
|
+
# (number of characters). Eg. 10 -> 0xA or 0x0A
|
36
38
|
# @return [String] the hexadecimal encoded string
|
37
39
|
# @example
|
38
40
|
# '255'.dec2hex # => "ff"
|
@@ -40,8 +42,11 @@ class String
|
|
40
42
|
def dec2hex(opts = {})
|
41
43
|
opts[:prefix] ||= ''
|
42
44
|
opts[:case] ||= :lower
|
45
|
+
opts[:padding] ||= 1
|
43
46
|
# convert
|
44
47
|
out = to_i.to_s(16)
|
48
|
+
# padding
|
49
|
+
out = ('0' * (opts[:padding] - 1)) + out if out.size < opts[:padding]
|
45
50
|
# char case management
|
46
51
|
out = out.upcase if opts[:case] == :upper
|
47
52
|
# adding prefix must be done after case change
|
@@ -90,6 +95,11 @@ class String
|
|
90
95
|
return opts[:prefix] + out
|
91
96
|
end
|
92
97
|
|
98
|
+
# Alias for {String#to_hex}.
|
99
|
+
def str2hex(opts = {})
|
100
|
+
to_hex(opts)
|
101
|
+
end
|
102
|
+
|
93
103
|
# Encode a string into hexadecimal in place as described
|
94
104
|
# for {String#to_hex}.
|
95
105
|
# @example
|
@@ -100,6 +110,11 @@ class String
|
|
100
110
|
replace(to_hex(opts))
|
101
111
|
end
|
102
112
|
|
113
|
+
# Alias for {String#to_hex!}.
|
114
|
+
def str2hex!(opts = {})
|
115
|
+
to_hex!(opts)
|
116
|
+
end
|
117
|
+
|
103
118
|
# Decode a hexadecimal string
|
104
119
|
# @param opts [Hash] optional parameters
|
105
120
|
# @option opts [String] :prefix Prefix of the input. Default value is a void
|
@@ -123,6 +138,11 @@ class String
|
|
123
138
|
raise ArgumentError ':nibble expects :high or :low'
|
124
139
|
end
|
125
140
|
|
141
|
+
# Alias for {String#from_hex}.
|
142
|
+
def hex2str(opts = {})
|
143
|
+
from_hex(opts)
|
144
|
+
end
|
145
|
+
|
126
146
|
# Decode a hexadecimal string in place as described
|
127
147
|
# for {String#from_hex}.
|
128
148
|
# @example
|
@@ -133,6 +153,11 @@ class String
|
|
133
153
|
replace(from_hex(opts))
|
134
154
|
end
|
135
155
|
|
156
|
+
# Alias for {String#from_hex!}.
|
157
|
+
def hex2str!(opts = {})
|
158
|
+
from_hex!(opts)
|
159
|
+
end
|
160
|
+
|
136
161
|
# Encode an hexadecimal string to a binary string
|
137
162
|
# @param opts [Hash] optional parameters
|
138
163
|
# @option opts [String] :prefix Prefix of the input. Default value is a void
|
@@ -189,4 +214,63 @@ class String
|
|
189
214
|
def bin2hex!(opts = {})
|
190
215
|
replace(bin2hex(opts))
|
191
216
|
end
|
217
|
+
|
218
|
+
# Decode a hexadecimal IP string into a dotted decimal one
|
219
|
+
# @param opts [Hash] optional parameters
|
220
|
+
# @option opts [String] :prefix Prefix of the input. Default value is a void
|
221
|
+
# string. Example of values: +0x+, +\x+.
|
222
|
+
# @option opts [Symbol] :nibble Display input with high nibble first
|
223
|
+
# (+:high+ default) or low nibble first (+:low+, used on Unix +/proc/net/tcp+).
|
224
|
+
# @return [String] the dotted decimal IP
|
225
|
+
# @example
|
226
|
+
# '0100007F'.from_hexip(nibble: :low) # => "127.0.0.1"
|
227
|
+
# '0x7f000001'.from_hexip(prefix: '0x') # => "127.0.0.1"
|
228
|
+
def from_hexip(opts = {})
|
229
|
+
opts[:prefix] ||= ''
|
230
|
+
opts[:nibble] ||= :high
|
231
|
+
# remove prefix
|
232
|
+
out = sub(opts[:prefix], '')
|
233
|
+
# convert
|
234
|
+
out = out.scan(/.{2}/).map(&:hex2dec)
|
235
|
+
out = out.reverse if opts[:nibble] == :low
|
236
|
+
out.join('.')
|
237
|
+
end
|
238
|
+
|
239
|
+
# Decode a hexadecimal IP string into a dotted decimal one in place as described
|
240
|
+
# for {String#from_hexip}.
|
241
|
+
def from_hexip!(opts = {})
|
242
|
+
replace(from_hexip(opts))
|
243
|
+
end
|
244
|
+
|
245
|
+
# Encode a dotted decimal IP into a hexadecimal one
|
246
|
+
# @param opts [Hash] optional parameters
|
247
|
+
# @option opts [String] :prefix Prefix of the output. Default value is a void
|
248
|
+
# string. Example of values: +0x+, +\x+.
|
249
|
+
# @option opts [Symbol] :case Char case of the ouput. Default value +:lower+.
|
250
|
+
# Other valid value +:upper+.
|
251
|
+
# @option opts [Symbol] :nibble Display output with high nibble first
|
252
|
+
# (+:high+ default) or low nibble first (+:low+, used on Unix +/proc/net/tcp+).
|
253
|
+
# @return [String] the hexadecimal encoded IP
|
254
|
+
# @example
|
255
|
+
# '127.0.0.1'.to_hexip # => "7f000001"
|
256
|
+
# '127.0.0.1'.to_hexip(nibble: :low) # => "0100007f"
|
257
|
+
def to_hexip(opts = {})
|
258
|
+
opts[:prefix] ||= ''
|
259
|
+
opts[:case] ||= :lower
|
260
|
+
opts[:nibble] ||= :high
|
261
|
+
# convert
|
262
|
+
out = split('.').map { |x| x.dec2hex(padding: 2) }
|
263
|
+
out = out.reverse if opts[:nibble] == :low
|
264
|
+
out = out.join
|
265
|
+
# char case management
|
266
|
+
out = out.upcase if opts[:case] == :upper
|
267
|
+
# adding prefix must be done after case change
|
268
|
+
return opts[:prefix] + out
|
269
|
+
end
|
270
|
+
|
271
|
+
# Encode a dotted decimal IP into a hexadecimal one in place as described
|
272
|
+
# for {String#to_hexip}.
|
273
|
+
def to_hexip!(opts = {})
|
274
|
+
replace(to_hexip(opts))
|
275
|
+
end
|
192
276
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class String
|
4
|
+
# Transform into leet speak (l337 5p34k)
|
5
|
+
# @example
|
6
|
+
# 'The quick brown fox jumps over the lazy dog'.leet # => "7h3 qu1ck 8r0wn f0x jump5 0v3r 7h3 14zy d06"
|
7
|
+
# 'leet speak'.leet # => "1337 5p34k"
|
8
|
+
def leet
|
9
|
+
tr = {
|
10
|
+
'T' => '7',
|
11
|
+
'E' => '3',
|
12
|
+
'I' => '1',
|
13
|
+
'L' => '1',
|
14
|
+
'O' => '0',
|
15
|
+
'S' => '5',
|
16
|
+
'A' => '4',
|
17
|
+
'G' => '6',
|
18
|
+
'B' => '8'
|
19
|
+
}
|
20
|
+
tr.merge! tr.transform_keys(&:downcase)
|
21
|
+
gsub(/[#{tr.keys.join}]/i, **tr)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Transform into leet speak (l337 5p34k) in place as described
|
25
|
+
# for {String#leet}.
|
26
|
+
def leet!
|
27
|
+
replace(leet)
|
28
|
+
end
|
29
|
+
end
|
data/lib/ctf_party/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ctf-party
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre ZANNI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '4.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '4.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-skip
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +114,14 @@ dependencies:
|
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
117
|
+
version: '1.8'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
124
|
+
version: '1.8'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: yard
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,10 +149,14 @@ files:
|
|
135
149
|
- bin/ctf_party_console
|
136
150
|
- lib/ctf_party.rb
|
137
151
|
- lib/ctf_party/base64.rb
|
152
|
+
- lib/ctf_party/binary.rb
|
138
153
|
- lib/ctf_party/case.rb
|
154
|
+
- lib/ctf_party/cgi.rb
|
155
|
+
- lib/ctf_party/dec.rb
|
139
156
|
- lib/ctf_party/digest.rb
|
140
157
|
- lib/ctf_party/flag.rb
|
141
158
|
- lib/ctf_party/hex.rb
|
159
|
+
- lib/ctf_party/leet.rb
|
142
160
|
- lib/ctf_party/rot.rb
|
143
161
|
- lib/ctf_party/version.rb
|
144
162
|
homepage: https://noraj.github.io/ctf-party/
|
@@ -166,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
184
|
- !ruby/object:Gem::Version
|
167
185
|
version: '0'
|
168
186
|
requirements: []
|
169
|
-
rubygems_version: 3.1.
|
187
|
+
rubygems_version: 3.1.4
|
170
188
|
signing_key:
|
171
189
|
specification_version: 4
|
172
190
|
summary: A library to enhance and speed up script/exploit writing for CTF players
|