Skip to Content
Operating Systems

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:

Connect to an industrial system

Provide the endpoint URL when opening a cnspec shell:

cnspec shell opcua --endpoint opc.tcp://HOST:PORT
PlaceholderValue
HOSTThe industrial system hostname or IP address
PORTThe 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:

FlagDescription
--endpointOPC UA endpoint URL in the format opc.tcp://<host>:<port> (required)
--usernameUsername for OPC UA username and password authentication
--passwordPassword for OPC UA username and password authentication
--cert-filePath to the PEM or DER encoded client certificate to present on the secure channel
--key-filePath to the PEM or DER encoded private key that belongs to the client certificate
--security-policySecurity policy to use: None, Basic128Rsa15, Basic256, Basic256Sha256, Aes128Sha256RsaOaep, or Aes256Sha256RsaPss
--security-modeMessage 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:4840

Scan 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.yaml

Secure 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-pass

The 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.yaml

To 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

Last updated on

On this page