pwn 0.4.462 → 0.4.465

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: 37d931b296420b63615c112480340d40f4acbdfb6bb256e913c455c8295c719c
4
- data.tar.gz: 55217d2337393257a470dd1fdc2db4ca06c51181aa58051d60c7abfdcee98c88
3
+ metadata.gz: 0ce80ecfe98017552fc1b5da930b332b64284fa51ae55465fd8774bcdc354a77
4
+ data.tar.gz: 70880e0ec3b2c750e0c2ac60cd41deaea5aada6bfd191cd9ce21d7a1dd7e7bbf
5
5
  SHA512:
6
- metadata.gz: 6a091c103a8fb6e5d57fa2016cde91ea6df3c3e48d6df55dc1e90aaab59c6c1a5ef22fa77b22560bf732dab9e7a74a7e4de8e00d83cbed203b9ed67ec322c7ea
7
- data.tar.gz: 621f3fadae40efe379949ea7f85cba3ed62b78740296daac6a08646468bade05c74b34da1399cb46a3c1f16c1c739a882e5d2d5b0f720d7c441987a780c06e87
6
+ metadata.gz: 3abe9759400c7cc906788386eb0efe23f0411a93f6ae299ad0f365ba9358c9440fd550d710eec59eba01fc7947e6403f44ce78b408a9a54e4e365fbff76a6140
7
+ data.tar.gz: a25c91a96cf55c80ba0ba8b3e080ddc1a6a712082a00c3b8fb16869d621f97a693b3220c105e942c1b9b36cc3453cd94fd7d6747f9517a6a0d8bd1244fb9eeee
data/.rubocop_todo.yml CHANGED
@@ -1,47 +1,47 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-05-08 06:06:43 UTC using RuboCop version 1.29.0.
3
+ # on 2022-05-27 23:04:56 UTC using RuboCop version 1.30.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 227
9
+ # Offense count: 234
10
10
  Lint/UselessAssignment:
11
11
  Enabled: false
12
12
 
13
- # Offense count: 246
13
+ # Offense count: 253
14
14
  # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
15
15
  Metrics/AbcSize:
16
16
  Max: 328
17
17
 
18
- # Offense count: 60
18
+ # Offense count: 63
19
19
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
20
20
  # IgnoredMethods: refine
21
21
  Metrics/BlockLength:
22
- Max: 194
22
+ Max: 196
23
23
 
24
24
  # Offense count: 45
25
25
  # Configuration parameters: CountBlocks.
26
26
  Metrics/BlockNesting:
27
27
  Max: 5
28
28
 
29
- # Offense count: 83
29
+ # Offense count: 89
30
30
  # Configuration parameters: IgnoredMethods.
31
31
  Metrics/CyclomaticComplexity:
32
32
  Max: 231
33
33
 
34
- # Offense count: 440
34
+ # Offense count: 459
35
35
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
36
36
  Metrics/MethodLength:
37
37
  Max: 466
38
38
 
39
- # Offense count: 33
39
+ # Offense count: 34
40
40
  # Configuration parameters: CountComments, CountAsOne.
41
41
  Metrics/ModuleLength:
42
42
  Max: 1186
43
43
 
44
- # Offense count: 75
44
+ # Offense count: 81
45
45
  # Configuration parameters: IgnoredMethods.
46
46
  Metrics/PerceivedComplexity:
47
47
  Max: 51
@@ -50,33 +50,33 @@ Metrics/PerceivedComplexity:
50
50
  Style/ClassVars:
51
51
  Enabled: false
52
52
 
53
- # Offense count: 281
54
- # This cop supports safe auto-correction (--auto-correct).
53
+ # Offense count: 285
54
+ # This cop supports safe autocorrection (--autocorrect).
55
55
  # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
56
56
  # SupportedStyles: assign_to_condition, assign_inside_condition
57
57
  Style/ConditionalAssignment:
58
58
  Enabled: false
59
59
 
60
60
  # Offense count: 2
61
- # This cop supports safe auto-correction (--auto-correct).
61
+ # This cop supports safe autocorrection (--autocorrect).
62
62
  Style/ExplicitBlockArgument:
63
63
  Exclude:
64
64
  - 'lib/pwn/plugins/nmap_it.rb'
65
65
 
66
66
  # Offense count: 95
67
- # This cop supports safe auto-correction (--auto-correct).
67
+ # This cop supports safe autocorrection (--autocorrect).
68
68
  Style/RedundantCondition:
69
69
  Exclude:
70
70
  - 'bin/pwn_simple_http_server'
71
71
  - 'lib/pwn/plugins/packet.rb'
72
72
 
73
73
  # Offense count: 44
74
- # This cop supports unsafe auto-correction (--auto-correct-all).
74
+ # This cop supports unsafe autocorrection (--autocorrect-all).
75
75
  Style/SlicingWithRange:
76
76
  Enabled: false
77
77
 
78
- # Offense count: 531
79
- # This cop supports safe auto-correction (--auto-correct).
78
+ # Offense count: 555
79
+ # This cop supports safe autocorrection (--autocorrect).
80
80
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
81
81
  # URISchemes: http, https
82
82
  Layout/LineLength:
data/README.md CHANGED
@@ -37,7 +37,7 @@ $ rvm use ruby-3.1.2@pwn
37
37
  $ rvm list gemsets
38
38
  $ gem install --verbose pwn
39
39
  $ pwn
40
- pwn[v0.4.462]:001 >>> PWN.help
40
+ pwn[v0.4.465]:001 >>> PWN.help
41
41
  ```
42
42
 
43
43
  [![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)
@@ -52,7 +52,7 @@ $ rvm use ruby-3.1.2@pwn
52
52
  $ gem uninstall --all --executables pwn
53
53
  $ gem install --verbose pwn
54
54
  $ pwn
55
- pwn[v0.4.462]:001 >>> PWN.help
55
+ pwn[v0.4.465]:001 >>> PWN.help
56
56
  ```
57
57
 
58
58
 
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
4
+ require 'pwn'
5
+ require 'optparse'
6
+
7
+ opts = {}
8
+ OptionParser.new do |options|
9
+ options.banner = "USAGE:
10
+ #{$PROGRAM_NAME} [opts]
11
+ "
12
+
13
+ options.on('-dDEV', '--block-dev=DEV', '<Optional - MSR206 block device path (defaults to /dev/ttyUSB0)>') do |d|
14
+ opts[:block_dev] = d
15
+ end
16
+
17
+ options.on('-bBAUD', '--baud=BAUD', '<Optional - (defaults to 9600)>') do |b|
18
+ opts[:baud] = b
19
+ end
20
+
21
+ options.on('-DDATABITS', '--data-bits=DATABITS', '<Optional - (defaults to 8)>') do |d|
22
+ opts[:data_bits] = d
23
+ end
24
+
25
+ options.on('-sSTOPBITS', '--stop-bits=STOPBITS', '<Optional - (defaults to 1)>') do |s|
26
+ opts[:stop_bits] = s
27
+ end
28
+
29
+ options.on('-pPARITY', '--parity=PARITY', '<Optional - even|mark|odd|space|none (defaults to none)>') do |p|
30
+ opts[:parity] = p
31
+ end
32
+
33
+ options.on('-fFLOWCTRL', '--flow-control=FLOWCTRL', '<Optional - none||hard||soft (defaults to none)>') do |f|
34
+ opts[:flow_control] = f
35
+ end
36
+ end.parse!
37
+
38
+ if opts.empty?
39
+ puts `#{$PROGRAM_NAME} --help`
40
+ exit 1
41
+ end
42
+
43
+ begin
44
+ block_dev = opts[:block_dev] if File.exist?(opts[:block_dev])
45
+ baud = opts[:baud]
46
+ data_bits = opts[:data_bits]
47
+ stop_bits = opts[:stop_bits]
48
+ parity = opts[:parity]
49
+ flow_control = opts[:flow_control]
50
+
51
+ msr206_obj = PWN::Plugins::MSR206.connect(
52
+ block_dev: block_dev,
53
+ baud: baud,
54
+ data_bits: data_bits,
55
+ stop_bits: stop_bits,
56
+ parity: parity,
57
+ flow_control: flow_control
58
+ )
59
+
60
+ puts "- Welcome to #{File.basename($PROGRAM_NAME)} -"
61
+ puts "Connected via: #{block_dev} @ #{msr206_obj[:serial_conn].modem_params}"
62
+ puts "Flow Control: #{msr206_obj[:serial_conn].flow_control}"
63
+ puts "Signals: #{msr206_obj[:serial_conn].signals}"
64
+
65
+ exec_resp = PWN::Plugins::MSR206.exec(
66
+ msr206_obj: msr206_obj,
67
+ cmd: :simulate_power_cycle_warm_reset
68
+ )
69
+
70
+ exec_resp = PWN::Plugins::MSR206.exec(
71
+ msr206_obj: msr206_obj,
72
+ cmd: :version_report
73
+ )
74
+ puts "Firmware Version: #{exec_resp[:decoded]}"
75
+
76
+ # Main Menu
77
+ menu_msg = ''
78
+ loop do
79
+ unless menu_msg.include?('ERROR')
80
+ exec_resp = PWN::Plugins::MSR206.exec(
81
+ msr206_obj: msr206_obj,
82
+ cmd: :yellow_on
83
+ )
84
+ end
85
+
86
+ puts "\n>> MAIN MENU OPTIONS:"
87
+ puts '[(R)ead Card]'
88
+ puts '[(C)opy Card]'
89
+ puts '[(E)dit Card]'
90
+ puts '[(B)ackup Card]'
91
+ puts '[(W)arm Reset]'
92
+ puts '[(Q)uit]'
93
+ puts menu_msg
94
+ print 'MAIN MENU OPTION >>> '
95
+ menu_msg = ''
96
+ option = gets.scrub.chomp.strip.upcase.to_sym
97
+
98
+ case option
99
+ when :R
100
+ menu_msg = 'READY TO READ - PLEASE SWIPE CARD'
101
+ # Read Card
102
+ PWN::Plugins::MSR206.wait_for_swipe(
103
+ msr206_obj: msr206_obj,
104
+ type: :arm_to_read
105
+ )
106
+ when :C
107
+ menu_msg = 'READY TO COPY - PLEASE SWIPE ORIGINAL CARD'
108
+ # Read Original Card
109
+ PWN::Plugins::MSR206.wait_for_swipe(
110
+ msr206_obj: msr206_obj,
111
+ type: :arm_to_read
112
+ )
113
+
114
+ # TODO: Save Original Card Contents
115
+ # arm_to_write card to clone
116
+ # read cloned card to verify successful write
117
+ when :E
118
+ menu_msg = 'READY TO EDIT - PLEASE SWIPE TARGET CARD'
119
+ # Read Target Card
120
+ PWN::Plugins::MSR206.wait_for_swipe(
121
+ msr206_obj: msr206_obj,
122
+ type: :arm_to_read
123
+ )
124
+
125
+ # TODO: Save Original Card Contents
126
+ # arm_to_write card to edit
127
+ # read edited card to verify successful write
128
+ when :B
129
+ menu_msg = 'READY TO BACKUP - PLEASE SWIPE CARD'
130
+ # Read Card
131
+ PWN::Plugins::MSR206.wait_for_swipe(
132
+ msr206_obj: msr206_obj,
133
+ type: :arm_to_read
134
+ )
135
+ when :W
136
+ exec_resp = PWN::Plugins::MSR206.exec(
137
+ msr206_obj: msr206_obj,
138
+ cmd: :simulate_power_cycle_warm_reset
139
+ )
140
+ puts exec_resp.inspect
141
+ when :Q
142
+ exit
143
+ else
144
+ menu_msg = '****** ERROR: Invalid Menu Option Selected ******'
145
+ exec_resp = PWN::Plugins::MSR206.exec(
146
+ msr206_obj: msr206_obj,
147
+ cmd: :yellow_off
148
+ )
149
+
150
+ exec_resp = PWN::Plugins::MSR206.exec(
151
+ msr206_obj: msr206_obj,
152
+ cmd: :red_flash
153
+ )
154
+ end
155
+ end
156
+ rescue StandardError => e
157
+ raise e
158
+ rescue SystemExit, Interrupt
159
+ puts "\nGoodbye."
160
+ ensure
161
+ # Lights Off
162
+ exec_resp = PWN::Plugins::MSR206.exec(
163
+ msr206_obj: msr206_obj,
164
+ cmd: :green_off
165
+ )
166
+
167
+ exec_resp = PWN::Plugins::MSR206.exec(
168
+ msr206_obj: msr206_obj,
169
+ cmd: :yellow_off
170
+ )
171
+
172
+ exec_resp = PWN::Plugins::MSR206.exec(
173
+ msr206_obj: msr206_obj,
174
+ cmd: :red_off
175
+ )
176
+
177
+ msr206_obj = PWN::Plugins::MSR206.disconnect(msr206_obj: msr206_obj) if msr206_obj
178
+ end
@@ -9,18 +9,20 @@ module PWN
9
9
  # msr206_obj = PWN::Plugins::MSR206.connect(
10
10
  # block_dev: 'optional - serial block device path (defaults to /dev/ttyUSB0)',
11
11
  # baud: 'optional - (defaults to 9600)',
12
- # data_bits: 'optional - (defaults to 7)',
12
+ # data_bits: 'optional - (defaults to 8)',
13
13
  # stop_bits: 'optional - (defaults to 1)',
14
- # parity: 'optional - (defaults to SerialPort::ODD)',
15
- # flow_control: 'optional - (defaults to SerialPort::HARD) SerialPort::NONE|SerialPort::SOFT|SerialPort::HARD'
14
+ # parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none),'
15
+ # flow_control: 'optional - :none||:hard||:soft (defaults to :none)'
16
16
  # )
17
17
 
18
18
  public_class_method def self.connect(opts = {})
19
19
  # Default Baud Rate for this Device is 19200
20
+ opts[:block_dev] = '/dev/ttyUSB0' unless opts[:block_dev]
20
21
  opts[:baud] = 9_600 unless opts[:baud]
21
- opts[:data_bits] = 7 unless opts[:data_bits]
22
+ opts[:data_bits] = 8 unless opts[:data_bits]
22
23
  opts[:stop_bits] = 1 unless opts[:stop_bits]
23
- opts[:parity] = :odd unless opts[:parity]
24
+ opts[:parity] = :none unless opts[:parity]
25
+ opts[:flow_control] = :none unless opts[:flow_control]
24
26
  msr206_obj = PWN::Plugins::Serial.connect(opts)
25
27
  rescue StandardError => e
26
28
  disconnect(msr206_obj: msr206_obj) unless msr206_obj.nil?
@@ -91,6 +93,221 @@ module PWN
91
93
  raise e
92
94
  end
93
95
 
96
+ # Supported Method Parameters::
97
+ # parsed_cmd_resp_arr = decode(
98
+ # raw_byte_arr: 'required - raw_byte_arr produced in #parse_responses'
99
+ # )
100
+
101
+ private_class_method def self.decode(opts = {})
102
+ raw_byte_arr = opts[:raw_byte_arr]
103
+
104
+ decoded_data_str = ''
105
+ if raw_byte_arr
106
+ raw_byte_arr.first.split.each do |byte_str|
107
+ case byte_str
108
+ when '1B'
109
+ decoded_data_str += ''
110
+ when '20'
111
+ decoded_data_str += ' '
112
+ when '21'
113
+ decoded_data_str += '!'
114
+ when '22'
115
+ decoded_data_str += '"'
116
+ when '23'
117
+ decoded_data_str += '#'
118
+ when '24'
119
+ decoded_data_str += '$'
120
+ when '25'
121
+ decoded_data_str += '%'
122
+ when '26'
123
+ decoded_data_str += '&'
124
+ when '27'
125
+ decoded_data_str += "'"
126
+ when '28'
127
+ decoded_data_str += '('
128
+ when '29'
129
+ decoded_data_str += ')'
130
+ when '2A', 'AA'
131
+ decoded_data_str += '*'
132
+ when '2B', 'AB'
133
+ decoded_data_str += '+'
134
+ when '2C', 'AC'
135
+ decoded_data_str += ','
136
+ when '2D', 'AD'
137
+ decoded_data_str += '-'
138
+ when '2E', 'AE'
139
+ decoded_data_str += '.'
140
+ when '2F', 'AF'
141
+ decoded_data_str += '/'
142
+ when '30', 'B0'
143
+ decoded_data_str += '0'
144
+ when '31', 'B1'
145
+ decoded_data_str += '1'
146
+ when '32', 'B2'
147
+ decoded_data_str += '2'
148
+ when '33', 'B3'
149
+ decoded_data_str += '3'
150
+ when '34', 'B4'
151
+ decoded_data_str += '4'
152
+ when '35', 'B5'
153
+ decoded_data_str += '5'
154
+ when '36', 'B6'
155
+ decoded_data_str += '6'
156
+ when '37', 'B7'
157
+ decoded_data_str += '7'
158
+ when '38', 'B8'
159
+ decoded_data_str += '8'
160
+ when '39', 'B9'
161
+ decoded_data_str += '9'
162
+ when '3A', 'BA'
163
+ decoded_data_str += ':'
164
+ when '3B', 'BB'
165
+ decoded_data_str += ';'
166
+ when '3C', 'BC'
167
+ decoded_data_str += '<'
168
+ when '3D', 'BD'
169
+ decoded_data_str += '='
170
+ when '3E', 'BE'
171
+ decoded_data_str += '>'
172
+ when '3F', 'BF'
173
+ decoded_data_str += '?'
174
+ when '40', 'C0'
175
+ decoded_data_str += '@'
176
+ when '41', 'C1'
177
+ decoded_data_str += 'A'
178
+ when '42', 'C2'
179
+ decoded_data_str += 'B'
180
+ when '43', 'C3'
181
+ decoded_data_str += 'C'
182
+ when '44', 'C4'
183
+ decoded_data_str += 'D'
184
+ when '45', 'C5'
185
+ decoded_data_str += 'E'
186
+ when '46', 'C6'
187
+ decoded_data_str += 'F'
188
+ when '47', 'C7'
189
+ decoded_data_str += 'G'
190
+ when '48', 'C8'
191
+ decoded_data_str += 'H'
192
+ when '49', 'C9'
193
+ decoded_data_str += 'I'
194
+ when '4A', 'CA'
195
+ decoded_data_str += 'J'
196
+ when '4B', 'CB'
197
+ decoded_data_str += 'K'
198
+ when '4C', 'CC'
199
+ decoded_data_str += 'L'
200
+ when '4D', 'CD'
201
+ decoded_data_str += 'M'
202
+ when '4E', 'CE'
203
+ decoded_data_str += 'N'
204
+ when '4F', 'CF'
205
+ decoded_data_str += 'O'
206
+ when '50', 'D0'
207
+ decoded_data_str += 'P'
208
+ when '51', 'D1'
209
+ decoded_data_str += 'Q'
210
+ when '52', 'D2'
211
+ decoded_data_str += 'R'
212
+ when '53', 'D3'
213
+ decoded_data_str += 'S'
214
+ when '54', 'D4'
215
+ decoded_data_str += 'T'
216
+ when '55', 'D5'
217
+ decoded_data_str += 'U'
218
+ when '56', 'D6'
219
+ decoded_data_str += 'V'
220
+ when '57', 'D7'
221
+ decoded_data_str += 'W'
222
+ when '58', 'D8'
223
+ decoded_data_str += 'X'
224
+ when '59', 'D9'
225
+ decoded_data_str += 'Y'
226
+ when '5A', 'DA'
227
+ decoded_data_str += 'Z'
228
+ when '5B', 'DB'
229
+ decoded_data_str += '['
230
+ when '5C', 'DC'
231
+ decoded_data_str += '\\'
232
+ when '5D', 'DD'
233
+ decoded_data_str += ']'
234
+ when '5E', 'DE'
235
+ decoded_data_str += '^'
236
+ when '5F', 'DF'
237
+ decoded_data_str += '_'
238
+ when '60', 'E0'
239
+ decoded_data_str += '`'
240
+ when '61', 'E1'
241
+ decoded_data_str += 'a'
242
+ when '62', 'E2'
243
+ decoded_data_str += 'b'
244
+ when '63', 'E3'
245
+ decoded_data_str += 'c'
246
+ when '64', 'E4'
247
+ decoded_data_str += 'd'
248
+ when '65', 'E5'
249
+ decoded_data_str += 'e'
250
+ when '66', 'E6'
251
+ decoded_data_str += 'f'
252
+ when '67', 'E7'
253
+ decoded_data_str += 'g'
254
+ when '68', 'E8'
255
+ decoded_data_str += 'h'
256
+ when '69', 'E9'
257
+ decoded_data_str += 'i'
258
+ when '6A', 'EA'
259
+ decoded_data_str += 'j'
260
+ when '6B', 'EB'
261
+ decoded_data_str += 'k'
262
+ when '6C', 'EC'
263
+ decoded_data_str += 'l'
264
+ when '6D', 'ED'
265
+ decoded_data_str += 'm'
266
+ when '6E', 'EE'
267
+ decoded_data_str += 'n'
268
+ when '6F', 'EF'
269
+ decoded_data_str += 'o'
270
+ when '70', 'F0'
271
+ decoded_data_str += 'p'
272
+ when '71', 'F1'
273
+ decoded_data_str += 'q'
274
+ when '72', 'F2'
275
+ decoded_data_str += 'r'
276
+ when '73', 'F3'
277
+ decoded_data_str += 's'
278
+ when '74', 'F4'
279
+ decoded_data_str += 't'
280
+ when '75', 'F5'
281
+ decoded_data_str += 'u'
282
+ when '76', 'F6'
283
+ decoded_data_str += 'v'
284
+ when '77', 'F7'
285
+ decoded_data_str += 'w'
286
+ when '78', 'F8'
287
+ decoded_data_str += 'x'
288
+ when '79', 'F9'
289
+ decoded_data_str += 'y'
290
+ when '7A', 'FA'
291
+ decoded_data_str += 'z'
292
+ when '7B', 'FB'
293
+ decoded_data_str += '{'
294
+ when '7C', 'FC'
295
+ decoded_data_str += '|'
296
+ when '7D', 'FD'
297
+ decoded_data_str += '}'
298
+ when '7E', 'FE'
299
+ decoded_data_str += '~'
300
+ else
301
+ decoded_data_str += "\u00BF"
302
+ end
303
+ end
304
+ end
305
+
306
+ decoded_data_str
307
+ rescue StandardError => e
308
+ raise e
309
+ end
310
+
94
311
  # Supported Method Parameters::
95
312
  # parsed_cmd_resp_arr = parse_responses(
96
313
  # cmd_resp: 'required - command response string'
@@ -98,11 +315,15 @@ module PWN
98
315
 
99
316
  private_class_method def self.parse_responses(opts = {})
100
317
  msr206_obj = opts[:msr206_obj]
101
- cmd = opts[:cmd].to_s.scrub.strip.chomp
318
+ cmd = opts[:cmd]
102
319
 
103
320
  keep_parsing_responses = true
104
321
  next_response_detected = false
105
- all_cmd_responses = []
322
+ response = {}
323
+ response[:cmd] = cmd
324
+ response[:cmd] ||= :na
325
+
326
+ raw_byte_arr = []
106
327
  a_cmd_r_len = 0
107
328
  last_a_cmd_r_len = 0
108
329
 
@@ -112,26 +333,57 @@ module PWN
112
333
 
113
334
  while keep_parsing_responses
114
335
  until next_response_detected
115
- all_cmd_responses = PWN::Plugins::Serial.response(serial_obj: msr206_obj)
116
- cmd_resp = all_cmd_responses.last
336
+ raw_byte_arr = PWN::Plugins::Serial.response(serial_obj: msr206_obj)
337
+ cmd_resp = raw_byte_arr.last
117
338
  bytes_in_cmd_resp = cmd_resp.split.length if cmd_resp
118
- a_cmd_r_len = all_cmd_responses.length
339
+ a_cmd_r_len = raw_byte_arr.length
119
340
 
120
341
  next_response_detected = true if a_cmd_r_len > last_a_cmd_r_len
121
342
  end
122
343
 
123
- # cmd_resp = all_cmd_responses.last
124
- # case cmd_resp
125
- # when '21', '28', '29', '2A', '2B', '2D', '2F', '3A', '31', '32', '33', '3E', '3F', '5E', '7E', '98 FE'
126
- # next_response_detected = true
127
- # end
344
+ case cmd_resp
345
+ when '21'
346
+ response[:msg] = :invalid_command
347
+ when '28'
348
+ response[:msg] = :card_speed_measurement_start
349
+ when '29'
350
+ response[:msg] = :card_speed_measurement_end
351
+ when '2A'
352
+ response[:msg] = :error
353
+ when '2B'
354
+ response[:msg] = :no_data_found
355
+ when '2D'
356
+ response[:msg] = :insufficient_leading_zeros_for_custom_writing
357
+ when '2F'
358
+ response[:msg] = :first_lsb_char_not_one_for_custom_writing
359
+ when '3A'
360
+ response[:msg] = :power_on_report
361
+ when '31'
362
+ response[:msg] = :unsuccessful_read_after_write_track1
363
+ when '32'
364
+ response[:msg] = :unsuccessful_read_after_write_track2
365
+ when '33'
366
+ response[:msg] = :unsuccessful_read_after_write_track3
367
+ when '3E'
368
+ response[:msg] = :card_edge_detected
369
+ when '3F'
370
+ response[:msg] = :communications_error
371
+ when '5E'
372
+ response[:msg] = :ack_command_completed
373
+ when '7E'
374
+ response[:msg] = :command_not_supported_by_hardware
375
+ else
376
+ response[:msg] = :na
377
+ end
378
+
128
379
  next_response_detected = false
129
380
  last_a_cmd_r_len = a_cmd_r_len
130
- print "\n"
131
381
  keep_parsing_responses = false
132
382
  end
133
383
 
134
- all_cmd_responses
384
+ response[:raw] = raw_byte_arr
385
+ response[:decoded] = decode(raw_byte_arr: raw_byte_arr)
386
+ response
135
387
  rescue StandardError => e
136
388
  raise e
137
389
  ensure
@@ -279,6 +531,119 @@ module PWN
279
531
  PWN::Plugins::Serial.flush_session_data
280
532
  end
281
533
 
534
+ # Supported Method Parameters::
535
+ # PWN::Plugins::MSR206.wait_for_swipe(
536
+ # msr206_obj: 'required - msr206_obj returned from #connect method'
537
+ # )
538
+
539
+ public_class_method def self.wait_for_swipe(opts = {})
540
+ msr206_obj = opts[:msr206_obj]
541
+ type = opts[:type].to_s.scrub.strip.chomp.to_sym
542
+ types_arr = %i[
543
+ arm_to_read
544
+ arm_to_read_w_speed_prompts
545
+ arm_to_write_no_raw
546
+ arm_to_write_with_raw
547
+ arm_to_write_with_raw_speed_prompts
548
+ ]
549
+
550
+ raise "ERROR Unsupported type in #wait_for_swipe - #{type}. Valid types:\n#{types_arr}" unless types_arr.include?(type)
551
+
552
+ exec_resp = exec(
553
+ msr206_obj: msr206_obj,
554
+ cmd: :red_off
555
+ )
556
+
557
+ exec_resp = exec(
558
+ msr206_obj: msr206_obj,
559
+ cmd: :yellow_off
560
+ )
561
+
562
+ exec_resp = PWN::Plugins::MSR206.exec(
563
+ msr206_obj: msr206_obj,
564
+ cmd: type
565
+ )
566
+
567
+ exec_resp = exec(
568
+ msr206_obj: msr206_obj,
569
+ cmd: :green_on
570
+ )
571
+
572
+ exec_resp = PWN::Plugins::MSR206.exec(
573
+ msr206_obj: msr206_obj,
574
+ cmd: :card_edge_detect
575
+ )
576
+
577
+ print 'Ready. Please Swipe Card Now:'
578
+ loop do
579
+ exec_resp = parse_responses(
580
+ msr206_obj: msr206_obj,
581
+ cmd: :card_edge_detect
582
+ )
583
+
584
+ break if exec_resp[:msg] == :ack_command_completed
585
+ end
586
+
587
+ puts "*** ISO Track Format: Standard #{'*' * 17}"
588
+ print 'TRACK 1 >>> '
589
+ exec_resp = exec(
590
+ msr206_obj: msr206_obj,
591
+ cmd: :tx_iso_std_data_track1,
592
+ params: [0x31]
593
+ )
594
+ puts exec_resp[:decoded]
595
+ puts exec_resp.inspect
596
+
597
+ # print ">> Track 1 (ALT DATA)\n"
598
+ # exec_resp = exec(
599
+ # msr206_obj: msr206_obj,
600
+ # cmd: :alt_tx_iso_std_data_track1,
601
+ # params: [0x31]
602
+ # )
603
+ # puts exec_resp.inspect
604
+
605
+ print "\nTRACK 2 >>> "
606
+ exec_resp = exec(
607
+ msr206_obj: msr206_obj,
608
+ cmd: :tx_iso_std_data_track2,
609
+ params: [0x32]
610
+ )
611
+ puts exec_resp[:decoded]
612
+ puts exec_resp.inspect
613
+
614
+ # print ">> Track 2 (ALT DATA)\n"
615
+ # exec_resp = exec(
616
+ # msr206_obj: msr206_obj,
617
+ # cmd: :alt_tx_iso_std_data_track2,
618
+ # params: [0x32]
619
+ # )
620
+ # puts exec_resp.inspect
621
+
622
+ print "\nTRACK 3 >>> "
623
+ exec_resp = exec(
624
+ msr206_obj: msr206_obj,
625
+ cmd: :tx_iso_std_data_track3,
626
+ params: [0x33]
627
+ )
628
+ puts exec_resp[:decoded]
629
+ puts exec_resp.inspect
630
+
631
+ # print ">> Track 3 (ALT DATA)\n"
632
+ # exec_resp = exec(
633
+ # msr206_obj: msr206_obj,
634
+ # cmd: :alt_tx_iso_std_data_track3,
635
+ # params: [0x33]
636
+ # )
637
+ # puts exec_resp.inspect
638
+ rescue StandardError => e
639
+ raise e
640
+ ensure
641
+ exec_resp = exec(
642
+ msr206_obj: msr206_obj,
643
+ cmd: :green_off
644
+ )
645
+ end
646
+
282
647
  # Supported Method Parameters::
283
648
  # PWN::Plugins::MSR206.disconnect(
284
649
  # msr206_obj: 'required - msr206_obj returned from #connect method'
@@ -307,10 +672,10 @@ module PWN
307
672
  msr206_obj = #{self}.connect(
308
673
  block_dev: 'optional serial block device path (defaults to /dev/ttyUSB0)',
309
674
  baud: 'optional (defaults to 9600)',
310
- data_bits: 'optional (defaults to 7)',
675
+ data_bits: 'optional (defaults to 8)',
311
676
  stop_bits: 'optional (defaults to 1)',
312
- parity: 'optional (defaults to SerialPort::ODD)',
313
- flow_control: 'optional (defaults to SerialPort::NONE)'
677
+ parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none),'
678
+ flow_control: 'optional - :none||:hard||:soft (defaults to :none)'
314
679
  )
315
680
 
316
681
  cmds = #{self}.list_cmds
@@ -16,8 +16,8 @@ module PWN
16
16
  # baud: 'optional - (defaults to 9600)',
17
17
  # data_bits: 'optional - (defaults to 8)',
18
18
  # stop_bits: 'optional - (defaults to 1)',
19
- # parity: 'optional - (defaults to SerialPort::NONE)',
20
- # flow_control: 'optional - (defaults to SerialPort::HARD) SerialPort::NONE|SerialPort::SOFT|SerialPort::HARD'
19
+ # parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none)',
20
+ # flow_control: 'optional - :none||:hard||:soft (defaults to :none)'
21
21
  # )
22
22
 
23
23
  public_class_method def self.connect(opts = {})
@@ -278,8 +278,8 @@ module PWN
278
278
  baud: 'optional (defaults to 9600)',
279
279
  data_bits: 'optional (defaults to 8)',
280
280
  stop_bits: 'optional (defaults to 1)',
281
- parity: 'optional (defaults to SerialPort::NONE)',
282
- flow_control: 'optional (defaults to SerialPort::NONE)'
281
+ parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none)',
282
+ flow_control: 'optional - :none||:hard||:soft (defaults to :none)'
283
283
  )
284
284
 
285
285
  line_state = #{self}.get_line_state(
@@ -11,16 +11,18 @@ module PWN
11
11
  # baud: 'optional - (defaults to 19_200)',
12
12
  # data_bits: 'optional - (defaults to 8)',
13
13
  # stop_bits: 'optional - (defaults to 1)',
14
- # parity: 'optional - (defaults to SerialPort::NONE)',
15
- # flow_control: 'optional - (defaults to SerialPort::HARD) SerialPort::NONE|SerialPort::SOFT|SerialPort::HARD'
14
+ # parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none)',
15
+ # flow_control: 'optional - :none||:hard||:soft (defaults to :none)'
16
16
  # )
17
17
 
18
18
  public_class_method def self.connect(opts = {})
19
19
  # Default Baud Rate for this Device is 19200
20
+ opts[:block_dev] = '/dev/ttyUSB0' unless opts[:block_dev]
20
21
  opts[:baud] = 19_200 unless opts[:baud]
21
22
  opts[:data_bits] = 8 unless opts[:data_bits]
22
23
  opts[:stop_bits] = 1 unless opts[:stop_bits]
23
24
  opts[:parity] = :none unless opts[:parity]
25
+ opts[:flow_control] = :none unless opts[:flow_control]
24
26
  son_micro_rfid_obj = PWN::Plugins::Serial.connect(opts)
25
27
  rescue StandardError => e
26
28
  disconnect(son_micro_rfid_obj: son_micro_rfid_obj) unless son_micro_rfid_obj.nil?
@@ -365,8 +367,8 @@ module PWN
365
367
  baud: 'optional (defaults to 19_200)',
366
368
  data_bits: 'optional (defaults to 8)',
367
369
  stop_bits: 'optional (defaults to 1)',
368
- parity: 'optional (defaults to SerialPort::NONE)',
369
- flow_control: 'optional (defaults to SerialPort::NONE)'
370
+ parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :odd),'
371
+ flow_control: 'optional - :none||:hard||:soft (defaults to :none)'
370
372
  )
371
373
 
372
374
  cmds = #{self}.list_cmds
data/lib/pwn/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PWN
4
- VERSION = '0.4.462'
4
+ VERSION = '0.4.465'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.462
4
+ version: 0.4.465
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-26 00:00:00.000000000 Z
11
+ date: 2022-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -1016,6 +1016,7 @@ executables:
1016
1016
  - pwn_perimeter_recon
1017
1017
  - pwn_sast
1018
1018
  - pwn_serial_check_voicemail
1019
+ - pwn_serial_msr206
1019
1020
  - pwn_serial_qualcomm_commands
1020
1021
  - pwn_simple_http_server
1021
1022
  - pwn_web_cache_deception
@@ -1075,6 +1076,7 @@ files:
1075
1076
  - bin/pwn_perimeter_recon
1076
1077
  - bin/pwn_sast
1077
1078
  - bin/pwn_serial_check_voicemail
1079
+ - bin/pwn_serial_msr206
1078
1080
  - bin/pwn_serial_qualcomm_commands
1079
1081
  - bin/pwn_simple_http_server
1080
1082
  - bin/pwn_web_cache_deception