Exemplo n.º 1
0
    def hide_file(self, hfile, image, param={}):
        hf = None
        dirs1 = self.fs.get_list_of_files(FLAG_DIRECTORY | FLAG_REGULAR)
        dirs2 = self.fs.get_list_of_files(FLAG_DIRECTORY | FLAG_SYSTEM)
        dirs = dirs1 + [dirs2[0]]
        try:
            newdir = param["directory"]
            internalpath = newdir + "/" + os.path.basename(hfile.name)
            targetfile = self.fs.fs_mountpoint + internalpath
            hf = internalpath
        except KeyError:
            try:
                dpr = choice(dirs)
                if dpr.filename != "/.":
                    targetdir = dpr.filename
                else:
                    targetdir = ""

                internalpath = targetdir + "/" + os.path.basename(hfile.name)
                targetfile = self.fs.fs_mountpoint + internalpath
                hf = internalpath

            except IndexError:
                raise ForensicError("No directory for hiding")
        finally:
            if self.fs.mount_image() != 0:
                raise ForensicError("Mount failed")
            dpath = os.path.dirname(targetfile)
            if not os.path.exists(dpath):
                try:
                    os.makedirs(dpath)
                except IOError:
                    raise ForensicError("Unable to create directory %s" % dpath)
        try:
            tfile = open(targetfile, "w")
            tfile.write(hfile.read())
            tfile.close()

        except IOError:
            errlog("Unable to write")
            try:
                tfile.close()
            except IOError:
                pass
            self.fs.dismount_image()
            raise ForensicError("Unable to write")
        finally:
            self.fs.dismount_image()

        return dict(instruction=hf, path=internalpath, newfile=True)
Exemplo n.º 2
0
    def hide_file(self, hfile, image, param = {}):
        hf = None
        dirs1 = self.fs.get_list_of_files(FLAG_DIRECTORY|FLAG_REGULAR)
        dirs2 = self.fs.get_list_of_files(FLAG_DIRECTORY|FLAG_SYSTEM)
        dirs = dirs1+[dirs2[0]]
        try:
            newdir = param["directory"]
            internalpath = newdir+"/"+os.path.basename(hfile.name)
            targetfile = self.fs.fs_mountpoint + internalpath
            hf = internalpath
        except KeyError:
            try:
                dpr = choice(dirs)
                if dpr.filename != "/.":
                    targetdir=dpr.filename
                else: 
                    targetdir=""
                
                internalpath = targetdir+"/"+os.path.basename(hfile.name)
                targetfile = self.fs.fs_mountpoint + internalpath
                hf = internalpath
            
            except IndexError:
                raise ForensicError("No directory for hiding")
        finally:
            if self.fs.mount_image() != 0:
                raise ForensicError("Mount failed")
            dpath = os.path.dirname(targetfile)
            if not os.path.exists(dpath):
                try:
                    os.makedirs(dpath)
                except IOError:
                    raise ForensicError("Unable to create directory %s" % dpath)
        try:
            tfile = open(targetfile, "w")
            tfile.write(hfile.read())
            tfile.close()

        except IOError:
            errlog("Unable to write")
            try:
                tfile.close()
            except IOError:
                pass
            self.fs.dismount_image()
            raise ForensicError("Unable to write")
        finally:
            self.fs.dismount_image()
        
        return dict(instruction=hf,path=internalpath,newfile=True)
Exemplo n.º 3
0
    def hide_file(self, hfile, image, param={}):
        files = self.fs.get_list_of_files(FLAG_REGULAR)
        hr = None
        try:
            itr = 0
            while True:
                c = choice(files)
                itr = itr + 1
                if image.check_trivial_usage_status(c.filename) == False:
                    break
                if itr > 20:
                    raise ForensicError("Cannot find unused trivial files")
            chosenfile = c.filename
        except IndexError:
            errlog("No files to target")
            raise ForensicError("no files to target")

        if self.fs.mount_image() != 0:
            raise ForensicError("Mount failed")

        targetfile = self.fs.fs_mountpoint + chosenfile
        try:
            tfile = open(targetfile, "a")
            tfile.write(hfile.read())
            tfile.close()
            try:
                result_file = hfile.name.rsplit("/", 1)[1]
            except IndexError:
                result_file = hfile.name
            hr = chosenfile + "+" + result_file
        except IOError:
            errlog("Unable to write")
            try:
                tfile.close()
            except IOError:
                pass
            self.fs.dismount_image()
            raise ForensicError("Unable to write")
        finally:
            self.fs.dismount_image()
        if chosenfile.find("/./") == 0:
            chosenfile = chosenfile[2:]

        try:
            if param["delete"] == "True":
                return dict(instruction=hr + " DELETED",
                            path=chosenfile,
                            todelete=[targetfile])
        except KeyError:
            return dict(instruction=hr, path=chosenfile)
Exemplo n.º 4
0
 def hide_file(self, hfile, image, param = {}):
     files = self.fs.get_list_of_files(FLAG_REGULAR)
     hr = None
     try:
         itr = 0
         while True:
             c = choice(files)
             itr = itr + 1
             if image.check_trivial_usage_status(c.filename) == False:
                 break
             if itr > 20:
                 raise ForensicError("Cannot find unused trivial files")
         chosenfile = c.filename
     except IndexError:
         errlog("No files to target")
         raise ForensicError("no files to target")
     
     if self.fs.mount_image() != 0:
         raise ForensicError("Mount failed")
     
     targetfile = self.fs.fs_mountpoint + chosenfile
     try:
         tfile = open(targetfile, "a")
         tfile.write(hfile.read())
         tfile.close()
         try:
             result_file = hfile.name.rsplit("/",1)[1]
         except IndexError:
             result_file = hfile.name
         hr = chosenfile+"+"+result_file
     except IOError:
         errlog("Unable to write")
         try:
             tfile.close()
         except IOError:
             pass
         self.fs.dismount_image()
         raise ForensicError("Unable to write")
     finally:
         self.fs.dismount_image()
     if chosenfile.find("/./") == 0:
         chosenfile = chosenfile[2:]  
     
     try:
         if param["delete"] == "True":
             return dict(instruction=hr+" DELETED", path=chosenfile, todelete=[targetfile])
     except KeyError:
         return dict(instruction=hr,path=chosenfile)
Exemplo n.º 5
0
def post_secret_view(request):
    if request.method == "POST":
        
        sfile = request.FILES['file']

        t = SecretFileItem(name=sfile.name, file = sfile, group = 0)
        try:
            t.save()
        except DatabaseError:
            try:
                t.save()
            except DatabaseError:
                errlog("can't post secret file")
                pass
        
 
    return render(request, "ui/files.html", {"cfunction": "postsecretfile", "instruction": "Drag and drop secret files here"}) 
Exemplo n.º 6
0
def post_secret_view(request):
    if request.method == "POST":

        sfile = request.FILES['file']

        t = SecretFileItem(name=sfile.name, file=sfile, group=0)
        try:
            t.save()
        except DatabaseError:
            try:
                t.save()
            except DatabaseError:
                errlog("can't post secret file")
                pass

    return render(
        request, "ui/files.html", {
            "cfunction": "postsecretfile",
            "instruction": "Drag and drop secret files here"
        })
Exemplo n.º 7
0
    def hide_file(self, hfile, image, param={}):
        hf = None
        dirs1 = self.fs.get_list_of_files(FLAG_DIRECTORY | FLAG_REGULAR)
        dirs2 = self.fs.get_list_of_files(FLAG_DIRECTORY | FLAG_SYSTEM)
        dirs = dirs1 + [dirs2[0]]
        try:
            givendir = param["directory"]
            internalpath = givendir + "/" + os.path.basename(hfile.name)
            targetfile = self.fs.fs_mountpoint + internalpath
            hf = internalpath
        except KeyError:
            try:
                dpr = choice(dirs)
                if dpr.filename != "/.":
                    targetdir = dpr.filename
                else:
                    targetdir = ""
                internalpath = targetdir + "/" + os.path.basename(hfile.name)
                targetfile = self.fs.fs_mountpoint + internalpath
                hf = internalpath

            except IndexError:
                raise ForensicError("No directory for hiding")

        try:
            if self.fs.mount_image() != 0:
                raise ForensicError("Mount failed")

            tf = open(targetfile, "w")
            tf.write(hfile.read())
            tf.close()
            #os.remove(targetfile)
            if self.fs.dismount_image() != 0:
                raise ForensicError("Dismount failed")

        except IOError:
            errlog("cannot write file")
            raise ForensicError("Cannot write file")
        if internalpath.find("/./") == 0:
            internalpath = internalpath[2:]
        return dict(instruction=hf, todelete=[targetfile])
Exemplo n.º 8
0
    def hide_file(self, hfile, image, param = {}):
        hf = None
        dirs1 = self.fs.get_list_of_files(FLAG_DIRECTORY|FLAG_REGULAR)
        dirs2 = self.fs.get_list_of_files(FLAG_DIRECTORY|FLAG_SYSTEM)
        dirs = dirs1+[dirs2[0]]
        try:
            givendir = param["directory"]
            internalpath = givendir+"/"+os.path.basename(hfile.name)
            targetfile = self.fs.fs_mountpoint + internalpath
            hf = internalpath
        except KeyError:
            try:
                dpr = choice(dirs)
                if dpr.filename != "/.":
                    targetdir=dpr.filename
                else: 
                    targetdir=""
                internalpath = targetdir+"/"+os.path.basename(hfile.name)
                targetfile = self.fs.fs_mountpoint + internalpath
                hf = internalpath
            
            except IndexError:
                raise ForensicError("No directory for hiding")

        try:
            if self.fs.mount_image() != 0:
                raise ForensicError("Mount failed")

            tf = open(targetfile, "w")
            tf.write(hfile.read())
            tf.close()
            #os.remove(targetfile)
            if self.fs.dismount_image() != 0:
                raise ForensicError("Dismount failed")
            
        except IOError:
            errlog("cannot write file")
            raise ForensicError("Cannot write file")
        if internalpath.find("/./") == 0:
            internalpath = internalpath[2:]      
        return dict(instruction=hf,todelete=[targetfile])
Exemplo n.º 9
0
    def hide_file(self, hfile, image, param = {}):
        slack = self.fs.get_file_slack()
        hf = ""
        if slack == None:
            errlog("Not enough slack space")
            raise ForensicError("Not enough slack space")
        available_slack = 0
        for i in slack:
            if i[2] == 0:
                available_slack = available_slack + i[1]
        try:
            buf = hfile.read()
        except IOError:
            raise ForensicError("cannot read secret file")

        if available_slack < len(buf):
            raise ForensicError("Not enough slack")
        bytes_written = 0
        bytes_remaining = len(buf)
        for i in slack:
            if i[2] != 0:
                continue
            if bytes_remaining <= i[1]:
                self.fs.write_location(i[0],buf[bytes_written:])
                hf = hf+","+str(i[0])+":"+str(bytes_remaining)
                self.fs.register_used_file_slack(i[0],bytes_remaining)
                if hf.find(",") == 0:
                    hf = hf[1:]
                return dict(instruction=hf)
            self.fs.write_location(i[0],buf[bytes_written:bytes_written+i[1]])
            self.fs.register_used_file_slack(i[0], i[1])
            hf = hf+","+str(i[0])+":"+str(i[1])   
            bytes_written += i[1] 
            bytes_remaining -= i[1]           
        """ this should never be reached """

        raise ForensicError ("This should not happen")
Exemplo n.º 10
0
    def hide_file(self, hfile, image, param = {}):
        extensions = ["jpg", "com", "zip", "xlsx", "doc", "xls", "exe", "dll", "pdf", "rar"]
        hf = None
        dirs1 = self.fs.get_list_of_files(FLAG_DIRECTORY|FLAG_REGULAR)
        dirs2 = self.fs.get_list_of_files(FLAG_DIRECTORY|FLAG_SYSTEM)
        """ Process all directories and the root directory """
        try:
            if param["notroot"] == "True":
                dirs = dirs1
            else:
                dirs = dirs1+[dirs2[0]]
        except KeyError:
            dirs = dirs1+[dirs2[0]]    

        try:
            short_targetdir=choice(dirs).filename
            internalpath = short_targetdir+"/"+os.path.basename(hfile.name)
            targetfile = self.fs.fs_mountpoint + internalpath
            targetdir = self.fs.fs_mountpoint + short_targetdir
            
            
        except IndexError:
            errlog("No directory for hiding")
            raise ForensicError("No directory for hiding")
        try:
            if self.fs.mount_image() != 0:
                raise ForensicError("Mount failed")

            tf = open(targetfile, "w")
            tf.write(hfile.read())
            tf.close()
            
            """ find extension """
            try:
                mfn,ext = targetfile.rsplit(".",1)
            except ValueError:
                mfn = targetfile
                ext = ""
            try:
                m2,e2 = internalpath.rsplit(".",1)
            except ValueError:
                m2=targetfile

                
            """ remove this extension from the list if it is there """
            try:
                extensions.remove(ext)
            except ValueError:
                pass
            
            
            """ count extensions in target directory """
            exti = {}
            dirt = os.listdir(targetdir)

            for f in dirt:
                try:
                    fn,e = f.rsplit(".",1)
                    try:
                        exti[e] += 1
                    except KeyError:
                        exti[e] = 1
                except ValueError:
                    continue

            """ choose extension """
            try:
                ext_to_use = max(exti,key=exti.get)
            except ValueError:
                ext_to_use = choice(extensions)
            finally:
                if ext_to_use == ext:
                    ext_to_use = choice(extensions)
                try:
                    ext_to_use = param["use"]
                except KeyError:
                    pass
            new_filename = mfn+"."+ext_to_use
            os.rename(targetfile,new_filename)
            hf = m2+"."+ext_to_use        
   

            if self.fs.dismount_image() != 0:
                raise ForensicError("Dismount failed")
            
        except IOError:
            errlog("cannot write file")
            try:
                tf.close()
            except IOError:
                pass
        
            self.fs.dismount_image()
            raise ForensicError("Cannot write file")
        if m2.find("/./") == 0:
            m2 = m2[2:] 
        if hf.find("/./") == 0:
            hf = hf[2:]
        try:
            if param["delete"] == "True":
                return dict(instruction=hf+" DELETED", path=m2+"."+ext_to_use, todelete=[new_filename])
        except KeyError:
            return dict(instruction=hf,path=m2+"."+ext_to_use)
Exemplo n.º 11
0
    def hide_file(self, hfile, image, param={}):
        extensions = [
            "jpg", "com", "zip", "xlsx", "doc", "xls", "exe", "dll", "pdf",
            "rar"
        ]
        hf = None
        dirs1 = self.fs.get_list_of_files(FLAG_DIRECTORY | FLAG_REGULAR)
        dirs2 = self.fs.get_list_of_files(FLAG_DIRECTORY | FLAG_SYSTEM)
        """ Process all directories and the root directory """
        try:
            if param["notroot"] == "True":
                dirs = dirs1
            else:
                dirs = dirs1 + [dirs2[0]]
        except KeyError:
            dirs = dirs1 + [dirs2[0]]

        try:
            short_targetdir = choice(dirs).filename
            internalpath = short_targetdir + "/" + os.path.basename(hfile.name)
            targetfile = self.fs.fs_mountpoint + internalpath
            targetdir = self.fs.fs_mountpoint + short_targetdir

        except IndexError:
            errlog("No directory for hiding")
            raise ForensicError("No directory for hiding")
        try:
            if self.fs.mount_image() != 0:
                raise ForensicError("Mount failed")

            tf = open(targetfile, "w")
            tf.write(hfile.read())
            tf.close()
            """ find extension """
            try:
                mfn, ext = targetfile.rsplit(".", 1)
            except ValueError:
                mfn = targetfile
                ext = ""
            try:
                m2, e2 = internalpath.rsplit(".", 1)
            except ValueError:
                m2 = targetfile
            """ remove this extension from the list if it is there """
            try:
                extensions.remove(ext)
            except ValueError:
                pass
            """ count extensions in target directory """
            exti = {}
            dirt = os.listdir(targetdir)

            for f in dirt:
                try:
                    fn, e = f.rsplit(".", 1)
                    try:
                        exti[e] += 1
                    except KeyError:
                        exti[e] = 1
                except ValueError:
                    continue
            """ choose extension """
            try:
                ext_to_use = max(exti, key=exti.get)
            except ValueError:
                ext_to_use = choice(extensions)
            finally:
                if ext_to_use == ext:
                    ext_to_use = choice(extensions)
                try:
                    ext_to_use = param["use"]
                except KeyError:
                    pass
            new_filename = mfn + "." + ext_to_use
            os.rename(targetfile, new_filename)
            hf = m2 + "." + ext_to_use

            if self.fs.dismount_image() != 0:
                raise ForensicError("Dismount failed")

        except IOError:
            errlog("cannot write file")
            try:
                tf.close()
            except IOError:
                pass

            self.fs.dismount_image()
            raise ForensicError("Cannot write file")
        if m2.find("/./") == 0:
            m2 = m2[2:]
        if hf.find("/./") == 0:
            hf = hf[2:]
        try:
            if param["delete"] == "True":
                return dict(instruction=hf + " DELETED",
                            path=m2 + "." + ext_to_use,
                            todelete=[new_filename])
        except KeyError:
            return dict(instruction=hf, path=m2 + "." + ext_to_use)