自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
网络安全性最佳实践
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本部分包含可确保 Android 设备上网络通信安全性的建议。
确保监听套接字的安全性
请谨慎使用监听套接字。通常情况下,设备上不应该有任何打开的监听套接字,因为它们可以让远程攻击者访问设备。
- Android 设备应尽量减少公开的互联网监听套接字的数量,尤其是在启动时或默认情况下。默认情况下,启动时不应在互联网上监听任何套接字。
- Root 进程和归系统唯一标识符 (UID) 所有的进程不应公开任何监听套接字。
- 必须能够在不使用 OTA 更新的情况下停用监听套接字的功能。这种停用行为可以通过更改服务器或用户设备配置来实现。
- 对于使用套接字的本地 IPC,应用必须使用只有某个组可以访问的 UNIX 域套接字。为 IPC 创建文件描述符,并允许特定 UNIX 组对其执行 +RW 操作。所有客户端应用都必须在该 UNIX 组内。
- 有些拥有多个处理器的设备(例如,无线装置/调制解调器从应用处理器中分离出来)会借助网络套接字在处理器之间进行通信。在这种情况下,处理器间通信所用的网络套接字必须使用隔离的网络接口,以防止设备上未经授权的应用访问(例如,使用 iptables 防止设备上的其他应用访问)。
- 负责处理监听端口的守护程序必须能够防范格式有误的数据。您应该使用未经授权的客户端(在可能的情况下,也可以使用已获授权的客户端)针对端口进行模糊测试。提交 bug 以跟进崩溃。
Android 兼容性测试套件 (CTS) 包含用于检查是否存在开放监听端口的测试。
停用 adb
Android 调试桥 (adb) 是一款非常实用的开发和调试工具,但它只适合在受控的安全环境中使用,不得针对一般使用情况启用该工具。
- 确保 adb 默认处于停用状态。
- 确保 adb 会要求用户先将其开启,然后再接受连接。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Network security best practices\n\nThis section contains recommendations to ensure the security of network\ncommunications from Android devices.\n\nSecure listening sockets\n------------------------\n\nUse listening sockets with caution. There should generally\nnot be any open listening sockets on devices as these provide a vector for a\nremote attacker to gain access to the device.\n\n- Android devices should minimize the number of internet listening sockets they expose, especially on boot or by default. No socket should be listening on the internet at boot by default.\n - Root processes and processes owned by the system unique identifier (UID) shouldn't expose any listening sockets.\n- Listening sockets must be able to be disabled without an OTA update. This can be performed using either a server or user-device configuration change.\n- For local IPC-using sockets, apps must use a UNIX domain socket with access limited to a group. Create a file descriptor for the IPC and make it +RW for a specific UNIX group. Any client apps must be within that UNIX group.\n- Some devices with multiple processors (for example, a radio/modem separate from the app processor) use network sockets to communicate between processors. In such instances, the network socket used for inter-processor communication must use an isolated network interface to prevent access by unauthorized apps on the device (i.e. use iptables to prevent access by other apps on the device).\n- Daemons that handle listening ports must be robust against malformed data. You should conduct fuzz-testing against the port using an unauthorized client, and, where possible, authorized client. File bugs to follow up on crashes.\n\nThe [Android Compatibility Test Suite](/docs/core/tests)\n(CTS) includes tests that check for the presence of open listening ports.\n\n### Disable adb\n\nAndroid Debug Bridge (adb) is a valuable development and debugging tool, but\nis designed for use in a controlled, secure environment and shouldn't be\nenabled for general use.\n\n- Ensure that adb is disabled by default.\n- Ensure that adb requires the user to turn it on before accepting connections."]]