Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Exploit Farm #

The utility for CTF hacker competition for lauching sploits for all teams
The utility for CTF hacker competition for launching sploits for all teams
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опечатка исправлена, спасибо

and submitting flags.

## Prepare ##
1. Set FLAG_FORMAT regexp in flag_format.py
2. Set TEAMS in team_list.py
2. Set teams in team_list.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По PEP8 константы пишутся заглавными буквами

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, знаю, но имеет смысл в течение игры обновлять список команд, чтобы взаимодействовать только с теми, которые сейчас активны. На Ructf_2017 мы это сделали на скорую руку с помощью парсинга страницы регулярным выражением, добавив функцию generate_teams, её ещё нужно будет привести в нормальный вид. Поэтому я и изменил teams, так как это больше не константа (хотя для тренировок можно будет просто комментировать вызовы этой функции, саму функцию, и заполнять teams руками, как и раньше)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в этом месте, наверно, можно написать отдельно генератор таких файлов, который может пытаться, например, законнектиться по TCP к каждой команде. Но вот как это сделать просто - я не придумал

3. Edit submit_flags in start_posting.py for the checking system

## Usage ##
Expand Down
2 changes: 1 addition & 1 deletion flag_format.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# put the regexp for flag here
FLAG_FORMAT = b"[0-9A-Fa-f]{32}"
FLAG_FORMAT = b"[Mm]oved"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В чём смысл этого изменения?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это отладочые изменения для локального тестирования, я потом верну всё как было

66 changes: 32 additions & 34 deletions start_posting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
from flag_format import FLAG_FORMAT

FLAGS_IN_SUMBIT_ITERATION = 100
RESTART_DELAY = 2 # in sec
FLAGS_GLOB = "flags/*.txt"
HOST = '127.0.0.1' # checksystem hostaddr here
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, наверно так будет лучше, закоммитил

PORT = 31337 # checksystem port here
TIMEOUT = 5 # checksystem timeout
RESTART_DELAY = 2 # in sec


def log(text):
print(strftime("%H:%M:%S") + " " + text)

print(strftime("%H:%M:%S ") + text)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут не вижу разницы, но нахожу исходный вариант более семантически правильным. Тоесть взять время добавить к нему пробел, а потом текст. В новом варианте берётся время в формате с пробелом в конце и добавляется текст

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Окей


class PostedFlags:
GOOD_FLAGS_FILE = "posted_good_flags.txt"
Expand Down Expand Up @@ -58,10 +60,6 @@ def submit_flags(flags, posted_flags):
"YOU LIKELY HAVE TO EDIT THIS FUNCTION"

# STAGE 0: connecting
HOST = '127.0.0.1' # checksystem hostaddr here
PORT = 31337 # checksystem port here
TIMEOUT = 5 # checksystem timeout

s = socket.create_connection((HOST, PORT), TIMEOUT)

# just an example how to use sockets over SSL
Expand All @@ -74,29 +72,29 @@ def submit_flags(flags, posted_flags):
# do_handshake_on_connect=1
# )

# STAGE 1: check if system greets us
greeting = s.recv(4096)
if b'Hello' not in greeting:
print("Not greeted: " + greeting)
return

# STAGE 2: send the team name
s.sendall(b"hackerdom\n")

# STAGE 3: check if system asks for a password
pass_greeting = s.recv(4096)
if b'pass' not in pass_greeting:
print("Not pass-greeted: %s" % pass_greeting)
return

# STAGE 4: send the password
s.sendall(b"pass\n")

# STAGE 5: check if system asks for flags
keys_prompt = s.recv(4096)
if b'keys' not in keys_prompt:
print("Not keys prompted %s" % keys_prompt)
return
# # STAGE 1: check if system greets us
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не вижу причины почему эти строки должны быть закомментированы

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

На ructf_2017 не было приветствия, эта часть кода не понадобилась. Но возможно понадобится в будущем, поэтому удалять я её не стал, возможно стоит добавить соответстующий комментарий об этом

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

там есть комментарий "YOU LIKELY HAVE TO EDIT THIS FUNCTION" :)

# greeting = s.recv(4096)
# if b'Hello' not in greeting:
# print("Not greeted: " + greeting)
# return
#
# # STAGE 2: send the team name
# s.sendall(b"hackerdom\n")
#
# # STAGE 3: check if system asks for a password
# pass_greeting = s.recv(4096)
# if b'pass' not in pass_greeting:
# print("Not pass-greeted: %s" % pass_greeting)
# return
#
# # STAGE 4: send the password
# s.sendall(b"pass\n")
#
# # STAGE 5: check if system asks for flags
# keys_prompt = s.recv(4096)
# if b'keys' not in keys_prompt:
# print("Not keys prompted %s" % keys_prompt)
# return

for flag in flags:
# STAGE 6: send a flag
Expand Down Expand Up @@ -128,21 +126,21 @@ def submit_flags(flags, posted_flags):
##################################################


def get_flags():
def get_all_flags():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ок, переименовал у себя

flags = list()

flag_files = glob(FLAGS_GLOB) # all files with flags

for flag_file in flag_files:
file_contents = open(flag_file, "rb" , 1).read()
flags += re.findall(FLAG_FORMAT, file_contents)

return flags

# main posting cycle
while True:
begin_load_time = time()
posted_flags = PostedFlags()
flags_set = set(get_flags()) - posted_flags.get()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

там дальше используется flags_set

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Действительно, проглядел

flags = list(flags_set)
flags = list(set(get_all_flags()) - posted_flags.get()) # get new flags

if len(flags) > FLAGS_IN_SUMBIT_ITERATION:
flags = random.sample(flags, FLAGS_IN_SUMBIT_ITERATION)
Expand Down
Loading