示例#1
0
def process_outguess(img, folder="./", passwd=""):
    """Compute Outguess with @passwd as password on @img image.

    Return text output and 7z file containing extracted files.
    """
    # Avoid race conditions on file upload: create tmp folder
    tmpfolder = "aperisolve_" + rand_string()
    os.mkdir(folder + tmpfolder)
    shutil.copyfile(folder + img, folder + tmpfolder + "/" + img)

    # Compute steghide

    if len(passwd) > 0:
        out = cmdline(f"cd {quote(folder+tmpfolder)} && "
                      f"outguess -k {quote(passwd)} -r {quote(img)} data 2>&1")
    else:
        out = cmdline(f"cd {quote(folder+tmpfolder)} && "
                      f"outguess -r {quote(img)} data 2>&1")

    # Zip output if exist and remove tmp folder
    if "Extracted datalen" not in out and \
       "Unknown data type" not in out:  # Create 7z file
        os.remove(folder + tmpfolder + "/" + img)  # Clean
        cmdline(f"cd {quote(folder)} && "
                f"7z a {quote(tmpfolder+'.7z')} {quote(tmpfolder)}")  # 7Zip
        shutil.rmtree(folder + tmpfolder)
        return {"Output": out, "File": f"{folder}{tmpfolder}.7z"}

    shutil.rmtree(folder + tmpfolder)
    return {"Output": out}
示例#2
0
def process_steghide(img, folder="./", passwd=""):
    """Compute Steghide with @passwd as password on @img image.

    Return text output and 7z file containing extracted files.
    """
    # Avoid race conditions on file upload: create tmp folder
    tmpfolder = "aperisolve_" + rand_string()
    os.mkdir(folder + tmpfolder)
    shutil.copyfile(folder + img, folder + tmpfolder + "/" + img)

    # Compute steghide
    out = cmdline(f"cd {quote(folder+tmpfolder)} && "
                  f"steghide extract -sf {quote(img)} "
                  f"-p {quote(passwd)} 2>&1")

    # Zip output if exist and remove tmp folder
    if "extracted" in out:  # Create 7z file
        os.remove(folder + tmpfolder + "/" + img)  # Clean
        cmdline(f"cd {quote(folder)} && "
                f"7z a {quote(tmpfolder+'.7z')} {quote(tmpfolder)}")  # 7Zip
        shutil.rmtree(folder + tmpfolder)
        return {"Output": out, "File": f"{folder}{tmpfolder}.7z"}

    shutil.rmtree(folder + tmpfolder)
    return {"Output": out}
示例#3
0
def uploads(path):
    """Route for uploaded/computed files.

    Remove old uploaded/computed files on each requests
    """
    # First remove old files
    cmdline(f"find {DIR_PATH}/uploads/ -mmin +{APP_RM_FILE_TIME} "
            r"-type f  \( -iname \"*\" ! -iname \".gitkeep\" \) "
            r"-exec rm -fv {} \;")
    return send_from_directory('uploads', path)
示例#4
0
def process_foremost(img, folder="./"):
    """Compute Foremost on @img image.

    Return text output and 7z file containing extracted files.
    """
    # Avoid race conditions on file upload: create tmp folder
    tmpfolder = "aperisolve_" + rand_string()
    os.mkdir(folder + tmpfolder)
    shutil.copyfile(folder + img, folder + tmpfolder + "/" + img)

    # Compute steghide
    out = cmdline(f"cd {quote(folder+tmpfolder)} && " f"foremost {quote(img)}")

    # Zip output and remove tmp folder
    os.remove(folder + tmpfolder + "/" + img)  # Clean
    cmdline(f"cd {quote(folder)} && "
            f"7z a {quote(tmpfolder+'.7z')} {quote(tmpfolder)}")  # 7Zip
    shutil.rmtree(folder + tmpfolder)
    return {"Output": out, "File": f"{folder}{tmpfolder}.7z"}
示例#5
0
def process_zsteg(img, folder="./", allzsteg=False, zstegfiles=False):
    """Compute zsteg on a given image and return output."""
    # First, cast to PNG if not PNG/BMP (zsteg support only PNG/BMP)
    if imghdr.what(f"{folder}{img}") not in ["png", "bmp"]:
        img_pil = Image.open(f"{folder}{img}")
        img_pil = img_pil.convert('RGBA')  # Cast RGBA PNG
        img = rm_ext(img) + "_zsteg.png"  # New name
        img_pil.save(f"{folder}{img}")

    if allzsteg:
        zsteg_out = cmdline(f"zsteg {quote(folder+img)} --all")
    else:
        zsteg_out = cmdline(f"zsteg {quote(folder+img)}")

    chans = []  # Extract zsteg chans containing "file:"
    rzsteg_out = re.split("\r|\n", zsteg_out)
    for elt in rzsteg_out:
        if elt[23:28] == "file:" and "," in elt[:20]:  # , Keep channels only
            chans.append(elt[:20].strip())

    if len(chans) > 0 and zstegfiles:  # If there is files
        # Extract files to tmp folder
        tmpfolder = "aperisolve_" + rand_string()
        os.mkdir(folder + tmpfolder)
        shutil.copyfile(folder + img, folder + tmpfolder + "/" + img)
        for channel in chans:
            cmdline(f"cd {quote(folder+tmpfolder)} && "
                    f"zsteg {quote(img)} "
                    f"-E {quote(channel)} > {quote(channel)}")

        # Zip output if exist and remove tmp folder
        os.remove(folder + tmpfolder + "/" + img)  # Clean
        cmdline(f"cd {quote(folder)} && "
                f"7z a {quote(tmpfolder+'.7z')} {quote(tmpfolder)}")  # 7Zip
        shutil.rmtree(folder + tmpfolder)
        return {"Output": zsteg_out, "File": f"{folder}{tmpfolder}.7z"}
    return {"Output": zsteg_out}
示例#6
0
def process_exif(img, folder="./"):
    """Compute exiftool for a given image `img`."""
    return cmdline("exiftool -E -a -u -g1 " + quote(folder + img))
示例#7
0
def process_strings(img, folder="./"):
    """Compute strings on img."""
    return cmdline("strings " + quote(folder + img))