Пример #1
0
 def run(self):
     if os.path.isdir(f"{self.folder}/view"):  # prevent multiple threads
         return
     self.set_config_status("running")
     # First verify if we do not already compute for original image
     md5_image = self.config["md5_image"]
     if self.config["md5_image"] != self.config["md5_full"] \
        and os.path.isdir(f"{UPLOAD_FOLDER}/{md5_image}/view") \
        and len([name for name in os.listdir(f"{UPLOAD_FOLDER}/{md5_image}/view") if \
            os.path.isfile(os.path.join(f"{UPLOAD_FOLDER}/{md5_image}/view", name))]) in [8*4, 8*5]:
         cmd_exec(
             f"cp -r {UPLOAD_FOLDER}/{md5_image}/view {self.folder}/view")
     else:  # Else compute
         self.process_image()
     global RUNNING
     RUNNING.remove(self.folder)
     self.set_config_status("finished")
Пример #2
0
 def run(self):
     self.set_config_status("running")
     # First verify if we do not already compute for original image
     md5_image = self.config["md5_image"]
     if self.config["md5_image"] != self.config["md5_full"] \
        and os.path.isfile(f"{UPLOAD_FOLDER}/{md5_image}/strings.txt") :
         cmd_exec(
             f"cp {UPLOAD_FOLDER}/{md5_image}/strings.txt {self.folder}/strings.txt"
         )
     else:  # Else compute
         image = self.config["image"]
         c_input = f"{self.folder}/{image}"  # image.png
         c_output = f"{self.folder}/strings.txt"  # strings.txt
         cmd_exec(f"strings {c_input} > {c_output}")
     global RUNNING
     RUNNING.remove(self.folder)
     self.set_config_status("finished")
Пример #3
0
    def process_image(self):
        """Apply compute_layers() on each `img` layers and save images."""
        cmd_exec(f"mkdir {self.folder}/view")  # create view folder

        image = self.config["image"]
        c_input = f"{self.folder}/{image}"

        img_pil = Image.open(c_input)

        # Convert all in RGBA exept RGB images
        if img_pil.mode in [
                "P", "1", "L", "LA", "RGBX", "RGBa", "CMYK", "LAB", "YCbCr",
                "HSV", "I", "F"
        ]:
            img_pil = img_pil.convert('RGBA')

        # Get numpy array
        npimg = np.array(img_pil)  # rgb

        # generate images from numpy array and save
        self.compute_layers(npimg, img_pil.mode, f"image_rgb")  # rgb
        self.compute_layers(npimg[:, :, 0], 'L', f"image_r")  # r
        self.compute_layers(npimg[:, :, 1], 'L', f"image_g")  # g
        self.compute_layers(npimg[:, :, 2], 'L', f"image_b")  # b

        # set images names
        images_name = {}
        images_name["Supperimposed"] = [
            f"image_rgb_{i+1}.png" for i in range(8)
        ]
        images_name["Red"] = [f"image_r_{i+1}.png" for i in range(8)]
        images_name["Green"] = [f"image_g_{i+1}.png" for i in range(8)]
        images_name["Blue"] = [f"image_b_{i+1}.png" for i in range(8)]

        if img_pil.mode == "RGBA":  # Should be RGB or RGBA
            self.compute_layers(npimg[:, :, 3], 'L', f"image_a")  # b
            images_name["Alpha"] = [f"image_a_{i+1}.png" for i in range(8)]

        return images_name
Пример #4
0
 def run(self):
     self.set_config_status("running")
     # First verify if we do not already compute for original image
     md5_image = self.config["md5_image"]
     if self.config["md5_image"] != self.config["md5_full"] \
        and os.path.isfile(f"{UPLOAD_FOLDER}/{md5_image}/foremost.7z") :
         cmd_exec(f"cp {UPLOAD_FOLDER}/{md5_image}/foremost.7z {self.folder}/foremost.7z")
     else: # Else compute
         image = self.config["image"]
         c_input = f"{self.folder}/{image}"  # image.png
         cmd_exec(f"foremost -i {c_input} -o {self.folder}/foremost 2>&1")
         cmd_exec(f"7z a {self.folder}/foremost.7z {self.folder}/foremost/*")
         cmd_exec(f"rm -r {self.folder}/foremost")  
     global RUNNING
     RUNNING.remove(self.folder)          
     self.set_config_status("finished")
Пример #5
0
 def run(self):
     self.set_config_status("running")
     # First verify if we do not already compute for original image
     md5_image = self.config["md5_image"]
     if self.config["md5_image"] != self.config["md5_full"] \
        and os.path.isfile(f"{UPLOAD_FOLDER}/{md5_image}/binwalk.7z") \
        and os.path.isfile(f"{UPLOAD_FOLDER}/{md5_image}/binwalk.txt") :
         cmd_exec(f"cp {UPLOAD_FOLDER}/{md5_image}/binwalk.7z {self.folder}/binwalk.7z")
         cmd_exec(f"cp {UPLOAD_FOLDER}/{md5_image}/binwalk.txt {self.folder}/binwalk.txt")
     else: # Else compute
         image = self.config["image"]
         c_input = f"{self.folder}/{image}"  # image.png
         output = cmd_exec(f"binwalk -e . -C {self.folder}/binwalk --dd='.*' {c_input} 2>&1")
         cmd_exec(f"7z a {self.folder}/binwalk.7z {self.folder}/binwalk/*/*")
         cmd_exec(f"rm -r {self.folder}/binwalk")
         with open(f"{self.folder}/binwalk.txt", "w") as f:
             f.write(output)
     global RUNNING
     RUNNING.remove(self.folder)
     self.set_config_status("finished")
Пример #6
0
 def run(self):
     self.set_config_status("running")
     image = self.config["image"]
     c_input = f"{self.folder}/{image}"  # image.png
     fold = f"{self.folder}/steghide"
     cmd_exec(f"mkdir {fold}")
     passwd = ''
     if self.config["use_password"]:
         passwd = self.config["password"]
     output = cmd_exec(
         f"cd {fold} && steghide extract -sf {c_input} -p {quote(passwd)} 2>&1"
     )
     cmd_exec(f"7z a {self.folder}/steghide.7z {fold}/*")
     cmd_exec(f"rm -r {fold}")
     with open(f"{self.folder}/steghide.txt", "w") as f:
         f.write(output)
     global RUNNING
     RUNNING.remove(self.folder)
     self.set_config_status("finished")
Пример #7
0
 def run(self):
     self.set_config_status("running")
     image = self.config["image"]
     c_input = f"{self.folder}/{image}"  # image.png
     if self.config["use_password"]:
         passwd = self.config["password"]
         output = cmd_exec(f"outguess -k {quote(passwd)} -r {c_input} {self.folder}/outguess.data 2>&1")
     else:
         output = cmd_exec(f"outguess -r {c_input} {self.folder}/outguess.data 2>&1")
     cmd_exec(f"7z a {self.folder}/outguess.7z {self.folder}/outguess.data")
     cmd_exec(f"rm -r {self.folder}/outguess.data")
     with open(f"{self.folder}/outguess.txt", "w") as f:
         f.write(output)
     global RUNNING
     RUNNING.remove(self.folder)
     self.set_config_status("finished")
Пример #8
0
    top = {
        k: v
        for k, v in sorted(count.items(), key=lambda item: item[1])[::-1][:n]
    }
    return top


while True:
    dirs = os.listdir(UPLOAD_FOLDER)
    for d in dirs:
        try:
            d = f"{UPLOAD_FOLDER}/{d}"
            if not os.path.isfile(f"{d}/config.json"):
                continue
            with FileLock(f"{d}/config.json.lock"):
                with open(f"{d}/config.json", "r") as jsonFile:
                    config = json.load(jsonFile)

            top = get_top_images()
            if config["md5_full"] in top or \
               time.time() < (config["last_submit_date"] + MAX_STORE_TIME):
                print(config["md5_full"] in top)
                print(time.time() < (config["last_submit_date"] +
                                     MAX_STORE_TIME))
                continue
            else:  # Remove if too old / not in top
                cmd_exec(f"rm -rf {d}")
        except:
            continue
    time.sleep(DELAY_GARBAGE)
Пример #9
0
    def run(self):
        self.set_config_status("running")
        # First verify if we do not already compute for original image
        md5_image = self.config["md5_image"]
        if self.config["md5_image"] != self.config["md5_full"] \
           and os.path.isfile(f"{UPLOAD_FOLDER}/{md5_image}/zsteg.txt") :
            cmd_exec(f"cp {UPLOAD_FOLDER}/{md5_image}/zsteg.7z {self.folder}/zsteg.7z")
            cmd_exec(f"cp {UPLOAD_FOLDER}/{md5_image}/zsteg.txt {self.folder}/zsteg.txt")
        else: # Else compute
            image = self.config["image"]
            c_input = f"{self.folder}/{image}"  # image.png
            img = c_input
            if imghdr.what(f"{c_input}") not in ["png", "bmp"]:
                img_pil = Image.open(f"{c_input}")
                img_pil = img_pil.convert('RGBA')  # Cast RGBA PNG
                img = f"{c_input}_zsteg.png"  # New name
                img_pil.save(f"{img}")
            
            if self.config["zsteg_all"]:
                output = cmd_exec(f"zsteg {img} --all")
            else:
                output = cmd_exec(f"zsteg {img}")
            with open(f"{self.folder}/zsteg.txt", "w") as f:
                f.write(output)
            
            # Extract files
            chans = []  # Extract zsteg chans containing "file:"
            rzsteg_out = re.split("\r|\n", output)
            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 self.config["zsteg_ext"]:
                cmd_exec(f"mkdir {self.folder}/zsteg")
                for channel in chans:
                    cmd_exec(f"zsteg {img} -E {channel} > {self.folder}/zsteg/{channel.replace(',','_')}")
                
                cmd_exec(f"7z a {self.folder}/zsteg.7z {self.folder}/zsteg/*")
                cmd_exec(f"rm -r {self.folder}/zsteg")

        global RUNNING
        RUNNING.remove(self.folder)
        self.set_config_status("finished")