コード例 #1
0
def save_artifact(session, filename, original_path):
    """
    :param session: Session
    :param filename: str
    :param original_path: str
    :return: str
    """
    new_path = ""
    for code, headers, body in get_artifact_from_endpoint(
            session, original_path):
        pass

    if code == 200:
        path = os.sep.join(
            [config.SCREENSHOTS_DIR,
             str(session.id),
             "%s.log" % filename])
        try:
            body = json.loads(body)
            utils.write_file(path, body.get("output", "no data"))
            new_path = path
            log.debug("File %s was saved to %s " % (filename, new_path))
        except:
            log.exception(
                "Selenium log file %s doesn't created for session %s" %
                (filename, session.id))
    return new_path
コード例 #2
0
ファイル: helpers.py プロジェクト: gridl/vmmaster
def save_screenshot(session, screenshot):
    if screenshot:
        log_step = session.current_log_step
        path = config.SCREENSHOTS_DIR + "/" + str(session.id) + \
            "/" + str(log_step.id) + ".png"
        utils.write_file(path, base64.b64decode(screenshot))
        log_step.screenshot = path
        log_step.save()
        make_thumbnail_for_screenshot(path)
コード例 #3
0
def beautify_js(data, full_file_path):
    """Beautify the Javascript source."""
    lines = data.splitlines()
    if len(lines) <= 2:
        # Possible Minified Single Line Code
        try:
            # Try Because of Possible Bug in JS Beautifier
            beautified_data = jsbeautifier.beautify(data)
            data = beautified_data
            utils.write_file(full_file_path, beautified_data)
        except:
            pass
    return data
コード例 #4
0
ファイル: idea.py プロジェクト: GrayDevs/CryptoSystem
def idea_main_decryption():
    """ Launch IDEA Decryption process """

    print(
        "========================================IDEA DECRYPTION========================================"
    )
    key_len, mod_of_operation = idea_menu()

    print(
        "---------------------------------------SELECTING A FILE---------------------------------------"
    )
    filename = utils.get_filename()
    print("File to Decrypt:", filename)

    # Grabbing original file extension
    file_extension = filename.split('.cypher', 1)[0]
    if len(file_extension.split('.', 1)) != 1:
        file_extension = '.' + file_extension.split('.', 1)[1]
    else:
        file_extension = ''

    print(
        "------------------------------------GATHERING FILE CONTENT------------------------------------"
    )
    hex_message = utils.get_file_hex(filename)
    true_hex_message = bytes.decode(
        bytes.fromhex(hex_message)
    )  # one more decoding step due to how the file is open ('rb')
    file_blocks = block_feeder.generate_blocks(true_hex_message)
    print("File Blocks: {0}\n{1}\n{2}\n...".format(file_blocks[:3],
                                                   file_blocks[3:7],
                                                   file_blocks[7:11]))

    print(
        "-------------------------------------------PASSWORD-------------------------------------------"
    )
    print(
        "Please type-in the Hexadecimal password given during the encryption process"
    )
    # key = int(input("> "), 16)
    key = input("IDEA/> ")
    bytes_key = bytes.fromhex(key[2:])
    if key_len == 128:
        key = int.from_bytes(hashlib.md5(bytes_key).digest(), 'little')
    elif key_len == 256:
        # key = int.from_bytes(hashlib.sha3_256(bytes_key).digest(), 'little')
        key = int(SHA3.sha3_int(int(key, 16), 256)[2:], 16)
    else:
        raise ValueError("Wrong key length value")

    print(
        "------------------------------------------DECRYPTION------------------------------------------"
    )
    # Managing mode of operation
    if mod_of_operation is "ECB":
        idea = IDEAModeOfOperationECB(key, key_len)
    elif mod_of_operation is "CBC":
        # iv = secrets.randbits(64)    # 16 hex long = 64 bits  # works with static iv
        idea = IDEAModeOfOperationCBC(key, key_len)
    elif mod_of_operation is "PCBC":
        # iv = secrets.randbits(64)    # 16 hex long = 64 bits  # works with static iv
        idea = IDEAModeOfOperationPCBC(key, key_len)
    else:
        raise ValueError("Wrong Mode of Operation.")

    # Decryption
    output = ''
    for i in range(len(file_blocks)):
        decrypted = idea.decrypt(file_blocks[i])
        decrypted = hex(decrypted)[2:].zfill(16)  # keeping the right format
        output += decrypted

    unpadded = block_feeder.PKCS7_unpadding(output)
    try:
        unpadded_to_bytes = bytes.fromhex(unpadded)

        wrap = textwrap.fill(str(unpadded_to_bytes)[2:], 94)
        print(wrap)

        print(
            "----------------------------------SAVING DECRYPTED TEXT-----------------------------------"
        )
        # new_file = utils.save_file() + ".txt"
        new_file = utils.save_file() + file_extension
        utils.write_file(new_file, unpadded_to_bytes)
    except:
        print("\033[1;31m[-]\x1b[0m",
              "It seems like you entered the wrong Password")

    try:
        print(
            "-----------------------------------HASH DECRYPTED FILE------------------------------------"
        )
        plaintext_hash = SHA3.sha3_file(new_file, 256)
        print("\033[1;32m[+]\033[1;m", "SHA_256:\033[1;32m", plaintext_hash,
              "\x1b[0m")
    except:
        print("\033[1;31m[-]\x1b[0m",
              "Something went wrong during the hash process")

    return 0
コード例 #5
0
    # Main loop
    while True:
        # Try to fetch new query
        payload = db_connector.get()
        if payload != None:
            print("PAYLOAD ------------------------------------")
            decor.puts.payload_info(payload)

            # Get config files accordingly
            # Subtitute placeholders
            kiyago_conf = get_kiyago_conf(init_kiyago_conf)
            problem_conf = get_problem_conf(kiyago_conf["problem_dir"])

            # Write subject source file.
            utils.write_file(kiyago_conf["subject_src"], payload.code)

            # Compile and judge; None = compile error
            result = on_recieve()

            if result == None:
                print("ERRMSG -------------------------------------")
                # Show error message
                with open(f"{kiyago_conf['cmp_err']}") as f:
                    errmsg = f.read()
                print(errmsg)
                db_connector.send_error(errmsg)
            else:
                db_connector.send_result(result)
            print("--------------------------------------------")
            decor.says.kiyago(