Secure OPC UA Industrial Systems with cnspec
Query industrial control systems and devices that run an OPC UA server with cnspec, and secure the operating system of Phoenix Contact PLCnext controllers.
Scan industrial control systems and devices that expose an OPC UA (Open Platform Communications Unified Architecture) server, such as programmable logic controllers (PLCs) and industrial gateways. cnspec connects to the OPC UA endpoint over the network and queries the server's status and build information, its namespaces, and the nodes in its address space. It talks only to the OPC UA server, so it works the same whatever operating system the device or server runs.
New to cnspec? Start with the Quickstart, or read the Operating systems overview to see every platform cnspec can secure.
Prerequisites
To scan an OPC UA system with cnspec, you must have:
- cnspec installed on your workstation
- Network access to the OPC UA endpoint on the industrial device
Connect to an industrial system
Provide the endpoint URL when opening a cnspec shell:
cnspec shell opcua --endpoint opc.tcp://HOST:PORT| Placeholder | Value |
|---|---|
HOST | The industrial system hostname or IP address |
PORT | The OPC UA server port (typically 4840) |
By default cnspec negotiates the strongest security policy and message security mode the server offers, falls back to weaker endpoints when it can't establish a session, and connects anonymously. Use these flags to authenticate or to control the secure channel:
| Flag | Description |
|---|---|
--endpoint | OPC UA endpoint URL in the format opc.tcp://<host>:<port> (required) |
--username | Username for OPC UA username and password authentication |
--password | Password for OPC UA username and password authentication |
--cert-file | Path to the PEM or DER encoded client certificate to present on the secure channel |
--key-file | Path to the PEM or DER encoded private key that belongs to the client certificate |
--security-policy | Security policy to use: None, Basic128Rsa15, Basic256, Basic256Sha256, Aes128Sha256RsaOaep, or Aes256Sha256RsaPss |
--security-mode | Message security mode to use: None, Sign, or SignAndEncrypt |
For example, to connect to the OPC UA server of a device at 192.168.1.50:
cnspec shell opcua --endpoint opc.tcp://192.168.1.50:4840Scan an industrial system
Mondoo doesn't provide an out-of-the-box policy for OPC UA servers. To assess an OPC UA server, write your own policy with checks on the opcua resources, like the examples below, and pass it to cnspec with --policy-bundle:
cnspec scan opcua --endpoint opc.tcp://192.168.1.50:4840 --policy-bundle my-opcua-policy.mql.yamlSecure the operating system of a PLCnext controller
The Phoenix PLCnext Security Policy checks the Linux operating system of Phoenix Contact PLCnext controllers, not their OPC UA server. Its 22 checks cover the PLCnext firmware version, the nftables firewall, time synchronization, and the SSH server's settings, cryptographic algorithms, and file permissions. The policy doesn't apply to an OPC UA scan.
To run the policy, scan the controller over SSH. cnspec detects the controller as the plcnext platform. The policy applies to controllers with an ARMv7 (armv7l) processor that have PLCnext installed in /opt/plcnext.
cnspec scan ssh user@HOST --ask-passThe firewall check reads the nftables ruleset, which only root can read. If you connect as a regular user who can run sudo without a password prompt, add --sudo.
Mondoo Platform users: Enable the policy in your space. In the Mondoo App, go to Findings > Policies, search for "PLCnext", and add the policy. To learn more, read Manage policies in Mondoo Platform.
Open source users: Pass the policy bundle URL directly to cnspec:
cnspec scan ssh user@HOST --ask-pass \
--policy-bundle https://raw.githubusercontent.com/mondoohq/cnspec/refs/heads/main/content/mondoo-phoenix-plcnext-security.mql.yamlTo learn more about SSH scans, such as authenticating with a key, read Secure Linux with cnspec.
Explore and test checks interactively
Open a cnspec shell (cnspec shell opcua --endpoint opc.tcp://HOST:PORT) to discover resources on the device and test queries interactively. The examples below show common OPC UA queries.
Retrieve OPC UA server information
cnspec> opcua.server
opcua.server: {
...
}Retrieve all namespaces
cnspec> opcua.namespaces
namespaces: [
0: opcua.namespace
...
]Retrieve the root node
cnspec> opcua.root
root: id="i=84" name="Root"List all nodes
cnspec> opcua.nodes
nodes: [
0: id="i=84" name="Root"
1: id="i=85" name="Objects"
...
]Ensure the server reports that it's running
cnspec> opcua.server.state == "ServerStateRunning"
[ok] value: "ServerStateRunning"List the nodes whose value clients can write
cnspec> opcua.nodes.where(writeable) { id name dataType accessLevel }Learn more
- OPC UA Resource Pack Reference: every OPC UA resource and field cnspec can query
- Write Effective MQL: guide to authoring checks and queries
Last updated on