Rating:
```
import telnetlib
class Telnet:
def __init__(self, host, port):
# self.tn = telnetlib.Telnet("pwn-2021.duc.tf", "31905")
self.tn = telnetlib.Telnet(host, port)
def read(self, has_quiz):
data = ""
while len(data) == 0:
data = self.tn.read_very_eager()
data = data.decode().strip()
if has_quiz:
quiz = data[data.index(": ") + 2:]
print(f"{data} ==> _{quiz}_")
return quiz
else:
print(data)
return data
def write(self, bin_text):
print("+ answer ==> ", end="")
print(bin_text)
self.tn.write(bin_text)
self.tn.write(b"\n")
def read(tn):
data = ""
while len(data) == 0:
data = tn.read_very_eager()
data = data.decode()
print(data)
return data
telnet = Telnet("pwn-2021.duc.tf", "31905")
telnet.read(False)
telnet.write(b"")
telnet.read(False)
telnet.write(b"2")
# decode hex string and provide number
quiz = telnet.read(True)
answer = str(int(quiz, 16)).encode("ascii")
telnet.write(answer)
# decode hex string and provide ASCII leter
quiz = telnet.read(True)
answer = chr(int(quiz, 16)).encode("ascii")
telnet.write(answer)
# url decode this string and provide ascii symbols
from urllib.parse import unquote_plus
quiz = telnet.read(True)
answer = unquote_plus(quiz).encode("ascii")
telnet.write(answer)
# base64 decode and provide plaintext
from base64 import b64decode
quiz = telnet.read(True)
answer = b64decode(quiz)
telnet.write(answer)
# Encode this plaintext string and provide me the Base64
from base64 import b64encode
quiz = telnet.read(True)
answer = b64encode(quiz.encode("ascii"))
telnet.write(answer)
# Decode this rot13 string and provide me the plaintext
def rot13_decrypt(cipher):
ascii = "abcdefghijklmnopqrstuvwxyz_"
rot13 = "nopqrstuvwxyzabcdefghijklm_"
return "".join([ascii[rot13.index(letter)] for letter in cipher])
quiz = telnet.read(True)
answer = rot13_decrypt(quiz)
telnet.write(answer.encode())
# Encode this plaintext string and provide me the ROT13 equilavent
def rot13_encrypt(text):
ascii = "abcdefghijklmnopqrstuvwxyz_"
rot13 = "nopqrstuvwxyzabcdefghijklm_"
return "".join([rot13[ascii.index(letter)] for letter in text])
quiz = telnet.read(True)
answer = rot13_encrypt(quiz)
telnet.write(answer.encode())
# Decode this binary string and provide me the original number (base 10)
quiz = telnet.read(True)
answer = str(int(quiz, 2)).encode()
telnet.write(answer)
# Encode this number and provide me the binary equivalent
quiz = telnet.read(True)
answer = bin(int(quiz))
telnet.write(answer.encode())
# Final Question, what is the best CTF competition in the universe
quiz = telnet.read(False)
telnet.write(b"DUCTF")
telnet.read(False)
```