-
Notifications
You must be signed in to change notification settings - Fork 14
Add workers #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add workers #2
Conversation
alexbers
left a comment
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По PEP8 константы пишутся заглавными буквами
There was a problem hiding this comment.
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 руками, как и раньше)
There was a problem hiding this comment.
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" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В чём смысл этого изменения?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут не вижу разницы, но нахожу исходный вариант более семантически правильным. Тоесть взять время добавить к нему пробел, а потом текст. В новом варианте берётся время в формате с пробелом в конце и добавляется текст
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вроде в дефолтной реализации питона есть GIL, который решает проблему с неатомарностью set'ов
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 и т.д
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут возникнет проблема с сплойтами, которые долго работают. Например пытаются содединиться с кем-то и ждут таймаута.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я посмотрю ещё как правильно завершать работу воркеров
|
|
||
|
|
||
| # teams = {} | ||
| # def generate_teams(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
код специфичен для конкретной странички конкретных соревнований
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
хм:) интересно что это за адрес
|
Сейчас проблема кода, на мой взгляд - в том что он создаёт по два потока и один процесс на команду. В линуксе от одного потока можно избаваться, если заменить чтение строки на select с таймаутом. Но в windows такое не работает :( |
Сырой код, я его ещё допишу