ctf-party 1.2.1 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3320dd66b3b305ed07cce2d8e9059f83f5c6c65b763401223af57d157bcbffb4
4
- data.tar.gz: 4ae59e35eb39beb3641cfa9e5d22609f93e18b9540884876d3982ab4ab7cc97e
3
+ metadata.gz: 588a5007de92c7e4c3fe7654f755eb9d1f9c81a738739455b3f9b89eb87ea9fa
4
+ data.tar.gz: 85bad8baf276cfa5315dc59f1804b4b21e21f46c8061d1d1bb2e5068e82167ad
5
5
  SHA512:
6
- metadata.gz: 72c0b492360e7a52af7e3abe000c275accc183f28ea3ca9753fdc92e43258abc45967cb0aa79448ebdcbd118d65aba33435c37354ba0595a0f3459d591b4d37b
7
- data.tar.gz: '0907211c7da78180930cfb8243169ae4bb3f63515fa3fd1538b576fa11f34e3278796c757dd494b6f206bca0b6dd09bda2e0308b7e3f42713cf40410e279e3b2'
6
+ metadata.gz: b0894030c2104ef8cd1421c8ec579e36760af961ad8782ff9ae9cab279a2ebd62dab7e19560d68b69bfabb616f5f84020735546d1470716cea0cf1e6ba6417ff
7
+ data.tar.gz: 923114873849d37ef0a3b1f5bd4a087e1a385c95e28dcd87761ecc247f51eda936ee058a977c6b25d7c35592133e40a602e89097cea68f8f36cdd61f2759d42d
data/lib/ctf_party.rb CHANGED
@@ -6,3 +6,7 @@ require 'ctf_party/rot'
6
6
  require 'ctf_party/digest'
7
7
  require 'ctf_party/flag'
8
8
  require 'ctf_party/hex'
9
+ require 'ctf_party/case'
10
+ require 'ctf_party/cgi'
11
+ require 'ctf_party/binary'
12
+ require 'ctf_party/leet'
@@ -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,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ # Change the case of characters randomly
5
+ # @return [String] the case modified string
6
+ # @example
7
+ # 'SELECT * FROM'.randomcase # => "SElECt * frOm"
8
+ # 'SELECT * FROM'.randomcase # => "selECT * FROm"
9
+ def randomcase
10
+ chars.map { |c| rand(0..1).zero? ? c.downcase : c.upcase }.join
11
+ end
12
+
13
+ # Change the case of characters randomly in place as described for
14
+ # {String#randomcase}.
15
+ def randomcase!
16
+ replace(randomcase)
17
+ end
18
+
19
+ # Change one characte on two upcase and the other downcase
20
+ # @param shift [Integer] 0: 1st character will be downcase, 1: 1st character
21
+ # will be upcase
22
+ # @return [String] the case modified string
23
+ # @example
24
+ # 'SELECT * FROM'.alternatecase # => "sElEcT * FrOm"
25
+ # 'SELECT * FROM'.alternatecase(1) # => "SeLeCt * fRoM"
26
+ def alternatecase(shift = 0)
27
+ chars.each_with_index.map { |c, i| (i + shift).even? ? c.downcase : c.upcase }.join
28
+ end
29
+
30
+ # Change one characte on two upcase and the other downcase in place as
31
+ # described for {String#alternatecase}.
32
+ def alternatecase!(shift = 0)
33
+ replace(alternatecase(shift))
34
+ end
35
+ 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 &quot;bar&quot; &lt;baz&gt;"
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 &quot;bar&quot; &lt;baz&gt;".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
data/lib/ctf_party/hex.rb CHANGED
@@ -22,7 +22,7 @@ class String
22
22
  # @example
23
23
  # a = 'ff'
24
24
  # a.hex2dec!
25
- # a # => => "255"
25
+ # a # => "255"
26
26
  def hex2dec!(opts = {})
27
27
  replace(hex2dec(opts))
28
28
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Version
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.4'
5
5
  end
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.2.1
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre ZANNI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-13 00:00:00.000000000 Z
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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: '0.80'
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: '0.80'
124
+ version: '1.8'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: yard
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -135,9 +149,13 @@ 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
153
+ - lib/ctf_party/case.rb
154
+ - lib/ctf_party/cgi.rb
138
155
  - lib/ctf_party/digest.rb
139
156
  - lib/ctf_party/flag.rb
140
157
  - lib/ctf_party/hex.rb
158
+ - lib/ctf_party/leet.rb
141
159
  - lib/ctf_party/rot.rb
142
160
  - lib/ctf_party/version.rb
143
161
  homepage: https://noraj.github.io/ctf-party/
@@ -165,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
183
  - !ruby/object:Gem::Version
166
184
  version: '0'
167
185
  requirements: []
168
- rubygems_version: 3.1.2
186
+ rubygems_version: 3.1.4
169
187
  signing_key:
170
188
  specification_version: 4
171
189
  summary: A library to enhance and speed up script/exploit writing for CTF players