Apply IoT Device Hardening
Remove default credentials, disable JTAG/UART debug interfaces, encrypt data at rest, and implement physical tamper detection — preventing both remote and physical compromise of deployed IoT devices.
Why This Is Best Practice
Adopted by: OWASP IoT Top 10 I9 (Insecure Default Settings) and I10 (Lack of Physical Hardening). ETSI EN 303 645 Section 5.1 mandates unique per-device credentials and prohibits default passwords. The UK Product Security and Telecommunications Infrastructure (PSTI) Act 2024 bans universal default passwords for consumer IoT — manufacturers face fines up to £10M. NIST SP 800-193 requires firmware resilience against physical access. Medical IoT (FDA guidance 2023), industrial IoT (IEC 62443), and automotive IoT (UNECE WP.29) all mandate these controls.
Impact: Mirai botnet's primary infection vector was default credentials (admin/admin, root/1234) on Telnet and HTTP — 600,000 devices compromised within weeks of release. Shodan 2023 found 2.3 million IoT devices still using factory default credentials. Physical hardware attacks allow credential extraction from unprotected UART/JTAG interfaces in under 5 minutes with a $30 FTDI adapter and publicly available firmware extraction tools. NIST estimates 30% of IoT breaches involve physical access to the device.
Why best: Remote hardening (network services, TLS) protects against internet-facing attacks; physical hardening adds a layer against supply chain attacks, insider threats, and theft of deployed devices. Default credentials are unique in that they're publicly known to attackers before the device is even deployed — per-device unique credentials eliminate this entire attack class at zero ongoing cost.
Sources: OWASP IoT Top 10 I9, I10; ETSI EN 303 645 sections 5.1 and 5.2; UK PSTI Act 2024; FDA "Cybersecurity in Medical Devices" guidance (2023)
Steps
Generate unique per-device credentials at manufacturing time:
# Manufacturing provisioning script — runs once per device
import secrets
import hashlib
def provision_device(device_serial: str, device_mac: str) -> dict:
# Generate cryptographically random password (not derived from serial/MAC)
admin_password = secrets.token_urlsafe(16)
# Generate unique device certificate
private_key = generate_ec_key()
cert = sign_device_certificate(
private_key=private_key,
subject=f"CN={device_serial},O=Company,C=US",
ca_key=MANUFACTURING_CA_KEY
)
# Store: password hash in device, plaintext in HSM-backed provisioning DB
device_config = {
"admin_password_hash": bcrypt.hash(admin_password),
"device_cert": cert,
"device_key": private_key,
"serial": device_serial,
}
# Label on physical device: serial + initial password (for setup only)
# Force password change on first login
return device_config
# NEVER: password = hashlib.md5(device_serial.encode()).hexdigest()
# NEVER: same default password across entire product line
Disable JTAG and UART debug interfaces in production:
/* STM32 — disable JTAG/SWD via option bytes at end of production test */
void disable_debug_interfaces(void) {
FLASH_OBProgramInitTypeDef ob_init = {0};
HAL_FLASHEx_OBGetConfig(&ob_init);
/* Disable SWD interface — write-once OTP operation */
ob_init.OptionType = OPTIONBYTE_USER;
ob_init.USERType = OB_USER_TZEN;
ob_init.USERConfig = OB_TZEN_ENABLE; /* Enable TrustZone */
/* Set RDP (Read-Out Protection) Level 2 — no debug, no readback */
ob_init.OptionType |= OPTIONBYTE_RDP;
ob_init.RDPLevel = OB_RDP_LEVEL_2; /* PERMANENT — cannot be reversed */
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_OBProgram(&ob_init);
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
}
# For embedded Linux: disable UART console in production
# Remove console= from kernel command line in bootloader config
# /etc/inittab or systemd getty: comment out ttyS0 entries
# Disable JTAG in Device Tree
# &jtag { status = "disabled"; };
Encrypt sensitive data at rest using hardware security:
/* Use hardware AES engine + device-unique key (UID) for storage encryption */
#include "aes.h"
/* Derive storage key from device UID — unique per device, never leaves hardware */
void derive_storage_key(uint8_t key_out[32]) {
/* STM32 unique device ID: 96-bit value burned at manufacturing */
uint32_t uid[3] = {
HAL_GetUIDw0(), HAL_GetUIDw1(), HAL_GetUIDw2()
};
/* HKDF with device UID as IKM and fixed info */
hkdf_sha256(key_out, 32,
(uint8_t *)uid, sizeof(uid),
(uint8_t *)"storage-key-v1", 15,
NULL, 0);
}
void encrypt_credentials(const char *plaintext, uint8_t *ciphertext_out) {
uint8_t key[32];
derive_storage_key(key);
uint8_t nonce[12];
crypto_get_random(nonce, sizeof(nonce));
aes_gcm_encrypt(key, nonce, (uint8_t *)plaintext, strlen(plaintext),
ciphertext_out);
memset(key, 0, sizeof(key)); /* clear key from stack */
}
Implement tamper detection and response:
/* Hardware tamper pin connected to case-open switch */
void tamper_detection_init(void) {
/* Configure tamper pin as interrupt */
GPIO_InitTypeDef gpio = {
.Pin = TAMPER_PIN,
.Mode = GPIO_MODE_IT_RISING, /* rising = case opened */
.Pull = GPIO_PULLDOWN,
};
HAL_GPIO_Init(TAMPER_PORT, &gpio);
HAL_NVIC_EnableIRQ(TAMPER_IRQn);
}
void TAMPER_IRQHandler(void) {
if (__HAL_GPIO_EXTI_GET_FLAG(TAMPER_PIN)) {
/* Log tamper event to persistent counter */
increment_tamper_counter();
log_security_event("physical_tamper_detected");
/* Policy: clear sensitive keys on tamper */
secure_erase_credentials();
/* Require re-provisioning — device will not boot normally */
set_boot_flag(BOOT_FLAG_TAMPERED);
HAL_NVIC_SystemReset();
}
}
Force credential change on first login:
# Embedded web server — enforce password change workflow
def handle_login(username: str, password: str, session) -> Response:
if not verify_credentials(username, password):
return Response(401, "Invalid credentials")
user = get_user(username)
# Force password change if using factory default
if user.must_change_password:
session["pending_password_change"] = True
return redirect("/change-password")
session["authenticated"] = True
return redirect("/dashboard")
def handle_change_password(new_password: str, session) -> Response:
if len(new_password) < 12:
return Response(400, "Password must be at least 12 characters")
if not has_complexity(new_password):
return Response(400, "Password must include letters, numbers, and symbols")
update_password(session["user"], bcrypt.hash(new_password))
session["pending_password_change"] = False
return Response(200, "Password updated")
Rules
- RDP Level 2 on STM32 (and equivalent on other MCUs) is permanent and irreversible — verify the production firmware is correct before enabling it.
- Per-device credentials must be generated with a CSPRNG — never derived from predictable values (MAC address, serial number, hash of serial number).
- Tamper detection response must clear keys before reset — a tampered device that reboots normally with keys intact defeats the tamper protection.
- Debug access restrictions must be in the release build configuration, verified by the manufacturing test procedure.
Common Mistakes
- Same credential on all devices of the same model — a single device's credential extraction compromises all devices of that model; per-device credentials are mandatory.
- UART debug console left enabled in release build —
CONFIG_CONSOLE_UART=y in Kconfig; audit release build configs before tapeout/production flash.
- Storing credentials in plaintext flash — flash memory is readable with a logic analyzer or by desoldering; encrypt all stored credentials with a hardware-derived key.
- Tamper detection only in application, not bootloader — an attacker can replace the application; tamper detection must be in the first-stage bootloader or hardware-enforced.
1---2name: apply-iot-device-hardening3description: Use when preparing IoT devices for production deployment — removing default credentials, disabling debug interfaces, encrypting stored data, and implementing physical tamper detection.4source: 'OWASP IoT Top 10 I9 I10 (owasp.org/www-project-internet-of-things/); ETSI EN 303 645; NIST SP 800-193; UK PSTI Act (2024 Product Security and Telecommunications Infrastructure Act)'5tags: [security, owasp, iot, device-hardening, credentials, tamper-detection, embedded, hardware]6metadata:7 source: https://skillmd.com/skills/jeffreytse/apply-iot-device-hardening8---910# Apply IoT Device Hardening1112Remove default credentials, disable JTAG/UART debug interfaces, encrypt data at rest, and implement physical tamper detection — preventing both remote and physical compromise of deployed IoT devices.1314## Why This Is Best Practice1516**Adopted by:** OWASP IoT Top 10 I9 (Insecure Default Settings) and I10 (Lack of Physical Hardening). ETSI EN 303 645 Section 5.1 mandates unique per-device credentials and prohibits default passwords. The UK Product Security and Telecommunications Infrastructure (PSTI) Act 2024 bans universal default passwords for consumer IoT — manufacturers face fines up to £10M. NIST SP 800-193 requires firmware resilience against physical access. Medical IoT (FDA guidance 2023), industrial IoT (IEC 62443), and automotive IoT (UNECE WP.29) all mandate these controls.17**Impact:** Mirai botnet's primary infection vector was default credentials (admin/admin, root/1234) on Telnet and HTTP — 600,000 devices compromised within weeks of release. Shodan 2023 found 2.3 million IoT devices still using factory default credentials. Physical hardware attacks allow credential extraction from unprotected UART/JTAG interfaces in under 5 minutes with a $30 FTDI adapter and publicly available firmware extraction tools. NIST estimates 30% of IoT breaches involve physical access to the device.18**Why best:** Remote hardening (network services, TLS) protects against internet-facing attacks; physical hardening adds a layer against supply chain attacks, insider threats, and theft of deployed devices. Default credentials are unique in that they're publicly known to attackers before the device is even deployed — per-device unique credentials eliminate this entire attack class at zero ongoing cost.1920Sources: OWASP IoT Top 10 I9, I10; ETSI EN 303 645 sections 5.1 and 5.2; UK PSTI Act 2024; FDA "Cybersecurity in Medical Devices" guidance (2023)2122## Steps23241. **Generate unique per-device credentials at manufacturing time**:2526 ```python27 # Manufacturing provisioning script — runs once per device28 import secrets29 import hashlib3031 def provision_device(device_serial: str, device_mac: str) -> dict:32 # Generate cryptographically random password (not derived from serial/MAC)33 admin_password = secrets.token_urlsafe(16)3435 # Generate unique device certificate36 private_key = generate_ec_key()37 cert = sign_device_certificate(38 private_key=private_key,39 subject=f"CN={device_serial},O=Company,C=US",40 ca_key=MANUFACTURING_CA_KEY41 )4243 # Store: password hash in device, plaintext in HSM-backed provisioning DB44 device_config = {45 "admin_password_hash": bcrypt.hash(admin_password),46 "device_cert": cert,47 "device_key": private_key,48 "serial": device_serial,49 }5051 # Label on physical device: serial + initial password (for setup only)52 # Force password change on first login53 return device_config5455 # NEVER: password = hashlib.md5(device_serial.encode()).hexdigest()56 # NEVER: same default password across entire product line57 ```58592. **Disable JTAG and UART debug interfaces in production**:6061 ```c62 /* STM32 — disable JTAG/SWD via option bytes at end of production test */63 void disable_debug_interfaces(void) {64 FLASH_OBProgramInitTypeDef ob_init = {0};65 HAL_FLASHEx_OBGetConfig(&ob_init);6667 /* Disable SWD interface — write-once OTP operation */68 ob_init.OptionType = OPTIONBYTE_USER;69 ob_init.USERType = OB_USER_TZEN;70 ob_init.USERConfig = OB_TZEN_ENABLE; /* Enable TrustZone */7172 /* Set RDP (Read-Out Protection) Level 2 — no debug, no readback */73 ob_init.OptionType |= OPTIONBYTE_RDP;74 ob_init.RDPLevel = OB_RDP_LEVEL_2; /* PERMANENT — cannot be reversed */7576 HAL_FLASH_Unlock();77 HAL_FLASH_OB_Unlock();78 HAL_FLASHEx_OBProgram(&ob_init);79 HAL_FLASH_OB_Lock();80 HAL_FLASH_Lock();81 }82 ```8384 ```bash85 # For embedded Linux: disable UART console in production86 # Remove console= from kernel command line in bootloader config87 # /etc/inittab or systemd getty: comment out ttyS0 entries8889 # Disable JTAG in Device Tree90 # &jtag { status = "disabled"; };91 ```92933. **Encrypt sensitive data at rest using hardware security**:9495 ```c96 /* Use hardware AES engine + device-unique key (UID) for storage encryption */97 #include "aes.h"9899 /* Derive storage key from device UID — unique per device, never leaves hardware */100 void derive_storage_key(uint8_t key_out[32]) {101 /* STM32 unique device ID: 96-bit value burned at manufacturing */102 uint32_t uid[3] = {103 HAL_GetUIDw0(), HAL_GetUIDw1(), HAL_GetUIDw2()104 };105 /* HKDF with device UID as IKM and fixed info */106 hkdf_sha256(key_out, 32,107 (uint8_t *)uid, sizeof(uid),108 (uint8_t *)"storage-key-v1", 15,109 NULL, 0);110 }111112 void encrypt_credentials(const char *plaintext, uint8_t *ciphertext_out) {113 uint8_t key[32];114 derive_storage_key(key);115 uint8_t nonce[12];116 crypto_get_random(nonce, sizeof(nonce));117 aes_gcm_encrypt(key, nonce, (uint8_t *)plaintext, strlen(plaintext),118 ciphertext_out);119 memset(key, 0, sizeof(key)); /* clear key from stack */120 }121 ```1221234. **Implement tamper detection and response**:124125 ```c126 /* Hardware tamper pin connected to case-open switch */127 void tamper_detection_init(void) {128 /* Configure tamper pin as interrupt */129 GPIO_InitTypeDef gpio = {130 .Pin = TAMPER_PIN,131 .Mode = GPIO_MODE_IT_RISING, /* rising = case opened */132 .Pull = GPIO_PULLDOWN,133 };134 HAL_GPIO_Init(TAMPER_PORT, &gpio);135 HAL_NVIC_EnableIRQ(TAMPER_IRQn);136 }137138 void TAMPER_IRQHandler(void) {139 if (__HAL_GPIO_EXTI_GET_FLAG(TAMPER_PIN)) {140 /* Log tamper event to persistent counter */141 increment_tamper_counter();142 log_security_event("physical_tamper_detected");143144 /* Policy: clear sensitive keys on tamper */145 secure_erase_credentials();146147 /* Require re-provisioning — device will not boot normally */148 set_boot_flag(BOOT_FLAG_TAMPERED);149 HAL_NVIC_SystemReset();150 }151 }152 ```1531545. **Force credential change on first login**:155156 ```python157 # Embedded web server — enforce password change workflow158 def handle_login(username: str, password: str, session) -> Response:159 if not verify_credentials(username, password):160 return Response(401, "Invalid credentials")161162 user = get_user(username)163164 # Force password change if using factory default165 if user.must_change_password:166 session["pending_password_change"] = True167 return redirect("/change-password")168169 session["authenticated"] = True170 return redirect("/dashboard")171172 def handle_change_password(new_password: str, session) -> Response:173 if len(new_password) < 12:174 return Response(400, "Password must be at least 12 characters")175 if not has_complexity(new_password):176 return Response(400, "Password must include letters, numbers, and symbols")177178 update_password(session["user"], bcrypt.hash(new_password))179 session["pending_password_change"] = False180 return Response(200, "Password updated")181 ```182183## Rules184185- RDP Level 2 on STM32 (and equivalent on other MCUs) is permanent and irreversible — verify the production firmware is correct before enabling it.186- Per-device credentials must be generated with a CSPRNG — never derived from predictable values (MAC address, serial number, hash of serial number).187- Tamper detection response must clear keys before reset — a tampered device that reboots normally with keys intact defeats the tamper protection.188- Debug access restrictions must be in the release build configuration, verified by the manufacturing test procedure.189190## Common Mistakes191192- **Same credential on all devices of the same model** — a single device's credential extraction compromises all devices of that model; per-device credentials are mandatory.193- **UART debug console left enabled in release build** — `CONFIG_CONSOLE_UART=y` in Kconfig; audit release build configs before tapeout/production flash.194- **Storing credentials in plaintext flash** — flash memory is readable with a logic analyzer or by desoldering; encrypt all stored credentials with a hardware-derived key.195- **Tamper detection only in application, not bootloader** — an attacker can replace the application; tamper detection must be in the first-stage bootloader or hardware-enforced.