ctf-party 1.2.0 → 1.3.3

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: cc518fdaca11359e723f1a25e93f159a791efb951098c6ddaf0dde1af2226476
4
- data.tar.gz: b18d37b97167e931c5e5a82303fda9ece61d8c3e460b57c8b280d80f1007be8d
3
+ metadata.gz: f5b53f3731ce007357cb7033f6758bbb8136bd7f66deddc1d519aa246f9aee6c
4
+ data.tar.gz: 5c17753bd1e9bbf34e82f639531c9fe496ca8dffc68a83b30d32cc05b5c0cc5d
5
5
  SHA512:
6
- metadata.gz: 9faca804bb4b67d01553d11516ba50eecfceff4d2ffad6c2a38c1db072b31e90b7740226637f45fca2b431d342be21457a4bc4ffd5f25fea9d015ff93ed89625
7
- data.tar.gz: fd5d70b588e54e6c863532ea2b11955d551242331b0e8c68f611ff6287bbb1259e6ebaf824b73310026c3ff93e4234c606abe0e118f3dba2d774d4d9a66a3d1a
6
+ metadata.gz: 2788b1c3b60d2f5ed5a3d05c1971e013f3c02317219368a408b0f375ce9bc3e92d9d67090ca92a39f4dfc908d8c6775d90e4a8cee91736474fd8f3b0ea9e0870
7
+ data.tar.gz: eae30b24bf35a6f6a8caab27bf13f496cc262abefd3d348f7c5e58835141c0a36261162045a17d86236277a0576b64ed9670d66812e82d3536d066fad4b59807
data/LICENSE.txt CHANGED
@@ -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
data/lib/ctf_party.rb CHANGED
@@ -6,3 +6,6 @@ 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'
@@ -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,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
@@ -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.
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
@@ -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
@@ -132,6 +148,11 @@ class String
132
148
  replace(from_hex(opts))
133
149
  end
134
150
 
151
+ # Alias for {String#from_hex!}.
152
+ def hex2str!(opts = {})
153
+ from_hex!(opts)
154
+ end
155
+
135
156
  # Encode an hexadecimal string to a binary string
136
157
  # @param opts [Hash] optional parameters
137
158
  # @option opts [String] :prefix Prefix of the input. Default value is a void
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Version
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.3'
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.0
4
+ version: 1.3.3
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: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.80'
103
+ version: '1.8'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.80'
110
+ version: '1.8'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: yard
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -135,22 +135,25 @@ files:
135
135
  - bin/ctf_party_console
136
136
  - lib/ctf_party.rb
137
137
  - lib/ctf_party/base64.rb
138
+ - lib/ctf_party/binary.rb
139
+ - lib/ctf_party/case.rb
140
+ - lib/ctf_party/cgi.rb
138
141
  - lib/ctf_party/digest.rb
139
142
  - lib/ctf_party/flag.rb
140
143
  - lib/ctf_party/hex.rb
141
144
  - lib/ctf_party/rot.rb
142
145
  - lib/ctf_party/version.rb
143
- homepage: https://orange-cyberdefense.github.io/ctf-party/
146
+ homepage: https://noraj.github.io/ctf-party/
144
147
  licenses:
145
148
  - MIT
146
149
  metadata:
147
150
  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:
151
+ bug_tracker_uri: https://github.com/noraj/ctf-party/issues
152
+ changelog_uri: https://github.com/noraj/ctf-party/blob/master/docs/CHANGELOG.md
153
+ documentation_uri: https://noraj.github.io/ctf-party/
154
+ homepage_uri: https://noraj.github.io/ctf-party/
155
+ source_code_uri: https://github.com/noraj/ctf-party/
156
+ post_install_message:
154
157
  rdoc_options: []
155
158
  require_paths:
156
159
  - lib
@@ -158,15 +161,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
161
  requirements:
159
162
  - - "~>"
160
163
  - !ruby/object:Gem::Version
161
- version: '2.4'
164
+ version: '2.7'
162
165
  required_rubygems_version: !ruby/object:Gem::Requirement
163
166
  requirements:
164
167
  - - ">="
165
168
  - !ruby/object:Gem::Version
166
169
  version: '0'
167
170
  requirements: []
168
- rubygems_version: 3.1.2
169
- signing_key:
171
+ rubygems_version: 3.1.4
172
+ signing_key:
170
173
  specification_version: 4
171
174
  summary: A library to enhance and speed up script/exploit writing for CTF players
172
175
  test_files: []