ctf-party 1.1.0 → 1.3.2

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: aa3a85e4dd2db7d636cd1e6f66ca0b32fb34567886901b1102eae35fcb1fbb1c
4
- data.tar.gz: aa6c2db8fb07651887d5711d0bfb6b544d422c4f091aaf1893cc6d345e467cc6
3
+ metadata.gz: 43e5c5fba11ab29415687644876bc3185a7b220adcc0da51bf36bac65b970600
4
+ data.tar.gz: 6dc55b3100a380a0ff2c11e61eda9f67fd7a7a1ae5fc9effae3bae870cf701df
5
5
  SHA512:
6
- metadata.gz: b1eebe8e48be92a2f4ce8141f6c41a8f4023a3db5d4091358b41a41f5f3b4d123552e382c323d80e29db256818934b2ca8f036e23af10f56a4c1a04861a4f9d9
7
- data.tar.gz: 067e1e47c7bad059917fa3774c9d5f37eb9ba37dcd0d8df0320a01bffeccae90a1958d8de8d41d6308040f5cc21e07025a5a34f4b6ef9ce8165ebb7246349134
6
+ metadata.gz: 36b8f7a716e66fcfb1aed39b71f586d5ad73e9c099a11651c7dfd29093e09f60b15e278036f7e4e7d74150ceca1c374308864634f8f58b8e4078ca261f60a389
7
+ data.tar.gz: 17618c1a863ed02b9f838bae87e2135e108d50350658c639494d9d9d2a7751319720a022f801a10a79a0bf0a03417d5262d043c137313d7a004dd08a81b5ab61
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Alexandre ZANNI
3
+ Copyright (c) 2020-2020 Alexandre ZANNI
4
+ Copyright (c) 2019-2020 Alexandre ZANNI at Orange Cyberdefense
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
@@ -6,3 +6,5 @@ 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'
@@ -74,14 +74,15 @@ class String
74
74
  (?:[a-zA-Z0-9+/]{2}==)|(?:[a-zA-Z0-9+/]{1}===))\Z}xn
75
75
  reg3 = /\A(?:[a-zA-Z0-9\-_]{4})*(?:|(?:[a-zA-Z0-9\-_]{3}=)|
76
76
  (?:[a-zA-Z0-9\-_]{2}==)|(?:[a-zA-Z0-9\-_]{1}===))\Z/xn
77
- if opts[:mode] == :strict || opts[:mode] == :rfc4648
77
+ case opts[:mode]
78
+ when :strict, :rfc4648
78
79
  b64 = true if reg1.match?(self)
79
- elsif opts[:mode] == :rfc2045
80
+ when :rfc2045
80
81
  b64 = true
81
82
  split("\n").each do |s|
82
83
  b64 = false unless reg1.match?(s)
83
84
  end
84
- elsif opts[:mode] == :urlsafe
85
+ when :urlsafe
85
86
  b64 = true if reg3.match?(self)
86
87
  else
87
88
  raise ArgumentError 'Wrong mode'
@@ -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
@@ -16,8 +16,6 @@ class String
16
16
  @@flag
17
17
  end
18
18
 
19
- # rubocop:disable Metrics/LineLength
20
-
21
19
  # Update the flag configuration.
22
20
  # @param hash [Hash] flag configuration
23
21
  # @option hash [String] :prefix prefix of the flag. Default: none.
@@ -40,8 +38,6 @@ class String
40
38
  @@flag.merge!(hash)
41
39
  end
42
40
 
43
- # rubocop:enable Metrics/LineLength
44
-
45
41
  # Format the current string into the configured flag format. See {.flag=}
46
42
  # example.
47
43
  # @return [String] the format flag.
@@ -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
@@ -78,9 +78,10 @@ class String
78
78
  opts[:nibble] ||= :high
79
79
  # convert
80
80
  out = ''
81
- if opts[:nibble] == :high
81
+ case opts[:nibble]
82
+ when :high
82
83
  out = unpack1('H*')
83
- elsif opts[:nibble] == :low
84
+ when :low
84
85
  out = unpack1('h*')
85
86
  end
86
87
  # char case management
@@ -89,6 +90,11 @@ class String
89
90
  return opts[:prefix] + out
90
91
  end
91
92
 
93
+ # Alias for {String#to_hex}.
94
+ def str2hex(opts = {})
95
+ to_hex(opts)
96
+ end
97
+
92
98
  # Encode a string into hexadecimal in place as described
93
99
  # for {String#to_hex}.
94
100
  # @example
@@ -99,6 +105,11 @@ class String
99
105
  replace(to_hex(opts))
100
106
  end
101
107
 
108
+ # Alias for {String#to_hex!}.
109
+ def str2hex!(opts = {})
110
+ to_hex!(opts)
111
+ end
112
+
102
113
  # Decode a hexadecimal string
103
114
  # @param opts [Hash] optional parameters
104
115
  # @option opts [String] :prefix Prefix of the input. Default value is a void
@@ -122,6 +133,11 @@ class String
122
133
  raise ArgumentError ':nibble expects :high or :low'
123
134
  end
124
135
 
136
+ # Alias for {String#from_hex}.
137
+ def hex2str(opts = {})
138
+ from_hex(opts)
139
+ end
140
+
125
141
  # Decode a hexadecimal string in place as described
126
142
  # for {String#from_hex}.
127
143
  # @example
@@ -131,4 +147,66 @@ class String
131
147
  def from_hex!(opts = {})
132
148
  replace(from_hex(opts))
133
149
  end
150
+
151
+ # Alias for {String#from_hex!}.
152
+ def hex2str!(opts = {})
153
+ from_hex!(opts)
154
+ end
155
+
156
+ # Encode an hexadecimal string to a binary string
157
+ # @param opts [Hash] optional parameters
158
+ # @option opts [String] :prefix Prefix of the input. Default value is a void
159
+ # string. Example of values: +0x+, +\x+.
160
+ # @return [String] the binary encoded string
161
+ # @example
162
+ # 'ab'.hex2bin # => "10101011"
163
+ # '\xf3'.hex2bin(prefix: '\x') # => "11110011"
164
+ def hex2bin(opts = {})
165
+ opts[:prefix] ||= ''
166
+ # remove prefix
167
+ out = sub(opts[:prefix], '')
168
+ # convert
169
+ return out.to_i(16).to_s(2)
170
+ end
171
+
172
+ # Encode an hexadecimal string to a binary string in place as described
173
+ # for {String#hex2bin}.
174
+ # @example
175
+ # a = 'ff'
176
+ # a.hex2bin!
177
+ # a # => => "11111111"
178
+ def hex2bin!(opts = {})
179
+ replace(hex2bin(opts))
180
+ end
181
+
182
+ # Encode an binary string to a hexadecimal string
183
+ # @param opts [Hash] optional parameters
184
+ # @option opts [String] :prefix Prefix of the output. Default value is a void
185
+ # string. Example of values: +0x+, +\x+.
186
+ # @option opts [Symbol] :case Char case of the ouput. Default value +:lower+.
187
+ # Other valid value +:upper+.
188
+ # @return [String] the hexadecimal encoded string
189
+ # @example
190
+ # '11110011'.bin2hex # => "f3"
191
+ # '11110011'.bin2hex({prefix: '0x', case: :upper}) # => "0xF3"
192
+ def bin2hex(opts = {})
193
+ opts[:prefix] ||= ''
194
+ opts[:case] ||= :lower
195
+ # convert
196
+ out = to_i(2).to_s(16)
197
+ # char case management
198
+ out = out.upcase if opts[:case] == :upper
199
+ # adding prefix must be done after case change
200
+ return opts[:prefix] + out
201
+ end
202
+
203
+ # Encode an binary string to a hexadecimal string in place as described
204
+ # for {String#bin2hex}.
205
+ # @example
206
+ # a = '11110011'
207
+ # a.bin2hex!
208
+ # a # => "f3"
209
+ def bin2hex!(opts = {})
210
+ replace(bin2hex(opts))
211
+ end
134
212
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Version
4
- VERSION = '1.1.0'
4
+ VERSION = '1.3.2'
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.1.0
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre ZANNI
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-03 00:00:00.000000000 Z
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,22 +135,24 @@ files:
135
135
  - bin/ctf_party_console
136
136
  - lib/ctf_party.rb
137
137
  - lib/ctf_party/base64.rb
138
+ - lib/ctf_party/case.rb
139
+ - lib/ctf_party/cgi.rb
138
140
  - lib/ctf_party/digest.rb
139
141
  - lib/ctf_party/flag.rb
140
142
  - lib/ctf_party/hex.rb
141
143
  - lib/ctf_party/rot.rb
142
144
  - lib/ctf_party/version.rb
143
- homepage: https://orange-cyberdefense.github.io/ctf-party/
145
+ homepage: https://noraj.github.io/ctf-party/
144
146
  licenses:
145
147
  - MIT
146
148
  metadata:
147
149
  yard.run: yard
148
- bug_tracker_uri: https://github.com/Orange-Cyberdefense/ctf-party/issues
149
- changelog_uri: https://github.com/Orange-Cyberdefense/ctf-party/blob/master/docs/CHANGELOG.md
150
- documentation_uri: https://orange-cyberdefense.github.io/ctf-party/
151
- homepage_uri: https://orange-cyberdefense.github.io/ctf-party/
152
- source_code_uri: https://github.com/Orange-Cyberdefense/ctf-party/
153
- post_install_message:
150
+ bug_tracker_uri: https://github.com/noraj/ctf-party/issues
151
+ changelog_uri: https://github.com/noraj/ctf-party/blob/master/docs/CHANGELOG.md
152
+ documentation_uri: https://noraj.github.io/ctf-party/
153
+ homepage_uri: https://noraj.github.io/ctf-party/
154
+ source_code_uri: https://github.com/noraj/ctf-party/
155
+ post_install_message:
154
156
  rdoc_options: []
155
157
  require_paths:
156
158
  - lib
@@ -158,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
160
  requirements:
159
161
  - - "~>"
160
162
  - !ruby/object:Gem::Version
161
- version: '2.4'
163
+ version: '2.7'
162
164
  required_rubygems_version: !ruby/object:Gem::Requirement
163
165
  requirements:
164
166
  - - ">="
@@ -166,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
168
  version: '0'
167
169
  requirements: []
168
170
  rubygems_version: 3.1.2
169
- signing_key:
171
+ signing_key:
170
172
  specification_version: 4
171
173
  summary: A library to enhance and speed up script/exploit writing for CTF players
172
174
  test_files: []