Created
November 27, 2017 08:19
-
-
Save framirez/4213461194d4a15d6169a1971ea6b420 to your computer and use it in GitHub Desktop.
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 string | |
import sys | |
import nclib | |
import time | |
""" | |
Script to resolv challengue CTF: | |
The Never Ending Crypto | |
Welcome to the never ending crypto! | |
How quickly can you make it through? | |
nc neverending.tuctf.com 12345 | |
First step. need calculate ROT | |
Second step. decipher the challengue with first step ROT | |
Finally we need 50 steps to get the flag | |
""" | |
plaintext = "abc09.#dz" | |
host = 'neverending.tuctf.com' | |
port = 12345 | |
alphabet = [chr(i) for i in xrange(32,95+32)] | |
alphabet = "".join(alphabet) | |
print("USE this alphabet: {}".format(alphabet)) | |
def caesar(plaintext, shift, alphabet): | |
shifted_alphabet = alphabet[shift:] + alphabet[:shift] | |
table = string.maketrans(alphabet, shifted_alphabet) | |
return plaintext.translate(table) | |
def connect_netcat(host, port): | |
nc = nclib.Netcat((host, port), udp=False, verbose=False) | |
nc.echo_hex = True | |
print("Netcat conect") | |
def send_netcat(nc, text): | |
time.sleep(1) | |
nc.send(u'{}\n'.format(text)) | |
time.sleep(1) | |
def recv_netcat(nc): | |
return nc.recv() | |
nc = connect_netcat(host, port) | |
while 1: | |
try: | |
send_netcat(nc, plaintext) | |
retr = recv_netcat(nc) | |
for row in str(retr).split("\n"): | |
if "encrypted is " in row: | |
solution = row.split(" encrypted is ")[-1] | |
if "decrypted?" in row: | |
next_r = row.replace("What is ","").replace(" decrypted?", "") | |
print("Looking ROT: plaintext->{} | cipher->{} | next_one->{}".format(plaintext, solution, next_r)) | |
for i in xrange(1,len(alphabet)): | |
if caesar(plaintext, i, alphabet) == solution: | |
print("Find ROT{}".format(i)) | |
final_solution = caesar(next_r, len(alphabet)-i, alphabet) | |
print("Sending: {}".format(final_solution)) | |
send_netcat(nc, final_solution) | |
print(recv_netcat(nc)) | |
except: | |
nc = connect_netcat(host, port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment