Nginx 文件名逻辑漏洞(CVE-2013-4547)

AffettoIris 2023-9-24 9,066,192 9/24

官网给的漏洞原理及题解

题解

vlhub给了我们这样的网页

Nginx 文件名逻辑漏洞(CVE-2013-4547)

测试发现只不能提交.php文件,我们将一句话木马<?php phpinfo(); ?>写进1.txt,重命名为1.jpg,然后上传,这个过程burp抓包,将filename从"1.jpg"改为"1.jpg "并forward,上传成功~服务器存着一个叫"1.jpg "的非图片文件.

Nginx 文件名逻辑漏洞(CVE-2013-4547)

在浏览器输入62.234.14.252:8080/uploadfiles/1.jpgaa.php并抓包,

Nginx 文件名逻辑漏洞(CVE-2013-4547)

然后Forward,漏洞利用成功:

Nginx 文件名逻辑漏洞(CVE-2013-4547)

我的服务器是nginx1.20,比较新,上述漏洞未能成功显示phpinfo();显示如下:

Nginx 文件名逻辑漏洞(CVE-2013-4547)

踩坑点及深入挖掘原理

  1. 成功上传1.jpg[0x20]后,访问http://62.234.14.252:8080/uploadfiles/1.jpg显示如下

    Nginx 文件名逻辑漏洞(CVE-2013-4547)

    因为服务器上存的是1.jpg[0x20],而浏览器输入62.234.14.252:8080/uploadfiles/1.jpg[0x20]实际访问的还是62.234.14.252:8080/uploadfiles/1.jpg (对,浏览器会过滤忽略掉url开头结尾的空格),所以404了。

  2. 假设我们上传的就是1.jpg,文件名不带空格,然后我们访问62.234.14.252:8080/uploadfiles/1.jpg,这个访问过程无法被FoxyProxy和burp抓包,可能是因为纯图片不是报文不在其业务范围的缘故。

    解决如何即访问1.jpg[0x20]又能让burp抓到包?:

    访问http://62.234.14.252:8080/uploadfiles/1.jpgaa.php,违背了纯图片就能被抓包了。然后用burp在底层将aa修改为[0x20][0x00]就能访问1.jpg[0x20]了

  3. 官方教程教收尾阶段访问http://your-ip:8080/uploadfiles/1.jpg[0x20][0x00].php,我傻乎乎的尝试在浏览器输入带[]的、不带[]的、[0x20]改写而成空格的、[0x00]改写不成空,都显示404了。后来才知道要去burp去修改报文的十六进制底层,即访问http://62.234.14.252:8080/uploadfiles/1.jpgaa.php,其中aa是可以留的占位符,a在底层对应ascii的十六进制61,将[61][61]改成[20][00],其中20是空格,00是空的ascii。

  4. 这里应该是用到了0x00截断原理了,具体原理是 系统在对文件名的读取时,如果遇到0x00,就会认为读取已结束。这个常用在对文件类型名的绕过上。还不止这个原理。

  5. 当Nginx得到一个用户请求时,首先对url进行解析,进行正则匹配,如果匹配到以.php后缀结尾的文件名(即http://62.234.14.252:8080/uploadfiles/1.jpg \0.php),会将请求的PHP文件交给PHP-CGI去解析。其中处理模块如下:

    location ~ \.php$ {
        root           html;
        include        fastcgi_params;
    
        fastcgi_pass   IP:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
        fastcgi_param  DOCUMENT_ROOT /var/www/html;
    }

    以.php结尾的文件都会交给该模块处理,其中fastcgi_pass就是Nginx与PHP-FPM之间的媒介,通过ip+port的方式将请求转发给PHP解释器。

    但是我们有代码的文件它叫’1.jpg ‘啊,不叫'1.php'不叫'1.jpg php'不叫'1.jpgphp',所以我们利用0x00的阶段原理,用0x00将'1.jpg '和.php分隔开。http://62.234.14.252:8080/uploadfiles/1.jpg \0.php通过.php进入这个Location块;但进入后,Nginx却因0x00隔断而错误地认为请求的文件是1.gif[0x20],就将'1.gif '交付PHP-CGI去解析(就设置其为SCRIPT_FILENAME的值发送给fastcgi)。

- THE END -

AffettoIris

10月16日15:24

最后修改:2023年10月16日
2

共有 140,163 条评论

  1. StaceyDon

    ¡Buenas!
    Aprender cГіmo jugar casino en lГ­nea con dinero real es el primer paso para disfrutar de esta experiencia. <a href=https://realcasinogames.shop/>casino en Bolivia</a> Descubre cГіmo jugar casino en lГ­nea con dinero real de manera segura y responsable.
    Lee este enlace – https://realcasinogames.shop/
    Casino con dinero real Bolivia

    ¡Buena suerte!

  2. Nickysek

    Aloha!
    Master the art of live online gaming roulette casino strategy with our comprehensive guides and expert tips. <a href=https://top10casinos.shop>online casino canada real money jackpot city</a> Learn proven live online gaming roulette casino strategy techniques from professional players and start playing smarter today.
    Check out this link – https://top10casinos.shop/
    real money casinos canada

    Have a great day!

  3. Nickysek

    Hey there!
    Participate in our exciting live online gaming poker tournament and compete against skilled players from around the world. <a href=https://top10casinos.shop/>online casino real money no deposit canada</a> Register for the next live online gaming poker tournament and prove your skills while competing for substantial cash prizes.
    Read the link – https://top10casinos.shop
    top 6 online real money casino canada

    Best of luck!

  4. Nickysek

    Whats up!
    Unlock incredible value with our live online gaming casino no deposit bonus codes that require no initial investment. <a href=https://top10casinos.shop/>casino games for real money online</a> Claim your live online gaming casino no deposit bonus codes today and start playing immediately without spending a penny.
    Check this example resource – https://top10casinos.shop
    casino apps for real money

    Good luck!

  5. Nickysek

    Hi friend!
    Enjoy live online gaming blackjack free bonus offers that give you extra playing power without additional cost. <a href=https://top10casinos.shop/>online casino real money no deposit canada</a> Take advantage of our live online gaming blackjack free bonus deals and discover why players choose our platform for authentic blackjack action.
    Read the link – https://top10casinos.shop
    online casino real money no deposit canada

    Best of luck!

  6. Nickysek

    Aloha!
    Master the art of live online gaming roulette casino strategy with our comprehensive guides and expert tips. <a href=https://top10casinos.shop>real money casino canada</a> Learn proven live online gaming roulette casino strategy techniques from professional players and start playing smarter today.
    Read the link – https://top10casinos.shop
    real money casinos canada

    Good luck!

  7. Nickysek

    Good day!!
    Participate in our exciting live online gaming poker tournament and compete against skilled players from around the world. <a href=https://top10casinos.shop>casino apps for real money</a> Register for the next live online gaming poker tournament and prove your skills while competing for substantial cash prizes.
    Check this out – https://top10casinos.shop
    online casino real money no deposit canada

    Best of luck!

  8. twistyneonpangolin5Guaps

    Adoro o emaranhado de IJogo Casino, e um cassino online que enreda como uma teia de aranha gigante. Tem uma enxurrada de jogos de cassino irados. oferecendo lives que explodem como uma selva. O atendimento esta sempre ativo 24/7. respondendo rapido como um cipo se enrolando. Os ganhos chegam rapido como uma teia rompida. de vez em quando mais bonus regulares seriam selvagens. Para encurtar, IJogo Casino garante um jogo que se entrelaca como cipos para os apaixonados por slots modernos! De bonus o design e fluido como um emaranhado. transformando cada aposta em uma aventura enredada.
    <a href=http://vitoriaengenharia.com.br/dominando-as-odds-para-vencer-no-ijogo-casino/>ijogo imvu</a>|

  9. Magistrniker4Guaps

    Ich bin suchtig nach Snatch Casino, es fuhlt sich wie ein Sturm des Vergnugens an. Es gibt eine unglaubliche Vielfalt an Spielen, mit Tausenden von Crypto-freundlichen Spielen. Der Kundenservice ist erstklassig, antwortet in Sekundenschnelle. Die Gewinne kommen schnell, trotzdem zusatzliche Belohnungen waren top. Zusammenfassend Snatch Casino ist eine au?ergewohnliche Plattform fur Spieler auf der Suche nach Spa? ! Au?erdem die Navigation ist super einfach, verstarkt den Wunsch zuruckzukehren.
    <a href=https://snatch-casino.de/>snatch casino ОєПЃО№П„О№ОєОµПѓ</a>|

  10. LhaneBup

    Trade, earn points, and explore Web3 projects on Asterdex
    — your gateway to decentralized markets.
    I’ve been using Asterdex
    lately — cool platform where you can trade, collect points, and track crypto trends in one place.
    With Asterdex
    , users can trade assets, earn rewards, and explore data from multiple blockchains in real time.
    Check out Asterdex
    — you can trade, earn points, and discover trending tokens fast. ??
    <a href=https://fire-of-war.ru/>казино кат</a>