4

My goal is to have files of original size that can't be opened (or recovered) in their respective software such as MS Office Word. My purpose is to simulate presence of files while I don't want to share any of the files contents. Ideally file contents should be fully overwritten with random bytes while file size should stay the same as original.

I know that sometimes this can be done with hex editor or even notepad where one could change just few bytes and the file renders unusable. But it may not always work for some formats like images and audio that still could be opened but with artifacts.

For the most inquisitive of users still demanding me to answer the question "Why do you need this?" - I need this because I don't want to share my developments with some people that force me to share the files. Sometimes you just need. You can think of many other use cases - to simulate payload for file copy or backup operations, or to test the software you develop can handle junk gracefully.

I've tested a number of secure shred utilities that are able overwrite files with random data but after that those files get deleted. I haven't seen an option to turn off the deletion step. If such an option existed that would be a solution.

Mike
  • 223
  • 3
  • 7

3 Answers3

6

I've wrote a quick approach utilizing the Random Data File Creator.

Mike noted that RDFC doesn't correctly fill the file with random data. I've emailed the author and reported this issue. For the time being, I've implemented a drop-in replacement for rdfc.exe. If you want to compile and use it, please see How do you compile a project from source?

This Windows command line script will do what you want:

@ECHO OFF
SETLOCAL
IF "%1"=="" GOTO missingParam
GOTO :begin

:missingParam
ECHO Missing target. Use %~nx0 [DRIVE:\]DIRECTORY
GOTO :eof

:begin
SET RDFC=%CD%\rdfc.exe
PUSHD %1
CALL :treeProcess
POPD
ENDLOCAL
GOTO :eof

:treeProcess
FOR %%f IN (*.*) DO (
  ECHO | SET /P=Shredding %%f... 
  %RDFC% %%f %%~zf B overwrite > NUL
  ECHO %%~zf random bytes written.
)
FOR /D %%d IN (*) DO (
    CD %%d
    CALL :treeProcess
    CD ..
)
EXIT /B

It requires that rdfc.exe is placed in the same directory as the script. The script will require 1 parameter, the target directory. Every single file in the target directory will be replaced with a file of exactly the same size, but filled with random data.

enter image description here

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
3

PowerShell

Doesn't require an external tool. As a bonus it preserves the LastWrite time. Other times are not altered.

# Get file as item to access content and file dates
$file = Get-Item "C:\Users\Nixda\Desktop\input.txt" 

# Save write time to temp variable for later use
$oldWriteTime = $file.LastWriteTime 

# Create an empty array of the same size as your file size in bytes
$content = New-Object Byte[] $file.length 

# Fill the array using a System.Random object. Here is the magic
(New-Object Random).NextBytes($content)

# Write the array to the same file with System.IO.File
[IO.File]::WriteAllBytes($file,$content)

# Set back old write time
$file.LastWriteTime = $oldWriteTime

Before

enter image description here

After

enter image description here

Inspiration

nixda
  • 27,634
0

bcrypt will work just fine. Build it in cygwin and bring the cygwin dll along on a usb pendrive.

Edit: Or rather trivially obfuscate it by xoring them with a key of your choosing. That would at least preserve filesizes. Theres no need to alter more than 8 bytes, at most a kb, from the start of the files if you have a lot of documents and just want it done quickly. There has been some ransomware that did this a while ago. Im obviously no cryptographer, but it's pretty boring stuff sifting through files deriving the key used to obfuscate them. Or use dd ( from unxutils.sf.net for windows ) thusly: $ dd conv=swab if=infile of=outfile in a loop across your docs. Warning: Using dd like that will make you look silly. The same command will reverse the process.