Skip to main content

Write up KKSI PWN 1, pwn perjuangan (ง ͠° ͟ل͜ ͡°)ง (day 33)

 Image result for mantab meme
 

KKSI adalah ajang kompetesi CTF Indonesia yang bertujuan untuk menjalin Komunikasi sosial antara TNI, khususnya TNI AD dengan Masyarakat umum di era digital. Karena saya sekarang lagi tidak ada Indonesia untuk studi master S2, jadi ga bisa ikut perlombaannya yang menurut saya sayang sekali. Tapi untung ada temen yang coba bagi beberapa soal reverse engineering dan PWN untuk saya coba.

Oleh karena itu saya coba pingin bikin write up untuk dua kategori ini agar semua teman-teman yang belom berhasil mengerjakan soalnya bisa dapat pencerahan. Tapi dimulai dari yang mudah dulu yah !

Ayo! kita bahas soal PWN 1 yang dikasih binari pwn_perjuangan

Pertama-tama, kita masukan file binari nya ke GDB dan coba cek mekanisme keamanan apa yang ada di dalamnya.

Hmmm! kalau diliat dari hasilnya program nya cukup aman karena ada beberapa keamanan yang dipakai seperti

  • NX (non-executable) berarti kita ga bisa melakukan eksekusi kode di dalam stack dengan shellcode 
  •  PIE (Position Independent Executable) berarti alamat memori di dalam program selalu acak jadi makin sulit untuk membuat shellcode juga.
 


biar lebih ngerti dengan mekanisme kodenya coba dimasukin ke ghidra yang merupakan alat decompiler jadi kita bisa analisa source codenya.


setelah di analisa sama ghidra coba kita liat isi dari fungsi yang ada didalam program. Saat dicari ga ada fungsi main yang bisa dipakai untuk titik mulai analisa. Jadi gimana selanjutnya ?

tips nya jadi gini, kan kita pingin cari di bagian kode mana sih yang punya fungsi menarik yang memberikan petunjuk buat dapatin flagnya nih. Kalau kita analisa dari program setiap kali kita kontak dia selalu keluarin string "Give me the number" kan ?

pasti buat ngeluarin string nya kan pake fungsi "prinft" oleh karena itu kita coba "cross reference" function printf biar tahu ini function di panggil di function mana lagi sih.

caranya cross reference di ghidra gmana ?

klik kana function abis itu pilih "show reference to"


nah kita dapat nih fungsi yang punya petunjuk tentang flag nya (coba baca2 dulu function decompilenya)

oke coba kita telaah source code nya

jadi mekanisme programnya kan minta kita nebak nomor kan ? dan ternyata nomor yang kita harus tebak di buat dari nomor random






dan input kita dibandingkan dengan hasil penghitungan randomnya. Bisa dilihat kalau input kita itu dimasukin ke function atoi() yang berati input kita akan diubah ke tipe integer.

int atoi(const char *str); https://en.wikibooks.org/wiki/C_Programming/stdlib.h/atoi

dan input dibandingkan (ivar1 + ivar2) - ivar3 yang 3 variable ini dibuat dari random.




disaat ini saya bingung gimana caranya kita nebak angka acak, oke coba kita teliti bagian randomnya lagi


function srand() itu diisi parameter 1, function ini dipakai untuk "seeding" agar bisa melakukan inisialisai pseurandom angka acak tapi karena cuma diisi satu angka acak nya akan sama terus. Kelemahan ini adalah  Random Number Vulnerability disebabkan karena angka tidak diacak dengan benar kita dapat menebaknya.

link: http://www.tech-faq.com/random-number-vulnerability.html



oke saya coba bikin program yang mirip dengan source code binary yang dikasih kita dapat hasilnya 969527492


saya coba jalankan di mesin yang lain dan ternyata hasilnya sama, coba kita masukin nomonya di binarynya






oke mantab! dapat sekian write up dari saya :D


Comments

Popular posts from this blog

Having fun analyzing nginx log to find malicious attacker in the net (ง'̀-'́)ง (day 37)

  What makes you sleepless at night? is it because of a ghost or scary stories? is it because you have an important meeting tomorrow? or is it because you have an exam? For me, what keeps me up all night is that I keep thinking about what happens to a website that I just created, is it safe from an attacker (certainly not) or did I missing some security adjustments that lead to vulnerability? well I'm not the best secure programmer in the world, I'm still learning and there is a big possibility that I can make a mistake but for me, a mistake can be a valuable investment to myself or yourself to be better so from this idea, I want to know more about what attackers casually do when attacking a website. Here in this post, I'm going to show you how I analyzed attack to the website that I have permission to design and also some interesting findings that I could get from the analysis Background: All of this analysis comes from the traffic that is targeted to th...

Utilize Pwntools for crafting ROP chain :') (day 69)

who doesn't like pwntools? it is a very versatile tool and can be customized according to our need using the python script but did you need to know that pwntools itself can help us to automatically craft a rop chain for us? so in this post, I will show you how to make rop chain less painful and make pwntools do all the heavy lifting. To demonstrate this I will use the binary challenge callme 64 bit from ropemporium link: https://ropemporium.com/challenge/callme.html Crashing the app: Like any other exploitation process, we need to crash the program by generating a long string pattern to determine the offset. based on the information from the above figure we can see that we required to provide 40 bytes of offset Fun stuff: now this where the fun stuff began write the following python script: as in the guideline of the challenged said we need to chain the function call by first to call the callme_one function, callme_two function and then callme_three funct...

Bypassing stack canaries protection :') (day 51)

In my previous blogs, I show you guys how to bypass some common protection usually used in Linux binary such as NX and ASLR but this time we are going to take it to the next level we are going to talk about protection employ in the modern Linux OS which is "The Canaries" and how to bypass it. note: this post was not originally mined it was inspired by the following resources https://ctf-wiki.github.io/ctf-wiki/pwn/linux/mitigation/canary/ (Credit goes to the author) we are going to start this post about what is stack canaries and types of different implementation of it then move to the implementation about how to bypass this protection. We are going to focus on "leak canaries" technique What is stack canary: In layman terms, canaries are just another protection mechanism to prevent stack overflow implemented by appending 4/8 bytes value (depend on the architecture) into the stack when a function is entered. When the function is at the end of its exec...