Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

completely deleting a file from server

Tags:

php

I want to delete a file by using PHP. I have used the unlink() function, but I was wondering about the security of unlink. Is the file completely deleted from the server? I want to make sure that there is no way to get the file back and the file is completely removed from the server.

like image 646
Amar Banerjee Avatar asked Jul 09 '13 13:07

Amar Banerjee


People also ask

How do you permanently delete files so they Cannot be recovered?

Go to Settings > Security > Advanced and tap Encryption & credentials. Select Encrypt phone if the option isn't already enabled. Next, go to Settings > System > Advanced and tap Reset options. Select Erase all data (factory reset), and press Delete all data.

How do I force delete a file in Windows server?

Press Shift + Delete to force delete a file or folder If the problem is due to the Recycle Bin, you can select the target file for folder, and press Shift + Delete keyboard shortcut to permanently delete it. This way will bypass the Recycle Bin.

Can a file be truly deleted?

The file will remain there until another file replaces that file in the exact location. If you accidentally and permanently delete a file, you can recover it using reliable data recovery software and retrieve the file straight from the hard drive.

How do I force delete a file on a network drive?

To do this, start by opening the Start menu (Windows key), typing run , and hitting Enter. In the dialogue that appears, type cmd and hit Enter again. With the command prompt open, enter del /f filename , where filename is the name of the file or files (you can specify multiple files using commas) you want to delete.


1 Answers

open the file in binary mode for writing, write 1's over the entire file, close the file, and then unlink it. overwrites any data within the file so it cannot be recovered.

Personally i would say use 1's instead of 0's as 1's are actual data and will always write, where as 0's may not write, depending on several factors.

Edit: After some thought, and reading of comments, i would go with a hybrid approach, depending on "how deleted" you want the file to be, if you simply wish to make it so the data cannot be recovered, overwrite the entire files length with 1's as this is fast, and destroys the data, the problem with this, is it leaves a set length of uniform data on the disk which infers a file USED to be there and gives away the files length, giving vital pieces of forensic information. Simply writing random data will not avoid this also, as if all the drive sectors around this file are untouched, this will also leave a forensic trace.

The best solution factoring in forensic deletion, obfuscation and plausible deniability (again, this is overkill, but im adding it for the sake of adding it), overwrite the entire length of the file with 1's and then, for HALF the length of the file in bytes, write from mt_rand in random length sizes, from random starting points, leaving the impression that many files of varying lengths used to be in this area, thus creating a false trail. (again, this is completely overkill and is generally only needed by serial killers and the CIA, but im adding it for the sake of doing so).

like image 127
bizzehdee Avatar answered Oct 06 '22 01:10

bizzehdee