ctf-party 1.3.2 → 1.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43e5c5fba11ab29415687644876bc3185a7b220adcc0da51bf36bac65b970600
4
- data.tar.gz: 6dc55b3100a380a0ff2c11e61eda9f67fd7a7a1ae5fc9effae3bae870cf701df
3
+ metadata.gz: e5265fb514b440bf6ddb5f4baef32204784bf36d564e16d1d05164e42be29693
4
+ data.tar.gz: 9f56032becda314e6da26c5b752f0cafaa95689262cead61f1c0699d237bf271
5
5
  SHA512:
6
- metadata.gz: 36b8f7a716e66fcfb1aed39b71f586d5ad73e9c099a11651c7dfd29093e09f60b15e278036f7e4e7d74150ceca1c374308864634f8f58b8e4078ca261f60a389
7
- data.tar.gz: 17618c1a863ed02b9f838bae87e2135e108d50350658c639494d9d9d2a7751319720a022f801a10a79a0bf0a03417d5262d043c137313d7a004dd08a81b5ab61
6
+ metadata.gz: 8329dc68bf53cd5bbd5d20060000db3b1bbd35f74fcb8881dabe7ac699b80b9b3ed65644480b48429da076d3a77938b44814295dbeb2b9b368a8f37bb1c79325
7
+ data.tar.gz: e3663bc5224918b291ff740edb2623604660d41c752e4c9eba7cfc0cd82b7a0987fe24fcbfa425a6c9a691d0088632aec0b50a403cc5deb7c305986135965077
data/bin/ctf-party ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Ruby internal
5
+ require 'pp'
6
+ # Project internal
7
+ require 'ctf_party'
8
+ require 'ctf_party/version'
9
+ # External
10
+ require 'docopt'
11
+
12
+ cmd_whitelist = {
13
+ alternatecase: 'Change one characte on two upcase and the other downcase',
14
+ bin2hex: 'Encode an binary string to a hexadecimal string',
15
+ bin2str: 'Alias for from_bin',
16
+ dec2hex: 'Encode an decimal string to a hexadecimal string',
17
+ dec2str: 'Alias for from_dec',
18
+ from_b64: 'Decode the string from base64',
19
+ from_bin: 'Decode a binary string',
20
+ from_dec: 'Decode a decimal string (decimal to hexadecimal then hexadecimal to string)',
21
+ from_hex: 'Decode a hexadecimal string',
22
+ from_hexip: 'Decode a hexadecimal IP string into a dotted decimal one',
23
+ hex2bin: 'Encode an hexadecimal string to a binary string',
24
+ hex2dec: 'Encode an hexadecimal string to a decimal string',
25
+ hex2str: 'Alias for from_hex',
26
+ htmlescape: 'HTML escape the string',
27
+ htmlunescape: 'HTML unescape the string',
28
+ leet: 'Transform into leet speak (l337 5p34k)',
29
+ md5: 'Calculate the md5 hash of the string',
30
+ randomcase: 'Change the case of characters randomly',
31
+ rmd160: 'Calculate the RIPEMD-160 hash of the string',
32
+ rot13: 'Encrypt / Decrypt the string with Caesar cipher with a shift of 13',
33
+ sha1: 'Calculate the sha1 hash of the string',
34
+ sha2: 'Calculate the sha2 hash of the string',
35
+ sha2_256: 'Alias for sha2 with bitlen of 256',
36
+ sha2_384: 'Alias for sha2 with bitlen of 384',
37
+ sha2_512: 'Alias for sha2 with bitlen of 512',
38
+ str2bin: 'Alias for to_bin',
39
+ str2dec: 'Alias for to_dec',
40
+ str2hex: 'Alias for to_hex',
41
+ to_b64: 'Encode the string into base64',
42
+ to_bin: 'Encode a string into binary',
43
+ to_dec: 'Encode a string into decimal (string to hexadecimal then hexadecimal to decimal)',
44
+ to_hex: 'Encode a string into hexadecimal',
45
+ to_hexip: 'Encode a dotted decimal IP into a hexadecimal one',
46
+ urldecode: 'URL-decode the string',
47
+ urlencode: 'URL-encode the string'
48
+ }
49
+
50
+ doc = <<~DOCOPT
51
+ ctf-party by noraj
52
+
53
+ Usage:
54
+ ctf-party <string> <cmd>... [--debug]
55
+ ctf-party --list-commands [--debug]
56
+ ctf-party -h | --help
57
+ ctf-party --version
58
+
59
+ Options:
60
+ -l, --list-commands List available commands (see https://noraj.github.io/ctf-party/yard/String.html)
61
+ --debug Display arguments
62
+ -h, --help Show this screen
63
+ --version Show version
64
+
65
+ Examples:
66
+ ctf-party 'security' to_hex
67
+ ctf-party 'NzQ2Zjc0NmY=' from_b64 hex2str str2bin
68
+ DOCOPT
69
+
70
+ begin
71
+ args = Docopt.docopt(doc, version: Version::VERSION)
72
+ # use case 1, using the tool
73
+ pp args if args['--debug']
74
+ if args['<string>']
75
+ wrong_cmd = args['<cmd>'] - cmd_whitelist.keys.map(&:to_s)
76
+ if wrong_cmd.empty?
77
+ output = args['<string>']
78
+ args['<cmd>'].each do |cmd|
79
+ output = output.public_send(cmd)
80
+ end
81
+ puts output
82
+ else
83
+ abort "Those commands don't exist: #{wrong_cmd}"
84
+ end
85
+ elsif args['--list-commands']
86
+ cmd_whitelist.each do |k, v|
87
+ puts "#{k.to_s.ljust(15)}#{v}"
88
+ end
89
+ end
90
+ # use case 2, help: already handled by docopt
91
+ # use case 3, version: already handled by docopt
92
+ rescue Docopt::Exit => e
93
+ puts e.message
94
+ end
data/lib/ctf_party.rb CHANGED
@@ -8,3 +8,6 @@ require 'ctf_party/flag'
8
8
  require 'ctf_party/hex'
9
9
  require 'ctf_party/case'
10
10
  require 'ctf_party/cgi'
11
+ require 'ctf_party/binary'
12
+ require 'ctf_party/leet'
13
+ require 'ctf_party/dec'
@@ -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,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
@@ -209,4 +214,63 @@ class String
209
214
  def bin2hex!(opts = {})
210
215
  replace(bin2hex(opts))
211
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
212
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/rot.rb CHANGED
@@ -16,9 +16,9 @@ class String
16
16
  def rot(opts = {})
17
17
  opts[:shift] ||= 13
18
18
  alphabet = Array('a'..'z')
19
- lowercase = Hash[alphabet.zip(alphabet.rotate(opts[:shift]))]
19
+ lowercase = alphabet.zip(alphabet.rotate(opts[:shift])).to_h
20
20
  alphabet = Array('A'..'Z')
21
- uppercasecase = Hash[alphabet.zip(alphabet.rotate(opts[:shift]))]
21
+ uppercasecase = alphabet.zip(alphabet.rotate(opts[:shift])).to_h
22
22
  encrypter = lowercase.merge(uppercasecase)
23
23
  chars.map { |c| encrypter.fetch(c, c) }.join
24
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Version
4
- VERSION = '1.3.2'
4
+ VERSION = '1.4.1'
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ctf-party
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.1
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-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docopt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +58,14 @@ dependencies:
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3.0'
61
+ version: '4.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '3.0'
68
+ version: '4.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: minitest
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-skip
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rake
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +128,14 @@ dependencies:
100
128
  requirements:
101
129
  - - "~>"
102
130
  - !ruby/object:Gem::Version
103
- version: '0.80'
131
+ version: '1.8'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
136
  - - "~>"
109
137
  - !ruby/object:Gem::Version
110
- version: '0.80'
138
+ version: '1.8'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: yard
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -122,24 +150,29 @@ dependencies:
122
150
  - - "~>"
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0.9'
125
- description: A library to enhance and speed up script/exploit writingfor CTF players
126
- (or security researchers, bug bountyhunters, pentesters but mostly focused on CTF)
127
- bypatching the String class to add a short syntax of usual code patterns.
153
+ description: A CLI tool & library to enhance and speed up script/exploitwriting for
154
+ CTF players (or security researchers, bug bountyhunters, pentesters but mostly focused
155
+ on CTF) bypatching the String class to add a short syntax of usualcode patterns.
128
156
  email: alexandre.zanni@engineer.com
129
157
  executables:
158
+ - ctf-party
130
159
  - ctf_party_console
131
160
  extensions: []
132
161
  extra_rdoc_files: []
133
162
  files:
134
163
  - LICENSE.txt
164
+ - bin/ctf-party
135
165
  - bin/ctf_party_console
136
166
  - lib/ctf_party.rb
137
167
  - lib/ctf_party/base64.rb
168
+ - lib/ctf_party/binary.rb
138
169
  - lib/ctf_party/case.rb
139
170
  - lib/ctf_party/cgi.rb
171
+ - lib/ctf_party/dec.rb
140
172
  - lib/ctf_party/digest.rb
141
173
  - lib/ctf_party/flag.rb
142
174
  - lib/ctf_party/hex.rb
175
+ - lib/ctf_party/leet.rb
143
176
  - lib/ctf_party/rot.rb
144
177
  - lib/ctf_party/version.rb
145
178
  homepage: https://noraj.github.io/ctf-party/
@@ -158,17 +191,21 @@ require_paths:
158
191
  - lib
159
192
  required_ruby_version: !ruby/object:Gem::Requirement
160
193
  requirements:
161
- - - "~>"
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: 2.7.0
197
+ - - "<"
162
198
  - !ruby/object:Gem::Version
163
- version: '2.7'
199
+ version: '3.1'
164
200
  required_rubygems_version: !ruby/object:Gem::Requirement
165
201
  requirements:
166
202
  - - ">="
167
203
  - !ruby/object:Gem::Version
168
204
  version: '0'
169
205
  requirements: []
170
- rubygems_version: 3.1.2
206
+ rubygems_version: 3.2.15
171
207
  signing_key:
172
208
  specification_version: 4
173
- summary: A library to enhance and speed up script/exploit writing for CTF players
209
+ summary: A CLI tool & library to enhance and speed up script/exploitwriting for CTF
210
+ players
174
211
  test_files: []