BlueHens CTF 2021: Minecraft: MineR Code

This is from the BlueHensCTF 2021.

Challenge Author: ProfNinja

For this challenge, We are given the following information and links:

Here is the mc86 Intro:

Here is the mc86 InitCode:

/give @p minecraft:written_book{title:"Init CPU",author:"UD Cyberscholars",generation:0,pages:[
"{\"text\":\"Click Here First\\n\",\"color\":\"dark_green\",\"bold\":true,\"underlined\":true,\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Creating RAM\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/setblock ~1 ~ ~ minecraft:lime_shulker_box\"},
\"extra\":[
{\"text\":\"Click Here Second\\n\",\"color\":\"dark_green\",\"bold\":true,\"underlined\":true,\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Start Timing Belt\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/setblock ~2 ~1 ~ minecraft:command_block[facing=up]{powered:0b,Command:\\\"setblock ~ ~-1 ~ air\\\"}\"}},
{\"text\":\"Click Here Third\\n\",\"color\":\"dark_green\",\"bold\":true,\"underlined\":true,\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Finishing Timing Belt\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/setblock ~2 ~2 ~ minecraft:chain_command_block[facing=up]{powered:0b,auto:1b,conditionMet:0b,Command:\\\"execute if data block ~-1 ~-2 ~ Items[0].tag.pages[0] run setblock ~ ~-2 ~ redstone_block\\\"}\"}},
{\"text\":\"Click Here Fourth\\n\",\"color\":\"dark_green\",\"bold\":true,\"underlined\":true,\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Start CPU\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/setblock ~3 ~ ~ minecraft:command_block[facing=east]{powered:0b,Command:\\\"data modify block ~2 ~ ~ Command set from block ~-2 ~ ~ Items[0].tag.pages[0]\\\"}\"}},
{\"text\":\"Click Here Fifth\\n\",\"color\":\"dark_green\",\"bold\":true,\"underlined\":true,\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Finishing CPU\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/setblock ~4 ~ ~ minecraft:chain_command_block[facing=east]{powered:0b,auto:1b,conditionMet:0b,Command:\\\"data remove block ~-3 ~ ~ Items[0].tag.pages[0]\\\"}\"}},
{\"text\":\"Click Here Sixth\\n\",\"color\":\"dark_green\",\"bold\":true,\"underlined\":true,\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Placing ALU\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/setblock ~5 ~ ~ minecraft:chain_command_block[facing=east]{powered:0b,auto:1b,conditionMet:0b}\"}}]}"]} 1

Finally, here is the challenge source code:

/give @p writable_book{pages:["/fill ~-1 ~26 ~-5 ~25 ~ ~-5 white_concrete","/fill ~0 ~25 ~-5 ~6 ~25 ~-5 black_concrete","/fill ~9 ~25 ~-5 ~11 ~25 ~-5 black_concrete","/fill ~14 ~25 ~-5 ~14 ~23 ~-5 black_concrete","/fill ~18 ~25 ~-5 ~24 ~25 ~-5 black_concrete","/fill ~0 ~24 ~-5 ~0 ~19 ~-5 black_concrete","/fill ~6 ~24 ~-5 ~6 ~19 ~-5 black_concrete","/fill ~11 ~24 ~-5 ~13 ~24 ~-5 black_concrete","/fill ~16 ~24 ~-5 ~16 ~24 ~-5 black_concrete","/fill ~18 ~24 ~-5 ~18 ~19 ~-5 black_concrete","/fill ~24 ~24 ~-5 ~24 ~19 ~-5 black_concrete","/fill ~2 ~23 ~-5 ~4 ~21 ~-5 black_concrete","/fill ~9 ~23 ~-5 ~11 ~23 ~-5 black_concrete","/fill ~20 ~23 ~-5 ~22 ~21 ~-5 black_concrete","/fill ~8 ~22 ~-5 ~8 ~21 ~-5 black_concrete","/fill ~10 ~22 ~-5 ~13 ~22 ~-5 black_concrete","/fill ~16 ~22 ~-5 ~16 ~21 ~-5 black_concrete","/fill ~10 ~21 ~-5 ~10 ~19 ~-5 black_concrete","/fill ~12 ~21 ~-5 ~13 ~21 ~-5 black_concrete","/fill ~9 ~20 ~-5 ~9 ~20 ~-5 black_concrete","/fill ~14 ~20 ~-5 ~14 ~18 ~-5 black_concrete","/fill ~1 ~19 ~-5 ~5 ~19 ~-5 black_concrete","/fill ~8 ~19 ~-5 ~8 ~19 ~-5 black_concrete","/fill ~12 ~19 ~-5 ~12 ~19 ~-5 black_concrete","/fill ~16 ~19 ~-5 ~16 ~18 ~-5 black_concrete","/fill ~19 ~19 ~-5 ~23 ~19 ~-5 black_concrete","/fill ~9 ~18 ~-5 ~9 ~17 ~-5 black_concrete","/fill ~15 ~18 ~-5 ~15 ~18 ~-5 black_concrete","/fill ~0 ~17 ~-5 ~1 ~17 ~-5 black_concrete","/fill ~5 ~17 ~-5 ~7 ~17 ~-5 black_concrete","/fill ~10 ~17 ~-5 ~10 ~16 ~-5 black_concrete","/fill ~13 ~17 ~-5 ~13 ~15 ~-5 black_concrete","/fill ~20 ~17 ~-5 ~21 ~16 ~-5 black_concrete","/fill ~2 ~16 ~-5 ~4 ~15 ~-5 black_concrete","/fill ~8 ~16 ~-5 ~8 ~16 ~-5 black_concrete","/fill ~11 ~16 ~-5 ~11 ~16 ~-5 black_concrete","/fill ~14 ~16 ~-5 ~16 ~16 ~-5 black_concrete","/fill ~19 ~16 ~-5 ~19 ~16 ~-5 black_concrete","/fill ~22 ~16 ~-5 ~23 ~16 ~-5 black_concrete","/fill ~0 ~15 ~-5 ~1 ~15 ~-5 black_concrete","/fill ~6 ~15 ~-5 ~6 ~15 ~-5 black_concrete","/fill ~9 ~15 ~-5 ~9 ~15 ~-5 black_concrete","/fill ~14 ~15 ~-5 ~15 ~15 ~-5 black_concrete","/fill ~21 ~15 ~-5 ~21 ~14 ~-5 black_concrete","/fill ~23 ~15 ~-5 ~24 ~15 ~-5 black_concrete","/fill ~5 ~14 ~-5 ~5 ~13 ~-5 black_concrete","/fill ~10 ~14 ~-5 ~11 ~12 ~-5 black_concrete","/fill ~14 ~14 ~-5 ~14 ~11 ~-5 black_concrete","/fill ~16 ~14 ~-5 ~19 ~14 ~-5 black_concrete","/fill ~24 ~14 ~-5 ~24 ~13 ~-5 black_concrete","/fill ~0 ~13 ~-5 ~0 ~9 ~-5 black_concrete","/fill ~4 ~13 ~-5 ~4 ~11 ~-5 black_concrete","/fill ~6 ~13 ~-5 ~9 ~13 ~-5 black_concrete","/fill ~16 ~13 ~-5 ~16 ~12 ~-5 black_concrete","/fill ~18 ~13 ~-5 ~18 ~13 ~-5 black_concrete","/fill ~2 ~12 ~-5 ~2 ~9 ~-5 black_concrete","/fill ~7 ~12 ~-5 ~8 ~12 ~-5 black_concrete","/fill ~15 ~12 ~-5 ~15 ~8 ~-5 black_concrete","/fill ~19 ~12 ~-5 ~19 ~9 ~-5 black_concrete","/fill ~23 ~12 ~-5 ~23 ~11 ~-5 black_concrete","/fill ~3 ~11 ~-5 ~3 ~11 ~-5 black_concrete","/fill ~5 ~11 ~-5 ~7 ~11 ~-5 black_concrete","/fill ~9 ~11 ~-5 ~9 ~10 ~-5 black_concrete","/fill ~12 ~11 ~-5 ~12 ~11 ~-5 black_concrete","/fill ~17 ~11 ~-5 ~17 ~11 ~-5 black_concrete","/fill ~20 ~11 ~-5 ~21 ~11 ~-5 black_concrete","/fill ~24 ~11 ~-5 ~24 ~10 ~-5 black_concrete","/fill ~5 ~10 ~-5 ~5 ~10 ~-5 black_concrete","/fill ~8 ~10 ~-5 ~8 ~6 ~-5 black_concrete","/fill ~16 ~10 ~-5 ~16 ~4 ~-5 black_concrete","/fill ~21 ~10 ~-5 ~22 ~10 ~-5 black_concrete","/fill ~6 ~9 ~-5 ~7 ~9 ~-5 black_concrete","/fill ~10 ~9 ~-5 ~10 ~9 ~-5 black_concrete","/fill ~13 ~9 ~-5 ~14 ~9 ~-5 black_concrete","/fill ~17 ~9 ~-5 ~18 ~9 ~-5 black_concrete","/fill ~20 ~9 ~-5 ~20 ~5 ~-5 black_concrete","/fill ~22 ~9 ~-5 ~22 ~9 ~-5 black_concrete","/fill ~9 ~8 ~-5 ~9 ~8 ~-5 black_concrete","/fill ~11 ~8 ~-5 ~11 ~6 ~-5 black_concrete","/fill ~0 ~7 ~-5 ~6 ~7 ~-5 black_concrete","/fill ~10 ~7 ~-5 ~10 ~5 ~-5 black_concrete","/fill ~12 ~7 ~-5 ~12 ~7 ~-5 black_concrete","/fill ~18 ~7 ~-5 ~18 ~7 ~-5 black_concrete","/fill ~24 ~7 ~-5 ~24 ~6 ~-5 black_concrete","/fill ~0 ~6 ~-5 ~0 ~1 ~-5 black_concrete","/fill ~6 ~6 ~-5 ~6 ~1 ~-5 black_concrete","/fill ~15 ~6 ~-5 ~15 ~4 ~-5 black_concrete","/fill ~2 ~5 ~-5 ~4 ~3 ~-5 black_concrete","/fill ~9 ~5 ~-5 ~9 ~3 ~-5 black_concrete","/fill ~13 ~5 ~-5 ~14 ~4 ~-5 black_concrete","/fill ~17 ~5 ~-5 ~19 ~5 ~-5 black_concrete","/fill ~22 ~5 ~-5 ~23 ~5 ~-5 black_concrete","/fill ~11 ~4 ~-5 ~11 ~4 ~-5 black_concrete","/fill ~17 ~4 ~-5 ~18 ~4 ~-5 black_concrete","/fill ~23 ~4 ~-5 ~24 ~4 ~-5 black_concrete","/fill ~17 ~3 ~-5 ~17 ~3 ~-5 black_concrete","/fill ~21 ~3 ~-5 ~22 ~3 ~-5 black_concrete","/fill ~24 ~3 ~-5 ~24 ~1 ~-5 black_concrete","/fill ~8 ~2 ~-5 ~8 ~1 ~-5 black_concrete","/fill ~12 ~2 ~-5 ~12 ~2 ~-5 black_concrete","/fill ~15 ~2 ~-5 ~16 ~2 ~-5 black_concrete","/fill ~19 ~2 ~-5 ~20 ~2 ~-5 black_concrete","/fill ~1 ~1 ~-5 ~5 ~1 ~-5 black_concrete","/fill ~16 ~1 ~-5 ~16 ~1 ~-5 black_concrete","/fill ~18 ~1 ~-5 ~18 ~1 ~-5 black_concrete","/fill ~21 ~1 ~-5 ~21 ~1 ~-5 black_concrete"]}

As recommended by the challenge text, I got the latest Minecraft Java Launcher and launched a world:

I followed the YouTube video and gave myself a command block, placed it with a button on it, and posted the mc86 initcode:

I clicked the button and received an enchanted book:

I followed the instructions and clicked each of the six links to generate my mc86 computer in my world:

Next, following the YouTube video, I pasted the challenge source code into the command block I created earlier and click the button:

This gave me a book and quill with 106 pages of instructions:

I then placed this book and quill into the Shulker Box:

I placed a button in the mc86 computer (as directed in the YouTube video) and and clicked it to run the challenge program:

This generated a giant QR code in my world:

After scanning the QR code, I got the following link:

https://gist.github.com/AndyNovo/30aa5b2665aa388dc81545f79ccb380f

This link gave me this code:

/give @p writable_book{pages:['/setblock ~5 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"bs",Color:4},{Pattern:"ls",Color:4},{Pattern:"rs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~6 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"rs",Color:4},{Pattern:"bs",Color:4},{Pattern:"ts",Color:4},{Pattern:"cbo",Color:11},{Pattern:"ls",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~7 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ts",Color:4},{Pattern:"bs",Color:4},{Pattern:"rs",Color:4},{Pattern:"ms",Color:11},{Pattern:"ls",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~8 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ts",Color:4},{Pattern:"cs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~9 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ms",Color:4},{Pattern:"rs",Color:11},{Pattern:"ts",Color:4},{Pattern:"ls",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~10 ~0 ~5 yellow_banner[rotation=0]{Patterns:[{Pattern:"cbo",Color:11},{Pattern:"vhr",Color:11},{Pattern:"bo",Color:11},{Pattern:"mr",Color:11}]}', '/setblock ~11 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"tt",Color:4},{Pattern:"tts",Color:11},{Pattern:"ls",Color:4},{Pattern:"rs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~12 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"tl",Color:4},{Pattern:"cs",Color:4},{Pattern:"bs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~13 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ls",Color:4},{Pattern:"tt",Color:11},{Pattern:"drs",Color:4},{Pattern:"rs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~14 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ts",Color:4},{Pattern:"bs",Color:4},{Pattern:"ms",Color:4},{Pattern:"rs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~15 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ts",Color:4},{Pattern:"bs",Color:4},{Pattern:"rs",Color:4},{Pattern:"ms",Color:11},{Pattern:"ls",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~16 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"hh",Color:4},{Pattern:"cs",Color:11},{Pattern:"ts",Color:4},{Pattern:"ls",Color:4},{Pattern:"drs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~17 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ls",Color:4},{Pattern:"hhb",Color:11},{Pattern:"ms",Color:4},{Pattern:"rs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~18 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ms",Color:4},{Pattern:"rs",Color:11},{Pattern:"ts",Color:4},{Pattern:"ls",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~19 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ts",Color:4},{Pattern:"cs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~20 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"bo",Color:4},{Pattern:"rud",Color:11},{Pattern:"ld",Color:11}]}', '/setblock ~21 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ls",Color:4},{Pattern:"hhb",Color:11},{Pattern:"ms",Color:4},{Pattern:"rs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~22 ~0 ~5 yellow_banner[rotation=0]{Patterns:[{Pattern:"mr",Color:11},{Pattern:"ms",Color:11},{Pattern:"drs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~23 ~0 ~5 yellow_banner[rotation=0]{Patterns:[{Pattern:"mr",Color:11},{Pattern:"ms",Color:11},{Pattern:"drs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~24 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ts",Color:4},{Pattern:"bs",Color:4},{Pattern:"ms",Color:4},{Pattern:"rs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~25 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"tt",Color:4},{Pattern:"tts",Color:11},{Pattern:"ls",Color:4},{Pattern:"rs",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~26 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"rs",Color:4},{Pattern:"bs",Color:4},{Pattern:"ts",Color:4},{Pattern:"cbo",Color:11},{Pattern:"ls",Color:4},{Pattern:"ms",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~27 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"bs",Color:4},{Pattern:"ls",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~28 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"drs",Color:4},{Pattern:"hhb",Color:11},{Pattern:"dls",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~29 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"bo",Color:4},{Pattern:"rud",Color:11},{Pattern:"ld",Color:11}]}', '/setblock ~30 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"drs",Color:4},{Pattern:"hhb",Color:11},{Pattern:"dls",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~31 ~0 ~5 blue_banner[rotation=0]{Patterns:[{Pattern:"ts",Color:4},{Pattern:"bs",Color:4},{Pattern:"rs",Color:4},{Pattern:"ls",Color:4},{Pattern:"bo",Color:11}]}', '/setblock ~32 ~0 ~5 yellow_banner[rotation=0]{Patterns:[{Pattern:"cbo",Color:11},{Pattern:"vh",Color:11},{Pattern:"mr",Color:11}]}']}

I then placed this code into my command block and clicked the button to run it:

This gave me another book and quill with 28 pages:

I placed it into the Shulker Box, added another button, and clicked it to run the code:

This generated the flag:

UDCTF{M1N3CR4FT_4SS3MBLY_Y0}

0x41414141 CTF: Misc: optimizer (400)

This is from the 0x41414141 CTF by pop_eax.

For this challenge, we are just given details for two server instances; one for US and one for EU.

Connecting via netcat, we are told that we will be given a number of problems and we have to solve them. It mentions that level 1 is tower of hanoi. A quick google search and I find more information about it. After some trial and error using different possibilities for the number of pegs.

This presentation was especially helpful in determining the formula (moves = 2n – 1) to get the number of moves: http://www.cs.uvm.edu/~rsnapp/teaching/cs32/lectures/hanoi.pdf

A manual check confirms the formula is correct, but the server responds with another problem.

There are four disks listed, so n=4. 24 – 1 = 15

We will need to automate this 🙂

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('45.134.3.200', 9660))

print('Server:', str(s.recv(1024)))
#print s.recv(1024)
while True:
    data = s.recv(1024).strip()
    if data:
	count = 0
        data = str(data)
        print(data)
        for i in data:
		if i == ',':
			count = count + 1
	count = count + 1
	n = pow(2, count) - 1
        if '[' in data:
		s.send(str(n))
        	print('Client: ', n)
s.close()

When I run this script, it iterates through quite a few problems, then the server reports that I’m in level 2: and have to give the number of inversions for the provided output.

A quick google search helps me figure out how to do this in python. https://www.geeksforgeeks.org/python-program-for-count-inversions-in-an-array-set-1-using-merge-sort/

I add some checks for the current level to help apply the appropriate process and then calculate the inversions:

import socket
import re

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('45.134.3.200', 9660))

def getInvCount(arr, n): 
  
    inv_count = 0
    for i in range(n): 
        for j in range(i + 1, n): 
            if (arr[i] > arr[j]): 
                inv_count += 1
  
    return inv_count 
level = 1
print('Server:', str(s.recv(1024)))
while True:
    data = s.recv(2048).strip()
    if data == '':
        break
    if data:
		if 'level 1' in data:
			level = 1
			print ('********************************** Level 1 **********************************')
		if 'level 2' in data:
			level = 2
			print ('********************************** Level 2 **********************************')

		if level == 1:
		
			count = 0
			data = str(data)
			print str(data)
			for i in data:
					if i == ',':
							count = count + 1
			count = count + 1
			n = pow(2, count) - 1
			if '[' in data:
				s.send(str(n))
				#print('Client: ', n)
	
		if level == 2:
			print str(data)
			
			if '[' in data:
			    sep = ']'
			    stripped = data.split(sep, 1)[0]
			    arr1 = stripped.split(', ')
			    arr1 = map(lambda each:each.strip("["), arr1)
			    arr = arr1
			    arr = [int(numeric_string) for numeric_string in arr1]
			    n = len(arr)
			    inversioncount = getInvCount(arr,n)
			    s.send(str(inversioncount))
s.close()

Here is a video of the script in action:

And the flag:

I really appreciate the challenge!

Shadow CTF: Misc: Tesseract (350)

This is from the Shadow CTF.

Disclaimer: I did this challenge quick and dirty in order to get first blood.

For this challenge, we are told that there is a program that can decrypt the flag for us using the right password. The password is a number between 16000 and 20000. We are provided a zip file containing an ELF binary (numgen)and another zip file that contains a bunch of small images. These images are named 0.png … 39.png. They are pictures of random letters, numbers, and characters.

Running the executable I am told it wants a number argument.

I provide a number (1600) and get a series of numbers as a response.

Looking at the image file names with relation to the numbers in the response, I see it translates to gibberish. I can make an educated guess that the flag should end with a “}”, which is 39.png and the the first character should be an “S” (7.png) or an “F” (32.png) based on the CTF flag format.

Using this method, I can write a script to try all possibilities from 16000 to 20000 (4000 possibilities).

#!/bin/bash
for i in {16000..20000}
do
  ./numgen $i
done

I can run the script and output the results to a file. Yes, a more elegant solution could be crafted that would grep for the right results, but it is only a 24-hour CTF.

/runnum.sh > numgenout.txt

The output file contains 8,000 lines (the resulting numbers and the “Randomizing names of images …” string.

7 5 8 39 11 33 33 33 23 6 8 21 38 36 38 14 9 20 24 
Randomizing names of images ... 
5 8 39 11 33 33 33 23 6 17 8 38 36 38 14 9 20 24 18 
Randomizing names of images ... 
8 39 11 33 33 33 23 6 17 21 8 36 38 14 9 20 24 18 27 
Randomizing names of images ... 
39 11 33 33 33 23 6 17 21 38 8 38 14 9 20 24 18 27 17 
Randomizing names of images ... 
11 33 33 33 23 6 17 21 38 36 8 ................................

Quick and dirty I copy the lines into excel (yeah, I know) and drop all cells containing the “Randomizing names of images …” string.

I create a quick formula to get the 1 or two digit number before the first space in the cell and then throw it in the “B” column.

=LEFT(A1,(FIND(" ",A1,1)-1))

A quick filter to only show the cells that start with 7 or 32 (S or F), and I get 189 cells.

I then do a quick filter using “ends with” and use 18 (“}”) as the criteria.

That narrows it down to 9 possible cells.

I now look for the second letter based on my assumption that the first word is “shadow” or “flag”. The numbers should be either 6, 4, or 31 (there are two “L” images).I do this with another filter.

It gives me only one result:

A quick and dirty translation using the images gives me the flag:

SHADOWCTF{W3LLD0N3}

After submitting the flag for first blood, I make an HTML file to make the flag look pretty:

<html>
<head><title>Gimmie The Flag</title></head>
<body>
<center>
<p>7 6 22 13 34 8 17 0 32 39 8 19 4 31 30 25 2 14 18</p>
<p><img src="7.png"><img src="6.png"><img src="22.png"><img src="13.png"><img src="34.png"><img src="8.png"><img src="17.png"><img src="0.png"><img src="32.png"><img src="39.png"><img src="8.png"><img src="19.png"><img src="4.png"><img src="31.png"><img src="30.png"><img src="25.png"><img src="2.png"><img src="14.png"><img src="18.png"></p>
</center>
</body>
</html>

HTH 2020 CTF: Misc: whoami (100)

This is from the Hackers Teaching Hackers HTH2020 CTF.

Full Disclosure: I did not complete this challenge in time for the CTF. I solved three of the four parts during the CTF and finally finished it the day after the CTF ended.

For this challenge, we are given a single file to download (no extention): “split” and the following text:

It’s a bird! It’s a plane! It’s…
A story in 4 parts.

We are also provided two hints:

Are we exclusive? Or…

ALL CAPS

To begin, I download the file and open it in notepad++ (as I always do for questionable files).

I initially see that this is a Linux executable (ELF), but I also see a bunch of strange text (strange for an ELF file).

There appears to be some non-printable binary (typical of ELF files), HTML, JAVA, and Unicode (indicative of a PDF).

I first will run the file in Kali to see what it does…

It gives me a hexadecimal string: 4854487b312d62316e7a5f725f66756e5f

I do a hex to ASCII conversion and get: HTH{1-b1nz_r_fun_

This must be part one of the flag.

Next, I copied the file and gave it a .html extension. I can read the HTML, but it would be fun to see how it presents as a webpage. I opened it in Firefox and receive a pop-up alert with another string.

This time, the string is not hex: Ml9odG1sX3J1bGV6X2QwMGRf

I try the usual suspects for decoding. In this case, Base64 was the ticket.

2_html_rulez_d00d_

This must be part two of the flag. Half way there!

Next, based on the text in the file indicative of PDF documents…

I copy the file and give it a .pdf extension and open it as such.

I see a string at the bottom of the PDF that matches the format I would expect for part three of the flag except it is URL encoded. After decoding that I get: 3_a_p0rtabl3_d0c_

One more part to go!

As I mentioned earlier, I saw some JAVA code in the file contents, so I ran the file with java…

That gives me a strange string: |y&x7$)a}5

After a lot of trial and error, I remembered to review the hints and determined this is most likely the output from an XOR cipher (Hint #1).

I used dcode.fr/xor-cipher to try and decode it.

The password must be all caps (Hint #2), but what is the password. I got lost in the weeds thinking that the password should be SUPERMAN because of the challenge name and text. This is where I stagnated.

After the CTF was over, I chatted with the challenge creator @mythdude and he indicated that the password is more simple than SUPERMAN.

I went back to dcode.fr/xor-cipher and tried simpler passwords that I could think of for the cipher. HTH was it.

That gave me the 4th part of the flag: 4-n0cla55}

The final full flag was:
HTH{1-b1nz_r_fun_2_html_rulez_d00d_3_a_p0rtabl3_d0c_4-n0cla55}

This challenge was amazing as it was a polyglot. It was a single file that would be executed/ran in four different way without generating any errors or junk messages. It was a Linux binary program, HTML webpage, PDF file and a JAVA jar file all in one. Certainly the first one I have seen.

I want to thank @mythdude for putting this challenge together. It was very creative!