美文网首页
De1CTF 2019-WEB-SSRF Me

De1CTF 2019-WEB-SSRF Me

作者: le3f | 来源:发表于2020-04-08 21:37 被阅读0次

复现地址:https://buuoj.cn/challenges#[De1CTF%202019]SSRF%20Me

#! /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):#python得构造方法
        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):#定义的命令执行函数,此处调用了scan这个自定义的函数
        result = {}
        result['code'] = 500
        if (self.checkSign()):
            if "scan" in self.action:#action要写scan
                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:#action要加read
                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):#!!!这个应该是本题关键点,此处注意顺序先是param后是action
    return hashlib.md5(secert_key + param + action).hexdigest()


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


def waf(param):#这个waf比较没用好像
    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')

先解释部分函数:

所在行 解释
第20行 init(self, action, param, …) 构造方法self代表对象,其他是对象的属性
71 request.args.get(param) 提取get方法传入的,参数名叫param对应得值
70 request.cookies.get(“action”) 提取cookie信息中的,名为action得对应值
92 hashlib.md5().hexdigest() hashlib.md5()#获取一个md5加密算法对象,hexdigest()是获得加密吼的16进制字符串
70,71,72 urllib.unquote() 将url编码解码
87 urllib.urlopen() 读取网络文件参数可以是url
77 json.dumps Python 对象编码成 JSON 字符串

参照这个吧
https://xz.aliyun.com/t/5927

相关文章

  • De1CTF 2019-WEB-SSRF Me

    复现地址:https://buuoj.cn/challenges#[De1CTF%202019]SSRF%20Me...

  • [De1CTF 2019]SSRF Me之愚见

    今天在buuctf上尝试了一下[De1CTF 2019]SSRF Me这个题目,名字直接提示了考点所在,提醒我们注...

  • De1CTF 2020

    终于到第二次XCTF了。没想到De1ta的题这次这么顶,果然是出给国际队伍的难度。(膜一波国内外大佬队伍)小绿草这...

  • 利用PHP反序列化免杀D盾等WAF软件

    这次这篇文章想法主要是在de1ctf一题shellshellshell过反序列化漏洞制造SSRF登录,然后如果用反...

  • 每日总结-第二十六天-复读机

    碎碎念 前天结束了De1CTF,再次被自己菜到说不出话来==,今天满血复活,继续努力吧。 小记录 - pizza复...

  • De1CTF 2019 PWN

    My Solve: 为抢血来的,前两题都是第四个交的,一丝难受,还好最后一个抢了二血真是愈来愈菜,近一个月没搞pw...

  • De1CTF 2020 - re

    碎碎念 wtclwtclwtclwtclwtcl......1w遍 参考链接 https://mp.weixin....

  • Inside me

    love me hate me kiss me hug me want me fuck me lips minds...

  • 夜未眠,梦将醒

    If you want me, show me If you need me, tell me ...

  • 2019 De1CTF Web wp

    0x01 SSRF ME 这题没什么难度,就不多说了,根据代码逻辑构造hash拓展攻击,坑的就是找flag找了半天...

网友评论

      本文标题:De1CTF 2019-WEB-SSRF Me

      本文链接:https://www.haomeiwen.com/subject/rxvxmhtx.html