0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Alpaca Hack : write up】SwapSwap

Posted at

Writeup: SwapSwap

2 回入れ替えればもとに戻る… よね?

1. 問題のソースコード

import os

flag = os.environ.get("FLAG", "Alpaca{*** REDACTED ***}")

inp = input("> ")

# This must be true, isn't it?
if inp == inp.swapcase().swapcase():
    print("Check passed!")
else:
    print("Check failed - !?")
    print("Here is your flag:", flag)

問題を見ると

if inp == inp.swapcase().swapcase():
    print("Check passed!")

ここでは「ユーザーの入力したもの」と「ユーザーの入力したものを2回 swapcase()を行ったもの」が一致した場合、Check passed!としていて

else:
    print("Check failed - !?")
    print("Here is your flag:", flag)

次に、else の時に flag を出すようにしている。

2. 解法・解説

問題のコードにより、swapcase()を2回しても一致させないようなものをユーザー入力として送ればいい。

swapcase()とは文字列内の大文字を小文字に、小文字を大文字に入れ替えるメソッドである。

そのようなものであげられるものがトルコ語やドイツ語の「İstanbul の"İ"」や「Groß の"ß"」がある。

これらを踏まえて入力すると。

nc 34.170.146.252 54861
> İ
Check failed - !?
Here is your flag: Alpaca{*****}

となりフラグが取得できる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?