Created
December 2, 2022 16:23
-
-
Save LevitatingBusinessMan/bbeafbafffd4d88983c5703703b2ee59 to your computer and use it in GitHub Desktop.
HTB university ctf
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
import Data.Char (ord) | |
import Data.Bits (xor) | |
-- Complete the incantation... | |
flag = "HTB{4_m0n4d_15_ju57_4_m0n01d_1n_7h3_c47360ry_0f_3nd0func70r5!!}" | |
extractFlag :: String -> String | |
extractFlag (s:rest) | |
| s == 'H' || s == 'T' || s == 'B' | |
= extractFlag rest | |
| s == '{' && last rest == '}' | |
= init rest | |
| otherwise = error ("Invalid format") | |
chunks :: Int -> [a] -> [[a]] | |
chunks n l | |
| n == 0 = [] | |
| n == 1 = [[x] | x <- l] | |
| length l <= n = [l] | |
| otherwise = [take n l] ++ (chunks n (drop n l)) | |
takeLast :: Int -> [a] -> [a] | |
takeLast n = reverse . take n . reverse | |
a = [-43, 61, 58, 5, -4, -11, 64, -40, -43, 61, 62, -51, 46, 15, -49, -44, 47, 4, 6, -7, 47, 7, -59, 52, -15, 11, 7, 61, 0] | |
b = [6, 106, 10, 0, 119, 52, 51, 101, 0, 0, 15, 48, 116, 22, 10, 58, 125, 100, 102, 33] | |
c = [304, 357, 303, 320, 304, 307, 349, 305, 257, 337, 340, 309, 428, 270, 66] | |
checkFlag :: String -> Bool | |
checkFlag flag = | |
length content == 58 && | |
all (==True) (map (\ (l,r) -> l == r) (zip one a)) && | |
all (==True) (map (\ (l,r) -> l == r) (zip two b)) && | |
all (==True) (map (\ (l,r) -> l == r) (zip three c)) | |
where content = map ord (extractFlag flag) | |
one = map (\ [l, r] -> (l - r)) (chunks 2 content) | |
two = map (foldr xor 0) (chunks 3 content) | |
three = map (foldr (+) 0) (chunks 4 content) | |
main = putStrLn (if (checkFlag flag) | |
then "The spell went off without a hitch!" | |
else "You disappear in a puff of smoke!" | |
) |
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
$a = [-43, 61, 58, 5, -4, -11, 64, -40, -43, 61, 62, -51, 46, 15, -49, -44, 47, 4, 6, -7, 47, 7, -59, 52, -15, 11, 7, 61, 0] | |
$b = [6, 106, 10, 0, 119, 52, 51, 101, 0, 0, 15, 48, 116, 22, 10, 58, 125, 100, 102, 33] | |
$c = [304, 357, 303, 320, 304, 307, 349, 305, 257, 337, 340, 309, 428, 270, 66] | |
def chunks n, arr | |
res = arr.each_slice(n).to_a | |
return res[..-2] if res.last.length != n | |
res | |
end | |
def checker flag | |
one = (chunks 2, flag).map {|a,b| a - b} | |
two = (chunks 3, flag).map {|a,b,c| a^b^c} | |
three = (chunks 4, flag).map &:sum | |
#puts "#{flag} pass a" if one == $a.first(one.length) | |
#puts "#{flag} pass b" if two == $b.first(two.length) | |
#puts "#{flag} pass c" if three == $c.first(three.length) | |
one == $a.first(one.length) && | |
two == $b.first(two.length) && | |
three == $c.first(three.length) | |
end | |
chars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_!".chars.map &:ord | |
# returns [52, 95, 109, 48] | |
# for pos in chars.permutation 4 | |
# # p pos if checker pos | |
# end | |
first = [52, 95, 109, 48] | |
possibilities = [first] | |
54.times do | |
newposs = [] | |
for c in chars | |
for pos in possibilities | |
flag = pos + [c] | |
if checker flag | |
print flag.map(&:chr).join + " \r" | |
newposs << flag | |
end | |
end | |
end | |
possibilities = newposs | |
end | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment