Skip to content

Instantly share code, notes, and snippets.

@k4kfh
Created July 27, 2017 20:34
Show Gist options
  • Save k4kfh/75437f91ec1819b443858fdf977f2011 to your computer and use it in GitHub Desktop.
Save k4kfh/75437f91ec1819b443858fdf977f2011 to your computer and use it in GitHub Desktop.
Recursive, random directory creation with Python
import os,sys,uuid
global injectedLegitFile
injectedLegitFile = True
def fillDirectoryWithFiles(path, numFiles, size):
file_names = [(str(uuid.uuid4())[:10] + ".xlsx") for i in range(0,numFiles)]
#print file_names
for name in file_names:
fileObject = open(path+"/"+name,"w+")
fileObject.write(os.urandom(size))
fileObject.close()
def fillDirectoryWithDirectories(path, numDirectories):
dir_names = [str(uuid.uuid4())[:10] for i in range(0,numDirectories)]
#print dir_names
for name in dir_names:
os.makedirs( path+"/"+name, 0755 )
def recursiveFill(path, numFiles, numDirectories, depth):
global injectedLegitFile
#print "Beginning recursiveFill() with depth=" + str(depth)
if (depth == 0):
#print "Ending recursiveFill() because depth=0!"
if (injectedLegitFile == False):
fileObject = open(path+"/passwords.xlsx","w+")
fileObject.close()
print "CREATING LEGIT PASSWORDS FILE IN " + path
injectedLegitFile = True
fillDirectoryWithFiles(path, numFiles, 25)
else:
fillDirectoryWithFiles(path, numFiles, 25)
fillDirectoryWithDirectories(path, numDirectories)
dir_list = listDirectories(path)
for directory in dir_list:
recursiveFill((path + "/" + directory), numFiles, numDirectories, (depth-1))
def listDirectories(path):
f = []
for (dirpath, dirnames, filenames) in os.walk(path):
f.extend(dirnames)
break
return f
print "CONFIGURATION:"
path = raw_input("Path (ie C:/Users/user/directory) :")
numberOfFiles = input("Number of Files: ")
numberOfDirectories = input("Number of Directories: ")
recursionAmount = input("Recursion Depth: ")
makeLegitFile = raw_input("Should we make a legit file? [y/n]")
if (makeLegitFile == "y"):
injectedLegitFile = False
else:
injectedLegitfile = True
print "Making decoy directory (no legitimate passwords file)!"
recursiveFill(path, numberOfFiles, numberOfDirectories, recursionAmount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment