-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. По PEP8 константы пишутся заглавными буквами
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Да, знаю, но имеет смысл в течение игры обновлять список команд, чтобы взаимодействовать только с теми, которые сейчас активны. На Ructf_2017 мы это сделали на скорую руку с помощью парсинга страницы регулярным выражением, добавив функцию generate_teams, её ещё нужно будет привести в нормальный вид. Поэтому я и изменил teams, так как это больше не константа (хотя для тренировок можно будет просто комментировать вызовы этой функции, саму функцию, и заполнять teams руками, как и раньше)
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ## | ||
|
|
||
| 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" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В чём смысл этого изменения?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это отладочые изменения для локального тестирования, я потом верну всё как было |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут не вижу разницы, но нахожу исходный вариант более семантически правильным. Тоесть взять время добавить к нему пробел, а потом текст. В новом варианте берётся время в формате с пробелом в конце и добавляется текст
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Окей |
||
|
|
||
| class PostedFlags: | ||
| GOOD_FLAGS_FILE = "posted_good_flags.txt" | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не вижу причины почему эти строки должны быть закомментированы
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. На ructf_2017 не было приветствия, эта часть кода не понадобилась. Но возможно понадобится в будущем, поэтому удалять я её не стал, возможно стоит добавить соответстующий комментарий об этом
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -128,21 +126,21 @@ def submit_flags(flags, posted_flags): | |
| ################################################## | ||
|
|
||
|
|
||
| def get_flags(): | ||
| def get_all_flags(): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. там дальше используется flags_set
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
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.
Опечатка исправлена, спасибо