Last active
December 21, 2019 20:58
-
-
Save Ninjex/10567762 to your computer and use it in GitHub Desktop.
Hackthisite Programming 2 (Requires Mechanize and RMagick gems) -- Autocompletion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# ███▄ █ ██▓ ███▄ █ ▄▄▄██▀▀▀▓█████ ▒██ ██▒ | |
# ██ ▀█ █ ▓██▒ ██ ▀█ █ ▒██ ▓█ ▀ ▒▒ █ █ ▒░ | |
# ▓██ ▀█ ██▒▒██▒▓██ ▀█ ██▒ ░██ ▒███ ░░ █ ░ | |
# ▓██▒ ▐▌██▒░██░▓██▒ ▐▌██▒▓██▄██▓ ▒▓█ ▄ ░ █ █ ▒ | |
# ▒██░ ▓██░░██░▒██░ ▓██░ ▓███▒ ░▒████▒▒██▒ ▒██▒ | |
# ░ ▒░ ▒ ▒ ░▓ ░ ▒░ ▒ ▒ ▒▓▒▒░ ░░ ▒░ ░▒▒ ░ ░▓ ░ | |
# ░ ░░ ░ ▒░ ▒ ░░ ░░ ░ ▒░ ▒ ░▒░ ░ ░ ░░░ ░▒ ░ | |
# ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ | |
# ░ ░ ░ ░ ░ ░ ░ ░ ░ | |
# | |
require_relative 'morse.rb' | |
require 'mechanize' | |
require 'RMagick' | |
require 'io/console' | |
print 'Username: ' | |
name = gets.chomp | |
print 'Password: ' | |
pass = STDIN.noecho(&:gets).chomp | |
client = Mechanize.new { |agent| agent.user_agent = 'Mechanize -- Ninjex' } | |
client.get('https://www.hackthissite.org/') do |page| | |
login_form = client.click(page.link_with(:text => /Login/)) | |
login_page = login_form.form_with(:action => '/user/login') do |f| | |
f.username = name | |
f.password = pass | |
end.click_button | |
end | |
client.get('https://www.hackthissite.org/missions/prog/2/') do |page| | |
client.get('https://www.hackthissite.org/missions/prog/2/PNG').save('encrypted.png') | |
img = Magick::Image::read("encrypted.png")[0] | |
offset, count = [], 0 | |
img.each_pixel do |pixel| | |
if pixel.to_s.include?('red=65535, green=65535, blue=65535') | |
offset << count | |
count = 0 | |
end | |
count += 1 | |
end | |
answer = decrypt_morse(offset.map!(&:chr).join) | |
submit_form = page.form_with(:action => '/missions/prog/2/index.php') { |f| f.solution = answer }.click_button | |
puts "\r\nSubmited Answer: #{answer}" | |
puts "Verify points @ https://www.hackthissite.org/user/view/#{name}" | |
end | |
File.delete('encrypted.png') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decrypt_morse(cipher) | |
morse = { | |
".-" => 'A', "-..." => 'B', "-.-." => 'C', "-.." => 'D', | |
"." => 'E', "..-." => 'F', "--." => 'G', "...." => 'H', | |
".." => 'I', ".---" => 'J', "-.-" => 'K', ".-.." => 'L', | |
"--" => 'M', "-." => 'N', "---" => 'O', ".--." => 'P', | |
"--.-" => 'Q', ".-." => 'R', "..." => 'S', "-" => 'T', | |
"..-" => 'U', "...-" => 'V', ".--" => 'W', "-..-" => 'X', | |
"-.--" => 'Y', "--.." => 'Z', ".----" => '1', "..---" => '2', | |
"...--" => '3', "....-" => '4', "....." => '5', "-...." => '6', | |
"--..." => '7', "---.." => '8', "----." => '9', "-----" => '0', | |
'/' => ' ', | |
} | |
plain = [] | |
cipher.split(' ').map{ |crypt| plain << morse[crypt] } | |
return plain.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment