Aller au contenu

TCP - Uncompress Me

Rédaction d'un script python

import socket
import re
import base64
import zlib

def netcat(HOST,PORT):

    # Create a socket object
    s = socket.socket()        

    # connect to the server on local computer
    s.connect((HOST, PORT))

    while True:
        try:

            # receive data from the server and decoding to get the string.
            res = s.recv(1024).decode()

            print(res)
            # read number
            regex = "\'(.*)\'"

            # Search regex
            search = re.search(regex, res)

            print(f"\nThe regex : {search.group(1)}\n")
            # # caclul square
            res = zlib.decompress(base64.b64decode(search.group(1))).decode("utf-8")

            #base64.b64decode(search.group(1)).decode('utf-8')
            print(f'The res : {res}')

            # send result
            s.sendall((str(res)+"\n").encode())
        except:
            return "FLAG!"


def main():
    print(netcat("challenge01.root-me.org",52022))

if __name__ == "__main__":
    main()

Flag :

RM{Y0u_Succ3ssfuLly_UnComPr3SS_M3}