Skip to content

Commit 510cd8f

Browse files
committed
add task Cartography
1 parent 2e91325 commit 510cd8f

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

Cartography/create/bootstrap.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Remove sudo
2+
rm -f /etc/sudoers.d/box
3+
4+
# Greeting
5+
cat <<'EOF' > /.box/greeting
6+
Welcome to Linux Challenge on
7+
_ _
8+
| | (_)
9+
___| |_ ___ _ __ _ ___ ___ _ __ __ _
10+
/ __| __/ _ \ '_ \| |/ __| / _ \| '__/ _` |
11+
\__ \ || __/ |_) | | (__ | (_) | | | (_| |
12+
|___/\__\___| .__/|_|\___(_)___/|_| \__, |
13+
| | __/ |
14+
|_| |___/
15+
16+
This box runs Ubuntu 14.04. You are logged in as user "box".
17+
18+
Web terminal usage
19+
==================
20+
* Click the titlebar to drag
21+
* Double-click the titlebar to maximize
22+
* Click and drag the lower-right corner to resize
23+
EOF
24+
25+
# Create flag.txt
26+
echo "# this is the first line of flag.txt
27+
STCTF#WellDumped#
28+
# this is the last line of flag.txt" > /home/box/flag.txt
29+
chown box:box /home/box/flag.txt
30+
31+
# Run process that reads flag.txt and sleeps forever
32+
echo "#!/usr/bin/env python3
33+
import os
34+
import time
35+
36+
content = open('/home/box/flag.txt').read()
37+
os.remove('/home/box/flag.txt')
38+
os.remove('/home/box/flagd')
39+
while True:
40+
time.sleep(1)" > /home/box/flagd
41+
42+
cd /home/box
43+
su box -c "python3 flagd &"

Cartography/create/test_scenario.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FLAG_CONTENT = "# this is the first line of flag.txt\r\nSTCTF#WellDumped#\r\n# this is the last line of flag.txt"
2+
3+
4+
def test_connection(s):
5+
assert s.run('true').succeeded, "Could not connect to server"
6+
7+
8+
def test_flag_exists(s):
9+
cmd = 'test -f /home/box/flag.txt'
10+
assert s.run(cmd).succeeded, "flag.txt not found"
11+
12+
13+
def test_flag_content(s):
14+
flag_content = s.run('cat /home/box/flag.txt')
15+
assert flag_content == FLAG_CONTENT, "Incorrect flag.txt content"

Cartography/solution/hints.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hint 1: Городская Детская Больница вам обязательно поможет

Cartography/solution/solution.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
В задании запускался python скрипт, который читает в память файл flag.txt, удаляет его, удаляет свой скрипт запуска и продолжает работать ничего не делая в системе:
2+
3+
#!/usr/bin/env python3
4+
import os
5+
import time
6+
7+
content = open('/home/box/flag.txt').read()
8+
os.remove('/home/box/flag.txt')
9+
os.remove('/home/box/flagd')
10+
while True:
11+
time.sleep(1)
12+
13+
Первым делом пробуем посмотреть список активных процессов:
14+
15+
$ ps ax
16+
PID TTY STAT TIME COMMAND
17+
1 ? Ss 0:00 /bin/sh -c /.box/start.sh
18+
6 ? S 0:00 /bin/bash /.box/start.sh
19+
22 ? Ss 0:00 /usr/sbin/sshd
20+
35 ? S 0:32 python3 flagd
21+
39 ? S 0:00 su box
22+
40 ? S 0:00 bash
23+
58 ? R+ 0:00 ps ax
24+
25+
Можно предположить, что процесс с PID 35 -- это то, на что и нужно обратить внимание. Смотрим список файловых дескрипторов, открытых этим процессом.
26+
27+
$ ls /proc/35/fd
28+
0 1 2
29+
30+
Видим, что у процесса открыты только стандартные файловые дескрипторы (0 standard input, 1 standard output, 2 standard error). Понимаем, что скорее всего прочитанный файл был закрыт, поэтому файлового дескриптора не осталось. Пробуем сдампить всю виртуальную память процесса. Для этого можно воспользоваться установленным отладчиком gdb:
31+
32+
$ gdb --pid 35
33+
(gdb) dump memory /root/output START_ADDRESS END_ADDRESS
34+
35+
Замапленные регионы памяти и права доступа к ним находятся в файле /proc/35/maps. Удобно воспользоваться предложенным скриптом http://serverfault.com/a/408929. Есть еще более простой способ сдампить всю память процесса -- воспользоваться утилитой gcore.
36+
37+
После того, как сдампили все доступные регионы памяти, ищем в них известный шаблон флага:
38+
$ grep STCTF# *.dump
39+
40+
обращаем внимание, что кроме флага в файле были записаны еще две строки, копируем все содержимое в файл /home/box/flag.txt:
41+
42+
# this is the first line of flag.txt
43+
STCTF#WellDumped#
44+
# this is the last line of flag.txt

Cartography/summary.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
answer_regex: STCTF#WellDumped#
3+
author: spy
4+
category: admin
5+
description: |
6+
Восстановите случайно удаленный файл /home/box/flag.txt. Кажется, кто-то недавно его открывал и читал.
7+
name: Cartography
8+
price: 300

0 commit comments

Comments
 (0)