Skip to content

Instantly share code, notes, and snippets.

@framirez
Created November 27, 2017 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save framirez/4213461194d4a15d6169a1971ea6b420 to your computer and use it in GitHub Desktop.
Save framirez/4213461194d4a15d6169a1971ea6b420 to your computer and use it in GitHub Desktop.
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