Skip to content

Obfuscation

Overview

The recipe hides what it does from whoever reads it. Encoding (R003, R043, R045), runtime assembly (R039, R040) and name indirection (H080) are all the same move: the line a reviewer sees is not the command that runs.

H065 is the counterpart rather than a detection. The tokenizer rebuilds these forms so the other rules match on meaning rather than spelling, and H065 is what tells the reader the reconstruction happened, so the report never quotes text the file does not contain.

Density, not shape, is H036: three or more indicators on one line, counted rather than pattern-matched. Integrity checks that read as hiding (a hidden drop, an archive trailer) belong to staging and reconnaissance and integrity, which own the target rather than the technique.

See Rule Mechanics for the field table, the severity weights and the reserved identifier ranges.


Threat context

Think of a message written in a private cipher: you are asked to deliver it, but you cannot read it, and you are told not to worry about what it says. Obfuscation in a recipe is exactly that. Fetch-and-execute is visible if a reviewer can read the command, so obfuscation exists to defeat the reading: base64 or hex decode before execution, string reassembly, eval, printf into a shell, or an interpreter fed a blob.

In PKGBUILDs the honest cases are rare, because the source tarball and its checksum already exist. A recipe that hides its text is hiding it from the one person positioned to approve it, so the concealment itself is treated as the evidence.

The rules therefore do not try to reverse the obfuscation, which would put the analyser inside the payload. They flag that the recipe is reaching for a decoder and let the reviewer decide.

Detection mechanisms

The rules that make up this category are listed below, each with the series that implements it and the severity it carries. Scoring, matching and identifier allocation are shared across every category: see Rule Mechanics.

Individual rules

Rule Name Severity
H014 Eval or Exec Usage -
H065 Obfuscated Literal Reconstructed INFO
H080 Indirect Command Expansion CRITICAL
R003 Base64 Decode and Execute CRITICAL
R039 Eval With Dynamic Content CRITICAL
R040 Shell -c With Dynamic Payload CRITICAL
R043 Base64 Blob Decode CRITICAL
R045 Binary Encoding Pipe MEDIUM

R003: Base64 Decode and Execute

  • Target: resolved
  • Severity: CRITICAL (weight 40)
  • Category: obfuscation

  • Pattern: base64(?:(?![|;&]).)*?(?:\-d|\-\-decode)\b.*(?<!\\)\|

  • Description: Detects base64 -d | and base64 --decode | piped to execution. Base64-encoded scripts are a common obfuscation technique to hide malicious commands from casual review.
  • Note: The pipe must be unescaped. An escaped bar is an argument to the command and starts no pipeline, so it is not a match. The tokenizer preserves the escape (tokenizer._ESCAPE_REMOVABLE) so the distinction survives resolution. A rules.toml written by an earlier release may hold a wider pattern that does match it; trustsight config sync-rules --update replaces patterns this project shipped previously.
  • Printed text: A base64 -d | ... that sits wholly inside a printer's quoted text is output for the reader, not an executed pipeline, so the rule stands down.

H014: Eval or Exec Usage

H014 is retained as a documentation anchor for a retired rule. It emits no finding: eval of a substitution is R039, and a top-level fetch that accompanies an exec is H077.

R039: Eval With Dynamic Content

  • Target: resolved
  • Severity: CRITICAL (weight 40)
  • Category: execution

  • Pattern: \beval\s+(?:"|\$\(|\$\{|`|\$[a-zA-Z_])

  • Description: Detects eval applied to a variable, command substitution, or backtick expression. The payload is assembled at runtime, so no static pattern can see what will execute.

R040: Shell -c With Dynamic Payload

  • Target: resolved
  • Severity: CRITICAL (weight 40)
  • Category: execution

  • Pattern: \b(?:(?:ba|z|da|k|mk|pdk|ya|po|a)?sh|busybox\s+(?:ash|sh))\s+-c\s+(?:\$\(|`|\$\{|["\x27]?\$[A-Za-z_]|"[^"]*\$)

  • Description: Detects sh -c / bash -c whose argument contains a variable or substitution rather than a literal command.

R043: Base64 Blob Decode

  • Target: resolved
  • Severity: CRITICAL (weight 40)
  • Category: obfuscation

  • Pattern: base64\s+(?:-d|--decode)\s*(?:<<<|<<\w*|\$\{?[a-zA-Z_])

  • Description: Detects base64 -d fed from a here-string or a variable, as opposed to decoding a file that is itself part of the source array.

R045: Binary Encoding Pipe

  • Target: resolved
  • Severity: MEDIUM (weight 15)
  • Category: obfuscation

  • Pattern: \b(?:xxd|uudecode)\s+[^|]*(?<!\\)\|

  • Description: Detects xxd or uudecode piped onward. Both reconstruct binary content from a text representation, a way to carry a payload past text review.
  • Note: The pipe must be unescaped. An escaped bar is an argument to the command and starts no pipeline, so it is not a match. The tokenizer preserves the escape (tokenizer._ESCAPE_REMOVABLE) so the distinction survives resolution. A rules.toml written by an earlier release may hold a wider pattern that does match it; trustsight config sync-rules --update replaces patterns this project shipped previously.
  • Printed text: An xxd | ... / uudecode | ... that sits wholly inside a printer's quoted text is output for the reader, not an executed pipeline, so the rule stands down.

H065: Obfuscated Literal Reconstructed

  • Severity: INFO (weight 0)
  • Category: obfuscation

  • Condition: An added line changes under literal reconstruction (ANSI-C hex $'\x62\x75\x6e', ANSI-C octal, empty-quote concatenation b''u''n, $(printf '\x62...')) and the reconstruction reveals a word the raw line did not carry, or an ANSI-C quote survives reconstruction.

The tokenizer rebuilds these forms so that H035, R003 and R039 match on what a line means rather than how it is spelled. H065 is what tells the reader that this happened: without it the report quotes text the file does not contain. It carries no weight, so it cannot move a score; it changes what the reader is looking at.

A literal that cannot be rebuilt is reported as the inconclusive case. Unreconstructable input is never read as UNFLAGGED.

Fire rate: 58 on the v1 corpus (1.55 %), all weight-0 reconstruction notes.

H080: Indirect Command Expansion

  • Severity: CRITICAL (weight 40)
  • Category: obfuscation

  • Condition: An added line contains the indirect-expansion form ${!name} where name is a plain (non-subscripted) variable name. The rule flags the form itself, on any added line, without requiring the expanded fragment to reach a shell.

${!C} expands to the value of the variable whose name is held in C, so C=curl; ${!C} URL | bash executes curl while the recipe carries no literal curl and no literal shell on the line R001/R002/H077/H069 read. The tokenizer refuses to evaluate indirection statically, so the obfuscated line reaches the rules verbatim and every literal-match rule steps over it: flagging the indirection itself closes that whole family at once.

Only the plain ${!name} form is indirection. ${!arr[@]} and ${!arr[*]} list an array's keys, and ${!prefix*} lists variable names by prefix - all common and benign - so the trailing } after the bare name is required, which excludes every subscripted or globbing form. Detected by _indirect_expansion_findings() in src/trustsight/analysis/build.py.

Interpretation

  • The finding names the concealment technique (base64, hex, eval, string slicing), with the matched fragment. It is about the technique's presence, which is decidable statically, not about what the blob would do.
  • Obfuscation next to a network call is the high-value pairing; obfuscation alone may still be a build quirk, but it is never nothing in a recipe whose checksums a reviewer is supposed to verify.
  • Findings here frequently co-fire with fetch-and-execution; that pairing is the intended escalation, not a duplicate.