Attacks OPCUA
Attacks OPCUA
Noam Moshe
Vulnerability researcher -
Pwn2Own, mostly breaking IoT
clouds
Open-source tools
• OPC-UA fuzzer
• Research Methodology
• Summary
What’s the Problem?
Water
level Proprietary
ICS Protocol ?
???
Water
level Water Level OPC-UA
Water Level
is 50%
Proprietary
is 50%
ICS Protocol
OPC-UA
Water Tank PLC Server HMI & SCADA
What is OPC-UA?
Detailed specifications
• Information Model: Object types, how to encode
• Many more
Protocol Stacks and Frameworks
Agenda
• What is OPC-UA?
• Research Methodology
• Summary
OPC-UA Protocol Stacks
protocol stacks
Java Stack .NET Stack ANSI C Stack
• ANSI C
Java Runtime .NET Runtime
• Java
• .NET
Win / Linux API
Operating System
OPC-UA Supply Chain
https://opcfoundation.org/products
OPC-UA Supply Chain
+ + +
Core lib
Focus on the Protocol Stacks
So we wanted to find
vulns in the base
protocol stacks
Protocol Stacks
Programing Is Open
We also researched popular products OPC-UA Protocol Stack
language Source?
• Research Methodology
• Summary
OPC-UA Nodes
Everything is a node
• Variable (e.g. “Water Level”)
• Namespace ID (ns=0)
Variable with
Fill Valve DataType Boolean
Variable with
Discharge Valve DataType Boolean
Variable with
Flow Meter DataType Float Tank (water level %50)
Variable with
Water Level DataType Float
Start/Stop Method
Nodes Encoding [ns=0, i=446]
Specifications
Binary Representation
Binary Parsing
Example: Read Service: Reading 12 Nodes
HEL
HEL: Hello message
HEL
HEL: Hello message
Endpoint URL
opc.tcp://SERVER_IP:62541/UA/Server
OPN
HEL: Hello message
Security Mode
• None
• Sign
Authentication
• Anonymous
• Username/password
• Certificate
• Research Methodology
• Summary
Building Basic OPC-UA Client
Why?
• Hands-on
• Focus on logic
• Customizable to our vuln research
needs
How?
• Specification
• Protocol analysis + Wireshark
FreeOpcUa Python OPC-UA
(Python)
Prosys OPC-UA Browser (Java)
Unified Automation UaExpert
(C/C++)
Building the Setup
Intel NUC x 2
• Intel Core i7-1165G7
• 32 GB RAM
OPC UA Servers
• Inductive Automation Ignition
• Unified Automation UaGateway
• PTC Kepware KepServerEx
• Prosys OPC UA Simulation Server
• Softing edgeConnector
Network Fuzzer
Fuzzing 6 Services
• Read Service
• Browse Service
https://github.com/claroty/opcua_network_fuzzer
Fuzzers: Coverage Based
libfuzzer
• Closed binary: using WinAFL,
• Research Methodology
• Summary
OPC-UA Server - Denial of Service
OPC-UA
Attacker
OPC-UA
Water Tank PLC Server/Gateway OPC-UA Client
Denial of Service - Vectors
• Threads deadlock
• Uncaught exceptions
while !isFinalChunk:
add(chunk)
MSG MSG
Chunk Chunk
MSG
MSG MSG MSG MSG
Chunk
Final Chunk Chunk MSG Chunk
MSG
Chunk
Chunk MSG
Attacker Chunk
OPC-UA
Server/Gateway
Denial of Service - Chunk Flooding
while !isFinalChunk:
add(chunk)
MSG
Chunk
MSG
Chunk MSG
Chunk MSG
MSG Chunk
MSG
Final Chunk
Attacker OPC-UA
Server/Gateway
Denial of Service - Chunk Flooding
while
!isFinalChunk:
add(chunk)
MSG
Chunk
MSG
Chunk MSG
Chunk MSG
MSG Chunk
MSG
Final Chunk
Attacker OPC-UA
Server/Gateway
Denial of Service - Chunk Flooding
while
!isFinalChunk:
add(chunk)
MSG
Chunk
MSG
Chunk MSG
Chunk MSG
MSG Chunk
MSG
Final Chunk
Attacker OPC-UA
Server/Gateway
CVE-2022-21208 CVE-2022-24381
CVE-2022-25761 CVE-2022-25888
CVE-2022-25304 CVE-2022-29864
Denial of Service – Attack Concepts
https://reference.opcfoundation.org/v104/Core/docs/Part4/5.11.2/
Denial of Service - Method Calling From Dead Session
https://reference.opcfoundation.org/v104/Core/docs/Part4/5.11.2/
Denial of Service - Method Calling From Dead Session
Exploit:
• Sending many Call Method
Request
• And immediately close the session
Denial of Service - Method Calling From Dead Session
MSG
Call Method 1
Call Method 2
…
Call Method n
Attacker OPC-UA
Server/Gateway
Denial of Service - Method Calling From Dead Session
MSG
Call Method 1
Call Method 2
…
Call Method n
Attacker OPC-UA
Server/Gateway
Denial of Service - Method Calling From Dead Session
MSG
Call Method 1
Call Method 2
…
Call Method n
Attacker OPC-UA
Server/Gateway
Denial of Service - Method Calling From Dead Session
MSG
Call Method 1
Call Method 2
…
Call Method n
Attacker OPC-UA
Server/Gateway
Denial of Service - Method Calling From Dead Session
MSG
Call Method 1
Call Method 2
…
Call Method n
OPC-UA
Server/Gateway
Denial of Service - Method Calling From Dead Session
CVE-2022-1748
Vulnerabilities and Exploits
RCE - Servers
OPC-UA Server - RCE
Attacker
OPC-UA
Water Tank PLC Server/Gateway OPC-UA Client
OPC-UA Server - RCE
OPC-UA
Attacker
OPC-UA
Water Tank PLC Server/Gateway OPC-UA Client
PTC Kepware KepServerEx
• Industry’s leading OPC-UA server, used
in biggest manufacturing lines, oil rigs,
wind farms, etc.
• Windows-based
Whatever starts
UTF-8: AAAÀ with C3 is
probably 2 bytes
long
AAAÀ
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAAÀ with C3 is
probably 2 bytes
long
41 41 41 c3 80 00 ……
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAAÀ with C3 is
probably 2 bytes
long
41 41 41 c3 80 00 ……
1 1 1 2
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAAÀ with C3 is
probably 2 bytes
long
41 41 41 c3 80 00 ……
Stop
1 1 1 2
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAAÀ with C3 is
probably 2 bytes
long
41 41 41 c3 80 00 ……
Stop
1 1 1 2
UTF-16:
\x41\x41\x41\xC3\x80
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAAÀ with C3 is
probably 2 bytes
long
OK
41 41 41 c3 80 00 ……
Stop
1 1 1 2
UTF-16:
\x41\x41\x41\xC3\x80
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAA\xC3 with C3 is
probably 2 bytes
long
AAA\xC3
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAA\xC3 with C3 is
probably 2 bytes
long
41 41 41 c3 00
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAA\xC3 with C3 is
probably 2 bytes
long
41 41 41 c3 00
1
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAA\xC3 with C3 is
probably 2 bytes
long
41 41 41 c3 00
1 1
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAA\xC3 with C3 is
probably 2 bytes
long
41 41 41 c3 00
1 1 2
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAA\xC3 with C3 is
probably 2 bytes
long
41 41 41 c3 00 XXXXXXXXX……00
1 1 2 1 1
UTF-8 to UTF-16 is Hard
Whatever starts
UTF-8: AAA\xC3 with C3 is
probably 2 bytes
long
41 41 41 c3 00 XXXXXXXXX……00
Stop
1 1 2 1 1
UTF-8 to UTF-16 is Hard
UTF-8: AAA\xC3
41 41 41 c3 00 XXXXXXXXX……00
Stop
1 1 2 1 1
UTF-16:
\x41\x41\x41\xC3LEAKINGTHEHEAP
UTF-8 to UTF-16 is Hard
UTF-8: AAA\xC3
FAIL
41 41 41 c3 00 XXXXXXXXX……00
Stop
1 1 2 1 1
UTF-16:
\x41\x41\x41\xC3LEAKINGTHEHEAP
Heap Overflow Primitive
UTF8 → UTF16
mspaint → \x00m\x00s\x00p\x00a\x00i\x00n\x00t
OOB Write
UTF8 → UTF16
mspaint → \x00m\x00s\x00p\x00a\x00i\x00n\x00t
UTF8 → UTF16
????? → mspaint
OOB Write
UTF8 → UTF16
????? → mspaint
UTF-8 to16(?UTF-8) = ‘ms’
OOB Write
- We have the pointers to start our ROP chain
- But the bytes written are UTF-16 converted
- To construct the ROP chain we need to control the whole
payload.
UTF8 → UTF16
?????UTF-8→
to16(? UTF-8) =
mspaint ‘ms’ → \x6d\x73
OOB Write
- We have the pointers to start our ROP chain
- But the bytes written are UTF-16 converted
- To construct the ROP chain we need to control the whole
payload.
UTF8 → UTF16
?????UTF-8→
to16(? UTF-8) =
mspaint ‘ms’ → \x6d\x73
OOB Write
- We have the pointers to start our ROP chain
- But the bytes written are UTF-16 converted
- To construct the ROP chain we need to control the whole
payload.
UTF8 → UTF16
?????UTF-8→
to16(? UTF-8) =
mspaint ‘ms’ → \x6d\x73
OOB Write
- We have the pointers to start our ROP chain
- But the bytes written are UTF-16 converted
- To construct the ROP chain we need to control the whole
payload.
UTF8 → UTF16
?????
UTF-8 to16(?UTF-8) =
→ mspaint
‘ms’ → \x6d\x73
Unicode(\x6d\x73 ) = 獭 UTF-16
OOB Write
- We have the pointers to start our ROP chain
- But the bytes written are UTF-16 converted
- To construct the ROP chain we need to control the whole
payload.
UTF8 UTF-8→
to16(? UTF-8) = ‘ms’ → \x6d\x73
UTF16
UTF-16) = 獭
→ mspaint
????? Unicode(\x6d\x73
UTF-8(獭) = \xe7\x8d\xad
OOB Write
- We have the pointers to start our ROP chain
- But the bytes written are UTF-16 converted
- To construct the ROP chain we need to control the whole
payload.
UTF-8(獭) = \xe7\x8d\xad
UTF-8to16(\xe7\x8d\xad ) = ? UTF-8
OOB Write
- We have the pointers to start our ROP chain
- But the bytes written are UTF-16 converted
- To construct the ROP chain we need to control the whole
payload.
UTF-8(獭) = \xe7\x8d\xad
UTF-8to16(\xe7\x8d\xad ) = \x6d\x73 UTF-8
OOB Write
- We have the pointers to start our ROP chain
- But the bytes written are UTF-16 converted
- To construct the ROP chain we need to control the whole
payload.
UTF-8(獭) = \xe7\x8d\xad
UTF-8to16(\xe7\x8d\xad ) = \x6d\x73 = ‘ms’ UTF-8
OOB Write
- We have the pointers to start our ROP chain
- But the bytes written are UTF-16 converted
- To construct the ROP chain we need to control the whole
payload.
UTF8 Unicode(\x6d\x73
→ UTF16 )=獭 UTF-16
????? → mspaint
UTF-8(獭) = \xe7\x8d\xad
UTF-8to16(\xe7\x8d\xad ) = \x6d\x73 = ‘ms’ UTF-8
Read
Water Level
OPC-UA Tag
Malicious OPC-UA
OPC-UA Client
Server
Web-Based OPC-UA Clients
OPC-UA
Malicious OPC-UA
OPC-UA Client
Server
XSS Over OPC-UA
Read
Water Level
OPC-UA Tag
Malicious OPC-UA
OPC-UA Client
Server
XSS Over OPC-UA
Sure, here
is your tag!
Read
Water Level
OPC-UA Tag
Malicious OPC-UA
OPC-UA Client
Server
XSS Over OPC-UA
Sure, here
is your tag!
Read
Water Level
Tag: “/><SCRIPT XSS> OPC-UA Tag
Malicious OPC-UA
OPC-UA Client
Server
XSS Over OPC-UA
Read
Water Level
Tag: “/><SCRIPT XSS> OPC-UA Tag
Malicious OPC-UA
OPC-UA Client
Server
XSS Over OPC-UA
Read
Tag: “/><SCRIPT XSS>
Water Level
OPC-UA Tag
Malicious OPC-UA
OPC-UA Client
Server
XSS Over OPC-UA
OPC-UA
Malicious OPC-UA
OPC-UA Client
Server
XSS Over OPC-UA
OPC-UA
Malicious OPC-UA
OPC-UA Client
Server
XSS Over OPC-UA
XSS Over OPC-UA
XSS Over OPC-UA
XSS Over OPC-UA to RCE
CVE-2023-38121
CVE-2023-38122
CVE-2023-38123
CVE-2023-38124
XSS Over OPC-UA to RCE
Backup
XSS Over OPC-UA to RCE
Restore
Backup
XSS Over OPC-UA to RCE
Restore
XSS Over OPC-UA to RCE
Restore
XSS Over OPC-UA to RCE
Restore
OPC-UA Exploitation Framework
Open-Source
Agenda
• What is OPC-UA?
• Research Methodology
• Summary
Results: 12 concepts, ~50 CVEs
OPC-UA Exploit Framework
github.com/claroty/opcua-exploit-framework
Claroty OPC Exploit Framework
Attack Name Description Vulnerability Function CVE and
Type Keyword Reference
Certificate Infinite Chain Some servers implemented the Denial of Service certificate_inf_chain CVE-2022-37013
Loop Certificate chain check by _loop
themselves and forgot to protect
against a chain loop. Example:
CertA is signed by CertB which is
signed by CertA
Chunk Flooding Sending huge amount of chunks Denial of Service chunk_flood CVE-2022-29864,
without the Final chunk CVE-2022-21208,
CVE-2022-25761,
CVE-2022-25304,
CVE-2022-24381,
CVE-2022-25888
Open Multiple Secure Flooding the server with many Denial of Service open_multiple_secur CVE-2023-32787
Channels open channel requests leads to a e_channels
denial of service
Claroty OPC Exploit Framework
Function Call Null Triggering an application crash Denial of Service function_call_null_ CVE-2022-1748
Dereference after several OPC UA methods deref
have been called and the OPC
UA session is closed before the
methods have been finished.
Race Change And Adding nodes to the server Denial of Service race_change_and_ CVE-2023-32172
Browse Address address space and removing the browse_address_s
Space nodes in a loop while browsing pace
the entire address space.
Complex Nested Sending a complex nested variant Denial of Service / complex_nested_ CVE-2022-25903,
Message leads to a call stack overflow Information message CVE-2021-27432
Leakage
Translate Browse Path Triggering a stack overflow Denial of Service translate_brows CVE-2022-29866
Call Stack Overflow exception in a server that doesn't e_path_call_sta
limit TranslateBrowsePath ck
resolving calls
Thread Pool Wait Thread pool deadlock due to Denial of Service thread_pool_wai CVE-2022-30551
Starvation concurrent worker starvation t_starvation
Unlimited Persistent Flooding the server with many Denial of Service unlimited_persi CVE-2022-25897,C
Subscriptions monitored items with 'delete' flag stent_subscript VE-2022-24375,CV
set to False leads to uncontrolled ions E-2022-24298
memory allocation and eventually
to a denial of service
Agenda
• What is OPC-UA?
• Research Methodology
• Summary
Summary