Attack All Around

今やCTFと競プロばかりだが、トビタテ生のアメリカ留学やTOEFL奮闘記

Red Team Lounge CTF 2021 writeup

最近、m1z0r3では週末に開催されているCTF全てに参加する方法を取っています。目指せ国内順位1桁



Result


f:id:partender810:20210803180706p:plain
Ranking

f:id:partender810:20210803180807p:plain
Stats


Writeup



Web


Basic 10pts

This is a really basic challenge made by gamerboy
http://139.59.252.147:10705/

アクセスするとusernameとpasswordを求められます。SQL injectionですね。初めて上手くいきました。

Username : admin
Password : ' OR 1 = 1 --

f:id:partender810:20210803181149p:plain
ログイン成功!


RTL{b@s1c_5ql}



Forensics


Expic 15pts

ex.zip - Google ドライブ

zipを解凍するとphotoというファイルがあります。fileコマンドで中身を確認します。

$ file photo
photo: JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72, segment length 16, progressive, precision 8, 1000x667, frames 3

JPEGファイルであることが分かったので、

$ mv photo photo.jpeg

で拡張子を変えます。

f:id:partender810:20210803181515j:plain
photo.jpeg

steghideとかstegonlineなので見ましたがよく分からず。exiftoolで怪しげな数値を発見。

$ exiftool photo.jpeg
ExifTool Version Number         : 10.80
File Name                       : photo.jpeg

(中略)

Author                          : p4ul
Number                          : 68747470733a2f2f706173746562696e2e636f6d2f514632557a6a56590a
Profile CMM Type                : Linotronic

(中略)

とりあえずこの数値をlong_to_bytesしてみます。

>>> from Crypto.Util.number import *
>>> x = 0x68747470733a2f2f706173746562696e2e636f6d2f514632557a6a56590a
>>> long_to_bytes(x)
b'https://pastebin.com/QF2UzjVY\n'

URLが出てきたので方向性は間違っていないと確信。アクセスしてみるとこのような文字列がありました。

T0tLIApSVEx7MTBiYmE5YTUyNDE3MDk1ZGU1MWRiOTQ1NjM2MWQ3NDR9Cg==

base64ですね。


RTL{10bba9a52417095de51db9456361d744}



OSINT


Where is this? 40pts

Thehackerscrew have sent this image. Can you find where this is?
Flag format: RTL{latitude_longitude} Round latitude and longitude to 3 decimal places. (Decimal degrees)
ファイル:where.png

f:id:partender810:20210803182035p:plain
where.png

中央の大きなタワーと、その左の旗のようなものが立っているのが鍵になりそうです。見た目がヨーロッパっぽいですね。

「世界 有名なタワー」でググると以下のサイトを発見

【2021最新】ヨーロッパの人気展望台・タワーランキングTOP30 | RETRIP[リトリップ]

パラパラと見ていると、Berliner Fernsehturmが似ているのでGoogle mapで検索。ベルリンのテレビ塔でした。近くを見てみると、赤の市庁舎が旗が立っている建物のよう。

あとは、テレビ塔と旗の角度から南に少し行った道路のところで調整して座標を確定。flagを出したら「既に解かれている」との表示。slack見たら数分先にチームメイトに解かれていました悔しい!


RTL{52.517_13.409}



Reversing


Bad Developers 10pts

A bad developer made this key verification algorithm in Python, he doesn't believe me that it can be cracked, can you show him the way?
https://pastebin.com/4qLbCkQn

a = "LTR"
b = "0D"
c = "S1"
 
inp = input("> ")
 
if len(inp) != 17:
    print("Wrong size.")
    exit()
 
if (inp[0] == a[2] and inp[1] == a[1] and inp[2] == a[0]) and inp[3] == "{" and \
   ((inp[4] + inp[5]) == b[::-1]) and (inp[6] == "N" and inp[7] == "T" and inp[8] == chr(95)) and \
   (inp[9] + inp[10] == b[::-1]) and (inp[11] + inp[12] + inp[13] == "_TH") and (inp[14] + inp[15] == c[::-1]) and \
   (inp[16] == "}"):
    print("Good job.")
else:
    print("Flag is incorrect.")

if文に合致するように文字列を繋げるだけですね。


RTL{D0NT_D0_TH1S}



The gate of ultimate success 50pts

This binary will ask you for a key, which will open the ultimate gate of success. The key should be wrapped inside RTL{}.
Download link: we_start_with_basics.exe - Google ドライブ

exeファイルを入手したので、実行すると文字列を入力しろと言われます。ある文字列を入力するとflagが出るようです。Ghidraを使って分析してみます。

f:id:partender810:20210803183731p:plain
main関数をデコンパイルしたやつ

文字列"'/5:/)4+62/(46>):(82(:9'"を0x7bでxorした値が求められているflagのよう。'TNATROPMITSOMERASCISAB'と出て入力してみるも違うと言われる。

なんでだろうとチームメイトに聞いてみると、strrevを見落としていました。逆順にすればいいだけでした。出てきた文字列に"SOME"があるので、方法が間違っていないとなかなか抜け出せなかったです。逆順にした文字列を入力すると、この文字列がflagのようです。


RTL{BASICSAREMOSTIMPORTANT}



Crypto


Welcome 5pts

This is a really easy challenge. It's purpose is to get you familiar with the platform.
UlRMe0g0VkVfRlVOX1BMNFkxTkchfQ==

base64ですね。


RTL{H4VE_FUN_PL4Y1NG!}



Triangle 10pts

My friend encoded the flag with XOR but forgot the key! He remembers that its a 4 byte key. Can you recover the flag?
133f29027034094a33253126395b3704

4bytesのkeyでxorしたとあります。flagの先頭4bytesがb"RTL{"というのが分かっているので、b"RTL{"と暗号文の先頭4bytesをxorしてkeyを特定します。

keyを特定したら残りの暗号文とxorしてflag全てを出します。

enc = "133f29027034094a33253126395b3704"
key = []
flag = "RTL{"
for i in range(0,8,2):
    key.append(int(enc[i:i+2],16)^ord(flag[i//2]))
print(key)
for i in range(0,len(enc),2):
    x = int(enc[i:i+2],16)^key[(i//2)%4]
    print(chr(x),end="")
print()


RTL{1_l3rNT_x0R}



Wait, what! 20pts

My mom stole my phone and encrypted it, she doesn't know much about cryptography.
NBY{9x175777156k5608n3x889n5nx9215n2}
Hint : The ................................ is a method of encrypting alphabetic text by using a series of interwoven Caesar ciphers, based on the letters of a keyword. It employs a form of polyalphabetic substitution.

ROT13でもないな、flag内は恐らく16進数だろうから現れているアルファベット3種類k,n,xがa~fになるんだろうという推測で止まってしまいました。
ヒントが5pts消費しないと見れないのですが、思い切って見ることに。

Vigenere暗号か!!!

CyberChefで先頭3文字がRTLになるようにkeyを調整したらflagの括弧内が16進数になりました。

問題文に騙されました。暗号をよく知らないお母さんが暗号化したとあるので超簡単な方法かと思ったら、Vigenere暗号ってめっちゃ詳しいやん!!


RTL{9b175777156c5608a3b889f5ab9215f2}



Ciphers Galores 40pts

The hackers from Thehackerscrew have been sending encrypted messages to each other. We have intercepted this code from them: hastebin
Looks like it’s up to you to solve this mystery. Can you find out what this message says?

$&Es6a@I+v5;|`h_$)q?2Kq75w=p|%tK+)8K)K}d!b_l

この文字列見ただけじゃあ、全然わからないです。base85かなと思いましたがdecodeしても意味のある文字列になりません。そういう時はdcodeで暗号方式を特定してもらいましょう。

Decrypt a Message - Cipher Identifier - Online Code Recognizer

一番最初にBase91がありますが、試しても違うよう。ではその次に出てくるROT47を試したら、次に繋がりそうです。

SUtDe2oxZGdjM190SXBnazBfdHlAMTEzZXgzXzN5P30=

これは明らかにbase64ですね。

IKC{j1dgc3_tIpgk0_ty@113ex3_3y?}

あとはROT[1~25]を試して"RTL{"から始まるものを探したところ、ROT9でした。


RTL{s1mpl3_cRypt0_ch@113ng3_3h?}



Last Words 50pts

My friend told me his father died and his father had a last message for me, but it was in this weird format. Can you help me out?
hastebin

n = p3RSA暗号です。factorDBなどで素因数分解可能です。

from Crypto.Util.number import *

n=(中略)
e=65537
ct=(中略)
p = (中略)

assert p**3 == n
assert isPrime(p)
phi = (p-1)*p*p
d = inverse(e,phi)
m = pow(ct,d,n)
print(long_to_bytes(m))


RTL{1_c0uld_pr0b4bly_m4k3_th15_al0t_h4rd3r_next_t1m3!!!-e82fac7a780f72579c47b6ce0d5b7fd82eb6192ed65949ca485309b5}



Diffie Hellman 100pts

Alice and Bob are communicating through a encrypted channel. To be more secure they exchange keys first and then exchange messages. Can you crack the message to find out the flag.
IP: 139.59.252.147 PORT: 19012

ncするとこんな感じになります。

$ nc 139.59.252.147 19012
g:5
p:23
Send your public message to BOB.Intercepted Alice's message: 4
1
Send your public message to ALICE.Intercepted Bob's message: 10
1
The message is encrypted.Bob sends message:SUMz5b6e839g472687gcd1e4g0e185b259c4|

Diffie-Hellmanというので、ga mod pなのでしょう。BobとAliceにメッセージを送れるらしいのですが、最後に貰える暗号文はBobに送るメッセージの値に依存しているようです。そこで1をBobに送るとflagっぽい形のが送られます。

結果的に暗号文のASCIIコードが奇数は-1, 偶数は+1すればflagになります。

Diffie-Hellman要素が無かったけど、何を求められているんだろう。


RTL{4c7d928f563796fbe0d5f1d094c348b5}



Unsolved


Crypto


Prime Wars 100pts

There's a battle between Good and Evil and the Evil empires messaging system is not fully functioning. We've intercepted their message they had to send twice.
hastebin Hint : There's something you should combine!

n1, n2が互いに素でないので、gcdとれば簡単に素因数分解できます。しかし復号しても意味ある文字列になりません。

b';\xd7\x11\xf2@\x17J\xa2<\x11\xf7\x13\xefw\xd8\xdd\x82A\xf8o4\xa5h\x07x\xa4\x1e/z\xd0\xf8;Tf<\xdd\xb3N\xe58\xd8\x06r\x1d\xc3\xe9>\xa1\x10of{Z\x06\xb2\xf3'
b'`\xd0\xa3s(>\x16\x94\x11u?\xa7~\xa2\xc5\xba\xd3\x04\xf9\x1c\x9c\x0e\x9a\xc9y\x02\xe3\x8c\xab\x9f\xad\x95\x0e@\x92\x08@\x11[\xb2b05b3bdd39da3e5}'

ただ、長さがともに56で、暗号文の値が1でも違うと長さが512になることから復号自体は間違っておらず、平文を暗号化する際に何か違う値をRSAで暗号化しているのかなと予想しています。
2個目の復号文の下位16bytesがflagっぽいので、ここから何かわからないかと思いましたが、ヒントを見てもピンと来ずタイムアップ。

CTF-Write-UP/Crypto/RTLXHA2021 - Prime Wars at master · MOCSCTF/CTF-Write-UP · GitHub

復号値をm1, m2とすると

flag = int(str(m1)+str(m2))
print(long_to_bytes(flag))
#RTL{th3r3_pr1m35_4nd_0pt1m4l_pr1m35_wh1ch_do_y0u_u53??-a1b8f0d453def3be67ebf3a313550f73e76951672b05b3bdd39da3e5}

だそうです。combineはそういうことか。

うーーーーん、m1,m2まで簡単に求められて思いつかない方が悪いのか、問題がエスパー要素強すぎるのか…。



Problems&solver


GitHub - ksbowler/Red_Team_Lounge_CTF