rename echo_string to strings

This commit is contained in:
thomashaw
2018-08-16 12:35:31 +01:00
committed by ts
parent a9451f7dc7
commit ea52909999
15 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1 @@
test successful wayyy :D

View File

@@ -0,0 +1,75 @@
require 'securerandom'
require 'timeout'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
# determine encoding format required
encoding_formats = %w[reverse hex_little_endian hex_big_endian binary_little_endian binary_big_endian base64 octal decimal]
encoding_format = encoding_formats.sample
case encoding_format
when 'reverse'
print_string = 'reverse'
operation = ->(data) {data.reverse}
when 'hex_little_endian'
print_string = 'hexadecimal (little endian / LSB first)'
operation = ->(data) {data.unpack('h*').first}
when 'hex_big_endian'
print_string = 'hexadecimal (big endian / MSB first)'
operation = ->(data) {data.unpack('H*').first}
when 'binary_little_endian'
print_string = 'binary (little endian / LSB first)'
operation = ->(data) {data.unpack('b*').first}
when 'binary_big_endian'
print_string = 'binary (big endian / MSB first)'
operation = ->(data) {data.unpack('B*').first}
when 'base64'
require 'base64'
print_string = 'base64'
operation = ->(data) {Base64.strict_encode64(data)}
when 'octal'
print_string = 'octal'
operation = -> (data) {
sum = []
data.each_char {|char| sum << char.ord.to_s(8).to_i}
sum.join
}
when 'decimal'
print_string = 'decimal'
operation = -> (data) {
sum = []
data.each_char {|char| sum << char.ord.to_s}
sum.join
}
else
print_string = 'ERROR'
operation = ->(data) {data}
end
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts "Echo the string back to me, in #{print_string}, before the script times out. Try writing a script of your own to make it easier!"
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
begin
Timeout.timeout 0.3 do
response = gets.chomp
valid_answer = operation.call(string)
if response == valid_answer
puts File.read(flag_path)
else
puts 'Incorrect!'
puts 'We were looking for: ' + valid_answer
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,17 @@
#!/usr/bin/ruby
require_relative '../../../../../../../lib/objects/local_ruby_challenge_generator.rb'
class EchoStringChallenge < RubyChallengeGenerator
def initialize
super
self.module_name = 'Echo String Script Generator'
end
def randomise_by_difficulty
__FILE__
end
end
EchoStringChallenge.new.run

View File

@@ -0,0 +1,37 @@
# #####################
# Programming Challenge
# Echo string - Repeat a string and repeat back to the script
# #####################
require 'securerandom'
require 'timeout'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts 'Echo the string back to me before the script times out. Try writing a script of your own to make it easier!'
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
STDOUT.flush
begin
Timeout.timeout 0.3 do
response = gets.chomp
if response == string
puts File.read(flag_path)
else
puts 'Incorrect answer!'
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,34 @@
require 'securerandom'
require 'timeout'
require 'base64'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts 'Echo the string back to me, in base64, before the script times out. Try writing a script of your own to make it easier!'
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
begin
Timeout.timeout 0.3 do
response = gets.chomp
valid_answer = Base64.strict_encode64(data)
if response == valid_answer
puts File.read(flag_path) # Flag path
else
puts 'Incorrect answer!'
puts 'We were looking for: ' + valid_answer
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,33 @@
require 'securerandom'
require 'timeout'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts 'Echo the string back to me, in binary (big endian / MSB first), before the script times out. Try writing a script of your own to make it easier!'
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
begin
Timeout.timeout 0.3 do
response = gets.chomp
valid_answer = string.unpack('B*').first
if response == valid_answer
puts File.read(flag_path) # Flag path
else
puts 'Incorrect answer!'
puts 'We were looking for: ' + valid_answer
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,33 @@
require 'securerandom'
require 'timeout'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts 'Echo the string back to me, in binary (little endian / LSB first), before the script times out. Try writing a script of your own to make it easier!'
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
begin
Timeout.timeout 0.3 do
response = gets.chomp
valid_answer = string.unpack('b*').first
if response == valid_answer
puts File.read(flag_path) # Flag path
else
puts 'Incorrect answer!'
puts 'We were looking for: ' + valid_answer
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,34 @@
require 'securerandom'
require 'timeout'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts 'Echo the string back to me, in decimal, before the script times out. Try writing a script of your own to make it easier!'
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
begin
Timeout.timeout 5 do
response = gets.chomp
sum = []
string.each_char{|char| sum << char.ord.to_s}
valid_answer = sum.join
if response == valid_answer
puts File.read(flag_path) # Flag path
else
puts 'Incorrect answer!'
puts 'We were looking for: ' + valid_answer
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,33 @@
require 'securerandom'
require 'timeout'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts 'Echo the string back to me, in hexadecimal (big endian / MSB first), before the script times out. Try writing a script of your own to make it easier!'
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
begin
Timeout.timeout 0.3 do
response = gets.chomp
valid_answer = string.unpack('H*').first
if response == valid_answer
puts File.read(flag_path) # Flag path
else
puts 'Incorrect answer!'
puts 'We were looking for: ' + valid_answer
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,33 @@
require 'securerandom'
require 'timeout'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts 'Echo the string back to me, in hexadecimal (little endian / LSB first), before the script times out. Try writing a script of your own to make it easier!'
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
begin
Timeout.timeout 0.3 do
response = gets.chomp
valid_answer = string.unpack('h*').first
if response == valid_answer
puts File.read(flag_path) # Flag path
else
puts 'Incorrect answer!'
puts 'We were looking for: ' + valid_answer
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,35 @@
require 'securerandom'
require 'timeout'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts 'Echo the string back to me, in octal, before the script times out. Try writing a script of your own to make it easier!'
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
begin
Timeout.timeout 0.3 do
response = gets.chomp
sum = []
string.each_char {|char| sum << char.ord.to_s(8).to_i}
valid_answer = sum.join
if response == valid_answer
puts File.read(flag_path) # Flag path
else
puts 'Incorrect answer!'
puts 'We were looking for: ' + valid_answer
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,44 @@
# #####################
# Programming Challenge
# Echo string - Medium: Reverse a string and repeat it back to the script
# #####################
require 'securerandom'
require 'timeout'
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
# Should the challenge types be separate scripts (medium1,medium2,medium3 etc?)
# so the challenge type is static on the box? less difficult + more replayable
# TODO: Implement other medium difficulty options:
# in reverse [done]
# but I only want every second character starting with index 0 e.g. [0,2,4...]
# but I only want every second character starting with index 1 e.g. [1,3,5...]
puts 'Prepare yourself. You need to work quickly for this challenge.'
sleep 2
puts 'Echo the string back to me, in reverse, before the script times out. Try writing a script of your own to make it easier!'
sleep 2
puts 'Get ready, here we go...'
sleep 2
# Generate random string
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
puts string
STDOUT.flush
begin
Timeout.timeout 0.3 do
response = gets.chomp
if response == string.reverse
puts File.read(flag_path) # Flag path
else
puts 'Incorrect answer!'
exit
end
end
rescue Timeout::Error
puts 'Too slow!'
exit
end

View File

@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<generator xmlns="http://www.github/cliffe/SecGen/generator"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.github/cliffe/SecGen/generator">
<name>String Challenge Generator</name>
<author>Thomas Shaw</author>
<module_license>MIT</module_license>
<description>TODO</description>
<type>ruby_script_challenge</type>
<type>programming_challenge</type>
<type>ctf_challenge</type>
<platform>linux</platform>
<platform>windows</platform>
<read_fact>difficulty</read_fact>
<default_input into="difficulty">
<encoder type="string_selector">
<input into="strings_to_encode">
<value>low</value>
<value>medium</value>
<value>high</value>
</input>
</encoder>
</default_input>
<output_type>script</output_type>
</generator>