import sys
from PIL import Image
if len(sys.argv) != 2:
print("Usage: readImgMorse.py $file")
exit()
# Step 1: Read Image and get the morse symbols (- .)
# Images look like this:
#########################
# #
# ### ### ### ### # #
# #
#########################
##########################
# #
# ### ### ### ### ### #
# #
# ### ### ### # # #
# #
##########################
# => only read lines 1,3,5,..., ignore first & last pixel
im = Image.open(sys.argv[1])
pix = im.load()
width,height = im.size
bgColor = pix[0,0]
morseCode = ""
count = 0
# Loop through the pixel lines
for y in range(1, height - 1, 2): # start at 1 to skip first line, - 1 cuz we index at 0, step by 2 (to skip even lines)
for x in range(1, width - 1): # start at 1 to skip first pixel, -1 cuz we index at 0
if pix[x,y] != bgColor:
count += 1 # add 1 to count if pixel has other color
else: # we back to bgcolor
if count != 0: # have we found a colored pixel?
morseCode += ("-" if count == 3 else ".") # depending on the length add morse char
count = 0 # reset pixel length
morseCode += " "
# Step 2: morse to readable
# https://stackoverflow.com/a/32094652
CODE = {'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': '--..',
'0': '-----', '1': '.----', '2': '..---',
'3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..',
'9': '----.'
}
CODE_REVERSED = {value:key for key,value in CODE.items()}
def from_morse(s):
return ''.join(CODE_REVERSED.get(i) for i in s.split())
print(from_morse(morseCode).lower())
getflag.sh
#!/bin/bash
Num=999
while [ $Num -ge 0 ]
do
pw=$(python3 ./readImgMorse.py pwd.png)
if [ -z "$pw" ]
then
echo "something wrong..."
exit
fi
echo $pw
unzip -q -P $pw -o flag_$Num.zip
rm flag_$Num.zip
Num=$((Num-1))
mv flag/* .
done
cat flag/flag
rm pwd.png
rm -r flag/
kali@kali:~/HTB/challenges/Misc/M0rsarchive$ ./getflag.sh
HTB{D0_y0u_L1k3_m0r53??}