Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Hardware
- `Facedancer <http://goodfet.sourceforge.net/hardware/facedancer21/>`_
is the recommended hardware for Umap2.
Umap2 was developed based on it, and you'll get the most support with it.
- `Cynthion <https://github.com/greatscottgadgets/cynthion>`_ is supported.
To get started, read the `Getting started with Cynthion <https://cynthion.readthedocs.io/en/latest/getting_started.html>`_ and `Using Cynthion with Facedancer <https://cynthion.readthedocs.io/en/latest/getting_started_facedancer.html>`_
guides to install all the required dependencies.
- `Raspdancer <http://wiki.yobi.be/wiki/Raspdancer>` is supported on RPi
- **GadgetFS** is partially supported.
This support is very experimental (even more than the rest of Umap2)
Expand Down
4 changes: 2 additions & 2 deletions data/vid_pid_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6185,8 +6185,8 @@
history = set()
for db_entry in db:
if (db_entry.vid, db_entry.pid) in history:
print 'Duplicate found: 0x%04x, 0x%04x' % (db_entry.vid, db_entry.pid)
print('Duplicate found: 0x%04x, 0x%04x' % (db_entry.vid, db_entry.pid))
sys.exit(1)
else:
history.add((db_entry.vid, db_entry.pid))
print 'DB OK!'
print('DB OK!')
4 changes: 2 additions & 2 deletions data/vid_pid_db_from_usb_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -15492,8 +15492,8 @@
history = set()
for db_entry in db:
if (db_entry.vid, db_entry.pid) in history:
print 'Duplicate found: 0x%04x, 0x%04x' % (db_entry.vid, db_entry.pid)
print('Duplicate found: 0x%04x, 0x%04x' % (db_entry.vid, db_entry.pid))
sys.exit(1)
else:
history.add((db_entry.vid, db_entry.pid))
print 'DB OK!'
print('DB OK!')
9 changes: 9 additions & 0 deletions umap2/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from umap2.phy.facedancer.max342x_phy import Max342xPhy
from umap2.phy.gadgetfs.gadgetfs_phy import GadgetFsPhy
# CynthionPhy import moved to load_phy method with error handling
from umap2.utils.ulogger import set_default_handler_level


Expand Down Expand Up @@ -79,6 +80,14 @@ def load_phy(self, phy_string):
self.logger.debug('Physical interface is GadgetFs')
phy = GadgetFsPhy(self)
return phy
elif phy_type == 'cynthion':
try:
from umap2.phy.cynthion.cynthion_phy import CynthionPhy
self.logger.debug('Physical interface is Cynthion')
phy = CynthionPhy(self)
return phy
except ImportError:
raise Exception('Cynthion support requires additional dependencies. Please follow the guides linked in the README file.')
raise Exception('Phy type not supported: %s' % phy_type)

def load_device(self, dev_name, phy):
Expand Down
1 change: 1 addition & 0 deletions umap2/apps/detect_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Physical layer:
fd:<serial_port> use facedancer connected to given serial port
gadgetfs use gadgetfs (requires mounting of gadgetfs beforehand)
cynthion use cynthion

Example:
umap2detect -P fd:/dev/ttyUSB0 -q
Expand Down
1 change: 1 addition & 0 deletions umap2/apps/emulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Physical layer:
fd:<serial_port> use facedancer connected to given serial port
gadgetfs use gadgetfs (requires mounting of gadgetfs beforehand)
cynthion use cynthion

Examples:
emulate keyboard:
Expand Down
1 change: 1 addition & 0 deletions umap2/apps/fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Physical layer:
fd:<serial_port> use facedancer connected to given serial port
gadgetfs use gadgetfs (requires mounting of gadgetfs beforehand)
cynthion use cynthion

Examples:
emulate disk-on-key:
Expand Down
4 changes: 2 additions & 2 deletions umap2/apps/list_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def run(self):
ks = self.umap_classes
verbose = self.options.get('--verbose', False)
if verbose:
print '%-20s %s' % ('Device', 'Description')
print '-------------------- ----------------------------------------------------'
print('%-20s %s' % ('Device', 'Description'))
print('-------------------- ----------------------------------------------------')
for k in ks:
if verbose:
print('%-20s %s' % (k, self.umap_class_dict[k][1]))
Expand Down
1 change: 1 addition & 0 deletions umap2/apps/makestages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Physical layer:
fd:<serial_port> use facedancer connected to given serial port
gadgetfs use gadgetfs (requires mounting of gadgetfs beforehand)
cynthion use cynthion
'''
import time
from umap2.apps.emulate import Umap2EmulationApp
Expand Down
1 change: 1 addition & 0 deletions umap2/apps/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Physical layer:
fd:<serial_port> use facedancer connected to given serial port
gadgetfs use gadgetfs (requires mounting of gadgetfs beforehand)
cynthion use cynthion

Example:
umap2scan -P fd:/dev/ttyUSB0 -q
Expand Down
1 change: 1 addition & 0 deletions umap2/apps/vsscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Physical layer:
fd:<serial_port> use facedancer connected to given serial port
gadgetfs use gadgetfs (requires mounting of gadgetfs beforehand)
cynthion use cynthion

DB_FILE:
a python file with a db member which is a list of DBEntry() objects.
Expand Down
64 changes: 32 additions & 32 deletions umap2/dev/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ def setup_local_handlers(self):
}
self._settings = {
# (val, index): [cur, min, max, res, (idle)]
(0x0100, 0x0001): ['\x44\xac\x00', '\x44\xac\x00', '\x80\xbb\x00', '\x80\xbb\x00'],
(0x0100, 0x0001): [b'\x44\xac\x00', b'\x44\xac\x00', b'\x80\xbb\x00', b'\x80\xbb\x00'],
# (0x0100, 0x0002): ['\x44\xac\x00', '\x44\xac\x00', '\x80\xbb\x00', '\x80\xbb\x00'],
(0x0100, 0x0082): ['\x44\xac\x00', '\x44\xac\x00', '\x80\xbb\x00', '\x80\xbb\x00'],
(0x0100, 0x0900): ['\x00', '\x00', '\xff', '\x00'],
(0x0100, 0x0a00): ['\x01', '\x00', '\xff', '\x00'],
(0x0100, 0x0d00): ['\x01', '\x00', '\xff', '\x00'],
(0x0101, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
(0x0102, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
(0x0200, 0x0a00): ['\x00\x00', '\x00\x00', '\x55\x00', '\x30\x00', '\x00\x00'],
(0x0200, 0x0d00): ['\x80\x22', '\x00\x00', '\xd0\x00', '\x30\x00'],
(0x0201, 0x0900): ['\x80\x22', '\x20\x00', '\xa0\x00', '\x30\x00'],
(0x0201, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
(0x0202, 0x0900): ['\xcf\x00', '\x00\x00', '\xcf\x00', '\x30\x00'],
(0x0202, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
(0x0301, 0x0f00): ['\x01', '\x00', '\xff', '\x00'],
(0x0302, 0x0f00): ['\x00\x00', '\x00\x00', '\x00\x00', '\x00\x00'],
(0x0700, 0x0a00): ['\x01', '\x00', '\xff', '\x00'],
(0x0100, 0x0082): [b'\x44\xac\x00', b'\x44\xac\x00', b'\x80\xbb\x00', b'\x80\xbb\x00'],
(0x0100, 0x0900): [b'\x00', b'\x00', b'\xff', b'\x00'],
(0x0100, 0x0a00): [b'\x01', b'\x00', b'\xff', b'\x00'],
(0x0100, 0x0d00): [b'\x01', b'\x00', b'\xff', b'\x00'],
(0x0101, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
(0x0102, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
(0x0200, 0x0a00): [b'\x00\x00', b'\x00\x00', b'\x55\x00', b'\x30\x00', b'\x00\x00'],
(0x0200, 0x0d00): [b'\x80\x22', b'\x00\x00', b'\xd0\x00', b'\x30\x00'],
(0x0201, 0x0900): [b'\x80\x22', b'\x20\x00', b'\xa0\x00', b'\x30\x00'],
(0x0201, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
(0x0202, 0x0900): [b'\xcf\x00', b'\x00\x00', b'\xcf\x00', b'\x30\x00'],
(0x0202, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
(0x0301, 0x0f00): [b'\x01', b'\x00', b'\xff', b'\x00'],
(0x0302, 0x0f00): [b'\x00\x00', b'\x00\x00', b'\x00\x00', b'\x00\x00'],
(0x0700, 0x0a00): [b'\x01', b'\x00', b'\xff', b'\x00'],
}

self._cur = b'\x44\xac\x00'
Expand Down Expand Up @@ -205,29 +205,29 @@ def __init__(self, app, phy, vid=0x0d8c, pid=0x000c, rev=0x0001, *args, **kwargs
app=app, phy=phy, iface_num=0, iface_alt=0, iface_str_idx=0,
cs_ifaces=[
# Class specific AC interface: header (4.3.2)
USBCSInterface('ACHeader', app, phy, '\x01\x00\x01\x64\x00\x02\x01\x02'),
USBCSInterface('ACHeader', app, phy, b'\x01\x00\x01\x64\x00\x02\x01\x02'),
# Class specific AC interface: input terminal (Table 4.3.2.1)
USBCSInterface('ACInputTerminal0', app, phy, '\x02\x01\x01\x01\x00\x02\x03\x00\x00\x00'),
USBCSInterface('ACInputTerminal1', app, phy, '\x02\x02\x01\x02\x00\x01\x01\x00\x00\x00'),
USBCSInterface('ACInputTerminal0', app, phy, b'\x02\x01\x01\x01\x00\x02\x03\x00\x00\x00'),
USBCSInterface('ACInputTerminal1', app, phy, b'\x02\x02\x01\x02\x00\x01\x01\x00\x00\x00'),
# Class specific AC interface: output terminal (Table 4.3.2.2)
USBCSInterface('ACOutputTerminal0', app, phy, '\x03\x06\x01\x03\x00\x09\x00'),
USBCSInterface('ACOutputTerminal1', app, phy, '\x03\x07\x01\x01\x00\x08\x00'),
USBCSInterface('ACOutputTerminal0', app, phy, b'\x03\x06\x01\x03\x00\x09\x00'),
USBCSInterface('ACOutputTerminal1', app, phy, b'\x03\x07\x01\x01\x00\x08\x00'),
# Class specific AC interface: selector unit (Table 4.3.2.4)
USBCSInterface('ACSelectorUnit', app, phy, '\x05\x08\x01\x0a\x00'),
USBCSInterface('ACSelectorUnit', app, phy, b'\x05\x08\x01\x0a\x00'),
# Class specific AC interface: feature unit (Table 4.3.2.5)
USBCSInterface('ACFeatureUnit0', app, phy, '\x06\x09\x0f\x01\x01\x02\x02\x00'),
USBCSInterface('ACFeatureUnit1', app, phy, '\x06\x0a\x02\x01\x43\x00\x00'),
USBCSInterface('ACFeatureUnit2', app, phy, '\x06\x0d\x02\x01\x03\x00\x00'),
USBCSInterface('ACFeatureUnit0', app, phy, b'\x06\x09\x0f\x01\x01\x02\x02\x00'),
USBCSInterface('ACFeatureUnit1', app, phy, b'\x06\x0a\x02\x01\x43\x00\x00'),
USBCSInterface('ACFeatureUnit2', app, phy, b'\x06\x0d\x02\x01\x03\x00\x00'),
# Class specific AC interface: mixer unit (Table 4.3.2.3)
USBCSInterface('ACMixerUnit', app, phy, '\x04\x0f\x02\x01\x0d\x02\x03\x00\x00\x00\x00'),
USBCSInterface('ACMixerUnit', app, phy, b'\x04\x0f\x02\x01\x0d\x02\x03\x00\x00\x00\x00'),
],
usb_class=usb_class
),
USBAudioStreamingInterface(
app=app, phy=phy, iface_num=1, iface_alt=0, iface_str_idx=0,
cs_ifaces=[
USBCSInterface('ASGeneral', app, phy, '\x01\x01\x01\x01\x00'),
USBCSInterface('ASFormatType', app, phy, '\x02\x01\x02\x02\x10\x02\x44\xac\x00\x44\xac\x00'),
USBCSInterface('ASGeneral', app, phy, b'\x01\x01\x01\x01\x00'),
USBCSInterface('ASFormatType', app, phy, b'\x02\x01\x02\x02\x10\x02\x44\xac\x00\x44\xac\x00'),
],
endpoints=[
USBEndpoint(
Expand All @@ -240,7 +240,7 @@ def __init__(self, app, phy, vid=0x0d8c, pid=0x000c, rev=0x0001, *args, **kwargs
interval=1,
handler=audio_streaming.data_available,
cs_endpoints=[
USBCSEndpoint('ASEndpoint', app, phy, '\x01\x01\x01\x01\x00')
USBCSEndpoint('ASEndpoint', app, phy, b'\x01\x01\x01\x01\x00')
],
usb_class=usb_class,
)
Expand All @@ -250,8 +250,8 @@ def __init__(self, app, phy, vid=0x0d8c, pid=0x000c, rev=0x0001, *args, **kwargs
USBAudioStreamingInterface(
app=app, phy=phy, iface_num=2, iface_alt=0, iface_str_idx=0,
cs_ifaces=[
USBCSInterface('ASGeneral', app, phy, '\x01\x07\x01\x01\x00'),
USBCSInterface('ASFormatType', app, phy, '\x02\x01\x01\x02\x10\x02\x44\xac\x00\x44\xac\x00'),
USBCSInterface('ASGeneral', app, phy, b'\x01\x07\x01\x01\x00'),
USBCSInterface('ASFormatType', app, phy, b'\x02\x01\x01\x02\x10\x02\x44\xac\x00\x44\xac\x00'),
],
endpoints=[
USBEndpoint(
Expand All @@ -264,7 +264,7 @@ def __init__(self, app, phy, vid=0x0d8c, pid=0x000c, rev=0x0001, *args, **kwargs
interval=1,
handler=audio_streaming.buffer_available,
cs_endpoints=[
USBCSEndpoint('ASEndpoint', app, phy, '\x01\x01\x00\x00\x00')
USBCSEndpoint('ASEndpoint', app, phy, b'\x01\x01\x00\x00\x00')
],
usb_class=usb_class,
)
Expand Down
2 changes: 1 addition & 1 deletion umap2/dev/cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def handle_getter(self, req):
key = (param_id, req.value, req.index)
if key in self.params:
return self.params[key]
return '\x00' * req.length
return b'\x00' * req.length

def handle_clear(self, req):
param_id = self.get_param_id_from_request(req.request)
Expand Down
2 changes: 1 addition & 1 deletion umap2/dev/cdc_acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, app, phy, vid=0x2548, pid=0x1001, rev=0x0010, cs_interfaces=N
cdc_cls = self.get_default_class(app, phy)
cs_interfaces = [
# Header Functional Descriptor
FD(app, phy, FD.Header, '\x01\x01'),
FD(app, phy, FD.Header, b'\x01\x01'),
# Call Management Functional Descriptor
FD(app, phy, FD.CM, struct.pack('BB', bmCapabilities, USBCDCDevice.bDataInterface)),
FD(app, phy, FD.ACM, struct.pack('B', bmCapabilities)),
Expand Down
2 changes: 1 addition & 1 deletion umap2/dev/cdc_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, app, phy, vid=0x2548, pid=0x1001, rev=0x0010, cs_interfaces=N
cdc_cls = self.get_default_class(app, phy)
cs_interfaces = [
# Header Functional Descriptor
FD(app, phy, FD.Header, '\x01\x01'),
FD(app, phy, FD.Header, b'\x01\x01'),
# Call Management Functional Descriptor
FD(app, phy, FD.CM, struct.pack('BB', bmCapabilities, USBCDCDevice.bDataInterface)),
FD(app, phy, FD.DLM, struct.pack('B', bmCapabilities)),
Expand Down
4 changes: 2 additions & 2 deletions umap2/dev/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def handle_get_descriptor(self, req):
num_bytes = self.num_ports // 7
if self.num_ports % 7 != 0:
num_bytes += 1
d += '\x00' * num_bytes
d += '\xff' * num_bytes
d += b'\x00' * num_bytes
d += b'\xff' * num_bytes
d = struct.pack('B', len(d) + 1) + d
return d

Expand Down
2 changes: 1 addition & 1 deletion umap2/dev/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def handle_buffer_available(self):
if self.keys:
letter = self.keys.pop(0)
else:
letter = '\x00'
letter = b'\x00'
self.type_letter(letter)

def type_letter(self, letter, modifiers=0):
Expand Down
4 changes: 2 additions & 2 deletions umap2/dev/mass_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def put_sector_data(self, address, data):
block_end = (address + 1) * self.block_size # slices are NON-inclusive

pad_len = (self.block_size - (len(data) % self.block_size)) % self.block_size
data += '\x00' * pad_len
data += b'\x00' * pad_len
self.image[block_start:block_end] = data[:self.block_size]
self.image.flush()

Expand Down Expand Up @@ -391,7 +391,7 @@ def handle_scsi_mode_sense(self, mode_type, page, subpage, alloc_len, ctrl, with
if report is None:
# default behaviour, taken from previous implementation
# this should probably be changed ...
report = '\x07\x00\x00\x00\x00\x00\x00\x00'
report = b'\x07\x00\x00\x00\x00\x00\x00\x00'
if with_header:
self.debug('SCSI mode sense (%d) - adding header' % (mode_type))
report = self._report_header(mode_type, len(report)) + report
Expand Down
4 changes: 2 additions & 2 deletions umap2/dev/smartcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def setup_local_handlers(self):

@mutable('get_clock_frequencies_response')
def handle_get_clock_frequencies(self, req):
response = ''
response = b''
for frequency in self.interface.clock_frequencies:
response += struct.pack('<I', frequency)
response = struct.pack('<I', len(response)) + response
return response

@mutable('get_data_rates_response')
def handle_get_data_rates(self, req):
response = ''
response = b''
for data_rate in self.interface.data_rates:
response += struct.pack('<I', data_rate)
response = struct.pack('<I', len(response)) + response
Expand Down
6 changes: 3 additions & 3 deletions umap2/fuzz/fuzz_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from kitty.model import GraphModel
from kitty.model import Template, Meta, String, UInt32

from templates import audio, cdc, enum, generic, hid, hub, mass_storage
from templates import smart_card
from .templates import audio, cdc, enum, generic, hid, hub, mass_storage
from .templates import smart_card

from controller import UmapController
from .controller import UmapController


def enumerate_templates(module):
Expand Down
11 changes: 5 additions & 6 deletions umap2/fuzz/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
'''

import traceback
import binascii
import inspect


class StageLogger(object):

def __init__(self, filename):
Expand All @@ -22,7 +20,8 @@ def stop(self):

def log_stage(self, stage):
if self.fd:
self.fd.write(stage + '\n')

self.fd.write(stage.encode() + b'\n')
self.fd.flush()


Expand All @@ -46,8 +45,8 @@ def mutable(stage, silent=False):
def wrap_f(func):
func_self = None
if inspect.ismethod(func):
func_self = func.im_self
func = func.im_func
func_self = func.__self__
func = func.__func__

def wrapper(*args, **kwargs):
if func_self is None:
Expand Down Expand Up @@ -79,7 +78,7 @@ def wrapper(*args, **kwargs):
self.logger.error(''.join(traceback.format_stack()))
raise e
if response is not None:
info('Response: %s' % binascii.hexlify(response))
info(f'Response: {response.hex()}')
return response
return wrapper
return wrap_f
6 changes: 3 additions & 3 deletions umap2/fuzz/templates/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from kitty.model import Template, Repeat, List, Container, ForEach, OneOf
from kitty.model import ElementCount, SizeInBytes
from kitty.model import ENC_INT_LE
from hid import GenerateHidReport
from generic import Descriptor, SizedPt, DynamicInt, SubDescriptor
from .hid import GenerateHidReport
from .generic import Descriptor, SizedPt, DynamicInt, SubDescriptor


class _AC_DescriptorSubTypes: # AC Interface Descriptor Subtype
Expand Down Expand Up @@ -138,7 +138,7 @@ class _AS_DescriptorSubTypes: # AS Interface Descriptor Subtype
audio_report_descriptor = Template(
name='audio_report_descriptor',
fields=GenerateHidReport(
'050C0901A1011500250109E909EA75019502810209E209008106050B092095018142050C09009503810226FF000900750895038102090095049102C0'.decode('hex')
bytes.fromhex('050C0901A1011500250109E909EA75019502810209E209008106050B092095018142050C09009503810226FF000900750895038102090095049102C0')
)
)

Expand Down
2 changes: 1 addition & 1 deletion umap2/fuzz/templates/cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from kitty.model import Template, Repeat, List, Container, ForEach, OneOf
from kitty.model import ElementCount
from kitty.model import MutableField
from generic import SubDescriptor
from .generic import SubDescriptor


cdc_control_interface_descriptor = Template(
Expand Down
Loading