Module: PWN::Plugins::FlipperZero

Defined in:
lib/pwn/plugins/flipper_zero.rb

Overview

This plugin is used for interacting with Bus Pirate v3.6 This plugin may be compatible with other versions, however, has not been tested with anything other than v3.6.

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <[email protected]>



92
93
94
95
96
# File 'lib/pwn/plugins/flipper_zero.rb', line 92

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <[email protected]>
  "
end

.connect(opts = {}) ⇒ Object

Supported Method Parameters

flipper_zero_obj = PWN::Plugins::FlipperZero.connect(

block_dev: 'optional serial block device path (defaults to /dev/ttyACM0)',
baud: 'optional (defaults to 9600)',
data_bits: 'optional (defaults to 8)',
stop_bits: 'optional (defaults to 1)',
parity: 'optional - :even||:odd|:none (defaults to :none)'

)



45
46
47
48
49
50
# File 'lib/pwn/plugins/flipper_zero.rb', line 45

public_class_method def self.connect(opts = {})
  PWN::Plugins::Serial.connect(opts)
rescue StandardError => e
  disconnect(flipper_zero_obj: opts[:flipper_zero_obj]) unless opts[:flipper_zero_obj].nil?
  raise e
end

.connect_via_screen(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::FlipperZero.connect_via_screen(

block_dev: 'optional - serial block device path (defaults to /dev/ttyACM0)'

)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pwn/plugins/flipper_zero.rb', line 14

public_class_method def self.connect_via_screen(opts = {})
  block_dev = opts[:block_dev].to_s if File.exist?(
    opts[:block_dev].to_s
  )

  block_dev ||= '/dev/ttyACM0'

  screen_bin = '/usr/bin/screen'
  raise "ERROR: #{screen_bin} not found." unless File.exist?(screen_bin)

  system(
    screen_bin,
    block_dev,
    '115200',
    '8',
    'N',
    '1'
  )
rescue StandardError => e
  raise e
end

.disconnect(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::FlipperZero.disconnect(

flipper_zero_obj: 'required - flipper_zero_obj returned from #connect method'

)



82
83
84
85
86
87
88
# File 'lib/pwn/plugins/flipper_zero.rb', line 82

public_class_method def self.disconnect(opts = {})
  PWN::Plugins::Serial.disconnect(
    serial_obj: opts[:flipper_zero_obj]
  )
rescue StandardError => e
  raise e
end

.helpObject

Display Usage for this Module



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/pwn/plugins/flipper_zero.rb', line 100

public_class_method def self.help
  puts "USAGE:
    #{self}.connect_via_screen(
      block_dev: 'optional serial block device path (defaults to /dev/ttyUSB0)'
    )

    flipper_zero_obj = #{self}.connect(
      block_dev: 'optional serial block device path (defaults to /dev/ttyUSB0)',
      baud: 'optional (defaults to 9600)',
      data_bits: 'optional (defaults to 8)',
      stop_bits: 'optional (defaults to 1)',
      parity: 'optional - :even||:odd|:none (defaults to :none)'
    )

    response = #{self}.request(
      flipper_zero_obj: 'required - flipper_zero_obj returned from #connect method',
      payload: 'required - payload to send to the device'
    );

    #{self}.disconnect(
      flipper_zero_obj: 'required - flipper_zero_obj returned from #connect method'
    )

    #{self}.authors
  "
end

.request(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::FlipperZero.request(

flipper_zero_obj: 'required - flipper_zero_obj returned from #connect method',
payload: 'optional - payload to send to the device (defaults to help)'

)



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/pwn/plugins/flipper_zero.rb', line 57

public_class_method def self.request(opts = {})
  serial_obj = opts[:flipper_zero_obj]
  payload = opts[:payload] ||= 'help'
  payload = "#{payload}\r\n"

  PWN::Plugins::Serial.request(
    serial_obj: serial_obj,
    payload: payload
  )
  sleep 0.1
  response = PWN::Plugins::Serial.dump_session_data.clone
  puts response.join
  PWN::Plugins::Serial.flush_session_data

  response
rescue StandardError => e
  disconnect(flipper_zero_obj: opts[:flipper_zero_obj]) unless opts[:flipper_zero_obj].nil?
  raise e
end