自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
網路安全性最佳做法
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本節提供建議,協助確保 Android 裝置的網路通訊安全。
安全的監聽 Socket
請謹慎使用監聽通訊端。裝置上通常不應有任何開放的監聽 Socket,因為這會為遠端攻擊者提供取得裝置存取權的途徑。
- Android 裝置應盡量減少公開的網路監聽通訊端口數量,尤其是在啟動時或預設情況下。根據預設,啟動時不應有任何 Socket 監聽網際網路。
- 根程序和系統專屬 ID (UID) 擁有的程序不應公開任何監聽 Socket。
- 監聽 Socket 必須能夠在沒有 OTA 更新的情況下停用。您可以使用伺服器或使用者裝置設定變更來執行這項操作。
- 針對使用本機 IPC 的通訊端,應用程式必須使用 UNIX 網域通訊端,並將存取權限限制在群組內。為 IPC 建立檔案描述元,並為特定 UNIX 群組設定 +RW。任何用戶端應用程式都必須位於該 UNIX 群組中。
- 部分裝置具有多個處理器 (例如無線電/數據機與應用程式處理器分開),會使用網路通訊端在處理器之間進行通訊。在這種情況下,用於處理器間通訊的網路通訊端必須使用隔離的網路介面,以免遭到裝置上未經授權的應用程式存取 (也就是使用 iptables 避免裝置上的其他應用程式存取)。
- 處理監聽埠的 Daemon 必須能有效防範格式錯誤的資料。您應使用未經授權的用戶端 (盡可能使用已授權的用戶端) 對通訊埠進行模糊測試。回報錯誤以便後續處理當機問題。
Android Compatibility Test Suite (CTS) 包含可檢查是否有開放監聽埠的測試。
停用 ADB
Android Debug Bridge (adb) 是實用的開發和偵錯工具,但其設計用途是在受控的安全環境中使用,因此不應用於一般用途。
- 確認預設情況下 adb 已停用。
- 請確認 adb 會要求使用者先開啟,才能接受連線。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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."]]