function merge(target, source) { for (let key in source) { if (key in source && key in target) { merge(target[key], source[key]) } else { target[key] = source[key] } } }
通过我们前面对javscript的原型链污染的学习我们可以知道
这里通过
1
target[key] = source[key]
实现原型链污染
这里就向上篇文章我们学习的那个例子一样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
function merge(target, source) { for (let key in source) { if (key in source && key in target) { merge(target[key], source[key]) } else { target[key] = source[key] } } } let o1 = {} let o2 = JSON.parse('{"a": 1, "__proto__": {"b": 2}}') merge(o1, o2) console.log(o1.a, o1.b)
o3 = {} console.log(o3.b)
分析代码可以看到if里面就是一个递归,else里面就是我们最终要使用的合并函数
我们打一点输出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
function merge(target, source) { for (let key in source) { console.log(key) if (key in source && key in target) { console.log("11111111111") merge(target[key], source[key]) } else { console.log(key) console.log("===========================") target[key] = source[key] } } } let o1 = {} let o2 = JSON.parse('{"a": 1, "__proto__": {"b": 2}}') merge(o1, o2)
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'):#判读dst里面是否存在__getitem__ if dst.get(k) and type(v) == dict:#判断dst中是否存在k键,存在返回对应键值而且判断v的类型是否是一个字典 merge(v, dst.get(k)) #递归运行merge,src=v,dst=dst.get(k) else: dst[k] = v #若dst里面不存在k键则添加到dst里面 elif hasattr(dst, k) and type(v) == dict:#判断dst里面是否存在k,并且判断v的类型是否是一个字典 merge(v, getattr(dst, k)) #执行merge递归,src=v,dst=getattr(dst,k) else: setattr(dst, k, v)#设置对象 dst 中属性名为 k 的属性值为 v。
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
print("sys" in dir(__import__("importlib.__init__"))) #True print("sys" in dir(__import__("importlib._bootstrap"))) #True print("sys" in dir(__import__("importlib._bootstrap_external"))) #True print("sys" in dir(__import__("importlib._common"))) #True print("sys" in dir(__import__("importlib.abc"))) #True print("sys" in dir(__import__("importlib.machinery"))) #True print("sys" in dir(__import__("importlib.metadata"))) #True print("sys" in dir(__import__("importlib.resources"))) #True print("sys" in dir(__import__("importlib.util"))) #True
def evilFunc(arg_1 , shell = False): if not shell: print(arg_1) else: print(__import__("os").popen(arg_1).read())
class cls: def __init__(self): pass
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
def evilFunc(arg_1 , * , shell = False): if not shell: print(arg_1) else: print(__import__("os").popen(arg_1).read())
class cls: def __init__(self): pass
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
class cls(): def __init__(self): pass
instance = cls()
@app.route('/',methods=['POST', 'GET']) def index(): if request.data: merge(json.loads(request.data), instance) return "[+]Config:%s"%(app.config['SECRET_KEY'])
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
class cls(): def __init__(self): pass
instance = cls()
flag = "Is flag here?"
@app.before_first_request def init(): global flag if hasattr(app, "special") and app.special == "U_Polluted_It": flag = open("flag", "rt").read()
@app.route('/',methods=['POST', 'GET']) def index(): if request.data: merge(json.loads(request.data), instance) global flag setattr(app, "special", "U_Polluted_It") return flag
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
class cls(): def __init__(self): pass
instance = cls()
@app.route('/',methods=['POST', 'GET']) def index(): if request.data: merge(json.loads(request.data), instance) return "flag in ./flag but heres only static/index.html"
from flask import Flask,request,render_template import json import os
app = Flask(__name__)
def merge(src, dst): # Recursive merge function for k, v in src.items(): if hasattr(dst, '__getitem__'): if dst.get(k) and type(v) == dict: merge(v, dst.get(k)) else: dst[k] = v elif hasattr(dst, k) and type(v) == dict: merge(v, getattr(dst, k)) else: setattr(dst, k, v)
class cls(): def __init__(self): pass
instance = cls()
@app.route('/',methods=['POST', 'GET']) def index(): if request.data: merge(json.loads(request.data), instance) return "flag in ./flag but u just can use /file to vist ./templates/file"
@app.route("/<path:path>") def render_page(path): if not os.path.exists("templates/" + path): return "not found", 404 return render_template(path)