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}
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"}
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}
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}