OverTheWire Bandit CTF Çözümleri

August 29, 2018

 Level 0

The goal of this level is for you to log into the game using SSH. The host to which you need to connect is bandit.labs.overthewire.org, on port 2220. The username is bandit0 and the password is bandit0. Once logged in, go to the Level 1 page to find out how to beat Level 1.

 Çözüm:

Herhangi bir SSH istemcisi ile veya komut satırı aracılığıyla port’u 2220 olarak ayarlayıp bağlanabilirsiniz.

ssh bandit0@bandit.labs.overthewire.org -p 2220

o1

Level 0 -> Level 1

The password for the next level is stored in a file called readme located in the home directory. Use this password to log into bandit1 using SSH. Whenever you find a password for a level, use SSH (on port 2220) to log into that level and continue the game.

Çözüm:

İlk erişimde “ls” ile mevcut ev dizininde listeleme yaptığımıza, “readme” adlı dosyayı görüyoruz, içeriği okuyup parolayı alabilirsiniz. Herhangi bir şifreleme uygulanmamış.

o2

Cevap: boJ9jbbUNNfktd78OOpsqOltutMc3MY1

Parolayı alıp bandit1 kullanıcısıyla yeniden bir SSH bağlantısı kuruyoruz, port yine 2220.

Level 1 -> Level 2

The password for the next level is stored in a file called “-” located in the home directory

Çözüm:

Basit fakat güzel soru. “-” karakterinin kabuk tarafındaki açıklaması, standart input ve standart output’ların çalışma prensibinden dolayı okunabilir bir nesne olarak yorumlanmıyor. “-” veya “-” ile başlayan herhangi bir dosyayı okumak için birden çok yol var.

o3

Cevap: CV1DtqXWVFXTvM2F0k09SHz0YwRINYA9

cat ./-

şeklinde de okuyabilirsiniz.

Level 2 -> Level 3

The password for the next level is stored in a file called spaces in this filename located in the home directory

Çözüm:

Yine birden çok çözüm yolu olan bir problem. En basit hali, dosya adını çift tırnak karakterleri arasına alarak okumak. Adında boşluk karakteri içeren bir dosyayı olduğu gibi yazmanız durumunda, kabuk string ifadeleri ayrı birer nesne olarak kabul eder.

o4

Cevap: UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK

Level 3 -> Level 4

The password for the next level is stored in a hidden file in the inhere directory.

Çözüm:

inhere klasöründe “ls” kullandığımızda herhangi bir dosya/dizin görünmüyor. İlk akla gelen gizli dosya(lar)ın olup olmadığını kontrol etmek. ls’i -a parametresi ile kullandığımızda .hidden dosyasını görüyoruz.

o5

Cevap: pIwrPrtPN36QITSp3EQaw936yaFoFgAB

Level 4 -> Level 5

The password for the next level is stored in the only human-readable file in the inhere directory. Tip: if your terminal is messed up, try the “reset” command.

Çözüm:

İlk dosyayı okumaya çalıştığımda (dikkat edin burada da dosya isimlerinin önünde “-” karakteri mevcut) karakter dizisinin yorumlanmadığını gördüm. Tek tek cat’leyip çözüme gidilebilir fakat burada 10 değil de 1000 dosya olsaydı? :] Basit bir script yazılabilir. Dizinde script oluşturmamıza izin verilmiyor haliyle, o zaman komut satırından ilerleyelim.

o6

for i in {0..9}; do cat — -file0$i; done

komutunu girdiğimde, gelen çıktılardan çözüm kendini gösterdi zaten.

Cevap: koReBOKuIDDepwhWk7jZC0RTdopnAYKh

Level 5 -> Level 6

The password for the next level is stored in a file somewhere under the inhere directory and has all of the following properties:

  • human-readable
  • 1033 bytes in size
  • not executable

Çözüm:

Tek tek girip bakmadım fakat iç içe klasörlerden oluştuğu belli olan bir yapı var. find komutu ile bize verilen boyut ve “çalıştırılamaz” bilgilerini kullanabiliriz.

find . -size 1033c ! -perm -a+x

o7

Cevap: DXjZPULLxYr17uwoI01bNLQbtFemEgo7

Level 6 -> Level 7

The password for the next level is stored somewhere on the server and has all of the following properties:

  • owned by user bandit7
  • owned by group bandit6
  • 33 bytes in size

Çözüm:

Bir önceki sorunun değişik versiyonu. Sadece bu sefer tüm sistemde arama yapmamız gerekiyor.

find / -user bandit7 -group bandit6 -size 33c 2> /dev/null

Çıktıda birçok yetkilendirme hatası olacağı için, stdout ile /dev/null’a yönlendiriyorum.

o8

Cevap: HKBPTKQnIay4Fw76bEy8PVxKEDQRKTzs

Level 7 -> Level 8

The password for the next level is stored in the file data.txt next to the word millionth

Çözüm:

Açıkçası bir an parolanın “millionth” ile bitişik olduğunu düşündüm, lakin bu seviye için biraz zor olabilirdi çözümü, daha basit düşünerek grep’ledim, o kadarmış :)

o9

Cevap: cvX2JJa4CFALtqS87jk27qwqGhBM9plV

Level 8 -> Level 9

The password for the next level is stored in the file data.txt and is the only line of text that occurs only once

Çözüm:

Metin dosyası içerisinden tekrar etmeyen satırı bulmamız gerekiyor. Fantezi seviyorsanız awk ile de çözüme gidebilirsiniz ama sort ve uniq gibi bu tip durumlar için tasarlanmış iki komutumuz varken ne gerek var değil mi?

cat data.txt | sort | uniq -u

Fantezi:

awk ‘{!get[$0]++}; END{for(i in get) if(get[i]==1)print i}’ data.txt

o10

Cevap: UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhR

Level 9 -> Level 10

The password for the next level is stored in the file data.txt in one of the few human-readable strings, beginning with several ‘=’ characters.

Çözüm:

Bir önceki sorunun değişik versiyonu diyerek bu sefer grep parametresini değiştiriyoruz fakat o da ne, soruda yazdığı gibi dosyanın tamamı okunabilir formatta değilmiş. Ne yapıyoruz, en basitinden sistemcinin dostu, reverse’cünün isviçre çakısı olmasa da kelebek bıçağı diyebileceğimiz “strings” komutunu kullanıyoruz.

strings data.txt | grep “=”

o11

Cevap: truKLdjsbJ5g7yyJ2X2R0o3a5HQJFuLk

Level 10 -> Level 11

The password for the next level is stored in the file data.txt, which contains base64 encoded data

Çözüm:

Özellikle CTF’lere yeni başlayan acemilerin sıklıkla karşılaşacağı o şirin encoding: base64

Online decode edebilirsiniz fakat lüzum yok.

cat data.txt | base64 — decode

o12

Cevap: IFukwKGsFW8MOq3IRFqrxE1hxTNEbUPR

Level 11 -> Level 12

The password for the next level is stored in the file data.txt, where all lowercase (a-z) and uppercase (A-Z) letters have been rotated by 13 positions

Çözüm:

Yine bir CTF klasiği diyebileceğimiz Sezar şifreleme karşımıza çıktı, namıdiğer ROT13. Bir önceki soruda olduğu gibi bunda da online servislerden yararlanmak yerine bash’in nimetlerinden yararlanmakta fayda var.

cat data.txt | tr ‘A-Za-z’ ‘N-ZA-Mn-za-m’

o13

Cevap: 5Te8Y4drgCRfCx8ugdwuEX8KFC6k2EUu

Level 12 -> Level 13

The password for the next level is stored in the file data.txt, which is a hexdump of a file that has been repeatedly compressed. For this level it may be useful to create a directory under /tmp in which you can work using mkdir. For example: mkdir /tmp/myname123. Then copy the datafile using cp, and rename it using mv (read the manpages!)

Çözüm:

Bu soruda bilinmesi gereken; hexdump’dan reverse alabilmek için xxd kullanmak ve sıkıştırma / arşivleme araçlarının decompress parametreleri.

o14

o15

o16

Cevap: 8ZjyCRiBWFYkneahHwxCv3wb2a1ORpYL

İşlemleri kısaltmak adına script de yazılabilir. Üşenmediğim bir ara onu da eklerim buraya.

Level 13 -> Level 14

The password for the next level is stored in /etc/bandit_pass/bandit14 and can only be read by user bandit14. For this level, you don’t get the next password, but you get a private SSH key that can be used to log into the next level. Note: localhost is a hostname that refers to the machine you are working on

Çözüm:

Local’e bandit14 kullanıcısı ile gidip dosyayı okumamız lazım. Elimizde parola yok fakat private key mevcut, tek yapmak gereken doğru SSH komutunu yazmak. ssh bandit14@localhost -i sshkey.private ‘cat /etc/bandit_pass/bandit14’

o17

Cevap: 4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e

Level 14 -> Level 15

The password for the next level can be retrieved by submitting the password of the current level to port 30000 on localhost.

Çözüm:

Bu aşamada kullanılabilecek komutlar arasında openssl ve nc’i görünce aslında başka şeyler belirdi aklımda ama soru çok açık olduğu için, ilk olarak en basit yolu denedim ve cevap geldi. 30000 port’una telnet ile gitmeniz yeterli.

o18

Cevap: BfMYroe26WYalil77FoDi9qh59eK5xNr

Level 15 -> Level 16

The password for the next level can be retrieved by submitting the password of the current level to port 30001 on localhost using SSL encryption. Helpful note: Getting “HEARTBEATING” and “Read R BLOCK”? Use -ign_eof and read the “CONNECTED COMMANDS” section in the manpage. Next to ‘R’ and ‘Q’, the ‘B’ command also works in this version of that command…

Çözüm:

İşin rengi değişmeye başlıyor hafiften :]

Aslında bir önceki sorudan tek farkı, bu sefer SSL ile gitmemiz gerekiyor. igneof’u zaten vermiş, sclient komutu ile kullanıldığında EOF’u engelleyerek bağlantının sonlanmasını engelliyor. İlk olarak igneof olmadan denediğimde parolayı girsem dahi input’u alamadım. Peki biz de öyle deneyelim. openssl sclient -ign_eof -connect localhost:30001

o19

Cevap: cluFn7wTiGryunymYOu4RcffSxQluehd

Level 16 -> Level 17

The credentials for the next level can be retrieved by submitting the password of the current level to a port on localhost in the range 31000 to 32000. First find out which of these ports have a server listening on them. Then find out which of those speak SSL and which don’t. There is only 1 server that will give the next credentials, the others will simply send back to you whatever you send to it.

Çözüm:

Güzel bir soru daha. 31000–32000 arasındaki açık portları Nmap ile taratıp direkt port numaralarını aldım.

nmap -p 31000–32000 localhost | grep tcp | awk -F “/” ‘{print $1}’

Geriye openssl ile port’lara tek tek gidip kontrol etmesi kaldı.

o20

31790 port’unda anahtarı yakaladım. Yine bir önceki aşamasının parolasını girdiğimde private key içeriği döndü.

o21

Anahtarı oluşturduktan sonra bağlanamadım, zira yetki doğru bir şekilde ayarlanmadığı için hata döndü haliyle. chmod 600 ile değiştirdikten sonra makineye bağlanabilirsiniz.

o22

Yine bir önceki sorudaki gibi /etc altında bandit17’ye ait olan dosyayı okuyoruz, bu kadar.

o23

Cevap: xLYVMN9WE5zQ5vHacb0sZEVqbrp7nBTn

Level 17 -> Level 18

There are 2 files in the homedirectory: passwords.old and passwords.new. The password for the next level is in passwords.new and is the only line that has been changed betweenpasswords.old and passwords.new

NOTE: if you have solved this level and see ‘Byebye!’ when trying to log into bandit18, this is related to the next level, bandit19

Çözüm:

Çok uzatmaya gerek yok, soru “diff” diye bağırıyor^^

diff passwords.old passwords.new

o24

Cevap: kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd

Level 18 -> Level 19

The password for the next level is stored in a file readme in the homedirectory. Unfortunately, someone has modified .bashrc to log you out when you log in with SSH.

Çözüm:

SSH ile login olduğunuz gibi session kill ediliyor, çünkü .bashrc üzerinde oynama yapılmış. Düşünce güzel, muhtemelen 18. seviye için beklenen benimkinden farklı bir çözümdür ama bizim olayımız pratik olmak değil midir sayın okuyucu? ssh bandit18@bandit.labs.overthewire.org -p 2220 ‘cat /home/bandit18/readme’

o25

Bu çözüm haricinde -T parametresi ile pty engellemesi yapılarak yine çözüme gidilebilir.

ssh -T bandit18@bandit.labs.overthewire.org -p 2220 /bin/bash

o26

Cevap: IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x

Level 19 -> Level 20

To gain access to the next level, you should use the setuid binary in the homedirectory. Execute it without arguments to find out how to use it. The password for this level can be found in the usual place (/etc/bandit_pass), after you have used the setuid binary.

Çözüm:

Hedef dosyada SUID bit olduğunu görüyoruz. İlk olarak SUID bit yetkisini almayı denedim beyhude bir çaba olacağını bile bile, yemedi tabi. Kullanıcı id’lerinin standart bir iterasyonla gittiğini gördüğüm için, dosya direktifindeki gibi bandit20 için 11020 id’sini verdim, o da olmadı. Önceki sorularda işimizi gören /etc/bandit_pass dizinini kurcaladım. Nitekim bandit20’ye ait olan dosya argüman olarak verildiğinde parolayı vermiş oldu.

o27

Cevap: GbKksEFF4yrVs6il55v6gwY5aVje5f0j

Level 20 -> Level 21

There is a setuid binary in the homedirectory that does the following: it makes a connection to localhost on the port you specify as a commandline argument. It then reads a line of text from the connection and compares it to the password in the previous level (bandit20). If the password is correct, it will transmit the password for the next level (bandit21).

NOTE: Try connecting to your own network daemon to see if it works as you think

Çözüm:

Benzer bir soru ile adını şu an hatırlayamadığım bir CTF’te karşılaşmıştım. Yine birden çok çözüm yolu var aslında. Öncelikle makinedeki port’ları kontrol edelim.

o28

suconnect dosyasını çalıştırdığımızda bize verilen bilgiye göre, listener olarak çalışacak bir port, önceki aşamadaki parolayı input olarak alıp nc ile client’tan gelecek isteği beklemeli. Pekalâ,

o29

Çeşitli yollar denesem de yetkilendirme hatasını gideremedim, /dev/tcp’de de sonuç alamadım. Kullanılabilir araçlarda nc zaten yazıyor, karşı taraftan kaynaklı bir problem var gibi geldi. Ta ki “olm neden tek port deniyorsun ki?” sorusunu sorana kadar…

echo “GbKksEFF4yrVs6il55v6gwY5aVje5f0j” | nc -l 7641 &

Bundan sonra ister ikinci bir terminal üzerinden client/server modeli gibi davranıp istek atarsınız ki buna da gerek yok, örnekte 7641 port’u için açtığım listener prosesini arka plana attım, bizden beklenen suconnect’i çalıştırırken listener port’una gitmek, bu kadar.

o30

Cevap: gE269g2h3mw3pwgrj0Ha9Uoqen1c9DGr

Level 21 -> Level 22

A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.

Çözüm:

crontab -l

ile kontrol etmek istediğimizde yetkimizin olmadığını görüyoruz.

o31

/etc/cron.d dizinini bir kurcalayalım.

o32

cronjob_bandi22.sh script’i ilgi çekici.

o33

/tmp altında t706… dosyasına uygun yetkiler verilerek, /etc/bandit_pass/bandit22 içeriği bu dosyaya aktarılmış, niyeti belli oldu, tek kalan dosyayı okumak.

Cevap: Yk7owGAcWjwMVRwrTesJEwB7WVOiILLI

Level 22 -> Level 23

A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.

NOTE: Looking at shell scripts written by other people is a very useful skill. The script for this level is intentionally made easy to read. If you are having problems understanding what it does, try executing it to see the debug information it prints.

Çözüm:

Bir önceki sorudaki gibi /etc/cron.d altında cronjob_bandit23.sh dosyasının içeriğini okuyoruz.

o34

myname=$(whoami)
mytarget=$(echo I am user $myname | md5sum | cut -d ‘ ‘ -f 1)
echo “Copying passwordfile /etc/bandit_pass/$myname to /tmp/$mytarget”
cat /etc/bandit_pass/$myname > /tmp/$mytarget

whoami, command substution olarak myname’e atanmış, bu durumda myname=bandit22 oluyor. Çalıştırıp kontrol edelim.

o35

İkinci satır kafa karıştırmak için yazılmış, olayı sadece /tmp altında parolanın aktarılacağı dosya adını kullanıcının md5 checksum’ına eşitlemek. O halde script üzerinde whoami tarafına müdahale ederek yeniden çalıştıralım.

o36

Cevap: jc1udXuA1tiHqjIsL8yaapX5XIAI6i0n

Level 23 -> Level 24

A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.

NOTE: This level requires you to create your own first shell-script. This is a very big step and you should be proud of yourself when you beat this level! NOTE 2: Keep in mind that your shell script is removed once executed, so you may want to keep a copy around…

Çözüm:

o37

Script aşamaları kabaca şu şekilde:

  • Mevcut kullanıcı adını myname parametresine eşitle, bir önceki soruda olduğu gibi.
  • /var/spool/$myname dizininde bütün dosya ve dizinleri döngüye al.
  • Dosya veya dizinin “.” veya “..” karakteriyle başlayıp başlamadığını kontrol ederek idle’a al.
  • Bu karakterlerle başlamıyorsa script’i kill etmeden önce 60 saniye çalıştır.
  • tmp altında basit bir script oluşturalım.

o38

Script içeriği:

cat /etc/bandit_pass/bandit24 > /tmp/pass1/x

o39

Yetkileri vererek script’i /var/spool/bandit24 dizini altına aldım ve döngü ile beklemeye koyuldum. Parola geldi.

o40

Cevap: UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ

Level 24 -> Level 25

A daemon is listening on port 30002 and will give you the password for bandit25 if given the password for bandit24 and a secret numeric 4-digit pincode. There is no way to retrieve the pincode except by going through all of the 10000 combinations, called brute-forcing.

Çözüm:

Brute-force, en sevdiğim :3

o41

Rastgele hatalı bir PIN ile 30002 port’unu dinlediğimizde, resimdeki gibi bir çıktıyla karşılaşıyoruz. Basit bir script işimizi görecektir.

o42

Script:

x=”UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ”
for i in {1000..10000}
do {
if
echo $x $i| nc localhost 30002 | grep -i “wrong” > /dev/null
then
echo $i >> letmein
else
echo $x $i| nc localhost 30002
exit
fi
}
done

gotcha!

o43

Cevap: uNG9O58gUE7snukf3bvZ0rxhtnjzSGzG

Level 25 -> Level 26

Logging in to bandit26 from bandit25 should be fairly easy… The shell for user bandit26 is not /bin/bash, but something else. Find out what it is, how it works and how to break out of it.

Çözüm:

Bu soru hoşuma gitti, özgün olmuş.

ssh -i bandit26.sshkey bandit26@localhost

dediğimizde bağlantı kurulduğu gibi sunucudan düşüyoruz. Bunun birden çok sebebi olabilir fakat SSH konfigürasyonuna müdahale ettirmeyecekleri için, alternatif düşünelim, bakalım bandit26’nın varsayılan kabuğunu görebiliyor muyuz:

o44

Soru kendini belli etti. Shell olarak atanan dosyayı okuyalım:

o45

ssh -i bandit26.sshkey bandit26@localhost ‘cat ~/text.txt’

Denedim, yemedi. Peki, gördüğümüz kadarıyla burada verilen ipucu “more”, akla gelmesi gereken ki başta ben düşünmemiştim buradan çıkacağını, text.txt’yi okurken bir şekilde prosesi sonlandırmadan müdahale etmemiz gerekli.

Terminal ekranını küçültüp tekrar SSH’la gidelim.

o46

Taşlar yerine oturmaya başladı^^

Şimdi yapmamız gereken, önceki sorularda olduğu gibi /etc/bandit_pass/ altında bulunan bandit26 dosyasını session’ı düşürmeden görüntülemek:

o47

vi editör’e geçip oturumu düşürmeden dosyayı okuyoruz ve bingo:

o48

Şu ana kadar en beğendiğim soru bu oldu.

Cevap: 5czgV9L3Xx8JPOyRbXh6lQbmIOWvPT6Z

Level 26 -> Level 27

Good job getting a shell! Now hurry and grab the password for bandit27!

Çözüm:

Böyle kısa sorular genelde CTF’lerin en zıpırlarından olur. İpucu olarak “ls” verilmiş ve bir önceki sorudaki gibi elimizde yine vi editor var. Önce eski bir kullanıcıdan /etc/passwd kontrolü yaptım, bandit27-git adında bir kullanıcı olduğunu gördüm, fakat asıl kullanıcının kabuğu normaldi.

Önce basit komutları çalıştırmak için bash set edelim:

:set shell=/bin/bash

Artık “ls” ile görüntüleme yaptığımızda “bandit27-do” adlı dosyayı görüyoruz. Burada terminalde “escape” metodu uygulamak için komutları :! şeklinde girmemiz gerekiyor.

:!cat bandit27-do

dediğimde yine strip edilmiş bir dosya ile karşılaştım. Önceki soruların birinde benzer bir dosya vardı. /etc/bandit_pass/bandit27 dosyasını bununla okumayı denedim:

o49

Cevap: 3ba3118a22e93127a4ed485be72ef5ea

Level 27 -> Level 28

There is a git repository at ssh://bandit27-git@localhost/home/bandit27-git/repo. The password for the user bandit27-git is the same as for the user bandit27. Clone the repository and find the password for the next level.

Çözüm:

Yine bazı CTF’lerde git ile ilgili sorularla karşılaşmıştım. Bir önceki sorudaki bandit27-git kullanıcısı demek ki bu soru içinmiş. İnceleyelim.

o50

Gayet basit bir soru gördüğünüz gibi. Ev dizininde clone işlemine izin verilmedi. /tmp dizini altında aynı işlemi uyguladım, repo’daki README dosyasını okudum, bu kadar.

Cevap: 0ef186ac70e04ea33b4c1853d2526fa2

Level 28 -> Level 29

There is a git repository at ssh://bandit28-git@localhost/home/bandit28-git/repo. The password for the user bandit28-git is the same as for the user bandit28.

Clone the repository and find the password for the next level.

Çözüm:

Bir önceki sorudaki gibi yine repo’yu çekiyoruz. Bu sefer README dosyasında parolanın asıl halini göremiyoruz.

o51

Daha önce aynı bu mantıkta olan bir soruyla karşılaşmıştım.

git log

ile geçmiş commit vb. işlemleri görüntüleyelim:

o52

commit id’leri checkout yapalım:

o53

Bingo.

Cevap: bbc96594b4e001778eee9975372716b2

Level 29 -> Level 30

There is a git repository at ssh://bandit29-git@localhost/home/bandit29-git/repo. The password for the user bandit29-git is the same as for the user bandit29. Clone the repository and find the password for the next level.

Çözüm:

Önceki sorular gibi başlayalım.

o54

Bu sefer checkout’larda username’in değiştiğini gördüm. .git içerisindeki packed-refs dosyasına baktığımda 3 commit id daha gördüm fakat değişikliklerin olduğu branch farklıydı.

Sırasıyla checkout yaptığımda herhangi bir değişiklik olmadığını gördüm. O yüzden id’leri sırayla girip README dosyasını kontrol ettim:

o55

Cevap: 5b90576bedb2cc04c86a9e924ce42faf

Kalan 4 soruyu da bir ara eklerim.



Written by Deniz Parlak