Skip to content

Conversation

@Parean
Copy link

@Parean Parean commented Dec 5, 2017

Сырой код, я его ещё допишу

Copy link
Owner

@alexbers alexbers left a comment

Choose a reason for hiding this comment

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

почитал, норм, что-то принял

# 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.

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

## 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 к каждой команде. Но вот как это сделать просто - я не придумал

@@ -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.

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

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.

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

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.

Окей

lock.acquire()
# We need to create a new object so we can later find new flags
# comparing two different sets
last_flags = [set(o.flags) for o in owners]
Copy link
Owner

Choose a reason for hiding this comment

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

вроде в дефолтной реализации питона есть GIL, который решает проблему с неатомарностью set'ов

Copy link
Author

Choose a reason for hiding this comment

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

Не очень понял про атомарность. Мне было непонятно, зачем писать set(o.flags), вместо o.flags, если o.flags -- это уже set. Я думал это ошибка, и изначально o.flags был списком, а потом в конструкторе его сразу сделали множеством, а здесь и в 181 строчке просто забыли добавить правки. Я убрал set в обоих местах, но потом понял, что здесь его нужно оставить, потому что в дальнейшем нам нужно узнать какие флаги добавились, а сделать это можно только сравнив два разных множества, которые друг от друга не зависят. Поэтому я добавил комментарий, но похоже не очень понятный

owners_queue.put(o)

curr_flags = [set(o.flags) for o in owners]
sleep(1) # show stat at zero second
Copy link
Owner

Choose a reason for hiding this comment

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

тут раньше был смысл, чтобы статистика писалась в 00 секунд каждой минуты. Т.е. не, например, в 12:09:11, 12:10:11, 12:11:11, а в 12:10:00, 12:11:00, 12:12:00 и т.д

Copy link
Author

Choose a reason for hiding this comment

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

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

for i in range(multiprocessing.cpu_count()):
owners_queue.put(None)
for w in workers:
w.join()
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.

Я посмотрю ещё как правильно завершать работу воркеров



# teams = {}
# def generate_teams():
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.

Да, его надо переписать

"team1" : "127.0.0.1",
"team2" : "127.0.0.2",
teams = {
"team1" : "172.217.4.3",
Copy link
Owner

Choose a reason for hiding this comment

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

хм:) интересно что это за адрес

@alexbers
Copy link
Owner

alexbers commented Dec 5, 2017

Сейчас проблема кода, на мой взгляд - в том что он создаёт по два потока и один процесс на команду. В линуксе от одного потока можно избаваться, если заменить чтение строки на select с таймаутом. Но в windows такое не работает :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants