tkh4ck.github.io

Personal website and blog of tkh4ck

View on GitHub

Hexordia Weekly CTF - Android - Week 1 - Karma’s relaxing thought

When was the user upvoted?

Solution

sqlite> .schema karma_statistics CREATE TABLE karma_statistics (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER NOT NULL, karma INTEGER NOT NULL); CREATE INDEX index_karma_statistics_timestamp ON karma_statistics (timestamp);

sqlite> select * from karma_statistics; 1|1703627653479|1


- We can also create a small Python script to solve the challenge ([karmas-relaxing-thought.py](/ctf/2024/hexordia-weekly-ctf/android/week-1/Karmas-relaxing-thought/files/karmas-relaxing-thought.py)):

```python
import sqlite3
import sys
import pathlib
from datetime import datetime

root = pathlib.Path(sys.argv[1])
app = 'com.reddit.frontpage'
databases = root / f'data/data/{app}/databases'
assert(databases.exists())

database = None
for db in databases.glob('reddit_db_*'):
    if 'anonymous' not in str(db):
        database = db
        break

assert(database is not None)
connection = sqlite3.connect(database)

sql = f"select timestamp from karma_statistics"

cursor = connection.cursor()
rows = cursor.execute(sql).fetchall()
assert(len(rows) >= 1)

ts = rows[0][0] / 1000
print(datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
$ python solve.py /path-to-extracted-image
2023-12-26 21:54:13

Flag: 2023-12-26 21:54:13