NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Real Package, Wrong Controller: Static Auditing of Vendor--Protocol Mismatches in LLM-Generated PLC Code

S M Zia Ur Rashid, Sazidul Islam Hira, Suman RatharXiv 2026

TL;DR

When large language models write Python scripts to control industrial hardware, they often import entirely real software libraries aimed at the completely wrong manufacturer—like trying to speak Siemens to a Schneider Electric device. Standard code checkers miss these mistakes because the packages genuinely exist, so the authors built a deterministic, zero-ML static auditor that catches vendor–protocol mismatches before a single packet hits the wire. Along the way, they uncover a sobering cautionary tale for AI-code detection: a "perfect" machine-versus-human classifier on their dataset was actually just memorizing whether a file ended with a newline character.

What Problem Does This Paper Address?

Programmable Logic Controllers (PLCs) are the ruggedized computers where code meets physical machinery—valves, turbines, and assembly lines. Recently, researchers showed that LLMs can generate PLC attack scripts from simple prompts, potentially lowering the barrier to industrial cyberattacks.

From a defensive standpoint, how do we statically audit this code? In mainstream software security, "hallucination checkers" verify whether an imported package or method actually exists (preventing supply-chain attacks on invented names). In Operational Technology (OT), however, existence is the wrong question. Industrial protocols are strictly vendor-bound: Python’s snap7 speaks Siemens’ S7comm, while pycomm3 speaks Rockwell’s EtherNet/IP. Prompt an LLM to target a Schneider Modicon controller, and it will happily write valid Python importing snap7 and calling real methods. Existence checkers give this a green light. Before this paper, no static, pre-execution tool checked whether an OT script's libraries actually match its declared hardware target.

Methods

The authors introduce PROTEUS-OT, a label-free static verifier requiring no training data or machine learning models.

Instead of ML, it relies on a version-pinned binding graph mapping the documented relationships between four entities: Vendors, Protocols, Libraries, and Symbols. Because a single library might support multiple protocols (including vendor-neutral ones like Modbus-TCP), validity is modeled relationally: an imported library is valid if at least one of its protocols is either vendor-neutral or documented as supporting the target vendor.

PROTEUS-OT parses a Python script into an Abstract Syntax Tree (AST)—never executing it—and checks its imports against the declared target vendor, emitting an inspectable "witness" whenever a mismatch occurs. Crucially, to prove an offending import isn't just dead weight, the tool tracks witness depth from L0 (imported, never referenced) up to L3 (reaches an actual network communication call like connect or db_read).

The authors also audit a secondary task: training ML classifiers (using character $n$-grams, CodeBERT, and AST histograms) to distinguish LLM-generated scripts from human-written ones, stress-testing the models by progressively stripping comments, formatting, identifiers, and top features.

Datasets

The authors evaluate a deterministic, deduplicated corpus of 1,006 Python files importing real OT libraries:

  • Machine class (883 scripts): Drawn from a prior LLM attack-synthesis benchmark (Cook et al.), spanning five LLMs and three target vendors, with target metadata extracted from file paths.
  • Human class (190 raw files, 28 with identifiable single-vendor targets): Collected from public OT security tools and mainstream Python OT library repositories.
  • For ML classification experiments, a balanced subset of 336 scripts is evaluated across five data splits (including task-, model-, vendor-, and repository-disjoint partitions).

Key Insights and Ideas

  • Real packages, wrong hardware: In specialized domains, LLMs fail by misapplying real tools rather than inventing fake ones. Checking domain constraints deterministically catches errors that existence baselines are blind to.
  • Provenance labels $\neq$ Authorship: Assembling "AI" code from one generation pipeline and "human" code from GitHub creates massive hidden confounds. First, there is a genre mismatch: 75% of the human files were library source and pytest suites, whereas the LLM files were standalone scripts.
  • The single-byte giveaway: Even after destroying all formatting via AST round-trips and anonymizing variables, character $n$-grams achieved near-perfect classification. Why? A serialization artifact: 95.2% of human files ended with a trailing newline (\n), while 0% of the LLM-generated scripts did. A single byte separated the classes without needing any AI detector at all.

Key Results

  • Audit prevalence: Across 883 LLM-generated scripts, 20.4% carried an inclusive vendor–protocol mismatch. Restricting to unambiguous single-vendor targets and requiring L3 communication-call depth yields a primary confirmed mismatch rate of 14.2% (roughly 1 in 7 scripts). None of the 28 adjudicable human files triggered a mismatch (0.0%), though the sample is too small to compare prevalence.
Fig. 1. Inclusive audit rates with Wilson intervals and library–target pairings.
  • Blindness of existence checks: Within the balanced subset, 96.6% of scripts with OT-semantic flags imported real packages and called real symbols, sailing right past an existence baseline. Furthermore, 87.8% of the 180 total witnesses reached full L3 communication calls—proving these are live functional bugs, not dead imports.
  • Degenerate ML detection: Character $n$-gram TF–IDF hit 1.000 macro-$F_1$ across random, task-, model-, and vendor-disjoint splits (beating frozen CodeBERT at ~0.98), while a modelless check on the trailing newline alone achieved an AUC of 0.024 (where values near 0 or 1 indicate near-total separation). Consequently, the authors formally retracted an earlier claim that their grounded features improved ML authorship detection.

Limitations and Future Work

  • Metadata sensitivity: Target vendors are inferred from filenames rather than verified user intent. On scripts where vendor names also appeared inside the code text, filename-derived flags (23.9%) were much higher than code-text flags (11.6%), as models tended to name the vendor matching the library they imported.
  • Graph coverage & evasion: The binding graph currently covers 7 of 24 mainstream Python OT packages; scripts using uncovered libraries pass silently as unaudited negatives. While static checks survive alias renaming and misleading comments (100% retention), dynamic imports like importlib or __import__ completely evade detection (0% retention).
  • Future directions: Expanding the binding graph to all 24 OT packages, incorporating conditional device-family contexts, conducting human rater adjudication on the flagged scripts, and building genre-matched, identically serialized human control datasets before attempting future provenance studies.

Summary updated

BibTeX
@misc{rashid2026real,
  author = {S M Zia Ur Rashid and Sazidul Islam Hira and Suman Rath},
  title = {{Real Package, Wrong Controller: Static Auditing of Vendor--Protocol Mismatches in LLM-Generated PLC Code}},
  year = {2026},
  eprint = {2611.33227},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.33227},
}
Figure