Skip to content

Commit d97eade

Browse files
committed
WiP
1 parent 4f00eb8 commit d97eade

File tree

2 files changed

+74
-17
lines changed

2 files changed

+74
-17
lines changed

config/hackthis.xml

+17-12
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
<got_shell>We have shell.</got_shell>
3737
<repeat>Let me know when you are 'ready', if you want to move on to another attack, say 'next', or 'previous' and I'll move things along</repeat>
3838
<repeat>Say 'ready', 'next', or 'previous'.</repeat>
39-
<say_answer>Say "The answer is *X*".</say_answer>
4039
<!--Single responses:-->
40+
<say_answer>Say "The answer is *X*".</say_answer>
41+
<correct_answer>Correct</correct_answer>
42+
<incorrect_answer>Incorrect</incorrect_answer>
4143
<invalid>That's not possible.</invalid>
4244
<non_answer>Wouldn't you like to know.</non_answer>
4345
</messages>
@@ -52,7 +54,7 @@
5254
<condition>
5355
<output_matches>Permission denied|Operation not permitted</output_matches>
5456
<message>:) Well done! flag{yay1!}</message>
55-
<trigger_next>true</trigger_next>
57+
<trigger_next_attack>true</trigger_next_attack>
5658
</condition>
5759
<condition>
5860
<output_equals>0</output_equals>
@@ -78,7 +80,7 @@
7880
<condition>
7981
<output_matches>Permission denied</output_matches>
8082
<message>:) Well done! flag{yay1!}</message>
81-
<trigger_next>true</trigger_next>
83+
<trigger_next_attack>true</trigger_next_attack>
8284
</condition>
8385
<condition>
8486
<output_equals>0</output_equals>
@@ -105,7 +107,7 @@
105107
<condition>
106108
<output_matches>Operation not permitted</output_matches>
107109
<message>:) Well done! flag{yay1!}</message>
108-
<trigger_next>true</trigger_next>
110+
<trigger_next_attack>true</trigger_next_attack>
109111
</condition>
110112
<condition> <!-- TODO: chmod to defeat the defense -->
111113
<output_matches>Permission denied</output_matches>
@@ -138,7 +140,7 @@
138140
<condition>
139141
<output_matches>Operation not permitted</output_matches>
140142
<message>:) Well done! flag{yay1!}</message>
141-
<trigger_next>true</trigger_next>
143+
<trigger_next_attack>true</trigger_next_attack>
142144
</condition>
143145
<condition>
144146
<output_matches>No such file or directory</output_matches>
@@ -160,7 +162,7 @@
160162
<condition>
161163
<output_matches>Read-only file system</output_matches>
162164
<message>:) Well done! flag{yay1!}</message>
163-
<trigger_next>true</trigger_next>
165+
<trigger_next_attack />
164166
</condition>
165167
<condition>
166168
<output_matches>Permission denied|Operation not permitted</output_matches>
@@ -182,12 +184,8 @@
182184
<condition>
183185
<output_matches>0</output_matches>
184186
<message>User added</message>
185-
<!--<trigger_next>true</trigger_next>-->
186-
<quiz>
187-
<question>Now after the attack, find the username added by diffing using a backup. What username was created?</question>
188-
<answer>hackerbot</answer>
189-
<correct_answer>flag{yay!}</correct_answer>
190-
</quiz>
187+
<!--<trigger_next_attack>true</trigger_next_attack>-->
188+
<trigger_quiz />
191189
</condition>
192190
<condition>
193191
<output_matches>already exists</output_matches>
@@ -201,6 +199,13 @@
201199
<message>:( Something was not right...</message>
202200
</else_condition>
203201

202+
<quiz>
203+
<question>Now after the attack, find the username added by diffing using a backup. What username was created?</question>
204+
<answer>hackerbot|test</answer>
205+
<correct_answer_response>:) flag{yay!}</correct_answer_response>
206+
<trigger_next_attack />
207+
</quiz>
208+
204209
</hack>
205210

206211
</hackerbot>

hackerbot.rb

+57-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def read_bots
4343
bots[bot_name] = {}
4444

4545
chatbot_rules = hackerbot.at_xpath('AIML_chatbot_rules').text
46-
Print.debug "Loading chat_ai from #{chatbot_rules}"
46+
Print.debug "Loading chatbot ai from #{chatbot_rules}"
4747
bots[bot_name]['chat_ai'] = ProgramR::Facade.new
4848
bots[bot_name]['chat_ai'].learn([chatbot_rules])
4949

@@ -87,6 +87,7 @@ def read_bots
8787
# is this the last one?
8888
if bots[bot_name]['current_hack'] < bots[bot_name]['hacks'].length - 1
8989
bots[bot_name]['current_hack'] += 1
90+
bots[bot_name]['current_quiz'] = nil
9091
current = bots[bot_name]['current_hack']
9192

9293
# prompt for current hack
@@ -107,6 +108,7 @@ def read_bots
107108
# is this a valid attack number?
108109
if requested_index < bots[bot_name]['hacks'].length
109110
bots[bot_name]['current_hack'] = requested_index
111+
bots[bot_name]['current_quiz'] = nil
110112
current = bots[bot_name]['current_hack']
111113

112114
# prompt for current hack
@@ -124,6 +126,52 @@ def read_bots
124126

125127
Print.debug "answer = #{answer}"
126128

129+
current_quiz = bots[bot_name]['current_quiz']
130+
current = bots[bot_name]['current_hack']
131+
132+
quiz = nil
133+
# is there ONE quiz question?
134+
if bots[bot_name]['hacks'][current].key?('quiz') && bots[bot_name]['hacks'][current]['quiz'].key?('answer')
135+
quiz = bots[bot_name]['hacks'][current]['quiz']
136+
# multiple quiz questions?
137+
# elsif bots[bot_name]['hacks'][current]['quiz'][current_quiz].key?('answer')
138+
# quiz = bots[bot_name]['hacks'][current]['quiz'][current_quiz]
139+
end
140+
141+
if quiz != nil
142+
if answer.match(quiz['answer'])
143+
m.reply 'CORRECT!!!!!!'
144+
m.reply quiz['correct_answer_response']
145+
146+
# Repeated logic
147+
if quiz.key?('trigger_next_attack')
148+
if bots[bot_name]['current_hack'] < bots[bot_name]['hacks'].length - 1
149+
bots[bot_name]['current_hack'] += 1
150+
bots[bot_name]['current_quiz'] = nil
151+
current = bots[bot_name]['current_hack']
152+
153+
sleep(1)
154+
# prompt for current hack
155+
m.reply bots[bot_name]['hacks'][current]['prompt']
156+
else
157+
m.reply bots[bot_name]['messages']['last_attack'].sample
158+
end
159+
end
160+
161+
else
162+
m.reply 'INCORRECT!!!!!'
163+
end
164+
else
165+
m.reply 'There is no question to answer'
166+
end
167+
168+
Print.debug bots[bot_name]['hacks'][current].to_s
169+
# Print.debug bots[bot_name]['hacks'][current]['condition']['quiz'][current_quiz]['answer']
170+
171+
# else
172+
# m.reply 'Not currently waiting on an answer'
173+
# end
174+
127175

128176
end
129177

@@ -133,6 +181,7 @@ def read_bots
133181
# is this the last one?
134182
if bots[bot_name]['current_hack'] > 0
135183
bots[bot_name]['current_hack'] -= 1
184+
bots[bot_name]['current_quiz'] = nil
136185
current = bots[bot_name]['current_hack']
137186

138187
# prompt for current hack
@@ -163,7 +212,7 @@ def read_bots
163212
return if m.message =~ /help|next|previous|list|^(goto|attack) [0-9]|(the answer is|answer)/
164213

165214
begin
166-
reaction = bots[bot_name]['chat_ai'].get_reaction(m.message)
215+
reaction = bots[bot_name]['chat_ai'].get_reaction(m.message.gsub /([^a-z0-9\- ]+)/i, '')
167216

168217
rescue Exception => e
169218
puts e.message
@@ -225,10 +274,12 @@ def read_bots
225274
end
226275

227276
if condition_met
228-
if condition.key?('trigger_next')
277+
# Repeated logic for trigger_next_attack
278+
if condition.key?('trigger_next_attack')
229279
# is this the last one?
230280
if bots[bot_name]['current_hack'] < bots[bot_name]['hacks'].length - 1
231281
bots[bot_name]['current_hack'] += 1
282+
bots[bot_name]['current_quiz'] = nil
232283
current = bots[bot_name]['current_hack']
233284

234285
sleep(1)
@@ -239,8 +290,9 @@ def read_bots
239290
end
240291
end
241292

242-
if condition.key?('quiz')
243-
m.reply condition['quiz']['question']
293+
if condition.key?('trigger_quiz')
294+
m.reply bots[bot_name]['hacks'][current]['quiz']['question']
295+
m.reply bots[bot_name]['messages']['say_answer']
244296
bots[bot_name]['current_quiz'] = 0
245297
end
246298
end

0 commit comments

Comments
 (0)