Created
December 8, 2019 00:14
-
-
Save GhostofGoes/3aeca02003fe6f5bb3df6c582f525d46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Velocioraptor. rawr.""" | |
# TODO: improve resiliency to unexpected format changes/deviations | |
# TODO: generate modbus register/tag map | |
# TODO: generate input to a scanning script (what that looks like is TBD) | |
import xml.etree.ElementTree as ET | |
from pathlib import Path | |
import sys | |
from pprint import pprint | |
proj = Path("C:/Users/goesc/Documents/projects/Cyberforce2019" | |
"/testing/ChemicalMixerSFC-Ace11-Completed").resolve() | |
viofs = proj.rglob("*.viof") | |
if not viofs: | |
print("Failed to find a .viof file") | |
viof_path = list(viofs)[0] | |
print(f".viof file: {viof_path.as_posix()}") | |
raw_data = viof_path.read_text(encoding="utf-8") | |
root = ET.fromstring(raw_data) | |
if "VelocioNetworks" not in root.tag: | |
print(f"Invalid project file: XML is missing the 'VelocioNetworks' tag") | |
sys.exit(1) | |
results = { | |
"ip": root.attrib["IPAddress"], | |
} | |
# Setup | |
setup = root.find("Setup") | |
results["project_type"] = setup.attrib["ProjectType"] | |
# Connections: this is the meat of the tag mappings and types | |
con_elements = root.find("Connections") | |
conversions = [ | |
("iModbusStart", "modbus_start", int), | |
("iModbusEnd", "modbus_end", int), | |
("iPort", "port", int), | |
("iPin", "pin", int), | |
("dataType", "type", str), | |
("dataSource", "source", str), | |
] | |
conns = {} | |
for conn in con_elements: | |
vals = { | |
"remote_writable": bool(conn.attrib.get("bRemoteWritable")), | |
} | |
for conv in conversions: | |
if conv[0] in conn.attrib: | |
vals[conv[1]] = conv[2](conn.attrib[conv[0]]) | |
conns[conn.attrib["sKey"]] = vals | |
results["connections"] = conns | |
pprint(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment