Exemplo n.º 1
0
def processOutguess(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_" + randString()
    os.mkdir(folder + tmpfolder)
    shutil.copyfile(folder + img, folder + tmpfolder + "/" + img)

    # Compute steghide

    if len(passwd):
        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"}
    else:
        shutil.rmtree(folder + tmpfolder)
        return {"Output": out}
Exemplo n.º 2
0
def uploads(path):
    """ Route for uploaded/computed files
    Remove old uploaded/computed files on each requests
    """

    # First remove old files
    cmdline(f"find uploads/ -mmin +{APP_RM_FILE_TIME} "
            r"-type f  \( -iname \"*\" ! -iname \".gitkeep\" \) "
            r"-exec rm -fv {} \;")
    return send_from_directory('uploads', path)
Exemplo n.º 3
0
def processForemost(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_" + randString()
    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"}
Exemplo n.º 4
0
def processBinwalk(img, folder="./"):
    """ Compute Binwalk on @img image.
    Return text output and 7z file containing extracted files. """

    # Avoid race conditions on file upload: create tmp folder
    tmpfolder = "aperisolve_" + randString()
    os.mkdir(folder + tmpfolder)
    shutil.copyfile(folder + img, folder + tmpfolder + "/" + img)

    # Compute steghide
    out = cmdline(f"cd {quote(folder+tmpfolder)} && "
                  f"binwalk --dd='.*' {quote(img)} 2>&1")

    # Zip output if exist and remove tmp folder
    if "0x" 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"}
    else:
        shutil.rmtree(folder + tmpfolder)
        return {"Output": out}
Exemplo n.º 5
0
def processZsteg(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 = rmExt(img) + "_zsteg.png"  # New name
        img_pil.save(f"{folder}{img}")

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

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

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

        # 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": zstegOut, "File": f"{folder}{tmpfolder}.7z"}
    return {"Output": zstegOut}
Exemplo n.º 6
0
def processExif(img, folder="./"):
    """ Compute exiftool for a given image `img`. """
    return cmdline("exiftool -E -a -u -g1 " + quote(folder + img))
Exemplo n.º 7
0
def processStrings(img, folder="./"):
    """ Compute strings on img """
    return cmdline("strings " + quote(folder + img))