Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Linux fork炸弹及其预防

在Linux系统下执行这段代码  :(){  :|:&  };:    就会引起死机,一旦执行起来后,唯一的方法就是重启系统。实际上这段代码是一段无限递归代码,将系统资源耗尽。本文下面有这段代码的详细解释,为了防止fork炸弹,方法就是限制用户能够启动的进程数。具体做法,编辑/etc/security/limits.conf文件,在末尾加入 :
              *      hard    nproc   200
将用户的进程数限制为200,经过测试,root账户不受这个限制。Q. Can you explain following bash code or bash fork() bomb?
:(){ :|:& };:A. This is a bash function. It gets called recursively (recursive function). This is most horrible code for any Unix / Linux box. It is often used by sys admin to test user processes limitations (Linux process limits can be configured via /etc/security/limits.conf and PAM).Once a successful fork bomb has been activated in a system it may not be possible to resume normal operation without rebooting, as the only solution to a fork bomb is to destroy all instances of it.WARNING! These examples may crash your computer if executed.

Understanding :(){ :|:& };: fork() bomb code

:() - It is a function name. It accepts no arguments at all. Generally, bash function is defined as follows:foo(){ arg1=$1 echo "" #do_something on $arg argument}fork() bomb is defined as follows::(){ :|:&};::|: - Next it call itself using programming technique called recursion and pipes the output to another call of the function ":". The worst part is function get called two times to bomb your system.& - Puts the function call in the background so child cannot die at all and start eating system resources.; - Terminate the function definition: - Call (run) the function aka set the fork() bomb.Here is more human readable code:bomb() { bomb | bomb &}; bombProperly configured Linux / UNIX box should not go down when fork() bomb sets off. Linux Kernel “fs/partitions/ldm.c”缓冲区溢出和拒绝服务漏洞Cisco TelePresence多个产品缓冲区溢出漏洞相关资讯      Linux安全 
  • 发现针对 Linux 服务器和代码库的  (11/08/2015 09:11:50)
  • Linux安全与优化  (12/05/2014 17:04:31)
  • 加强 Linux 桌面安全  (08/15/2014 11:36:10)
  • 牢记这七点 让你的Linux服务器变得  (08/12/2015 15:39:07)
  • 树大招风,Linux的安全威胁正在不  (08/24/2014 21:44:47)
  • GNU/Linux安全基线与加固  (07/22/2014 13:51:21)
本文评论 查看全部评论 (1)
表情: 姓名: 字数


评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款