#!/usr/bin/python3 from itertools import permutations import os import re dtmf_table = {'6971209':'1', '6971336':'2', '6971477':'3', '7701209':'4', '7701336':'5', '7701477':'6', '8521209':'7', '8521336':'8', '8521477':'9'} os.system("tshark -r ancientsignal.pcapng -q -z follow,tcp,ascii,3 > sslkey.log") print("") print("Extracting SSL session keys: Done") print("") os.system("tshark -r ancientsignal.pcapng -o tls.keylog_file:sslkey.log -T fields -e http.file_data http.response_number eq 1 and tcp.stream eq 0 > info.txt") print("Decrypting TLS session: Done") print("") inFile = open('info.txt','r') text = inFile.read() inFile.close() m = re.search('This is the message: (.+?). I will', text) if m: string_dtmf = m.group(1) print("DTMF string:") print(string_dtmf) print("") list_dtmf = [] while string_dtmf: list_dtmf.append(string_dtmf[:7]) string_dtmf = string_dtmf[7:] ciphertxt = '' for i in list_dtmf: ciphertxt +=str(dtmf_table[i]) print("Morbit string:") print(ciphertxt) print("") startflag = 'CTFCURLYBRACKET' ######## Code from CTF CryptoTool###### MORSE_CODE_DICT = {'..-': 'U', '--..--': ', ', '....-': '4', '.....': '5', '-...': 'B', '-..-': 'X', '.-.': 'R', '--.-': 'Q', '--..': 'Z', '.--': 'W', '-..-.': '/', '..---': '2', '.-': 'A', '..': 'I', '-.-.': 'C', '..-.': 'F', '---': 'O', '-.--': 'Y', '-': 'T', '.': 'E', '.-..': 'L', '...': 'S', '-.--.-': ')', '..--..': '?', '.----': '1', '-----': '0', '-.-': 'K', '-..': 'D', '----.': '9', '-....': '6', '.---': 'J', '.--.': 'P', '.-.-.-': '.', '-.--.': '(', '--': 'M', '-.': 'N', '....': 'H', '---..': '8', '...-': 'V', '--...': '7', '--.': 'G', '...--': '3', '-....-': '-', '\n' : ' '} MORBIT = ['..', '.-', '. ', '-.', '--', '- ', ' .', ' -', ' '] lookup_table = {'A' : 'Z', 'B' : 'Y', 'C' : 'X', 'D' : 'W', 'E' : 'V','F' : 'U', 'G' : 'T', 'H' : 'S', 'I' : 'R', 'J' : 'Q', 'K' : 'P', 'L' : 'O', 'M' : 'N', 'N' : 'M', 'O' : 'L', 'P' : 'K', 'Q' : 'J', 'R' : 'I', 'S' : 'H', 'T' : 'G', 'U' : 'F', 'V' : 'E', 'W' : 'D', 'X' : 'C', 'Y' : 'B', 'Z' : 'A'} def morse(ciphertxt): plaintxt = '' for word in ciphertxt.strip().split(" "): for c in word.strip().split(" "): if c in MORSE_CODE_DICT: plaintxt += MORSE_CODE_DICT[c] else: pass plaintxt += ' ' return plaintxt for p in permutations('123456789'): MORBIT_CODE_DICT = dict(zip(p, MORBIT)) morsetxt = "" for c in ciphertxt: if c in MORBIT_CODE_DICT: morsetxt += MORBIT_CODE_DICT[c] if startflag in morse(morsetxt): flag = morse(morsetxt) print("Pre flag: " + flag) print("") flag = flag.replace("CTFCURLYBRACKET", "CTF{") flag = flag.replace("CURLYBRACKET", "}") break print("Flag:" + flag) print("") ######## End code ################# os.system("rm sslkey.log") os.system("rm info.txt")