Skip to content

Commit ea35d38

Browse files
committed
Gemfile && PWN::Plugins::Serial module - migrate deprecated serialport gem to uart gem :P
1 parent 8ede362 commit ea35d38

File tree

10 files changed

+75
-102
lines changed

10 files changed

+75
-102
lines changed

.rubocop_todo.yml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-10-30 18:35:44 UTC using RuboCop version 1.66.1.
3+
# on 2025-01-14 18:50:21 UTC using RuboCop version 1.70.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 5
10-
# This cop supports safe autocorrection (--autocorrect).
11-
# Configuration parameters: EnforcedStyle.
12-
# SupportedStyles: space, no_space
13-
Layout/LineContinuationSpacing:
14-
Exclude:
15-
- 'packer/provisioners/beef.rb'
16-
- 'packer/provisioners/metasploit.rb'
17-
- 'packer/provisioners/wpscan.rb'
18-
- 'vagrant/provisioners/beef.rb'
19-
209
# Offense count: 21
2110
# This cop supports safe autocorrection (--autocorrect).
22-
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
11+
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
2312
# URISchemes: http, https
2413
Layout/LineLength:
2514
Exclude:
@@ -41,7 +30,7 @@ Lint/NestedMethodDefinition:
4130
Exclude:
4231
- 'lib/pwn/plugins/repl.rb'
4332

44-
# Offense count: 312
33+
# Offense count: 316
4534
# This cop supports safe autocorrection (--autocorrect).
4635
# Configuration parameters: AutoCorrect.
4736
Lint/UselessAssignment:
@@ -117,7 +106,7 @@ Style/Alias:
117106
Style/ClassVars:
118107
Enabled: false
119108

120-
# Offense count: 282
109+
# Offense count: 280
121110
# This cop supports safe autocorrection (--autocorrect).
122111
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
123112
# SupportedStyles: assign_to_condition, assign_inside_condition
@@ -150,6 +139,21 @@ Style/MapIntoArray:
150139
- 'lib/pwn/plugins/credit_card.rb'
151140
- 'lib/pwn/plugins/nexpose_vuln_scan.rb'
152141

142+
# Offense count: 9
143+
# This cop supports safe autocorrection (--autocorrect).
144+
# Configuration parameters: AllowMethodComparison, ComparisonsThreshold.
145+
Style/MultipleComparison:
146+
Exclude:
147+
- 'lib/pwn/sast/banned_function_calls_c.rb'
148+
- 'lib/pwn/sast/cmd_execution_python.rb'
149+
- 'lib/pwn/sast/cmd_execution_ruby.rb'
150+
- 'lib/pwn/sast/deserial_java.rb'
151+
- 'lib/pwn/sast/factory.rb'
152+
- 'lib/pwn/sast/logger.rb'
153+
- 'lib/pwn/sast/throw_errors.rb'
154+
- 'lib/pwn/www/duckduckgo.rb'
155+
- 'lib/pwn/www/twitter.rb'
156+
153157
# Offense count: 1
154158
# This cop supports safe autocorrection (--autocorrect).
155159
Style/RedundantBegin:

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ gem 'ruby-saml', '1.17.0'
8888
gem 'rvm', '1.11.3.9'
8989
gem 'savon', '2.15.1'
9090
gem 'selenium-devtools', '0.131.0'
91-
gem 'serialport', '1.3.2'
91+
# gem 'serialport', '1.3.2'
9292
# gem 'sinatra', '4.0.0'
9393
gem 'slack-ruby-client', '2.4.0'
9494
gem 'socksify', '1.7.1'
@@ -97,6 +97,7 @@ gem 'sqlite3', '2.5.0'
9797
gem 'thin', '1.8.2'
9898
gem 'tty-prompt', '0.23.1'
9999
gem 'tty-spinner', '0.9.3'
100+
gem 'uart', '1.0.0'
100101
gem 'watir', '7.3.0'
101102
gem 'waveform', '0.1.3'
102103
gem 'webrick', '1.9.1'

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $ cd /opt/pwn
3737
$ ./install.sh
3838
$ ./install.sh ruby-gem
3939
$ pwn
40-
pwn[v0.5.228]:001 >>> PWN.help
40+
pwn[v0.5.229]:001 >>> PWN.help
4141
```
4242

4343
[![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)
@@ -48,21 +48,21 @@ pwn[v0.5.228]:001 >>> PWN.help
4848
It's wise to update pwn often as numerous versions are released/week:
4949
```
5050
$ rvm list gemsets
51-
$ rvm use ruby-3.3.5@pwn
51+
$ rvm use ruby-3.4.1@pwn
5252
$ gem uninstall --all --executables pwn
5353
$ gem install --verbose pwn
5454
$ pwn
55-
pwn[v0.5.228]:001 >>> PWN.help
55+
pwn[v0.5.229]:001 >>> PWN.help
5656
```
5757

5858
If you're using a multi-user install of RVM do:
5959
```
6060
$ rvm list gemsets
61-
$ rvm use ruby-3.3.5@pwn
61+
$ rvm use ruby-3.4.1@pwn
6262
$ rvmsudo gem uninstall --all --executables pwn
6363
$ rvmsudo gem install --verbose pwn
6464
$ pwn
65-
pwn[v0.5.228]:001 >>> PWN.help
65+
pwn[v0.5.229]:001 >>> PWN.help
6666
```
6767

6868
PWN periodically upgrades to the latest version of Ruby which is reflected in `/opt/pwn/.ruby-version`. The easiest way to upgrade to the latest version of Ruby from a previous PWN installation is to run the following script:

git_commit_test_reinit_gem.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ if (( $# == 3 )); then
1212
git add . --all
1313
echo 'Updating Gems to Latest Versions in Gemfile...'
1414
./find_latest_gem_versions_per_Gemfile.sh
15+
if [[ $? -ne 0 ]]; then
16+
echo 'ERROR: find_latest_gem_versions_per_Gemfile.sh failed!'
17+
exit 1
18+
fi
19+
1520
pwn_autoinc_version
21+
if [[ $? -ne 0 ]]; then
22+
echo 'ERROR: pwn_autoinc_version failed! Investigate and bump pwn version manually.'
23+
exit 1
24+
fi
25+
26+
# Generate RDoc JSONL for fine-tunning LLMs
1627
pwn_rdoc_to_jsonl --rdoc-root-dir '/opt/pwn/rdoc/PWN' --jsonl-results '/opt/pwn/third_party/pwn_rdoc.jsonl'
1728

1829
# Tag for every 100 commits (i.e. 0.1.100, 0.1.200, etc)
@@ -24,6 +35,10 @@ if (( $# == 3 )); then
2435

2536
git commit -a -S --author="${1} <${2}>" -m "${3}"
2637
./update_pwn.sh
38+
if [[ $? -ne 0 ]]; then
39+
echo 'ERROR: update_pwn.sh failed!'
40+
exit 1
41+
fi
2742

2843
latest_gem=$(ls pkg/*.gem)
2944
if [[ $latest_gem != "" ]]; then

lib/pwn/plugins/bus_pirate.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ module BusPirate
127127
baud: 'optional (defaults to 9600)',
128128
data_bits: 'optional (defaults to 8)',
129129
stop_bits: 'optional (defaults to 1)',
130-
parity: 'optional (defaults to SerialPort::NONE)',
131-
flow_control: 'optional (defaults to SerialPort::HARD) SerialPort::NONE|SerialPort::SOFT|SerialPort::HARD'
130+
parity: 'optional - :even||:odd|:none (defaults to :none)'
132131
)
133132
134133
#{self}.init_mode(

lib/pwn/plugins/msr206.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,7 @@ module MSR206
11691169
baud: 'optional (defaults to 9600)',
11701170
data_bits: 'optional (defaults to 8)',
11711171
stop_bits: 'optional (defaults to 1)',
1172-
parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none),'
1173-
flow_control: 'optional - :none|:hard|:soft (defaults to :none)'
1172+
parity: 'optional - :even||:odd|:none (defaults to :none)'
11741173
)
11751174
11761175
cmds = #{self}.list_cmds

lib/pwn/plugins/serial.rb

Lines changed: 26 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'serialport'
3+
require 'uart'
44
require 'io/wait'
55

66
module PWN
@@ -16,63 +16,34 @@ module Serial
1616
# baud: 'optional - (defaults to 9600)',
1717
# data_bits: 'optional - (defaults to 8)',
1818
# stop_bits: 'optional - (defaults to 1)',
19-
# parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none)',
20-
# flow_control: 'optional - :none||:hard||:soft (defaults to :none)'
19+
# parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none)'
2120
# )
2221

2322
public_class_method def self.connect(opts = {})
24-
block_dev = opts[:block_dev].to_s if File.exist?(
25-
opts[:block_dev].to_s
26-
)
27-
block_dev = '/dev/ttyUSB0' if opts[:block_dev].nil?
28-
29-
baud = if opts[:baud].nil?
30-
9_600
31-
else
32-
opts[:baud].to_i
33-
end
34-
35-
data_bits = if opts[:data_bits].nil?
36-
8
37-
else
38-
opts[:data_bits].to_i
39-
end
40-
41-
stop_bits = if opts[:stop_bits].nil?
42-
1
43-
else
44-
opts[:stop_bits].to_i
45-
end
23+
block_dev = opts[:block_dev] ||= '/dev/ttyUSB0'
24+
raise "Invalid block device: #{block_dev}" unless File.exist?(block_dev)
25+
26+
baud = opts[:baud] ||= 9_600
27+
data_bits = opts[:data_bits] ||= 8
28+
stop_bits = opts[:stop_bits] ||= 1
4629

30+
parity = nil
4731
case opts[:parity].to_s.to_sym
4832
when :even
49-
parity = SerialPort::EVEN
50-
when :mark
51-
parity = SerialPort::MARK
33+
parity = 'E'
5234
when :odd
53-
parity = SerialPort::ODD
54-
when :space
55-
parity = SerialPort::SPACE
56-
else
57-
parity = SerialPort::NONE
35+
parity = 'O'
36+
when :none
37+
parity = 'N'
5838
end
39+
raise "Invalid parity: #{opts[:parity]}" if parity.nil?
5940

60-
case opts[:flow_control].to_s.to_sym
61-
when :hard
62-
flow_control = SerialPort::HARD
63-
when :soft
64-
flow_control = SerialPort::SOFT
65-
else
66-
flow_control = SerialPort::NONE
67-
end
41+
mode = "#{data_bits}#{stop_bits}#{parity}"
6842

69-
serial_conn = SerialPort.new(
43+
serial_conn = UART.open(
7044
block_dev,
7145
baud,
72-
data_bits,
73-
stop_bits,
74-
parity,
75-
flow_control
46+
mode
7647
)
7748

7849
serial_obj = {}
@@ -124,7 +95,9 @@ module Serial
12495
public_class_method def self.get_line_state(opts = {})
12596
serial_obj = opts[:serial_obj]
12697
serial_conn = serial_obj[:serial_conn]
127-
serial_conn.get_signals
98+
# Should return something like:
99+
# {"rts"=>1, "dtr"=>1, "cts"=>1, "dsr"=>1, "dcd"=>0, "ri"=>0}
100+
serial_conn.lstat
128101
rescue StandardError => e
129102
disconnect(serial_obj: serial_obj) unless serial_obj.nil?
130103
raise e
@@ -138,6 +111,8 @@ module Serial
138111
public_class_method def self.get_modem_params(opts = {})
139112
serial_obj = opts[:serial_obj]
140113
serial_conn = serial_obj[:serial_conn]
114+
# Should return something like:
115+
# {"baud"=>9600, "data_bits"=>8, "stop_bits"=>1, "parity"=>0}
141116
serial_conn.get_modem_params
142117
rescue StandardError => e
143118
disconnect(serial_obj: serial_obj) unless serial_obj.nil?
@@ -155,8 +130,10 @@ module Serial
155130
payload = opts[:payload]
156131
serial_conn = serial_obj[:serial_conn]
157132

158-
byte_arr = payload
133+
byte_arr = nil
134+
byte_arr = payload if payload.instance_of?(Array)
159135
byte_arr = payload.chars if payload.instance_of?(String)
136+
raise "ERROR: Invalid payload type: #{payload.class}" if byte_arr.nil?
160137

161138
byte_arr.each do |byte|
162139
serial_conn.putc(byte)
@@ -168,18 +145,6 @@ module Serial
168145
raise e
169146
end
170147

171-
# public_class_method def self.request(opts = {})
172-
# serial_obj = opts[:serial_obj]
173-
# request = opts[:request].to_s.scrub
174-
# serial_conn = serial_obj[:serial_conn]
175-
# chars_written = serial_conn.write(request)
176-
# serial_conn.flush
177-
# chars_written
178-
# rescue StandardError => e
179-
# disconnect(serial_obj: serial_obj) unless serial_obj.nil?
180-
# raise e
181-
# end
182-
183148
# Supported Method Parameters::
184149
# PWN::Plugins::Serial.response(
185150
# serial_obj: 'required - serial_obj returned from #connect method'
@@ -218,14 +183,6 @@ module Serial
218183
raise e
219184
end
220185

221-
# public_class_method def self.response(opts = {})
222-
# serial_obj = opts[:serial_obj]
223-
# @session_data.last
224-
# rescue StandardError => e
225-
# disconnect(serial_obj: serial_obj) unless serial_obj.nil?
226-
# raise e
227-
# end
228-
229186
# Supported Method Parameters::
230187
# session_data = PWN::Plugins::Serial.dump_session_data
231188

@@ -278,8 +235,7 @@ module Serial
278235
baud: 'optional (defaults to 9600)',
279236
data_bits: 'optional (defaults to 8)',
280237
stop_bits: 'optional (defaults to 1)',
281-
parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none)',
282-
flow_control: 'optional - :none||:hard||:soft (defaults to :none)'
238+
parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none)'
283239
)
284240
285241
line_state = #{self}.get_line_state(

lib/pwn/plugins/son_micro_rfid.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ module SonMicroRFID
476476
baud: 'optional (defaults to 19_200)',
477477
data_bits: 'optional (defaults to 8)',
478478
stop_bits: 'optional (defaults to 1)',
479-
parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :odd),'
480-
flow_control: 'optional - :none||:hard||:soft (defaults to :none)'
479+
parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :odd)'
481480
)
482481
483482
cmds = #{self}.list_cmds

lib/pwn/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module PWN
4-
VERSION = '0.5.228'
4+
VERSION = '0.5.229'
55
end

reinstall_pwn_gemset.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ export rvmsudo_secure_path=1
2020
rvmsudo gem install bundler
2121
if [[ $(uname -s) == "Darwin" ]]; then
2222
bundle config build.pg --with-pg-config=/opt/local/lib/postgresql96/bin/pg_config
23-
bundle config build.serialport \
24-
--with-cflags=-Wno-implicit-function-declaration \
25-
--with-cflags=-Wno-int-conversion
23+
# bundle config build.serialport \
24+
# --with-cflags=-Wno-implicit-function-declaration \
25+
# --with-cflags=-Wno-int-conversion
2626
fi
27-
bundle config build.serialport --with-cflags=-Wno-int-conversion
27+
# bundle config build.serialport --with-cflags=-Wno-int-conversion
2828
bundle install
2929
# bundle install --full-index
3030
rvm --default ruby-$ruby_version@$ruby_gemset

0 commit comments

Comments
 (0)