Beginner - Fruit Basket
- Author: P3g4su5
- Difficulty: Easy
- Description : 🍎🍌🍇🍓🍊🥭🍍🍑🍈🍉
- Attachments : fruit_basket.zip
Writeup
In this challenge you had to exploit the fact that the program uses
srand(time(NULL))
to set theRNG seed
, and since theUNIX time
will be constant for everyone irrespective of local time, you can predict theseed
and predict all the fruits asked by the programAfter sending
50
correct inputs the program will give the shellHere is the decokmpiled program by IDA
The array of fruits can be recoved by using any debugger
fruits = [
"Apple",
"Orange",
"Mango",
"Banana",
"Pineapple",
"Watermelon",
"Guava",
"Kiwi",
"Strawberry",
"Peach"
]
The program is randomly selecting the fruits from the array with
fruits[rand() % 10]
Here is the complete exploit :
from pwn import *
import time
import ctypes
context.log_level = 'debug'
fruits = [
"Apple",
"Orange",
"Mango",
"Banana",
"Pineapple",
"Watermelon",
"Guava",
"Kiwi",
"Strawberry",
"Peach"
]
libc = ctypes.CDLL("/lib/x86_64-linux-gnu/libc.so.6")
p = process('./chal')
libc.srand(int(time.time()))
for i in range(50):
p.sendlineafter("guess : ", (fruits[libc.rand() % 10]).encode())
p.interactive()
- Remember we might have to add
+5
or+6
time delay, due to some error intime.time()