Tips Q:什么是Seccomp,有什么作用,怎么用? A:Seccomp 是 Secure computing mode 的缩写,它是Linux 内核在2.6.12版本(2005年3月8日)开始引入的一种安全机制,用于限制一个进程可以执行的系统调用,在/proc/${pid}/status文件中的Seccomp字段可以查看进程的Seccomp。当然,我们需要有一个配置文件来指明进程到底可以执行哪些系统调用,不可以执行哪些系统调用。那么在Docker中,就可以利用这个机制来限制容器中可以执行的系统调用。 Docker 官方文档中关于 Seccomp 的使用详见 https://docs.docker.com/engine/security/seccomp/。docker 默认使用的seccomp 配置文件可以在 https://github.com/moby/moby/blob/master/profiles/seccomp/default.json 查看。 在运行容器时,除非使用 --security-opt选项进行覆盖,否则都将使用默认配置文件。默认seccomp配置文件是白名单,白名单中指定了允许的调用。
一、使用实践
1.1部署使用环境
sudo apt update
sudo apt install -y python3.7
sudo apt install -y sysdig
1.2操作指南
1.2.1 主脚本confine.py
-l : 指定 glibc调用图
-m : 指定musl-libc调用图 -i : 包含镜像JSON信息的输入文件 -o : 存储从容器中提取的二进制文件和库的路径 -p : Docker默认seccomp配置文件的路径 -r : 存储结果的路径 -g : 特殊容器(例如golang容器)的路径 -d : 启用或禁用调试 --skip: [可选] 如果设置了这个选项,脚本将不会对之前运行的镜像进行分析,这些镜像的结果已插入到profile.results.csv 文件中 -f : [可选] glibc共享库 -n : [可选] musl-libc共享库 --finegrain : [可选]传递此参数可以生成细粒度策略。不建议使用此特性,因为它正在开发中。 --othercfgfolder : 如果您通过设置 --finegrain启用了细粒度分析,您也必须设置此选项。该文件夹应该包含细粒度分析中使用的其他库的调用图。 --allbinaries : 传递这个参数会导致提取所有二进制文件,而不是只提取30秒内运行的二进制文件。
1.2.2 操作1 - 使用Confine强化Docker容器
{
"nginx": {
"enable": "true",
"image-name": "nginx",
"image-url": "nginx",
"dependencies": {}
}
}
sudo python3.7 confine.py -l libc-callgraphs/glibc.callgraph -m libc-callgraphs/musllibc.callgraph -i myimages.json -o output/ -p default.seccomp.json -r results/ -g go.syscalls/
sudo docker run --name container-hardened --security-opt seccomp=results/nginx.seccomp.json -td nginx
sudo docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container-hardened
wget http://[IP-Address]
cat index.html
sudo docker exec -it container-hardened /bin/bash
sudo docker exec -it container-hardened /bin/sh
1.2.4 操作3 - 强化效果
cat results/nginx.seccomp.json | grep name
cat results/nginx.seccomp.json | grep name | wc -l
msync、mincore、shmctl、pause、getitimer、getpeername、fork、semget、semop、semctl、msgget、msgsnd、msgrcv、msgctl、flock、fdatasync、truncate、symlink、lchown、getrusage、ptrace、syslog、setreuid、setregid、getpgid、setfsuid、setfsgid、rt_sigpending、rt_sigqueueinfo、utime、mknod、uselib、personality、ustat、sysfs、getpriority、sched_rr_get_interval、munlock、mlockall、munlockall、vhangup、modify_ldt、pivot_root、adjtimex、chroot、sync、acct、settimeofday、swapon、swapoff、reboot、sethostname、setdomainname、iopl、init_module、delete_module、quotactl、readahead、tkill、set_thread_area、io_submit、io_cancel、get_thread_area、lookup_dcookie、remap_file_pages、restart_syscall、semtimedop、timer_create、timer_settime、timer_gettime、timer_getoverrun、timer_delete、clock_settime、clock_nanosleep、mbind、set_mempolicy、get_mempolicy、mq_open、mq_unlink、mq_timedsend、mq_timedreceive、mq_notify、mq_getsetattr、kexec_load、waitid、add_key、request_key、keyctl、ioprio_set、ioprio_get、inotify_init、inotify_add_watch、inotify_rm_watch、migrate_pages、mkdirat、mknodat、fchownat、futimesat、renameat、linkat、symlinkat、fchmodat、pselect6、ppoll、unshare、get_robust_list、tee、sync_file_range、vmsplice、move_pages、signalfd、timerfd_create、eventfd、fallocate、timerfd_settime、timerfd_gettime、signalfd4、epoll_create1、dup3、inotify_init1、preadv、rt_tgsigqueueinfo、perf_event_open、recvmmsg、fanotify_init、fanotify_mark、name_to_handle_at、open_by_handle_at、clock_adjtime、syncfs、sendmmsg、getcpu、process_vm_readv、process_vm_writev、kcmp、finit_module、sched_setattr、sched_getattr、renameat2、seccomp、memfd_create、kexec_file_load、bpf、execveat、userfaultfd、membarrier、mlock2、copy_file_range、preadv2、pwritev2、pkey_mprotect、pkey_alloc、pkey_free、statx
python3.7 filterProfileToCve.py -c cve.files/cveToStartNodes.csv.validated -f results/profile.report.details.csv -o results -v cve.files/cveToFile.json.type.csv --manualcvefile cve.files/cve.to.syscall.manual --manualtypefile cve.files/cve.to.vulntype.manual
-
Cveid,可缓解的 CVE 编号,值为 CVE-2015-8539; -
系统调用的名字(可以有多个),值为 add_key, keyctl; -
CVE 的类型 (可以有多个),值为 Denial Of Service,,Gain privileges; -
是否可被docker默认的Seccomp策略缓解,值为 True; -
受影响 docker 镜像的个数,值为 1; -
受影响 docker 镜像的名字,值为 nginx;
二、Confine的有效性验证
2.1公开容器的分析
2.1.1 数据集收集
2.1.2 容器统计
2.2过滤系统调用
2.2.1 可用性验证
2.2.2 可用性结果
2.3量化减小的攻击面
2.3.1 将内核CVE映射到系统调用
2.3.2 通过Confine缓解了的CVEs
三、设计思路&实现细节
3.1需求来源
[8,68,69,75],我们的目标是提供一个更通用、更实用的解决方案,以达到在不需要训练的情况下随时应用于任何容器的保护。
-
提出了一种更通用的方法,用于自动生成任意容器的限制性Seccomp策略,而不必依赖于目标程序的源代码。 -
对Linux内核CVE进行了彻底的分析,并将它们与内核代码里的功能建立了映射关系。我们确定了可以使用哪些系统调用来利用某个CVE,并以此映射为基础来评估我们方法的有效性。 -
我们检查了200多个来自Docker Hub[7]中最流行的公开Docker镜像,并对它们的特点进行了分析。 -
我们用上述镜像对系统进行了实验评估,并证明Confine在生成限制性系统调用策略方面的有效性,该策略使得之前披露的51个内核漏洞无法被利用。
3.2威胁场景
3.3静态分析的必要性
3.4设计
3.4.1 动态分析识别容器中运行的所有应用程序
3.4.2 静态分析
3.4.3 强化容器镜像
3.5实现
3.5.1 将Libc函数映射到系统调用
3.5.1.1 Musl-Libc
强符号与弱符号 在C语言中,函数和初始化的全局变量(包括显示初始化为0)是强符号,未初始化的全局变量是弱符号。其规则如下: 同名的强符号只能定义一次,否则编译错误。 同名的强弱符号同时存在时,以强符号为准。 多个弱符号相同存在时,则从多个弱符号中任选一个。
3.5.1.2 Glibc
3.5.2 二进制文件分析
为了捕捉所有被调用的可执行文件,我们利用Sysdig[26]来监控容器启动最初30秒(这个时间可配置)内的execve调用。在我们生成容器运行的程序列表后,我们进一步进行静态分析,提取正常执行容器所需的系统调用列表。
3.5.2.1 通过Libc进行的系统调用
3.5.2.2 直接系统调用
3.5.2.3 动态加载函数库
3.5.3 编程语言方面的考虑因素
3.5.4 Seccomp配置文件生成
3.6讨论与局限
3.7相关工作
3.7.1 和Confine 类似的工具
3.7.2 应用Debloating
3.8小结
参考链接
[1]Capabilities(7) - Linux Programmer’s Manual.http:
//man7.org/linux/man-pages/man7/capabiliti
es.7.html.
[2]Cassandra - Docker Hub. https://hub.docker.com/_/cassandra
[3]Cgroups(7) - Linux Programmer’s Manual.http://man7.org/linux/man-pages/man7/cgroups.7.html.
[4]Chronograf - Docker Hub. https://hub.docker.com/_/chronograf
[5]Common vulnerabilities and exposuresdatabase.
https://www.cvedetails.com.
[6]CVE-2017-5123. https://www.cvedetails.com/cve/CVE-2017-5123/.
[7]Docker Hub. https://hub.docker.com.
[8]DockerSlim. https://dockersl.im.
[9]Elasticsearch - Docker Hub.https://hub.docker.com/_/elasticsearch.
[10]Elgg. https://elgg.org/.
[11]GNU Compiler Collection.https://gcc.gnu.org.
[12]Influxdb - Docker Hub.https://hub.docker.com/_/influxdb.
[13]Kubernetes - Production-Grade ContainerOrchestration.https://kubernetes.io.
[14]The LLVM compiler infrastructure.http://llvm.org.
[15]Mongo-perf. https://github.com/mongodb/mongo-perf.
[16]MongoDB - Docker Hub.https://hub.docker.com/_/mongo/.
[17]Musl Libc. https://www.musl-libc.org.
[18]Namespaces(7) - Linux Programmer’s Manual.
http://man7.org/linux/man-pages/man7/namespaces.7.html.
[19]Package Callgraph - GoDoc.https://godoc.org/golang.org/x/tools/go/callgraph.
[20] Pgbench. https://www.postgresql.org/docs/10/pgbench.html.
[21]Python AST. https://docs.python.org/3/library/ast.html.
[22]Redis-benchmark. https://redis.io/topics/benchmarks.
[23]Seccomp BPF (SECure COMPuting withfilters).
https://www.kernel.org/doc/html/v4.16/userspace-api/seccomp_filter.html.
[24]Selenium. https://selenium.dev/.
[25]Sematext Agent Monitoring and Logging -Docker Hub.
https://hub.docker.com/_/sematext-agent-monitoring-and-logging.
[26] Sysdig. https://github.com/draios/sysdig.
[27]Ioannis Agadakos, Di Jin, David Williams-King,
Vasileios P Kemerlis, and Georgios Portokalidis.Nibbler: debloating binary shared libraries. In Proceedings of the 35th AnnualComputer Security Applications Conference (ACSAC), pages 70–83, 2019.
[28]Babak Amin Azad, Pierre Laperdrix, and NickNikiforakis. Less is more: Quantifying the security benefits of debloating webapplications. In Proceedings of the 28th USENIX Security Symposium, 2019.
[29]Lars Ole Andersen. Program analysis andspecialization for the C programming language. PhD thesis, University ofCophenhagen, 1994.
[30]Brandon Butler. Which is cheaper:Containers or virtual machines? https://www.networkworld.com/article/3126069/which-is-cheaper-containers-orvirtual-machines.html, September 2016.
[31]Theo Combe, Antony Martin, and Roberto DiPietro. To Docker or not to Docker: A security perspective. IEEE CloudComputing, 3(5):54–62, 2016.
[32]Nicholas DeMarinis, Kent Williams-King, DiJin, Rodrigo Fonseca, and Vasileios P. Kemerlis. Sysfilter: Automated systemcall filtering for commodity software.
In Proceedings of the International Conferenceon Research in Attacks, Intrusions, and Defenses (RAID), 2020.
[33]Henry Hanping Feng, Jonathon T Giffin, YongHuang, Somesh Jha, Wenke Lee, and Barton P Miller. Formalizing sensitivity instatic analysis for intrusion detection. In Proceedings of the IEEE Symposiumon Security & Privacy (S&P), pages 194–208, 2004.
[34]Stephanie Forrest, Steven A Hofmeyr, AnilSomayaji, and Thomas A Longstaff. A sense of self for Unix processes. In Proceedingsof the IEEE Symposium on Security & Privacy (S&P), pages 120–128, 1996.
[35]Tal Garfinkel, Ben Pfaff, and MendelRosenblum. Ostia: A delegating architecture for secure system callinterposition. In Proceedings of the Network and Distributed System SecuritySymposium (NDSS), 2004.
[36]Masoud Ghaffarinia and Kevin W. Hamlen.Binary control-flow trimming. In Proceedings of the 26th ACM Conference onComputer and Communications Security
(CCS), 2019.
[37]Seyedhamed Ghavamnia, Tapti Palit, ShacheeMishra, and Michalis Polychronakis. Temporal system call specialization forattack surface reduction. In Proceedings of the 29th USENIX Security Symposium,2020.
[38]Andreas Gustafsson. Egypt. https://www.gson.org/egypt/egypt.html.
[39] Ashish Gehani Hashim Sharif, MuhammadAbubakar and Fareed Zaffar. Trimmer: Application specialization for codedebloating. In Proceedings of the 33rd ACM/IEEE InternationalConference on Automated Software Engineering (ASE), 2018.
[40]Haifeng He, Saumya K Debray, and Gregory RAndrews. The revenge of the overlay: automatic compaction of OS kernel code viaon-demand code loading. In Proceedings
of the 7th ACM & IEEE internationalconference on Embedded software, pages 75–83, 2007.
[41]Kihong Heo, Woosuk Lee, PardisPashakhanloo, and Mayur Naik. Effective program debloating via reinforcementlearning. In Proceedings of the 24th ACM Conference on Computer andCommunications Security (CCS), 2018.
[42]Michael Hind. Pointer analysis: Haven’t wesolved this
problem yet? In Proceedings of the ACMSIGPLANSIGSOFT Workshop on Program Analysis for Software Tools and Engineering(PASTE), pages 54–61, 2001.
[43]Kapil Jain and R Sekar. User-levelinfrastructure for system call interposition: A platform for intrusiondetection and confinement. In Proceedings of the Network and
Distributed System Security Symposium (NDSS),2000.
[44]Yufei Jiang, Can Zhang, Dinghao Wu, andPeng Liu. Feature-based software customization: Preliminary analysis, formalization,and methods. In Proceedings
of the 17th IEEE International Symposium on HighAssurance Systems Engineering (HASE), 2016.
[45]Vasileios P. Kemerlis. Protecting CommodityOperating Systems through Strong Kernel Isolation. PhD thesis, ColumbiaUniversity, 2015.
[46]Vasileios P. Kemerlis, MichalisPolychronakis, and Angelos D. Keromytis. ret2dir: Rethinking kernel isolation.In Proceedings of the 23rd USENIX Security Symposium, pages 957–972, 2014.
[47]Hyungjoon Koo, Seyedhamed Ghavamnia, andMichalis Polychronakis. Configuration-driven software debloating. InProceedings of the 12th European Workshop on Systems Security, 2019.
[48] Alexey Kopytov. Sysbench.https://github.com/akopytov/sysbench.
[49]Christopher Kruegel, Engin Kirda, DarrenMutz,William Robertson, and Giovanni Vigna. Automating mimicry attacks usingstatic binary analysis. In Proceedings of
the USENIX Security Symposium, 2005.
[50]Anil Kurmus, Reinhard Tartler, DanielaDorneanu, Bernhard Heinloth, Valentin Rothberg, Andreas Ruprecht, WolfgangSchroder-Preikschat, Daniel Lohmann, and
Rudiger Kapitza. Attack surface metrics andautomated compile-time OS kernel tailoring. In Proceedings of the Network andDistributed System Security Symposium (NDSS), 2013.
[51]Chi-Tai Lee, Jim-Min Lin, Zeng-Wei Hong,and Wei-Tsong Lee. An application-oriented Linux kernel customization forembedded systems. J. Inf. Sci. Eng.,
20(6):1093–1107, 2004.
[52]Lingguang Lei, Jianhua Sun, Kun Sun, ChrisShenefiel, Rui Ma, Yuewu Wang, and Qi Li. SPEAKER: Split-phase execution ofapplication containers. In Proceedings of the 12th Conference on Detection of Intrusionsand Malware, and Vulnerability Assessment
(DIMVA), pages 230–251, 2017.
[53]Yiwen Li, Brendan Dolan-Gavitt, Sam Weber,and Justin Cappos. Lock-in-pop: Securing privileged operating system kernels bykeeping on the beaten path. In Proceedings of the USENIX Annual Technical Conference(ATC), 2017.
[54]Xin Lin, Lingguang Lei, Yuewu Wang, JiwuJing, Kun Sun, and Quan Zhou. A measurement study on Linux container security:Attacks and countermeasures. In
Proceedings of the 34th Annual Computer SecurityApplications Conference (ACSAC), pages 418–429, 2018.
[55]Steven McCanne and Van Jacobson. The BSDpacket filter: A new architecture for user-level packet capture. In Proceedingsof the USENIX Winter Conference, 1993.
[56]Shachee Mishra and Michalis Polychronakis.Shredder: Breaking Exploits through API Specialization. In Proceedings of the34th Annual Computer Security
Applications Conference (ACSAC), 2018.
[57]Shachee Mishra and Michalis Polychronakis.Saffire: Context-sensitive function specialization against code reuse attacks.In Proceedings of the 5th IEEE European
Symposium on Security and Privacy (EuroS&P),2020.
[58]Collin Mulliner and MatthiasNeugschwandtner. Breaking payloads with runtime code stripping and imagefreezing, 2015. Black Hat USA.
[59]Karen Scarfone Murugiah Souppaya, JohnMorello. Application Container Security Guide, 2017. https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-190.pdf.
[60]Tapti Palit, Yongming Shen, and MichaelFerdman. Demystifying cloud benchmarking. In Proceedings of the InternationalSymposium on Performance Analysis of Systems and Software (ISPASS), pages122–132, 2016.
[61]Chetan Parampalli, R Sekar, and RobJohnson. A practical mimicry attack against powerful system-call monitors. InProceedings of the ACM Symposium on Information, Computer and CommunicationsSecurity (ASIACCS), pages 156–167, 2008.
[62]Nikita Popov. PHP abstract syntax tree. https://github.com/nikic/php-ast.
[63]Chris Porter, Girish Mururu, PrithayanBarua, and Santosh Pande. Blankit library debloating: Getting what you wantinstead of cutting what you don’t. In Proceedings of the 41st ACM SIGPLANConference on Programming Language Design and Implementation
(PLDI), pages 164–180, 2020.
[64]Chenxiong Qian, Hong Hu, Mansour Alharthi,Pak Ho
Chung, Taesoo Kim, and Wenke Lee. RAZOR: Aframework for post-deployment software debloating. In Proceedings of the 28thUSENIX Security Symposium, 2019.
[65]Anh Quach and Aravind Prakash. Bloatfactors and binary specialization. In Proceedings of the 3rd ACM Workshop onForming an Ecosystem Around Software
Transformation (FEAST), pages 31–38, 2019.
[66]Anh Quach, Aravind Prakash, and Lok Yan.Debloating software through piece-wise compilation and loading. In Proceedingsof the 27th USENIX Security Symposium,
pages 869–886, 2018.
[67]Mohan Rajagopalan, Matti Hiltunen, TrevorJim, and Richard Schlichting. Authenticated system calls. In Proceedings of theInternational Conference on Dependable Systems and Networks (DSN), pages358–367, 2005.
[68]Vaibhav Rastogi, Drew Davidson, Lorenzo DeCarli, Somesh Jha, and Patrick D. McDaniel. Cimplifier: automatically debloatingcontainers. In Proceedings of the 11th Joint Meeting on Foundations of SoftwareEngineering (ESEC/FSE), 2017.
[69]Vaibhav Rastogi, Chaitra Niddodi, SibinMohan, and Somesh Jha. New directions for container debloating. In Proceedingsof the 2nd Workshop on Forming an Ecosystem Around Software Transformation(FEAST), pages 51–56, 2017.
[70]Daniel Shapira. Escaping Docker containerusing waitid() – CVE-2017-5123, 2017. https://www.twistlock.com/labs-blog/escaping-doc
ker-container-using-waitid-cve-2017-5123/.
[71]Rui Shu, Xiaohui Gu, and William Enck. Astudy of security vulnerabilities on Docker Hub. In Proceedings of the 7th ACMConference on Data and Application Security and Privacy (CODASPY), pages269–280, 2017.
[72]Linhai Song and Xinyu Xing. Fine-grainedlibrary customization. In Proceedings of the 1st ECOOP International Workshopon Software Debloating and
Delayering (SALAD), 2018.
[73]Kanchi Gopinath Suparna Bhattacharya andMangala Gowri Nanda. Combining concern input with program analysis for bloatdetection. In Proceedings of the ACM SIGPLAN International Conference on ObjectOriented Programming Systems Languages & Applications (OOPSLA), 2013.
[74]David Wagner and Drew Dean. Intrusiondetection via static analysis. In Proceedings of the IEEE Symposium on Security& Privacy, pages 156–168, 2001.
[75]Zhiyuan Wan, David Lo, Xin Xia, Liang Cai,and Shanping Li. Mining Sandboxes for Linux Containers. In Proceedings of the10th IEEE International Conference
on Software Testing, Verification and Validation(ICST), pages 92–102, 2017.
[76]David Williams-King, Hidenori Kobayashi,Kent Williams-King, Graham Patterson, Frank Spano, Yu Jian Wu, Junfeng Yang,and Vasileios P Kemerlis. Egalito: Layout-agnostic binary recompilation. InProceedings of the 25th International Conference on Architectural Support forProgramming Languages and Operating Systems (ASPLOS), pages 133–147, 2020.
[77]Dinghao Wu Yufei Jiang and Peng Liu. Jred:Program customization and bloatware mitigation based on static analysis. InProceedings of the 40th Annual Computer Software and Applications Conference(ACSAC), 2016.
[78]Tong Zhang, Wenbo Shen, Dongyoon Lee,Changhee Jung, Ahmed M. Azab, and Ruowen Wang. PeX: A permission check analysisframework for linux kernel. In Proceedings of the 28th USENIX SecuritySymposium, pages 1205–1220, 2019.
[79]Zhi Zhang, Yueqiang Cheng, Surya Nepal,Dongxi Liu, Qingni Shen, and Fethi Rabhi. KASR: A reliable and practical approachto attack surface reduction of commodity OS kernels. In Proceedings of the InternationalConference on Research in Attacks,
Intrusions, and Defenses (RAID), pages 691–710,2018.
[80]Xiangyu Zhang Zhongshu Gu, BrendanSaltaformaggio and Dongyan Xu. Face-change: Application-driven dynamic kernelview switching in a virtual machine. In
Proceedings of the 44th IEEE/IFIP InternationalConference on Dependable Systems and Networks (DSN), 2014.
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论