OT Cybersecurity
Fuzzing with AFL - finding vulnerabilities in ICS software
How to use AFL/AFL++ fuzzing to find security vulnerabilities in ICS software. Case study: a crash in the DLMS energy meter library found by fuzzing.
Dominik M.
Bartłomiej BojarczukPublished Updated 9 min read

Contents
A protocol parser in a network-reachable device processes data from anyone who connects, so a single malformed message can stop a service. A manual test cannot cover every combination of fields, while a fuzzer covers millions of them. The Gurux release notes and the GuruxDLMS.c code show that:
- fuzzing with AFL detected a crash in 2019 while parsing an AARQ message, the association request in the DLMS protocol,
- the cause was an
unusedBitsfield value greater than 8 in theapdu_parseProtocolVersionfunction, - the fix shipped in the release of 3 June 2019, and the release notes give no CVE number,
- the test targeted the library’s example server, not a physical meter.
What fuzzing is
Fuzzing (fuzz testing) means feeding a program randomly generated or modified input and observing whether any of it causes incorrect behavior, for example a crash, a memory leak or an infinite loop. The method detects memory access errors (buffer overflow, use after free, out-of-bounds reads and writes), which occur in programs written in C and C++.
Modern fuzzers such as AFL++ use instrumentation: the program tells the fuzzer which parts of the code it executed. The fuzzer builds new inputs from those that previously reached new code paths. This way it increases code coverage instead of shooting at random.
AFL++ is an actively developed fork of the original AFL. The steps below were done with AFL, and new tests should use AFL++, because AFL++ is the one under development.
Why fuzzing matters for OT
Software on industrial devices such as PLCs, RTUs, energy meters and BMS controllers is often written in C or C++ and processes network data through protocols such as Modbus, DNP3, DLMS or OPC. A vulnerability in the parser of such a protocol can allow a takeover of the device or its shutdown. MITRE ATT&CK for ICS describes the techniques Exploitation of Remote Services (T0866) and Denial of Service (T0814), which use such flaws.
Forescout’s 2026 report describes a record number of ICS advisories published in 2025. The most affected assets are Purdue Level 1 devices, that is, field controllers, RTUs, PLCs and IEDs.
| Indicator for 2025 | Value |
|---|---|
| Number of CVEs described in ICS advisories | 2,155 |
| Number of ICS advisories (Forescout calls it a record) | 508 |
Fuzzing is useful for three reasons:
- A fuzzer tests inputs nobody would type by hand, so it finds flaws that a manual test misses.
- A fuzzer runs unattended, so it can work overnight or over a weekend.
- Every crash can be reproduced with the same input file, so a developer can check whether the fix works.
Case study: GuruxDLMS.c
Target: DLMS library for energy meters
GuruxDLMS.c is an open-source implementation of the DLMS/COSEM protocol, which is used for remote reading of energy meters. A server built on this library processes data from anyone who connects. The goal of the test was to check whether a crafted message stops such a server.
Step 1: Preparing the program for fuzzing
AFL delivers input through a file and passes the program the path to it as a command-line argument. The example server, which listens on a TCP port by default, therefore has to be rewritten to read data from a file:
// GuruxDLMSSimpleServerExample/src/main.c (modified)
int main(int argc, char **argv){
unsigned char data;
FILE *f;
if(argc < 2){
puts("Error. Please provide a filename");
return 1;
}
svr_init(&settings, 1, DLMS_INTERFACE_TYPE_HDLC,
HDLC_BUFFER_SIZE, PDU_BUFFER_SIZE,
frame, HDLC_BUFFER_SIZE, pdu, PDU_BUFFER_SIZE);
svr_InitObjects(&settings);
if(svr_initialize(&settings)){
puts("Server init error");
return 2;
}
if(!(f = fopen(argv[1], "rb"))){
puts("Error reading file");
return 3;
}
while(fread(&data, sizeof(unsigned char), 1, f)){
if(svr_handleRequest3(&settings, data, &reply)){
puts("Error when handling request");
break;
}
if(reply.size != 0){
printf("Server reply: %s\n", reply.data);
bb_clear(&reply);
}
}
fclose(f);
return 0;
}
The data processing logic stays identical to the original server; only the data source changes, a file instead of a TCP connection. This way the flaws found concern the parser code, not the changes made.
Step 2: Compiling with instrumentation
AFL requires the program to be compiled with instrumentation, that is, special code that tracks which parts of the program execute. In addition, AddressSanitizer (ASAN) should be used, a compiler tool that stops the program as soon as it detects an invalid memory access and points to the exact place in the code.
# Replace the gcc compiler with afl-clang-fast (AFL++)
# Add the -fsanitize=address flag to CFLAGS and LFLAGS
cd development && make
cp lib/libgurux_dlms_c.a ../GuruxDLMSSimpleServerExample/obj/
cd ../GuruxDLMSSimpleServerExample && make
Step 3: Preparing seed inputs
AFL needs a directory of example inputs from which it creates mutations. Valid DLMS frames work best. When none are available, even a single space is enough:
mkdir input output
echo ' ' > input/1
The fuzzer gradually discovers valid DLMS communication based on code coverage, but the process is faster with sensible starting data.
Step 4: Running the fuzzer
afl-fuzz -i input/ -o output/ bin/gurux.dlms.simple.server.bin @@
The @@ symbol marks the place where AFL substitutes the path to the generated file. The status screen shows the number of paths discovered, and with sufficient code coverage also the files that cause a crash.
Problem: checksums
After a few hours the fuzzer found no new paths. The DLMS protocol verifies message checksums, so the parser rejects mutated data with a wrong checksum before it reaches deeper code. According to the AFL++ documentation, a fuzzer has limited coverage when checksums wrap the whole tested format.
TIP
Solutions to the checksum problem in fuzzing:
- Disable the verification in the tested code. The AFL++ documentation lists this method first, and this test used it.
- A postprocessor (the
post_processfunction in the AFL++ custom mutator mechanism) that adds correct checksums to the data before the program runs. - Libprotobuf-mutator for protocols whose structure is described by a protobuf definition.
Disabling the verification is enough to find flaws in the parser. To exploit a flaw in a penetration test on a running device, the data sent must carry correct checksums, because the device verifies them.
Step 5: The vulnerability found
After disabling checksum verification and restarting the fuzzer, AFL found files that cause a crash. The ASAN analysis pointed to the cause:
==10691==ERROR: AddressSanitizer: stack-buffer-overflow
on address 0x7fffffffd5c1
at pc 0x7ffff6ee2397
READ of size 8187 at 0x7fffffffd5c1 thread T0
#0 __asan_memcpy
#1 ba_copy src/bitarray.c:203
#2 apdu_parseProtocolVersion src/apdu.c:1067
#3 apdu_parsePDU src/apdu.c:1428
#4 svr_HandleAarqRequest src/server.c:325
#5 svr_handleCommand src/server.c:2398
#6 svr_handleRequest3 src/server.c:2467
In the apdu_parseProtocolVersion() function, the value of the unusedBits variable, read from the input, could exceed 8. The function passed it to ba_copy(), which read beyond the stack buffer boundary, and ASAN reported this as stack-buffer-overflow. The current library code returns DLMS_ERROR_CODE_INVALID_PARAMETER in this case, and the 20190603.1 release notes mention this fix.
Vulnerability assessment
The release notes describe the flaw as a crash while parsing AARQ. The call stack runs through svr_HandleAarqRequest, the handler of the association request, so a message sent at the start of a session triggers the crash.
The test targeted the library’s example server, rewritten to read from a file, not a physical meter. The consequence for a meter depends on the software of the device that uses the library.
The excess data copied from the buffer was not sent in a response, so the flaw did not leak data. Even in the build without ASAN, some calls ended with a segmentation fault, which is enough to stop a service.
Tools for fuzzing OT software
| Tool | Type | Use in OT | Notes |
|---|---|---|---|
| AFL++ | Mutation guided by code coverage | Protocol libraries, for example DLMS or Modbus. | A fork of AFL (release 5.03c according to the README). Supports CMPLOG mode and custom mutators. |
| libFuzzer | In-process, guided by code coverage | Parsers and libraries. | The original authors stopped active work and develop Centipede, and important bugs are still fixed. |
| Honggfuzz | Guided by code coverage, multi-process and multi-threaded | Parsers and libraries. | Persistent mode tests an API inside the process. |
| Boofuzz | Generation-based, network | OT protocols over the network, for example Modbus TCP. | Successor to Sulley. Tests through the network, so it needs no source code of the target. |
| Peach Fuzzer | Model-based, network | Complex network protocols. | GitLab released the core of Peach as Protocol Fuzzer Community Edition. |
TIP
For OT protocols with checksums (DLMS, DNP3, Modbus), the two methods should be combined. AFL++ with a custom mutator that adds correct frames and checksums tests the parser in depth when source code is available. Boofuzz tests the protocol over the network and also checks a physical device (PLC, meter), because it does not need source code.
Fuzzing as part of OT security testing
Fuzzing should be applied in the development process of OT software (SDL, Security Development Lifecycle) and during penetration testing of devices. The results complement network segmentation and monitoring in a defense in depth model, because fuzzing removes flaws in code, while segmentation limits the consequences of flaws that were not found.
Rules that follow from the test described:
- Fuzzing should be combined with code review, manual testing and architecture analysis, because a fuzzer finds flaws in data parsing, not logic or configuration errors.
- When source code is available, it should be compiled with instrumentation, because AFL instrumentation requires source code. Without it, QEMU mode in AFL++ or network fuzzing, for example with Boofuzz, can be used.
- Checksum handling should be planned before the start, because protocols such as DLMS verify them, and without it the fuzzer has limited coverage.
- Flaws found should be reported to the vendor, and publication should wait for the fix, because the vendor needs time to prepare it.
Where we help
During penetration testing of OT devices, the SEQRED team can perform fuzzing of protocol parsers when the vendor provides the software or a test device. To start a conversation, use the contact form.
Sources
- ICS Cybersecurity in 2026: Vulnerabilities and the Path Forward - Forescout (accessed: )
- gurux.dlms.c 20190603.1 release notes - Gurux (accessed: )
- GuruxDLMS.c - source code (development/src/apdu.c) - Gurux (accessed: )
- AFL++ - README - AFLplusplus (accessed: )
- AFL++ - Fuzzing in depth - AFLplusplus (accessed: )
- AFL++ - Custom mutators - AFLplusplus (accessed: )
- libFuzzer - a library for coverage-guided fuzz testing - LLVM (accessed: )
- Honggfuzz - README - Google (accessed: )
- boofuzz: Network Protocol Fuzzing for Humans - boofuzz (accessed: )
- We're open sourcing Protocol Fuzzer Community Edition! - GitLab (accessed: )
- Exploitation of Remote Services, Technique T0866 - ICS - MITRE ATT&CK (accessed: )
- Denial of Service, Technique T0814 - ICS - MITRE ATT&CK (accessed: )
Need help in this area?
Our experts will help you assess the risk and plan next steps.