{"id":69,"date":"2017-03-23T15:49:05","date_gmt":"2017-03-23T07:49:05","guid":{"rendered":"\/\/hqidi.com\/?p=69"},"modified":"2017-03-23T15:49:05","modified_gmt":"2017-03-23T07:49:05","slug":"%e8%81%8a%e8%81%8afork%e7%82%b8%e5%bc%b9","status":"publish","type":"post","link":"https:\/\/hqidi.com\/69.html","title":{"rendered":"\u804a\u804aFork\u70b8\u5f39"},"content":{"rendered":"<p>Fork\u70b8\u5f39\uff08fork bomb\uff09\u5728\u8ba1\u7b97\u673a\u9886\u57df\u4e2d\u662f\u4e00\u79cd\u5229\u7528\u7cfb\u7edf\u8c03\u7528fork\uff08\u6216\u5176\u4ed6\u7b49\u6548\u7684\u65b9\u5f0f\uff09\u8fdb\u884c\u7684\u62d2\u7edd\u670d\u52a1\u653b\u51fb\u3002\u4e0e\u75c5\u6bd2\u4e0e\u8815\u866b\u4e0d\u540c\u7684\u662f\uff0cfork\u70b8\u5f39\u6ca1\u6709\u4f20\u67d3\u6027\uff0c<br \/>\n\u800c\u4e14fork\u70b8\u5f39\u4f1a\u4f7f\u6709\u8fdb\u7a0b\/\u7a0b\u5e8f\u9650\u5236\u7684\u7cfb\u7edf\u65e0\u6cd5\u5f00\u8d77\u65b0\u7684\u8fdb\u7a0b\uff0c\u5bf9\u4e8e\u4e0d\u9650\u5236\u8fdb\u7a0b\u6570\u7684\u7cfb\u7edf\u5219\u4f7f\u4e4b\u505c\u6b62\u54cd\u5e94\u3002\u4ee5fork\u70b8\u5f39\u4e3a\u4ee3\u8868\u7684\u81ea\u6211\u590d\u5236\u7a0b\u5e8f\u6709\u65f6\u4ea6\u88ab\u79f0\u4e3awabbit\u3002<\/p>\n<h2>\u539f\u7406\u4e0e\u5f71\u54cd<\/h2>\n<p>fork\u70b8\u5f39\u4ee5\u6781\u5feb\u7684\u901f\u5ea6\u521b\u5efa\u5927\u91cf\u8fdb\u7a0b\uff08\u8fdb\u7a0b\u6570\u5448\u4ee52\u4e3a\u5e95\u6570\u7684\u6307\u6570\u589e\u957f\u8d8b\u52bf\uff09\uff0c\u5e76\u4ee5\u6b64\u6d88\u8017\u7cfb\u7edf\u5206\u914d\u4e88\u8fdb\u7a0b\u7684\u53ef\u7528\u7a7a\u95f4\u4f7f\u8fdb\u7a0b\u8868\u9971\u548c\uff0c\u800c\u7cfb\u7edf\u5728\u8fdb\u7a0b\u8868\u9971\u548c\u540e\u5c31\u65e0\u6cd5\u8fd0\u884c\u65b0\u7a0b\u5e8f\uff0c\u9664\u975e\u8fdb\u7a0b\u8868\u4e2d\u7684\u67d0\u4e00\u8fdb\u7a0b\u7ec8\u6b62\uff1b\u4f46\u7531\u4e8efork\u70b8\u5f39\u7a0b\u5e8f\u6240\u521b\u5efa\u7684\u6240\u6709\u5b9e\u4f8b\u90fd\u4f1a\u4e0d\u65ad\u63a2\u6d4b\u7a7a\u7f3a\u7684\u8fdb\u7a0b\u69fd\u5e76\u5c1d\u8bd5\u53d6\u7528\u4ee5\u521b\u5efa\u65b0\u8fdb\u7a0b\uff0c\u56e0\u800c\u5373\u4f7f\u5728\u67d0\u8fdb\u7a0b\u7ec8\u6b62\u540e\u4e5f\u57fa\u672c\u4e0d\u53ef\u80fd\u8fd0\u884c\u65b0\u8fdb\u7a0b\u3002fork\u70b8\u5f39\u751f\u6210\u7684\u5b50\u7a0b\u5e8f\u5728\u6d88\u8017\u8fdb\u7a0b\u8868\u7a7a\u95f4\u7684\u540c\u65f6\u4e5f\u4f1a\u5360\u7528CPU\u548c\u5185\u5b58\uff0c\u4ece\u800c\u5bfc\u81f4\u7cfb\u7edf\u4e0e\u73b0\u6709\u8fdb\u7a0b\u8fd0\u884c\u901f\u5ea6\u653e\u7f13\uff0c\u54cd\u5e94\u65f6\u95f4\u4e5f\u4f1a\u968f\u4e4b\u5927\u5e45\u589e\u52a0\uff0c\u4ee5\u81f4\u4e8e\u65e0\u6cd5\u6b63\u5e38\u5b8c\u6210\u4efb\u52a1\uff0c\u4ece\u800c\u4f7f\u7cfb\u7edf\u7684\u6b63\u5e38\u8fd0\u4f5c\u53d7\u5230\u4e25\u91cd\u5f71\u54cd\u3002<\/p>\n<h2>\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u7a0b\u5e8f\u6bb5\u5c31\u662f\u7531Jaromil\u6240\u4f5c\u7684\u5728\u7c7bUNIX\u7cfb\u7edf\u7684shell\u73af\u5883\u4e0b\u89e6\u53d1fork\u70b8\u5f39\u7684shell\u811a\u672c\u4ee3\u7801\uff0c\u603b\u5171\u53ea\u7528\u4e8613\u4e2a\u5b57\u7b26\uff08\u5305\u62ec\u7a7a\u683c\uff09\uff1a<br \/>\n:(){ :|:& };:<br \/>\n\u8fd9\u4e2a\u9012\u5f52\u51fd\u6570\u80fd\u591f\u8c03\u7528\u81ea\u8eab\uff0c\u4e0d\u65ad\u5730\u751f\u6210\u65b0\u7684\u8fdb\u7a0b\uff0c\u6700\u7ec8\u9020\u6210\u62d2\u7edd\u670d\u52a1\u653b\u51fb\uff0c\u51fd\u6570\u8c03\u7528\u524d\u7684&\u8bb2\u5b50\u8fdb\u7a0b\u653e\u5165\u540e\u53f0\uff0c\u8fd9\u6bb5\u5371\u9669\u7684\u4ee3\u7801\u4f1a\u5206\u652f\u51fa\u5927\u91cf\u7684\u8fdb\u7a0b\uff0c\u56e0\u800c\u88ab\u79f0\u4e3aFork\u70b8\u5f39\u3002\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\/etc\/security\/limits.conf\u6765\u9650\u5236\u53ef\u751f\u6210\u7684\u6700\u5927\u8fdb\u7a0b\u6570\u6765\u907f\u5f00\u8fd9\u679a\u70b8\u5f39\u3002<br \/>\n\u5176\u4e2d\u51fd\u6570\u540d\u201c:\u201d\u53ea\u662f\u51cf\u5316\u7684\u4e00\u4f8b\uff0c\u5b9e\u9645\u4e0a\u53ef\u4ee5\u968f\u610f\u8bbe\u7f6e\uff0c\u4e00\u4e2a\u8f83\u6613\u7406\u89e3\uff08\u5c06\u51fd\u6570\u540d\u66ff\u6362\u4e3a\u201cfb\u201d\uff09\u7684\u7248\u672c\u5982\u4e0b\uff1a<br \/>\nfb(){ fb|fb& };fb<br \/>\n\u6ce8\u89e3\u5982\u4e0b\uff1a<\/p>\n<pre class=\"prettyprint\" >\r\nfb()      # \u5b9a\u4e49\u51fd\u6570,\u51fd\u6570\u540d\u4e3a\"fb\",\u5373\u6bcf\u5f53\u8f93\u5165\"fb\"\u65f6\u5c31\u4f1a\u81ea\u52a8\u8c03\u7528{}\u5185\u4ee3\u7801\r\n{        # \"fb\"\u51fd\u6570\u5f00\u59cb\u6807\u8bc6\r\n    fb    # \u7528\u9012\u5f52\u65b9\u5f0f\u8c03\u7528\"fb\"\u51fd\u6570\u672c\u8eab\r\n    |    # \u5e76\u7528\u7ba1\u9053(pipe)\u5c06\u5176\u8f93\u51fa\u5f15\u81f3...\uff08\u56e0\u4e3a\u6709\u4e00\u4e2a\u7ba1\u9053\u64cd\u4f5c\u5b57\u7b26\uff0c\u56e0\u6b64\u4f1a\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\uff09\r\n    fb    # \u518d\u4e00\u6b21\u9012\u5f52\u8c03\u7528\u7684\"fb\"\u51fd\u6570\r\n# \u7efc\u4e0a,\"fb|fb\"\u8868\u793a\u7684\u5373\u662f\u6bcf\u6b21\u8abf\u7528\u51fd\u6570\"fb\"\u7684\u6642\u5019\u5c31\u4f1a\u4ea7\u751f\u4e24\u4efd\u62f7\u8d1d\r\n    &    # \u5373\u4f7f\u6700\u521d\u7684\"fb\"\u51fd\u6570\u88ab\u5173\u95ed\uff0c\u540e\u53f0\u8fd8\u6709\u4e24\u4e2afb\u51fd\u6570\u5728\u4e00\u76f4\u8fd0\u884c\r\n}        # \"fb\"\u51fd\u6570\u7d42\u6b62\u6807\u8bc6\r\n;        # \"fb\"\u51fd\u6570\u5b9a\u4e49\u7ed3\u675f\u540e\u5c06\u8981\u8fdb\u884c\u7684\u64cd\u4f5c...\r\nfb        # \u8c03\u7528\"fb\"\u51fd\u6570,\"\u5f15\u7206\"fork\u70b8\u5f39\r\n<\/pre>\n<h2>\u505a\u5927\u6b7b<\/h2>\n<p>\u73b0\u5728\u6211\u4eec\u76f4\u63a5\u6765\u8dd1\u8fd9\u4e2a\u51fd\u6570\uff0c\u770b\u770b\u5230\u5e95\u4ec0\u4e48\u6548\u679c\uff0c\u5f53\u7136\u8981\u5148\u505a\u597d\u51c6\u5907\u5de5\u4f5c\uff0c\u88c5\u597dsysstat\u8bb0\u5f55\u7cfb\u7edf\u8d1f\u8f7d\uff0cyum install sysstat -y,\u5e76\u542f\u52a8 \/etc\/init.d\/sysstat start<\/p>\n<p>\u7cfb\u7edf\u4fe1\u606f\uff1a<\/p>\n<pre class=\"prettyprint\" >\r\n[root@disz ~]# lscpu \r\nArchitecture:          x86_64\r\nCPU op-mode(s):        32-bit, 64-bit\r\nByte Order:            Little Endian\r\nCPU(s):                1\r\nOn-line CPU(s) list:   0\r\nThread(s) per core:    1\r\nCore(s) per socket:    1\r\nSocket(s):             1\r\nNUMA node(s):          1\r\nVendor ID:             GenuineIntel\r\nCPU family:            6\r\nModel:                 62\r\nStepping:              4\r\nCPU MHz:               2593.746\r\nBogoMIPS:              5187.49\r\nHypervisor vendor:     KVM\r\nVirtualization type:   full\r\nL1d cache:             32K\r\nL1i cache:             32K\r\nL2 cache:              256K\r\nL3 cache:              20480K\r\nNUMA node0 CPU(s):     0\r\n\r\n[root@disz ~]# free -m\r\n             total       used       free     shared    buffers     cached\r\nMem:          1877       1652        224          0        231        387\r\n-\/+ buffers\/cache:       1033        844\r\nSwap:            0          0          0\r\n<\/pre>\n<p>\u7cfb\u7edf\u5f53\u524d\u5141\u8bb8\u6253\u5f00\u7684\u6700\u5927\u8fdb\u7a0b\u6570<\/p>\n<pre class=\"prettyprint\" >\r\n[root@disz ~]# ulimit -a |grep processes\r\nmax user processes              (-u) 102400\r\n<\/pre>\n<p>\u505a\u597d\u91cd\u542f\u7cfb\u7edf\u7684\u8ba1\u5212\u4efb\u52a1<br \/>\necho '25 14 * * * \/sbin\/reboot -n &>\/dev\/null' >>\/var\/spool\/cron\/root<br \/>\n\u76f4\u63a5\u8f93\u5165:(){ :|:& };: \u5e76\u56de\u8f66\u540e\u7684\u7cfb\u7edf\u72b6\u6001\uff1a<br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/1.png\" alt=\"\" \/><\/p>\n<p>\u4e3b\u8981\u662f\u7cfb\u7edf\u4e0a\u4e0b\u6587\u5207\u6362\u5360\u7528\u4e86CPU\u7684\u8d44\u6e90\uff0c\u5e76\u5f00\u59cb\u4ea7\u751f\u5c11\u89c1\u7684\u50f5\u5c38\u8fdb\u7a0b<br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/2.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/3.png\" alt=\"\" \/><br \/>\nxshell\u754c\u9762\u8fd8\u53ef\u4ee5\u6b63\u5e38\u56de\u8f66\uff0c\u4f46\u547d\u4ee4\u5df2\u7ecf\u6ca1\u6709\u56de\u663e<br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/4.png\" alt=\"\" \/><br \/>\n\u8fc7\u4e86\u9884\u5b9a\u91cd\u542f\u7684\u65f6\u95f4\uff0c\u4f9d\u7136\u8fde\u63a5\u4e0d\u662f\uff0c\u5e94\u8be5\u662f\u91cd\u542f\u5931\u8d25\u4e86<br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/6.jpg\" alt=\"\" \/><br \/>\nconsole\u4e5f\u8fde\u63a5\u4e0d\u4e0a\u4e86<br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/7.png\" alt=\"\" \/><br \/>\n\u63a7\u5236\u53f0\u70b9\u51fb\u91cd\u542f\u540e\uff0cconsole\u7a97\u53e3\u6709\u4e86\u53cd\u6620\uff0cOOM\u673a\u5236\u88ab\u89e6\u53d1\uff0c\u5207\u6362\u5230\u5176\u4ed6console\u6ca1\u7528<br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/8.png\" alt=\"\" \/><br \/>\n\u63a7\u5236\u53f0\u65e0\u6cd5\u6b63\u5e38\u91cd\u542f\uff0c\u4e00\u76f4\u663e\u793a\u505c\u6b62\u4e2d\uff0c\u770b\u6765\u5f97\u5f3a\u5236\u91cd\u542f\uff0c\u5176\u5b9e5\u5206\u949f\u5de6\u53f3\u7684\u6837\u5b50\uff0c\u6b63\u5e38\u91cd\u542f\u6210\u529f\u3002<br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/9.png\" alt=\"\" \/><\/p>\n<h2>\u9884\u9632<\/h2>\n<p>\u7531\u4e8eFork Bomb\u901a\u8fc7\u4e0d\u65ad\u7684\u5f00\u65b0\u8fdb\u7a0b\u6765\u762b\u75ea\u7cfb\u7edf\uff0c\u4e00\u4e2a\u9632\u6b62\u5176\u4e25\u91cd\u5f71\u54cd\u7cfb\u7edf\u7684\u65b9\u6cd5\u5c31\u662f\u9650\u5b9a\u4e00\u4e2a\u7528\u6237\u80fd\u591f\u521b\u5efa\u7684\u8fdb\u7a0b\u6570\u7684\u4e0a\u9650\uff0c\u5728Linux\u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7ulimit\u8fd9\u4e2a\u6307\u4ee4\u8fbe\u5230\u76f8\u5e94\u7684\u6548\u679c\uff0c\u4f8b\u5982\uff1a ulimit -Hu 30 \u8fd9\u4e2a\u6307\u4ee4\u53ef\u4ee5\u9650\u5236\u6bcf\u4e00\u4e2a\u7528\u6237\u6700\u591a\u53ea\u80fd\u521b\u5efa30\u4e2a\u8fdb\u7a0b\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\/etc\/security\/limits.conf\u6765\u9650\u5236\u53ef\u751f\u6210\u7684\u6700\u5927\u8fdb\u7a0b\u6570\u6765\u907f\u5f00\u8fd9\u679a\u70b8\u5f39\u3002\u800cFreeBSD\u7cfb\u7edf\u7684\u8bdd\u7cfb\u7edf\u7ba1\u7406\u8005\u53ef\u5728\/etc\/login.conf\u5e95\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u76f8\u5173\u7684\u8bbe\u7f6e\u3002<\/p>\n<h2>windows\u4e0b\u7684\u70b8\u5f39<\/h2>\n<p>Windows\u4e0b\u5219\u53ef\u4ee5\u6279\u5904\u7406\u547d\u4ee4\u5982\u4e0b\u5b9e\u73b0\uff1a<br \/>\n%0|%0<br \/>\n\u8fd9\u4e2a\u547d\u4ee4\u770b\u8d77\u6765\u592a\u9ad8\u5927\u4e0a\u4e86\uff0cwindows\u4e5f\u4e0d\u503c\u5f97\u8fd9\u4e48\u53bb\u7814\u7a76\uff0c\u6240\u4ee5\u6211\u4eec\u770b\u4e00\u6761\u7b80\u5355\u7684\u547d\u4ee4<br \/>\nstart 1<br \/>\n\u8bb0\u4e8b\u672c\u91cc\u9762\u8f93\u5165start 1\u540e\uff0c\u4fdd\u5b58\uff0c\u628a\u6587\u4ef6\u540d\u6539\u62101.bat\uff0c\u770b\u770b\u8fd0\u884c\u6548\u679c<br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/10.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/11.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"\/\/hqidi.com\/img\/69\/12.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fork\u70b8\u5f39\uff08fork bomb\uff09\u5728\u8ba1\u7b97\u673a\u9886\u57df\u4e2d\u662f\u4e00\u79cd\u5229\u7528\u7cfb\u7edf\u8c03\u7528fork\uff08\u6216\u5176\u4ed6\u7b49\u6548\u7684\u65b9\u5f0f\uff09\u8fdb\u884c\u7684\u62d2\u7edd\u670d\u52a1\u653b\u51fb\u3002\u4e0e\u75c5\u6bd2\u4e0e\u8815\u866b\u4e0d\u540c\u7684\u662f\uff0cfork\u70b8\u5f39\u6ca1\u6709\u4f20\u67d3\u6027\uff0c \u800c\u4e14fork\u70b8\u5f39\u4f1a\u4f7f\u6709\u8fdb\u7a0b\/\u7a0b\u5e8f\u9650\u5236\u7684\u7cfb\u7edf\u65e0\u6cd5\u5f00\u8d77\u65b0\u7684\u8fdb\u7a0b\uff0c\u5bf9\u4e8e\u4e0d\u9650\u5236\u8fdb\u7a0b\u6570\u7684\u7cfb\u7edf\u5219\u4f7f\u4e4b\u505c\u6b62\u54cd\u5e94\u3002\u4ee5fork\u70b8\u5f39\u4e3a\u4ee3\u8868\u7684\u81ea\u6211\u590d\u5236\u7a0b\u5e8f\u6709\u65f6\u4ea6\u88ab\u79f0\u4e3awabbit\u3002 \u539f\u7406\u4e0e\u5f71\u54cd fork\u70b8\u5f39\u4ee5\u6781\u5feb\u7684\u901f\u5ea6\u521b...<\/p>\n<a class=\"read-more\" href=\"https:\/\/hqidi.com\/69.html\">\u9605\u8bfb\u5168\u6587 &raquo;<\/a>","protected":false},"author":1,"featured_media":3037,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[46],"class_list":["post-69","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-study","tag-fork"],"_links":{"self":[{"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/posts\/69"}],"collection":[{"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":1,"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":3038,"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/posts\/69\/revisions\/3038"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/media\/3037"}],"wp:attachment":[{"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hqidi.com\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}