T03 · Remote Payload Retrieval and Execution
Error
- Location
- assets/template/main.py:325
- Finding
- Remote OTA Packages Are Installed Without Cryptographic Authenticity Verification<![CDATA[ ## Vulnerability Details **File Location**: `assets/template/config.py:40`; `assets/template/main.py:325-370` **Vulnerability Type**: Unauthenticated remote firmware installation **Risk Level**: Critical ### Vulnerable Code ```python # assets/template/config.py:40 URL_OTA = "https://hu-wei-di-tu-a98abc-1258458441.ap-shanghai.app.tcloudbase.com/ota" ``` ```python # assets/template/main.py:325-370 resp = request.post(url, data=body, headers=headers) print("[HTTP][{}] 状态码:".format(tag), resp.status_code) if resp.status_code != 200: led_flash(led_net, 0.1, 0.1, 3) report_fail_cnt += 1 return False # 成功 led_flash(led_net, 0.25, 0.25, 4) led_net.on() report_fail_cnt = 0 # 解析响应(流式读取) for chunk in resp.text: try: ret = ujson.loads(chunk) print("[HTTP][{}] 响应:".format(tag), ret) # OTA 升级检测 if tag == "ota" and ret.get("code") == 200: file_list = ret.get("file_list", []) if file_list: _run_ota(file_list) except: pass return True def _run_ota(file_list): """下载文件列表并触发 OTA 重启。""" print("[OTA] 开始升级,文件列表:", file_list) try: fota = app_fota.new() fota.bulk_download(file_list) fota.set_update_flag() Power.powerRestart() except Exception as e: print("[OTA] 升级失败:", e) ``` ### Technical Analysis The OTA service controls the `file_list` passed directly to `app_fota.bulk_download()`. After downloading the supplied files, the code sets the update flag and immediately restarts the device. No application-level authenticity or authorization controls are present. In particular, the implementation does not: - Verify a digital signature over the update manifest or firmware. - Verify a trusted cryptographic hash for every downloaded artifact. - Restrict download URLs to an approved host and path. - Pin the OTA service's public key or certificate. - Validate the target device model or firmware compatibility. - Enforce a ...[truncated 1769 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Disable OTA by default and skip `check_ota()` when `URL_OTA` is empty. 2. Use a vendor-controlled, access-restricted OTA endpoint. 3. Require a signed manifest containing the firmware hash, version, device model, size, and approved download location. 4. Verify the manifest and firmware with an asymmetric signature whose trusted public key is embedded in protected device storage. 5. Verify a SHA-256 or stronger hash before setting the update flag. 6. Allowlist the exact OTA scheme, hostname, port, and path; reject redirects and user-controlled download hosts. 7. Add certificate or public-key pinning where supported. 8. Enforce device-model compatibility, monotonic versioning, expiration times, and anti-rollback protection. 9. Use staged deployment and explicit administrative authorization for production updates. 10. Fail closed: malformed responses, unknown fields, failed signature checks, and unexpected URLs must prevent installation. ]]>
