android ndc firewall 命令type 黑名單 白名單差異

可以看到以白名單方式使能防火墻,fw_FORWARD fw_INPUT fw_OUTPUT 的操作是DROP或REJEDCT。即默認所有應用不允許上網,需要

XXX:/ # ndc firewall enable whitelist
200 0 Firewall command succeeded
XXX:/ # iptables -t filter -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destinationChain FORWARD (policy ACCEPT)
target     prot opt source               destinationChain OUTPUT (policy ACCEPT)
target     prot opt source               destinationChain fw_FORWARD (0 references)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachableChain fw_INPUT (0 references)
target     prot opt source               destination
DROP       all  --  anywhere             anywhereChain fw_OUTPUT (0 references)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable
static const std::vector<const char*> FILTER_INPUT = {// Bandwidth should always be early in input chain, to make sure we// correctly count incoming traffic against data plan.BandwidthController::LOCAL_INPUT,FirewallController::LOCAL_INPUT,
};
const char BandwidthController::LOCAL_INPUT[] = "bw_INPUT";
const char BandwidthController::LOCAL_FORWARD[] = "bw_FORWARD";
const char BandwidthController::LOCAL_OUTPUT[] = "bw_OUTPUT";
const char BandwidthController::LOCAL_RAW_PREROUTING[] = "bw_raw_PREROUTING";
const char BandwidthController::LOCAL_MANGLE_POSTROUTING[] = "bw_mangle_POSTROUTING";
const char BandwidthController::LOCAL_GLOBAL_ALERT[] = "bw_global_alert";
const char* FirewallController::TABLE = "filter";const char* FirewallController::LOCAL_INPUT = "fw_INPUT";
const char* FirewallController::LOCAL_OUTPUT = "fw_OUTPUT";
const char* FirewallController::LOCAL_FORWARD = "fw_FORWARD";const char* FirewallController::LOCAL_DOZABLE = "fw_dozable";
const char* FirewallController::LOCAL_STANDBY = "fw_standby";
const char* FirewallController::LOCAL_POWERSAVE = "fw_powersave";
void Controllers::initChildChains() {/** This is the only time we touch top-level chains in iptables; controllers* should only mutate rules inside of their children chains, as created by* the constants above.** Modules should never ACCEPT packets (except in well-justified cases);* they should instead defer to any remaining modules using RETURN, or* otherwise DROP/REJECT.*/// Create chains for child modules.//往filter表的INPUT鏈添加子鏈fw_INPUTcreateChildChains(V4V6, "filter", "INPUT", FILTER_INPUT, true);//往filter表的FORWARD鏈添加子鏈fw_FORWARDcreateChildChains(V4V6, "filter", "FORWARD", FILTER_FORWARD, true);createChildChains(V4V6, "raw", "PREROUTING", RAW_PREROUTING, true);createChildChains(V4V6, "mangle", "FORWARD", MANGLE_FORWARD, true);createChildChains(V4V6, "mangle", "INPUT", MANGLE_INPUT, true);createChildChains(V4, "nat", "PREROUTING", NAT_PREROUTING, true);createChildChains(V4, "nat", "POSTROUTING", NAT_POSTROUTING, true);//往filter表的OUTPUT鏈添加子鏈fw_OUTPUTcreateChildChains(V4, "filter", "OUTPUT", FILTER_OUTPUT, false);createChildChains(V6, "filter", "OUTPUT", FILTER_OUTPUT, false);createChildChains(V4, "mangle", "POSTROUTING", MANGLE_POSTROUTING, false);createChildChains(V6, "mangle", "POSTROUTING", MANGLE_POSTROUTING, false);
}
/* static */
//以 createChildChains(V4V6, "filter", "INPUT", FILTER_INPUT, true);為例
void Controllers::createChildChains(IptablesTarget target, const char* table,const char* parentChain,const std::vector<const char*>& childChains,bool exclusive) {std::string command = StringPrintf("*%s\n", table);//*后指跟的table表,這里是filter//*filter// We cannot just clear all the chains we create because vendor code modifies filter OUTPUT and// mangle POSTROUTING directly. So://// - If we're the exclusive owner of this chain, simply clear it entirely.// - If not, then list the chain's current contents to ensure that if we restart after a crash,//   we leave the existing rules alone in the positions they currently occupy. This is faster//   than blindly deleting our rules and recreating them, because deleting a rule that doesn't//   exists causes iptables-restore to quit, which takes ~30ms per delete. It's also more//   correct, because if we delete rules and re-add them, they'll be in the wrong position with//   regards to the vendor rules.//// TODO: Make all chains exclusive once vendor code uses the oem_* rules.std::set<std::string> existingChildChains;if (exclusive) {// Just running ":chain -" flushes user-defined chains, but not built-in chains like INPUT.// Since at this point we don't know if parentChain is a built-in chain, do both.StringAppendF(&command, ":%s -\n", parentChain);// 鏈名默認策略表示相應的鏈及默認策略,具體的規則部分省略了命令名iptables//:INPUT -StringAppendF(&command, "-F %s\n", parentChain);//-F指代清空防火墻規則,默認規則除外//-F INPUT} else {existingChildChains = findExistingChildChains(target, table, parentChain);}for (const auto& childChain : childChains) {// Always clear the child chain.StringAppendF(&command, ":%s -\n", childChain);// But only add it to the parent chain if it's not already there.if (existingChildChains.find(childChain) == existingChildChains.end()) {//static const char* CHILD_CHAIN_TEMPLATE = "-A %s -j %s\n";StringAppendF(&command, CHILD_CHAIN_TEMPLATE, parentChain, childChain);}}command += "COMMIT\n";execIptablesRestore(target, command);
}
//以 createChildChains(V4V6, "filter", "INPUT", FILTER_INPUT, true);為例,相當于執行了
iptable-restore <
*filter \n
:INPUT -  \n
-F INPUT \n
:fw_INPUT - \n
-A INPUT -j  fw_INPUT 
//即在filter表的INPUT鏈處理時調用 fw_INPUT 鏈,所以fw_INPUT 時INPUT鏈的子鏈

int FirewallController::resetFirewall(void) {mFirewallType = WHITELIST;mIfaceRules.clear();// flush any existing rulesstd::string command ="*filter\n"":fw_INPUT -\n"":fw_OUTPUT -\n"":fw_FORWARD -\n""COMMIT\n";return (execIptablesRestore(V4V6, command.c_str()) == 0) ? 0 : -EREMOTEIO;
}int FirewallController::setFirewallType(FirewallType ftype) {int res = 0;if (mFirewallType != ftype) {// flush any existing rulesresetFirewall();if (ftype == WHITELIST) {// create default rule to drop all trafficstd::string command ="*filter\n""-A fw_INPUT -j DROP\n""-A fw_OUTPUT -j REJECT\n""-A fw_FORWARD -j REJECT\n""COMMIT\n";res = execIptablesRestore(V4V6, command.c_str());}// Set this after calling disableFirewall(), since it defaults to WHITELIST theremFirewallType = ftype;}return res ? -EREMOTEIO : 0;
}

所以調用ndc firewall enable whitelist相當于:

無論防火墻是黑白名單哪種類型,都先清空規則,此時所有應用可以上網
iptable-restore < "*filter\n"":fw_INPUT -\n"":fw_OUTPUT -\n"":fw_FORWARD -\n""COMMIT\n";//白名單類型再調用如下規則,再將所有鏈的數據都DROp或REJECT,相當與所有應用默認無法上網。
iptable-restore < "*filter\n""-A fw_INPUT -j DROP\n""-A fw_OUTPUT -j REJECT\n""-A fw_FORWARD -j REJECT\n""COMMIT\n";

即,黑名單默認上網,白名單默認不上網

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/16192.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/16192.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/16192.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

酷黑簡潔大氣體育直播自適應模板賽事直播門戶網站源碼

源碼名稱&#xff1a;酷黑簡潔大氣體育直播自適應模板賽事直播門戶網站源碼 開發環境&#xff1a;帝國cms 7.5 安裝環境&#xff1a;phpmysql 支持PC與手機端同步生成html&#xff08;多端同步生成插件&#xff09; 帶軟件采集&#xff0c;可以掛著自動采集發布&#xff0c;無…

【HSQL001】HiveSQL內置函數手冊總結(更新中)

1.熟悉、梳理、總結下Hive SQL相關知識體系。 2.日常研發過程中使用較少&#xff0c;隨著時間的推移&#xff0c;很快就忘得一干二凈&#xff0c;所以梳理總結下&#xff0c;以備日常使用參考 3.歡迎批評指正&#xff0c;跪謝一鍵三連&#xff01; 文章目錄 1.函數清單 1.函數清…

某某某加固系統分析

某某某加固系統內核so dump和修復&#xff1a; 某某某加固系統采取了內外兩層native代碼模式&#xff0c;外層主要為了保護內層核心代碼&#xff0c;從分析來看外層模塊主要用來反調試&#xff0c;釋放內層模塊&#xff0c;維護內存模塊的某些運行環境達到防止分離內外模塊&am…

網上比較受認可的賺錢軟件有哪些?眾多兼職選擇中總有一個適合你

在這個互聯網高速發展的時代&#xff0c;網上賺錢似乎成了一種潮流。但是&#xff0c;你是否還在靠運氣尋找賺錢的機會&#xff1f;是否還在為找不到靠譜的兼職平臺而苦惱&#xff1f; 今天&#xff0c;就為你揭秘那些真正靠譜的網上賺錢平臺&#xff0c;讓你的賺錢之路不再迷…

等保測評的流程是怎樣的

等保測評概述 等保測評&#xff0c;即信息安全等級保護測評&#xff0c;是指對信息系統安全性能進行等級評估的過程。其目的是通過評估系統的安全性能&#xff0c;為系統提供一個安全等級&#xff0c;并規定相應的保護措施。等保測評的流程通常包括定級、備案、安全建設、等級測…

Python--List列表

list列表?? 1高級數據類型 Python中的數據類型可以分為&#xff1a;數字型&#xff08;基本數據類型&#xff09;和非數字型&#xff08;高級數據類型&#xff09; ●數字型包含&#xff1a;整型int、浮點型float、布爾型bool、復數型complex ●非數字型包含&#xff1a;字符…

TypeScript-type注解對象類型

type注解對象類型 在TS中對于對象數據的類型注解&#xff0c;除了使用interface之外還可以使用類型別名來進行注解&#xff0c;作用類似 type Person {name: stringage: number }const p:Person {name: lily,age: 16 } type 交叉類型&模擬繼承 類型別名配合交叉類型…

docker創建的rabbitmq,啟動容器時報:Failed to create thread: Operation not permitted (1)

原因&#xff1a;docker內的用戶權限受限 啟動docker時加上參數 --privilegedtrue docker run --privilegedtrue -d --name rabbitmq --restartalways -p 5671:5671 -p 5672:5672 -p 15672:15672 -p 15671:15671 -p 25672:25672 -v /home/rabbitmq/data/:/var/rabbitm…

整合SSM框架筆記

整合SSM框架筆記 Spring5 Spring MVC MyBatis Druid MySQL Thymeleaf 感謝尚硅谷課程&#xff1a;B站課程 前言 單Spring框架時&#xff0c;是Java工程。 Spring與Spring MVC可以共用一個配置文件&#xff0c;也可以不共用一個&#xff0c;推薦不共用一個。 Spring與Sp…

Quartus 聯合 ModelSim 仿真 IP 核(RAM)

文章目錄 ModelSim 路徑設置創建 RAM進行仿真 本文主要介紹如何在包含 IP 核的 Quartus 項目中使用 Modelsim 進行仿真&#xff0c;本文基于 IP 核 RAM: 2-PORT&#xff0c;其他 IP 核類似。 ModelSim 路徑設置 點擊 Tools->Options 點擊 EDA Tool Options&#xff0c;設置…

BeanFactory、FactroyBean、ApplicationContext

BeanFactory Ioc容器、定義接口規范來管理spring bean的生命周期、依賴、注入&#xff0c;spring中有各種Ioc容器 FactroyBean 定制的工廠Bean&#xff0c;可以通過抽象工廠方式創建的bean&#xff0c;不納入spring的生命周期、依賴、注入特性&#xff0c;相當于spring給第三…

string OJ題

下面分享一下string做題心得 1. 明白字符串中存儲的數字為0 8 9與0 8 9 完全不同&#xff0c;字符0其實在串中存儲的是48&#xff0c;要有意識的轉化。字符串中如果存數字8&#xff0c;意味著存了BS&#xff08;退格&#xff09; 例如1&#xff1a; 算出結果為5&#xff0c;存…

MySQL 用戶變量賦值、查詢賦值、滾動賦值

在MySQL中&#xff0c;用戶變量是一種在會話級別存儲和重用值的方式&#xff0c;它們以符號開頭。用戶變量可以在查詢中用來存儲和傳遞數據&#xff0c;增強SQL腳本的功能性。 定義和賦值用戶變量用戶變量可以直接在查詢中定義并賦值&#xff0c;不需要預先聲明。賦值可以使用S…

springboot+mybatis+druid 配置單實例多數據源

第一步&#xff1a;pom中添加依賴 <!--mybatis多數據源--><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>2.5.6</version></dependency> 第…

Selenium 自動化測試工具<2>(Selenium 常用API的使用方法)

文章目錄 瀏覽器操作瀏覽器最大化設置瀏覽器的大小瀏覽器的前進和后退操作瀏覽器滾動條 鍵盤事件單個按鍵用法鍵盤組合鍵用法 鼠標事件不同窗口搜索定位一組元素定位多層框架下拉框定位alert、confirm、prompt 的處理上傳文件操作自動截屏 繼上一篇文章對 Selenium API 的使用&…

RT-DRET在實時目標檢測上超越YOLO8

導讀 目標檢測作為計算機視覺的核心任務之一&#xff0c;其研究已經從基于CNN的架構發展到基于Transformer的架構&#xff0c;如DETR&#xff0c;后者通過簡化流程實現端到端檢測&#xff0c;消除了手工設計的組件。盡管如此&#xff0c;DETR的高計算成本限制了其在實時目標檢測…

搭建屬于自己的 Git 倉庫:GitLab

搭建屬于自己的 Git 倉庫&#xff1a;使用 GitLab 文章目錄 搭建屬于自己的 Git 倉庫&#xff1a;使用 GitLab什么是 GitLab&#xff1f;準備工作安裝 Docker使用Docker Compose 快速構建GitLab1、從docker compose快速搭建GitLab2、部署到服務器并訪問3、瀏覽器訪問 在現代軟件…

【數據結構】------C語言實現二叉樹

作者主頁&#xff1a;作者主頁 數據結構專欄&#xff1a;數據結構 創作時間 &#xff1a;2024年5月20日 一、二叉樹的定義 二叉樹(Binary Tree) 是由n個結點構成的有限集(n≥0)&#xff0c;n0時為空樹&#xff0c;n>0時為非空樹。 對于非空樹&#xff1a; 有且僅有一個根…

接口自動化核心模塊Requests詳解(一)

一、Requests簡介 Python的Requests庫是一個功能強大且簡潔的庫&#xff0c;提供了簡單易用的接口來處理HTTP請求。 二、Requests的使用步驟 2.1 安裝Requests庫 在終端命令行&#xff0c;使用pip命令進行安裝&#xff0c; pip install requests 2.2 Requests庫常用方法…

騰訊Java社招面試題真題,最新面試題

Java中synchronized和ReentrantLock有什么區別&#xff1f; 1、鎖的實現方式不同&#xff1a; synchronized是JVM層面的鎖&#xff0c;主要依賴于監視器對象&#xff08;monitor&#xff09;實現。ReentrantLock是JDK層面的鎖&#xff0c;通過Java代碼實現&#xff0c;提供了更…