S4CTF 2021: ninidibi

ninidibi

Category: misc

110 points

let’s shuffle it!

File: ninidibi

Solution

Given file is actually SQLite database without the header. I’ve quickfixed it with below.

echo -n 'SQLite' > ninidibi.db
cat ninidibi >> ninidibi.db

There are two tables in the database.

sqlite3 ninidibi.db 
SQLite version 3.34.1 2021-01-20 14:10:07
Enter ".help" for usage hints.
sqlite> .tables
flag    orders
sqlite> .schema flag
CREATE TABLE flag (value INTEGER);
sqlite> .schema orders
CREATE TABLE orders (place INTEGER);
sqlite>

Table flag is full of numbers not bigger than 255, orders has values from 0 to 53.

I’ve written below script with hope that some shuffling with pattern stored in orders will give me the flag.

import sqlite3

db = sqlite3.connect('ninidibi.db')

flag_table = [i[0] for i in db.execute("SELECT * FROM flag")]
orders_table = [i[0] for i in db.execute("SELECT * FROM orders")]

for i in range(len(flag_table)):
    if i not in orders_table:
        missing = i

# yup, first run has been done with 'S4CTF{' condition ;-) it gave me a bit messy "flag", fortunately I was able to
# figure out that it should start with 'S4CTF{B4bY', so I adjust it :-)
while 'S4CTF{B4bY' not in ''.join(chr(j) for j in flag_table):
    flag = []
    for i in orders_table:
        if i is None:
            i = missing
        flag.append(flag_table[i])
    flag_table = flag

print("Flag: {}".format(''.join(chr(i) for i in flag)))

Output:

Flag: S4CTF{B4bY___f0r3n5iCS___7AsK_f0R_WaRMUP_blah_blah!!!}

Flag

S4CTF{B4bY___f0r3n5iCS___7AsK_f0R_WaRMUP_blah_blah!!!}

Privacy Policy
luc © 2021