Blue Water CTF 2024 - RSAjail 1/2/3
Challenge
RSAjail 1
1行あたり3文字以下。
RSAjail 2
1行あたり2文字以下。
RSAjail 3
1行あたり1文字以下。
code = input()lines = code.split('\n')
MAX_CHARS = 3 # 2 or 1 for harder versions
for line in lines: if len(line) > MAX_CHARS: print(f"Line too long: {len(line)} > {MAX_CHARS}") exit()
exec(code)Solution
RSAjail 1 (3文字/行)
# 変数を使って文字列を構築a=\"_"b=\"_"# ... 続く継続行 (\) を使用:
x=\1y=\x+\1RSAjail 2 (2文字/行)
# 代入と継続a\=\1RSAjail 3 (1文字/行)
極端に制限された環境では、Unicode 文字や特殊な構文が必要:
# 括弧の継続(\)Technical Details
継続行
バックスラッシュ (\) で行を継続:
x = 1 + \ 2 + \ 3# x = 6括弧内の暗黙的継続
x = ( 1 + 2 + 3)文字列の継続
s = ( "a" "b" "c")# s = "abc"Alternative Solutions
別解1: exec に文字列を渡す
# 最終的に exec("command") を構築e\x\e\c\(\"...")別解2: import の分割
im\po\rt\ o\sAdvanced Technique
変数に1文字ずつ格納して結合:
a\=\"o"b\=\"s"# getattr を使ってアクセスFlag
bwctf{...}
References
- Blue Water CTF 2024 Official
- Python Line Continuation