Created
March 22, 2020 17:18
-
-
Save streanger/cc94b7c7a9a60390b8d1cc5024c0df00 to your computer and use it in GitHub Desktop.
ascii_art_0_writeup
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 sys | |
import os | |
import json | |
from string import ascii_lowercase, ascii_uppercase, digits | |
import nclib | |
def read_json_to_dict(file): | |
with open(file) as f: | |
data = json.load(f) | |
return data | |
def write_to_json(file, data): | |
with open(file, 'w') as fp: | |
json.dump(data, fp, sort_keys=True, indent=4, ensure_ascii=False) | |
return True | |
def characters_map(s): | |
dictio = read_json_to_dict('dictio.json') | |
if s in list(dictio.keys()): | |
return dictio[s] | |
return False | |
def join_columns(data, start, stop): | |
return '\n'.join([''.join(line) for line in list(zip(*data[start:stop]))]) | |
def create_dictio(s): | |
'''s is string''' | |
lines_list = [line for line in s.splitlines() if line.strip()] # remove white lines | |
stripped = '\n'.join([line for line in lines_list if line.strip()]) | |
line_length = len(stripped.splitlines()[0]) | |
swapped = list(zip(*[list(line) for line in stripped.splitlines()])) | |
equation = '' | |
start_key = 0 | |
dictio = {} | |
for key, _ in enumerate(swapped): | |
character = join_columns(swapped, start_key, key+1) | |
character = '\n'.join([line for line in character.splitlines() if line.strip()]) | |
print(character) | |
ask = input() | |
if ask.strip(): | |
char_to_map = ask.strip() | |
dictio[character] = char_to_map | |
start_key = key+1 | |
return dictio | |
def get_response(s): | |
'''s is string''' | |
lines_list = [line for line in s.splitlines() if line.strip()] # remove white lines | |
stripped = '\n'.join([line for line in lines_list if line.strip()]) | |
line_length = len(stripped.splitlines()[0]) | |
swapped = list(zip(*[list(line) for line in stripped.splitlines()])) | |
equation = '' | |
start_key = 0 | |
for key, _ in enumerate(swapped): | |
character = join_columns(swapped, start_key, key+1) | |
character = '\n'.join([line for line in character.splitlines() if line.strip()]) | |
value = characters_map(character) | |
if value: | |
equation += value | |
start_key = key+1 | |
return equation | |
def map_all_characters(): | |
# create dictionary for store all characters | |
try: | |
dictio = read_json_to_dict('dictio.json') | |
except: | |
dictio = {} | |
all_characters_set = set(ascii_lowercase + ascii_uppercase + digits) | |
while True: | |
nc = nclib.Netcat(('3.91.74.70', 1337), udp=False) | |
wait_newline = False | |
first_stuff = True | |
while True: | |
full_lines = b'' | |
while True: | |
try: | |
line = nc.recvline() | |
except nclib.errors.NetcatError: | |
print('Connection dropped!') | |
print('\nFLAG:\n\t{}'.format(full_lines.decode('utf-8'))) | |
sys.exit() | |
full_lines += line | |
if b'\r\n' in line: | |
wait_newline = True | |
if wait_newline and not b'\r\n' in line: | |
wait_newline = False | |
break | |
lines_list = [line.decode('utf-8') for line in full_lines.splitlines()] | |
if first_stuff: | |
lines_list = lines_list[3:] | |
first_stuff = False | |
else: | |
lines_list = [line[1:] if not key else line for key, line in enumerate(lines_list)] | |
s = '\n'.join(lines_list) | |
print(s) | |
break | |
# map characters here | |
ask = input('ask: ') | |
if ask == 'map': | |
mapped = create_dictio(s) | |
dictio = {**dictio, **mapped} | |
if ask == 'skip': | |
continue | |
if ask == 'break': | |
break | |
# check if we have all ascii_lowercase, ascii_uppercase and digits | |
dictio_values_set = set(dictio.values()) | |
characters_left = all_characters_set.symmetric_difference(dictio_values_set) | |
print('characters_left: {}'.format(characters_left)) | |
write_to_json('dictio.json', dictio) | |
print('dictio written to dictio.json') | |
return dictio | |
def main(): | |
test_cmd = 'nc 3.91.74.70 1337' # ASCII ART 0, NEW IP | |
nc = nclib.Netcat(('3.91.74.70', 1337), udp=False) | |
wait_newline = False | |
first_stuff = True | |
while True: | |
full_lines = b'' | |
while True: | |
try: | |
line = nc.recvline() | |
except nclib.errors.NetcatError: | |
print('Connection dropped!') | |
print('\nFLAG:\n\t{}'.format(full_lines.decode('utf-8'))) | |
sys.exit() | |
full_lines += line | |
if b'\r\n' in line: | |
wait_newline = True | |
if wait_newline and not b'\r\n' in line: | |
wait_newline = False | |
break | |
lines_list = [line.decode('utf-8') for line in full_lines.splitlines()] | |
if first_stuff: | |
lines_list = lines_list[3:] | |
first_stuff = False | |
else: | |
lines_list = [line[1:] if not key else line for key, line in enumerate(lines_list)] | |
s = '\n'.join(lines_list) | |
print(s) | |
response = get_response(s) | |
print('response: {}'.format(response)) | |
response_bytes = '{}'.format(response).encode('utf-8') | |
nc.sendline(response_bytes) | |
''' | |
response: wUUuFK | |
__ _ __ __ _ _ | |
/ /_ | |__ / _| / _| (_) (_) | |
| '_ \ | '_ \ | |_ | |_ | | | | | |
| (_) || | | || _|| _| | | | | | |
\___/ |_| |_||_| |_| _/ | _/ | | |
|__/ |__/ | |
response: 6hffjj | |
__ __ ____ _ _ _ _ _ | |
\ \ / /| __ ) | || | | | (_)| |__ | |
\ V / | _ \ | || |_ | | | || '_ \ | |
| | | |_) ||__ _|| | | || |_) | | |
|_| |____/ |_| |_| _/ ||_.__/ | |
|__/ | |
response: YB4ljb | |
Connection dropped! | |
FLAG: | |
>securinets{w3ll_d0n3_g00d!!} | |
''' | |
return True | |
if __name__ == "__main__": | |
current_path = os.path.realpath(os.path.dirname(sys.argv[0])) | |
os.chdir(current_path) | |
# ********* solution ********* | |
main() | |
# ********* create dictionary ********* | |
# dictio = map_all_characters() | |
# ********* show dictio elements ********* | |
# dictio = read_json_to_dict('dictio.json') | |
# for key, value in dictio.items(): | |
# print(key, value) | |
# input() | |
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
{ | |
" _ \n | |\n _ | |\n| |_| |\n \\___/ ": "J", | |
" _ \n __| |\n / _` |\n| (_| |\n \\__,_|": "d", | |
" _ \n / \\ \n / _ \\ \n / ___ \\ \n/_/ \\_\\": "A", | |
" _ \n (_)\n | |\n | |\n _/ |\n|__/ ": "j", | |
" __ \n / _|\n| |_ \n| _|\n|_| ": "f", | |
" __ \n / /_ \n| '_ \\ \n| (_) |\n \\___/ ": "6", | |
" __ _ \n / _` |\n| (_| |\n \\__, |\n |_|": "q", | |
" __ _ \n / _` |\n| (_| |\n \\__, |\n |___/ ": "g", | |
" __ _ \n / _` |\n| (_| |\n \\__,_|": "a", | |
" ___ \n / _ \\\n| __/\n \\___|": "e", | |
" ___ \n / __|\n| (__ \n \\___|": "c", | |
" ___ \n ( _ ) \n / _ \\ \n| (_) |\n \\___/ ": "8", | |
" ___ \n / _ \\ \n| (_) |\n \\__, |\n /_/ ": "9", | |
" ___ \n / _ \\ \n| (_) |\n \\___/ ": "o", | |
" ___ \n / _ \\ \n| | | |\n| |_| |\n \\__\\_\\": "Q", | |
" ___ \n / _ \\ \n| | | |\n| |_| |\n \\___/ ": "O", | |
" ____ \n / ___|\n| | \n| |___ \n \\____|": "C", | |
" ____ \n / ___|\n| | _ \n| |_| |\n \\____|": "G", | |
" _ \n(_)\n| |\n| |\n|_|": "i", | |
" _ \n/ |\n| |\n| |\n|_|": "1", | |
" _ \n| |\n| |\n| |\n|_|": "l", | |
" _ \n| |_ \n| __|\n| |_ \n \\__|": "t", | |
" _ \n| | __\n| |/ /\n| < \n|_|\\_\\": "k", | |
" _ \n| | \n| | \n| |___ \n|_____|": "L", | |
" _ \n| |__ \n| '_ \\ \n| | | |\n|_| |_|": "h", | |
" _ \n| |__ \n| '_ \\ \n| |_) |\n|_.__/ ": "b", | |
" _ _ \n| \\ | |\n| \\| |\n| |\\ |\n|_| \\_|": "N", | |
" _ _ \n| | | |\n| | | |\n| |_| |\n \\___/ ": "U", | |
" _ _ \n| | | |\n| |_| |\n \\__, |\n |___/ ": "y", | |
" _ _ \n| | | |\n| |_| |\n \\__,_|": "u", | |
" _ _ \n| | | |\n| |_| |\n| _ |\n|_| |_|": "H", | |
" _ _ \n| || | \n| || |_ \n|__ _|\n |_| ": "4", | |
" _ __\n| |/ /\n| ' / \n| . \\ \n|_|\\_\\": "K", | |
" _ __ \n| '__|\n| | \n|_| ": "r", | |
" _ __ \n| '_ \\ \n| | | |\n|_| |_|": "n", | |
" _ __ \n| '_ \\ \n| |_) |\n| .__/ \n|_| ": "p", | |
" _ __ ___ \n| '_ ` _ \\ \n| | | | | |\n|_| |_| |_|": "m", | |
" __ __ \n| \\/ |\n| |\\/| |\n| | | |\n|_| |_|": "M", | |
" ___ \n/ __|\n\\__ \\\n|___/": "s", | |
" ___ \n|_ _|\n | | \n | | \n|___|": "I", | |
" ____\n|_ /\n / / \n/___|": "z", | |
" ____ \n/ ___| \n\\___ \\ \n ___) |\n|____/ ": "S", | |
" ____ \n| _ \\ \n| | | |\n| |_| |\n|____/ ": "D", | |
" ____ \n| _ \\ \n| |_) |\n| _ < \n|_| \\_\\": "R", | |
" ____ \n| _ \\ \n| |_) |\n| __/ \n|_| ": "P", | |
" ____ \n| __ ) \n| _ \\ \n| |_) |\n|____/ ": "B", | |
" ____ \n| ___| \n|___ \\ \n ___) |\n|____/ ": "5", | |
" ____ \n|___ \\ \n __) |\n / __/ \n|_____|": "2", | |
" _____\n|__ /\n / / \n / /_ \n/____|": "Z", | |
" _____ \n| ___|\n| |_ \n| _| \n|_| ": "F", | |
" _____ \n| ____|\n| _| \n| |___ \n|_____|": "E", | |
" _____ \n|_ _|\n | | \n | | \n |_| ": "T", | |
" _____ \n|___ |\n / / \n / / \n /_/ ": "7", | |
" _____ \n|___ / \n |_ \\ \n ___) |\n|____/ ": "3", | |
"__ __\n\\ \\ / /\n \\ \\ /\\ / / \n \\ V V / \n \\_/\\_/ ": "W", | |
"__ __\n\\ \\ /\\ / /\n \\ V V / \n \\_/\\_/ ": "w", | |
"__ __\n\\ \\ / /\n \\ \\ / / \n \\ V / \n \\_/ ": "V", | |
"__ __\n\\ \\ / /\n \\ V / \n \\_/ ": "v", | |
"__ __\n\\ \\ / /\n \\ V / \n | | \n |_| ": "Y", | |
"__ __\n\\ \\/ /\n > < \n/_/\\_\\": "x", | |
"__ __\n\\ \\/ /\n \\ / \n / \\ \n/_/\\_\\": "X" | |
} |
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
_ ___ __ __ __ ___ ____ | |
| | / _ \ | \/ | / /_ / _ \ |___ \ | |
| | | | | || |\/| || '_ \ | (_) | __) | | |
| |___ | |_| || | | || (_) | \__, | / __/ | |
|_____| \__\_\|_| |_| \___/ /_/ |_____| | |
response: LQM692 | |
_ ____ _ _ __ __ _ _ | |
| |_ |___ \ __| || | \ \/ /| | | | | |
| __| __) | / _` || | \ / | | | | | |
| |_ / __/ | (_| || |___ / \ | |_| | | |
\__||_____| \__,_||_____|/_/\_\ \___/ | |
response: t2dLXU | |
____ _ _ ____ ____ ___ | |
| _ \ | \ | || _ \ | _ \ ___ / _ \ | |
| | | || \| || | | || |_) | / _ \| | | | | |
| |_| || |\ || |_| || _ < | __/| |_| | | |
|____/ |_| \_||____/ |_| \_\ \___| \___/ | |
response: DNDReO | |
_ _ __ __ | |
| | ___ __ __ ___ __| |\ \ / / | |
| | / _ \ \ \/ / / _ \ / _` | \ \ / / | |
| || (_) | > < | __/| (_| | \ V / | |
|_| \___/ /_/\_\ \___| \__,_| \_/ | |
response: loxedV | |
_ ____ __ _ | |
_ __ __ _ (_)|___ \ / /_ (_) | |
| '_ \ / _` || | __) || '_ \ | | | |
| |_) || (_| || | / __/ | (_) || | | |
| .__/ \__, ||_||_____| \___/ |_| | |
|_| |_| | |
response: pqi26i | |
_____ _ ____ _ _ _ | |
|__ / (_)/ ___| | \ | |__ __ __| | | |
/ / | |\___ \ | \| |\ \/ / / _` | | |
/ /_ | | ___) || |\ | > < | (_| | | |
/____| _/ ||____/ |_| \_|/_/\_\ \__,_| | |
|__/ | |
response: ZjSNxd | |
_ ____ _ _ | |
/ \ / ___| (_) _ __ ___ _ __ / \ | |
/ _ \ \___ \ | || '_ ` _ \ | '_ \ / _ \ | |
/ ___ \ ___) | | || | | | | || |_) | / ___ \ | |
/_/ \_\|____/ _/ ||_| |_| |_|| .__/ /_/ \_\ | |
|__/ |_| | |
response: ASjmpA | |
_____ ____ _ _ _ | |
|__ / ___ |___ \ _ _ | |__ | | | | | |
/ / / _ \ __) || | | || '_ \ | |_| | | |
/ /_ | __/ / __/ | |_| || |_) || _ | | |
/____| \___||_____| \__,_||_.__/ |_| |_| | |
response: Ze2ubH | |
____ _ _____ ____ _ | |
| _ \ | |_ |___ || _ \ __ _ | |__ | |
| | | || __| / / | |_) | / _` || '_ \ | |
| |_| || |_ / / | __/ | (_| || | | | | |
|____/ \__| /_/ |_| \__, ||_| |_| | |
|_| | |
response: Dt7Pqh | |
____ _ _ __ ____ ___ | |
|___ \ | |__ | |/ /__ __| ___| / _ \ | |
__) || '_ \ | ' / \ \ / /|___ \ | | | | | |
/ __/ | |_) || . \ \ V / ___) || |_| | | |
|_____||_.__/ |_|\_\ \_/ |____/ \___/ | |
response: 2bKv5O | |
____ ___ __ __ _ _ _ | |
__ _ / ___| / _ \ \ \ / /| | | |(_) | |
/ _` |\___ \ | (_) | \ V / | | | || | | |
| (_| | ___) | \__, | | | | |_| || | | |
\__,_||____/ /_/ |_| \___/ |_| | |
response: aS9YUi | |
__ _ | |
__ _ / /_ __ __| |__ __ _ _ _ | |
/ _` || '_ \ \ \ / /| '_ \ / _` || | | | | |
| (_| || (_) | \ V / | | | || (_| || |_| | | |
\__, | \___/ \_/ |_| |_| \__, | \__,_| | |
|_| |___/ | |
response: q6vhgu | |
____ _ ____ _____ ____ ____ | |
| _ \ | | / ___|| ____|| ___| | _ \ | |
| | | || | | | | _| |___ \ | | | | | |
| |_| || |___ | |___ | |___ ___) || |_| | | |
|____/ |_____| \____||_____||____/ |____/ | |
response: DLCE5D | |
_ _ _ | |
| \ | | _ __ | | _ _ _ _ _ _ | |
| \| || '_ \ _ | || | | || | | || | | | | |
| |\ || |_) || |_| || |_| || |_| || |_| | | |
|_| \_|| .__/ \___/ \__, | \__, | \__,_| | |
|_| |___/ |___/ | |
response: NpJyyu | |
_ ___ ___ ____ | |
__ __| |__ |_ _| _ _ / _ \ / ___| | |
\ \ / /| '_ \ | | | | | || | | || | _ | |
\ V / | |_) | | | | |_| || |_| || |_| | | |
\_/ |_.__/ |___| \__, | \__\_\ \____| | |
|___/ | |
response: vbIyQG | |
_ _ __ __ __ _ | |
___ | || | / _|\ \ / /| | __ | |
/ _ \ _ | || | | |_ \ \ /\ / / | |/ / | |
| __/| |_| || |___ | _| \ V V / | < | |
\___| \___/ |_____||_| \_/\_/ |_|\_\ | |
response: eJLfWk | |
____ _ _ | |
__ __ / ___| _ __ __ _ | | | | _ __ | |
\ \/ /| | _ | '_ \ / _` || |_| || '__| | |
> < | |_| || | | || (_| || _ || | | |
/_/\_\ \____||_| |_| \__,_||_| |_||_| | |
response: xGnaHr | |
_ ____ ____ _ _ | |
| | | __ ) ___ | _ \ (_)/ | | |
| | | _ \ / _ \ | |_) || || | | |
| |___ | |_) || (_) || _ < | || | | |
|_____||____/ \___/ |_| \_\|_||_| | |
response: LBoRi1 | |
_ _ ___ | |
| | _ _ / \ ___ ___ |_ _| | |
| | | | | | / _ \ / __| / _ \ | | | |
| |___ | |_| | / ___ \ \__ \| __/ | | | |
|_____| \__, |/_/ \_\|___/ \___||___| | |
|___/ | |
response: LyAseI | |
____ _____ ___ ____ | |
|___ \ |_ _| / _ \ __ _ ___ | _ \ | |
__) | | | | | | | / _` | / __|| |_) | | |
/ __/ | | | |_| || (_| || (__ | _ < | |
|_____| |_| \__\_\ \__, | \___||_| \_\ | |
|_| | |
response: 2TQqcR | |
_ ____ ____ __ __ ___ | |
/ \ _ __ / ___| | _ \ \ \ / / / _ \ | |
/ _ \ | '_ \ \___ \ | | | | \ \ / / | | | | | |
/ ___ \ | | | | ___) || |_| | \ V / | |_| | | |
/_/ \_\|_| |_||____/ |____/ \_/ \___/ | |
response: AnSDVO | |
_ _ _ _ ____ ____ | |
| | | || | | | _ __ __ _ / ___|| __ ) | |
| |_| || | | || '_ \ / _` || | _ | _ \ | |
| _ || |_| || |_) || (_| || |_| || |_) | | |
|_| |_| \___/ | .__/ \__,_| \____||____/ | |
|_| | |
response: HUpaGB | |
_ _ __ __ __ __ | |
| | | | _ __ __ _ _ __ ___ | \/ |\ \ / / | |
| | | || '_ \ / _` || '_ ` _ \ | |\/| | \ \ / / | |
| |_| || |_) || (_| || | | | | || | | | \ V / | |
\___/ | .__/ \__, ||_| |_| |_||_| |_| \_/ | |
|_| |___/ | |
response: UpgmMV | |
____ ____ ___ _ | |
/ ___|| _ \ |_ _| __ _ __| | ___ | |
| | | |_) | | | / _` | / _` | / __| | |
| |___ | _ < | | | (_| || (_| || (__ | |
\____||_| \_\|___| \__, | \__,_| \___| | |
|_| | |
response: CRIqdc | |
___ | |
____ __ _ _ __ ___ / _ \ __ __ __ _ | |
|_ / / _` || '_ ` _ \ | | | |\ \/ / / _` | | |
/ / | (_| || | | | | || |_| | > < | (_| | | |
/___| \__,_||_| |_| |_| \___/ /_/\_\ \__,_| | |
response: zamOxa | |
____ _ __ __ _ | |
___ | ___| | |\ \ / / ___ | |__ | |
/ _ \ |___ \ | | \ \ / / / _ \| '_ \ | |
| (_) | ___) || | \ V / | __/| |_) | | |
\___/ |____/ |_| \_/ \___||_.__/ | |
response: o5lVeb | |
__ __ __ __ __ _ _ _____ | |
\ \ / / / _|\ \ / /(_)| | __|___ | | |
\ \ / / | |_ \ V / | || |/ / / / | |
\ V / | _| | | | || < / / | |
\_/ |_| |_| |_||_|\_\ /_/ | |
response: VfYik7 | |
___ _ ____ __ __ ___ _ | |
( _ ) | |_ / ___|\ \/ / / _ \ / \ | |
/ _ \ | __|| | _ \ / | | | | / _ \ | |
| (_) || |_ | |_| | / \ | |_| | / ___ \ | |
\___/ \__| \____|/_/\_\ \___/ /_/ \_\ | |
response: 8tGXOA | |
____ _ _ __ __ _ _ ____ | |
/ ___|| \ | || \/ || \ | | ___ |___ \ | |
| | _ | \| || |\/| || \| |/ __| __) | | |
| |_| || |\ || | | || |\ |\__ \ / __/ | |
\____||_| \_||_| |_||_| \_||___/|_____| | |
response: GNMNs2 | |
___ _____ ____ _ _____ | |
/ _ \ | ___|| _ \ _ __ ___ | |__ |___ / | |
| (_) || |_ | |_) || '_ ` _ \ | '_ \ |_ \ | |
\__, || _| | _ < | | | | | || | | | ___) | | |
/_/ |_| |_| \_\|_| |_| |_||_| |_||____/ | |
response: 9FRmh3 | |
Connection dropped! | |
FLAG: | |
>securinets{w3ll_d0n3_g00d!!} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment