Files
pruefwerk/docs/guide/plc.md
Sharang ParnerkarandClaude Opus 5.5 1f3beb5786
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 5m24s
CI / Check (pull_request) Successful in 23m17s
fix(tia): a type identifier gives only a concrete article and its version
Siemens' Openness notes: catalog identifiers carry wildcards
(6SL3040-1MA01-0Axx), drive identifiers a family after the version
(/V5.2.3/S120), some a catalog variant instead (//10002). Only a
concrete article and a V-version are taken; the rest is not matched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
2026-12-01 14:23:24 +01:00

356 lines
17 KiB
Markdown

# PLC / SPS Projects (CODESYS)
Prüfwerk analyzes industrial control logic (IEC 61131-3) for PLC/SPS targets such
as CODESYS projects. A single PLC/SPS target is treated as a **composite device**:
the control application *and* the device it runs on.
| What you provide | What Prüfwerk does |
| --- | --- |
| PLC project (PLCopen XML / ST, or a `.projectarchive`) | **Control-logic SAST** — semantic security rules over ST **and** graphical FBD/LD |
| A `.projectarchive` | **Control-app SBOM** — the referenced CODESYS libraries + the runtime version, matched against known CVEs |
| A device firmware image | *Not analysed yet* — the run lists it under **Nicht ausgeführt**, and says so. Firmware is covered from its **sources** |
| A reachable endpoint (WebVisu, OPC UA) | DAST / pentest / ICS probe (opt-in; not available in a source-only deployment such as the pilot) |
## Anatomy: a soft PLC is a SoC + Linux + runtime
A CODESYS controller is **not** a monolithic appliance like a classic Siemens
S7. It is **PC-based ("soft") control** — commodity silicon running a
general-purpose Linux, with a **software PLC runtime** as just another process:
| Classic PLC (e.g. Siemens S7) | Soft PLC (CODESYS-on-Yocto, OpenPLC-on-Raspbian) |
| --- | --- |
| Proprietary hardware + firmware | Commodity SoC (x86 / ARM) |
| Proprietary OS | General-purpose Linux (a **Yocto** image, or Raspbian) |
| Proprietary runtime | Software runtime (**CODESYS Control**, or OpenPLC) |
| STEP7 / TIA project | IEC 61131-3 control app (ST / LD / FBD / SFC) |
Because of this, the device is built along **two independent tracks**, by
different people, on different timelines, and shipped separately. It also
inherits the **entire Linux / IT attack surface on top of** the OT / control
one — which is exactly why a PLC/SPS target is treated as a **composite**:
Prüfwerk ingests one artifact per layer and scans each with the right pipeline.
```mermaid
flowchart TB
subgraph TA["Track A · Device platform — built by the hardware OEM / vendor"]
direction LR
A1["Yocto / OpenEmbedded<br/>BSP + RT kernel"] --> A2["Bake in the CODESYS<br/>Control for Linux runtime"] --> A3["bitbake → device image<br/>.wic / .tar + manifest"]
end
subgraph TB2["Track B · Control application — built by the machine builder / customer"]
direction LR
B1["CODESYS IDE<br/>ST / LD / FBD / SFC + WebVisu"] --> B2["Reference CODESYS +<br/>vendor libraries"] --> B3["Compile → download<br/>to device (gateway 11740)"]
end
A3 --> DEV(["Running soft-PLC device<br/>SoC + Linux + runtime + control app<br/>Modbus · OPC UA · EtherNet/IP · WebVisu"])
B3 --> DEV
subgraph CERT["What Prüfwerk scans — one layer per artifact"]
direction LR
S1["Firmware layer<br/>not analysed yet — recorded as skipped"]
S2["Control-logic layer<br/>PLC SAST — ST + FBD/LD"]
S3["Control-app SBOM<br/>libraries + runtime → CVE"]
S4["Running layer<br/>ICS probe · DAST (WebVisu)"]
end
A3 -. firmware image .-> S1
B1 -. PLCopen XML / ST via git .-> S2
B2 -. projectarchive (zip) .-> S3
DEV -. live URL / provisioned .-> S4
classDef yocto fill:#fde68a,stroke:#b45309,color:#111
classDef codesys fill:#bfdbfe,stroke:#1d4ed8,color:#111
classDef dev fill:#e9d5ff,stroke:#7e22ce,color:#111
classDef cert fill:#bbf7d0,stroke:#15803d,color:#111
class A1,A2,A3 yocto
class B1,B2,B3 codesys
class DEV dev
class S1,S2,S3,S4 cert
```
::: tip Where Yocto fits
Yocto is **Track A** — the *build system* for the device platform. It produces
the Linux image and bakes in the CODESYS runtime, so it is the **firmware
layer**, entirely separate from the control application. Hand it to Prüfwerk as
its own **firmware image** artifact. Nothing unpacks an image yet: the scan run
records that layer as skipped and names the reason, so an unanalysed image is
never mistaken for a clean one. Until it lands, the firmware layer is covered
from its **sources**: its components are derived from the source tree. The device OS need not be Yocto — Raspbian/Debian/Buildroot, or
even an RTOS / bare-metal, are all possible — but Yocto is the common,
product-grade industrial choice.
:::
## Two ways to deliver the project
You can either **upload** the project when onboarding, or point Prüfwerk at a
**git repository** (recommended — every scan is just a `git pull`, no re-upload).
### Option A — Upload
On the onboarding wizard, choose target type **PLC / SPS**, then attach a **PLC
project** artifact and pick its format:
- **PLCopen XML** (`.xml`) — export from CODESYS via *Project → Export PLCopenXML*.
- **Structured Text** (`.st`) — a raw ST file.
- **Project archive** (`.projectarchive`) — *File → Project Archive → Save/Send
Archive…* with **"Referenced libraries"** ticked. This is the only form that
also yields the **library + runtime SBOM**.
### Option B — Git repository (recommended)
Attach a **Git repository** artifact to the PLC/SPS target. Prüfwerk clones it and
runs the control-logic scan over the exported source in the repo.
## Exporting PLCopen XML automatically
Prüfwerk reads the control logic from the PLCopen XML export, never from the
binary `.project`. Instead of exporting by hand before every upload or commit,
let CODESYS do it with the script
[codesys-export-plcopen.py](/docs/downloads/codesys-export-plcopen.py){target="_self" download} (CODESYS
Script Engine, no extra packages). It exports every object of the project into
one PLCopen XML file, ST as well as graphical FBD/LD/SFC/CFC POUs, and exits with
an error if the export holds no POU.
- **In CODESYS:** open the project, then *Tools → Scripting → Execute Script
File* and pick the script. The export is written next to the project as
`<project>.plcopen.xml`.
- **Without a window**, for example in a build pipeline before the commit or
upload:
```bat
"C:\Program Files\CODESYS 3.5.19.50\CODESYS\Common\CODESYS.exe" ^
--profile="CODESYS V3.5 SP19 Patch 5" --noUI ^
--runscript="C:\tools\codesys-export-plcopen.py" ^
--scriptargs:"C:\src\Line.project C:\src\export\Line.plcopen.xml"
```
Use the path and profile name of your CODESYS installation. The first script
argument is the project, the second the export file (optional).
A `.projectarchive` has to be extracted first (*File → Project Archive →
Extract Archive*). Commit or upload the export next to the `.projectarchive`:
the export carries the control logic, the archive the library SBOM.
## Best-case git repository layout
Because the binary `.project` does not diff or merge in git, commit **textual
exports** for review-friendly SAST, and include the **`.projectarchive`** so the
library/runtime SBOM is available too:
```text
my-plc-project/
├── src/
│ ├── PLC_PRG.xml # PLCopen XML export (ST or FBD/LD) — one per POU
│ ├── PumpController.xml
│ ├── SafetyInterlock.xml
│ └── GVL.xml # global variable lists, also as PLCopen XML
├── PumpStation.projectarchive # optional but recommended → library + runtime SBOM
└── README.md
```
**Guidelines**
- **Export to PLCopen XML** (`Project → Export PLCopenXML`), one file per POU, and
commit those. ST, **and graphical FBD/LD**, are both analyzed.
- Alternatively commit raw `.st` / `.exp` / `.scl` files — also analyzed.
- **Do not** commit only the binary `.project` — it cannot be parsed (and does not
diff). If you want the library SBOM, commit the **`.projectarchive`** as well.
A native `.project` or `.projectarchive` without an export is listed on the
scan run under **SPS-Projekt (natives Format)**, so a missing export never
reads as clean control logic.
- Test data (`fixtures/`, `testdata/` and similar) and the paths excluded under
**Von der Prüfung ausgenommen** are left out of the control-logic analysis as
well; findings an earlier scan reported there are closed with that reason.
- CODESYS's built-in Git integration, which stores an exported representation,
works too — as long as the committed form is PLCopen XML / textual.
::: tip What unlocks what
- **Control-logic SAST** needs textual source in the repo (PLCopen XML or `.st`).
- **Library + runtime SBOM** needs a **`.projectarchive`** — PLCopen XML exports do
**not** carry the referenced libraries.
:::
A `.projectarchive` (or a CODESYS `.project`) in a repository or an uploaded
archive marks it as a PLC project when Prüfwerk detects the type and the
repository holds no application code with a build manifest. A repository
created through the managed git source with only a CODESYS project therefore
becomes **SPS / PLC** on its first scan, and later scans run the control-logic
analysis; one that also holds, say, a `package.json` or `pom.xml` stays a code
target. Whatever the
target's type, the library + runtime SBOM and its CVEs come from every
`.projectarchive` the code holds, so a target kept as **Backend / API** still
lists its CODESYS components.
## What the scanner finds
The control-logic rules are CWE-mapped and include: hardcoded credentials
(CWE-798), default/weak passwords (CWE-1393), safety interlock / watchdog bypass
(CWE-1384), unchecked array indexing (CWE-129), division-by-zero (CWE-369,
guard-aware), cleartext/insecure communication (CWE-319), insecure protocol ports
(CWE-319, e.g. Modbus 502, FTP 21, Telnet 23), and unstructured jumps (CWE-691).
The **SBOM** view lists the CODESYS libraries (`pkg:codesys/<name>@<version>`) and
the runtime; matching runtime components (e.g. the `Cmp*` / `3SLicense` libraries)
surface real CODESYS advisories as CVE alerts. Besides NVD, the runtime and
libraries are matched against CODESYS's own CSAF advisories (published through
CERT@VDE): the alert links the advisory (e.g. `VDE-2026-094`) and carries the
vendor's remediation and the fixed version.
A CVE alert a later scan no longer finds (the project now references a fixed
runtime or library version) is marked resolved, as for code targets; this needs
both lookups (OSV and NVD) to have covered every component. The scan does not
state VEX `fixed` for it: that is a person's statement. For a PLC project in a
managed Git repository, its CVE issue stays open with a note that the CVE is no
longer found, and a person closes it.
## Siemens controllers by order number
A Siemens CPU is matched by what is printed on it, without a project file. On the
target's page, the **Steuerungen** card opens the target's controllers. Each
controller is entered with:
- its **order number** (Artikelnummer, MLFB), such as `6ES7511-1AK02-0AB0`, from
the rating plate or from TIA Portal (device configuration, Properties,
General, Catalog information);
- its **firmware**, such as `V3.1.4`, also shown on the CPU web server's start
page;
- optionally a name (`Hauptsteuerung Zelle 2`).
The form recognises the order number while it is typed, by the name Siemens
uses for it. A valid number that no advisory names yet is accepted: Prüfwerk
checks it against every new advisory.
Siemens ProductCERT names every affected CPU in its CSAF advisories by order
number and firmware range. Prüfwerk reads them daily and shows each controller
as a module on a DIN rail, with a light:
| Light | Meaning |
| --- | --- |
| red | an advisory affects the installed firmware |
| green | advisories name the controller, none affects this firmware |
| grey | no advisory names the order number |
The controller's panel lists the advisories with their severity, the firmware
that fixes them (`Behoben ab V3.1.5`, read from Siemens' remediation) and a
**Quelle** link to the advisory, which Siemens' terms require. The page shows
the current advisories at once. The target's CVE alerts and issues follow at
its next scan.
Not matched yet: advisories that name only a whole series ("S7-1200 CPU
family") instead of order numbers.
The API takes `devices` on `POST /api/v1/targets` and `PATCH
/api/v1/targets/{id}` (`order_number`, `firmware`, `label`).
`GET /api/v1/targets/{id}/devices` returns each device with the advisories
naming it, and `GET /api/v1/devices/lookup?order_number=` what the advisories
know of an order number.
## Siemens TIA Portal projects (TIA export)
A TIA Portal project reaches Prüfwerk as a **TIA export**: a zip that a TIA
connector writes on the engineering PC, reading the project through TIA Portal
Openness and never changing it. It is uploaded to a PLC/SPS target as a PLC
project with the format `tia_export`, with an API key holding
`pruefwerk:uploads.write` ([API keys](./api-keys)):
```bash
curl -H "Authorization: Bearer bp_…" \
-F kind=plc_project -F plc_format=tia_export \
-F file=@linie1.tia-export.zip \
https://pruefwerk.breakpilot.com/api/v1/targets/<id>/artifacts/upload
```
Its manifest is read on upload: a file that is not an export is refused with
`422` and a `code` (`not_zip`, `no_manifest`, `manifest_too_large`,
`manifest_invalid`, `bundle_version`). A new export of a target replaces the
last one.
What the export brings today:
- **Devices**: each device with a Siemens order number and a firmware version
joins the target's controllers (above), named as in the project, and is
matched against Siemens' advisories like one entered by hand. A controller
entered by hand with the same order number wins: it says which firmware is
installed, the export only what was configured. Devices without either are
listed on the run as not matched.
- **Blocks**: their code is not analysed yet; the run says how many and in
which languages. Know-how-protected blocks are listed as not analysable,
never counted as clean.
- **Security settings** of each CPU: carried in the export, not checked yet.
### The export's contract
`manifest.json` at the root of the zip, at most 4 MiB; fields Prüfwerk does not
know are ignored. Nothing in it is a secret: a connector never exports
passwords or keys.
```json
{
"bundle_version": 1,
"tia_version": "V20",
"project": { "name": "Linie 1", "modified": "2026-11-30T10:00:00Z",
"protected": { "value": true } },
"exported_at": "2026-12-01T09:00:00Z",
"connector": { "name": "Breakpilot TIA Connector", "version": "0.1.0" },
"devices": [
{ "name": "PLC_1", "role": "cpu",
"type_identifier": "OrderNumber:6ES7 515-2UM01-0AB0/V2.9",
"security": {
"access_level": { "unreadable": "no password set" },
"put_get": { "value": false },
"web_server": { "value": true },
"web_server_https_only": { "value": true },
"opc_ua_server": { "value": true },
"opc_ua_security_policies": { "value": ["Basic256Sha256"] },
"secure_pg_hmi_only": { "value": true },
"confidential_data_protected": { "value": true }
} },
{ "name": "HMI_1", "role": "hmi", "order_number": "6AV2 124-0GC01-0AX0",
"firmware": "V17.0.0.0" }
],
"blocks": [
{ "device": "PLC_1", "name": "Main", "kind": "ob", "language": "LAD",
"file": "blocks/PLC_1/Main.xml" },
{ "device": "PLC_1", "name": "FB_42", "kind": "fb", "protected": true }
]
}
```
| Field | |
| --- | --- |
| `bundle_version` | `1` |
| `tia_version` | the TIA Portal version read with: `V20`, `V21` |
| `devices[].role` | `cpu`, `hmi`, `module`, anything else counts as other |
| `devices[].type_identifier` | TIA's type identifier; order number and firmware are taken from it unless given as `order_number` and `firmware`. A catalog order number with wildcards (`…-0Axx`) or a variant without a version (`//10002`) leaves the device not matched |
| `devices[].security` | a CPU's settings as configured in the project; each is `{"value": …}` when read, `{"unreadable": "<why>"}` when Openness could not read it, absent when not looked at |
| `security.access_level` | `full_access_including_failsafe`, `full_access`, `read_access`, `hmi_access`, `no_access`, `none` |
| `blocks[].kind` | `ob`, `fb`, `fc`, `db`, `udt` |
| `blocks[].file` | where the block's export lies in the zip: SimaticML (`.xml`), SIMATIC SD (`.s7dcl` with its `.s7res`, V21) or SCL (`.scl`) |
| `blocks[].protected` | know-how protected: no `file`, listed as not analysable |
## Dynamic testing — ICS protocol probe
Beyond the static analysis, Prüfwerk can **probe the running device** over
industrial protocols. Attach a **Live-URL** artifact (the device host / WebVisu
URL) to the PLC/SPS target and enable the probe under **Optionale Prüfungen**
(opt-in scans) in the last step of the wizard.
::: info Not in source-only deployments
A deployment that scans source code only, such as the cloud pilot, does not run
the ICS probe: the **Live-URL** artifact kind cannot be chosen, and where a
scan would have run it, it lists **Industrieprotokolle (ICS)** under
**Nicht ausgeführt** with „In dieser Umgebung nicht aktiviert.“
:::
The probe is **read-only** — it never writes to the live process. It currently
speaks **Modbus/TCP** (port 502): it confirms whether the device answers
unauthenticated Modbus requests and reads its device identity (vendor / product /
revision). Because Modbus/TCP has no authentication or encryption in the protocol,
a reachable endpoint that answers is reported as an exposed control interface
(CWE-306). OPC UA and EtherNet/IP probes are planned.
::: warning
The ICS probe connects to the live device. It is **opt-in** (off by default) and
should only be run against targets you are authorized to test. It performs reads
only, never writes.
:::