-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i love morse code and bash scripting
- Loading branch information
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
echo "M0rsarchive HTB Solution Script" | ||
echo "Usage: ./m0rsarchive.sh M0rsarchive.zip morsedecode.py" | ||
echo "[!] Starting in 10 seconds..." | ||
sleep 10 | ||
|
||
#make a new, clean working directory | ||
mkdir ./flagzips | ||
|
||
#move to working dir | ||
cd flagzips | ||
|
||
#unzip M0rsarchive.zip | ||
unzip -j -o -P hackthebox ../$1 1> /dev/null | ||
|
||
#rename original pwd image | ||
mv pwd.png orig_pwd.png | ||
|
||
#backup original pwd image | ||
cp orig_pwd.png pwd_999.png | ||
|
||
#unzip -j flattens one dir when extracting | ||
#unzip -o overwrites; useful for testing | ||
|
||
for ((i=999;i>=0;i--)); do | ||
unzip -j -o -P $(python3 ../$2 pwd_$i.png) flag_$i.zip 1> /dev/null; | ||
mv pwd.png pwd_$(( $i-1 )).png | ||
clear; echo $((1000 - $i))/1000 | ||
done | ||
|
||
echo "M0rsarchive HTB Solution Script" | ||
|
||
#show flag | ||
cat flag | ||
|
||
#clean up | ||
cd .. | ||
rm -r ./flagzips | ||
|
||
#one-liner: mv pwd.png pwd_999.png; for i in {999..0}; do unzip -j -P $(python3 morsedecode.py pwd_$i.png) flag_$i.zip; mv pwd.png pwd_$(($i - 1)).png ;done ; cat flag | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import sys | ||
from PIL import Image | ||
|
||
if len(sys.argv) != 2: | ||
print(" did you mean?: python3 morsedecode.py pwd.png") | ||
exit() | ||
|
||
filename=sys.argv[1] | ||
image = Image.open(filename) | ||
pixels = image.load() | ||
width, height = image.size | ||
bgcolour = pixels[0,0] | ||
|
||
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", | ||
"-----":"0", | ||
".----":"1", | ||
"..---":"2", | ||
"...--":"3", | ||
"....-":"4", | ||
".....":"5", | ||
"-....":"6", | ||
"--...":"7", | ||
"---..":"8", | ||
"----.":"9" | ||
} | ||
|
||
morsecode = "" | ||
|
||
|
||
for i in range(height): | ||
line = [0 for i in range(width) ] | ||
#print(line) | ||
|
||
mcode = "" | ||
|
||
for x in range(width): | ||
if pixels[x,i] != bgcolour: | ||
line[x]=1 | ||
left = pixels[x-1,i] | ||
right = pixels[x+1,i] | ||
if left != bgcolour and right != bgcolour: | ||
mcode += "-" | ||
elif left == bgcolour and right == bgcolour: | ||
mcode += "." | ||
else: | ||
pass | ||
|
||
if mcode: | ||
morsecode += morse[mcode] | ||
#print(mcode) | ||
#print(line) | ||
|
||
print(morsecode, end='') | ||
|
||
|
||
#convert image to morse code | ||
|
||
#output ascii rep |