Section 1.5

Attack surface

Definition

The attack surface of a system is the set of all places where an attacker can influence the system or obtain data from it: every interface the attacker can reach, together with the code that runs, the state it changes and the resources it consumes while handling the attacker’s input. The attack surface depends on the attacker. One within radio range reaches the radio interfaces; one who holds the device also reaches its debug port and hardware. A smaller attack surface leaves fewer places where a flaw can be exploited.

The idea

A device accepts a command only if it carries a valid authentication §1.6 tag, a short value that only a holder of the secret key can compute. It is tempting to conclude that an attacker without the key can do nothing. But before the device can reject a forged command, it must receive the radio packets, join the fragments, read the length field, reserve a buffer and compute the tag it compares against. All of that code runs on bytes the attacker chose. A flaw in the length handling, or buffer reservations that are never released, can be exploited by anyone within radio range, key or no key.

The attack surface answers the question “where can the attacker touch the system?” A building is a fair picture: its attack surface is every door, window, vent and delivery hatch, plus the lobby in front of the security desk, which anyone may enter. Reducing the surface means bricking up unused doors and keeping the lobby small. The picture fails in one respect. In software the lobby is not empty space: it is code that runs on the visitor’s input, and a flaw there can bring down or take over the system before the security desk is reached.

How it works

Map the attack surface in this order.

  1. Fix the attacker. The threat model §1.2 says where the attacker is: within radio or network range, running code on the same computer, or holding the device.

  2. List the entry points, the places where outside data enters: network and radio services, command handlers, files and stored records that are read back, update and recovery paths, debug interfaces, and sensors or other hardware inputs. Include undocumented and rarely used ones.

  3. List the exit points, the places where data leaves: replies, error messages, logs, and measurable effects such as response time §9.32 or power use, which can form a side channel §1.29.

  4. Trace each entry point. Follow the attacker’s bytes forward and record which code runs, which state it can change, which privilege level §6.10 it runs at, and how much memory, processor time, storage or energy it can consume.

  5. Split each path at the authentication check. Everything before the check is reachable by every attacker in position. Everything after it is reachable only with a message that passes the check. An attacker without a valid key cannot create such a message, but can record a genuine one and deliver it later or more than once, unless a freshness check §1.26 rejects that copy.

  6. Reduce and harden. Remove entry points that are not needed, disable debug interfaces on production devices, put the cheapest rejection first, cap every resource that code before authentication can consume, and run exposed code with the least privilege §1.15 it needs.

The part before authentication needs the most care, because every attacker in position reaches it. It contains the transport code that receives packets, the framing that splits a stream of bytes into messages, the decoding of every field that must be read to find and check the tag, the choice of key, the tag computation and comparison, and the memory held while a message is assembled.

Manadhata and Wing (2011) [237] proposed measuring an attack surface along three kinds of resources: methods, meaning entry and exit points; communication channels; and untrusted data items. Each resource is weighted by the ratio of the damage it could enable to the effort an attacker needs to use it. Such a measure compares two versions of one system. It is not an absolute score of security.

Worked example

A hypothetical device receives long commands in fragments. Its receive path is:

  1. accept a connection;

  2. reserve an 80-byte record for the incoming message: 64 bytes for fragment data and 16 bytes for bookkeeping;

  3. read a 2-byte length field;

  4. collect fragments until the message is complete;

  5. verify the tag;

  6. carry out the command.

Steps 1 to 5 run for every sender, including one with no key. Only step 6 lies behind authentication.

Suppose the device allows up to 1000 incomplete messages at once and never discards one. An attacker starts 1000 messages and finishes none. Each record takes 64+16=8064 + 16 = 80 bytes, so the device must reserve 1000×80=80,0001000 \times 80 = 80{,}000 bytes. A microcontroller §6.1 with 64 KiB of RAM has 64×1024=65,53664 \times 1024 = 65{,}536 bytes in total, and 65,536/80=819.265{,}536 / 80 = 819.2, so even with every byte free the reservation for message number 820 fails. From then on, legitimate senders are refused: a denial of service §1.28 by an attacker who never produced a valid tag.

The repair caps the cost before authentication. Allow at most 4 incomplete messages, and discard any message not completed within 2 seconds. The worst-case reservation becomes 4×80=3204 \times 80 = 320 bytes, which is 320/65,536≈0.49%320 / 65{,}536 \approx 0.49\% of the memory. Also check the length field against the largest permitted message as soon as it is read, and discard the record at once if the length is too large. An attacker who keeps starting new messages can still occupy the 4 places and delay legitimate senders: the cap bounds memory, not every form of denial of service.

Removing code helps only when nothing else reaches it. Disabling an unused command handler shrinks the surface only if no other path, such as a recovery mode or a debug command, still calls that handler.

Stated precisely

Fix an attacker AA from the threat model. An entry point is reachable by AA when, in some execution, AA can deliver input to it. The attack surface for AA consists of

The pre-authentication surface is the part of that code which runs before an authentication check has accepted the input.

The attack surface places a contract on the system. Every piece of code on the surface must behave safely for every input AA can deliver, not only for well-formed input, and the total resources it can consume must have a bound the system can afford. Removing an entry point removes every attack that needs that entry point. It says nothing about attacks through the entry points that remain.

Limits and common mistakes

Counting is a proxy. The number of interfaces, commands or lines of code ignores reachability §3.21 and privilege: one recovery command that can replace keys outweighs dozens of read-only status queries.

Authentication does not shrink the part of the surface in front of it. It limits which messages reach the code behind it; every attacker in range still reaches the framing code and the tag check.

The surface depends on the attacker. An analysis for remote attackers that leaves out the debug port is correct for remote attackers only.

Dependencies are part of the surface. A radio stack, a parsing library or the cryptographic library that checks tags runs on attacker input, whoever wrote it.

Exit points leak. Error replies that distinguish “bad length” from “bad tag”, or a response time that depends on secret data, give the attacker information.

Holders of a valid key, including insiders and thieves of a key, reach the surface behind authentication as well.

A smaller surface means less exposure, not proof of correctness. The code that remains must still be shown to be safe.

Questions answered

Which inputs are reachable before authentication succeeds?

Every byte of every received message is reachable before authentication succeeds, because the system must receive and process a message before it can decide whether the message is authentic. The code that runs on those bytes is the pre-authentication part of the attack surface, the set of places where an attacker can influence the system. It typically contains, in order:

To find the exact set for one system, follow a forged message from the antenna or network socket to the point where it is rejected. Everything it touched on the way is reachable without a key, must be safe for every possible input, and must have its resource use capped.

Related entries: Threat model (§1.2), Denial of service (DoS) (§1.28), Deserialization (§4.29), Trust boundary (§1.3), Authentication (§1.6), Least privilege (§1.15), Side channel (§1.29). Further reading: [237].