Self-Destructing Python Script - Programming / Tutorials - 0x00sec
On Linux:
#!/usr/bin/env python
import subprocess as sp
from os import path
# This gives us the absolute(full) path to this python script
self_path = path.abspath(__file__)
# Do stuff -- I just created a folder
sp.call(["mkdir", "/home/User/Desktop/thinair"])
# At the end of the script, the file shreds itself
sp.call(["/usr/bin/shred", "-fuz" , self_path])
On Windows:
import os
# This gives us the absolute(full) path to this python script
file_path = os.path.abspath(__file__)
# Do stuff -- I just created a folder
os.system("mkdir %USERPROFILE%\Desktop\dontlook")
# At the end of the script, the file is deleted & over-written
os.remove(file_path)
folder_path = os.path.dirname(file_path)
os.system("cipher /W:%s" % folder_path)
The Python codes needed to actually delete a file/folder are given in this4 stackoverflow accepted answer, those being:
os.remove() will remove a file.
os.rmdir() will remove an empty directory.
shutil.rmtree() will delete a directory and all its contents.
permalink -
-
https://0x00sec.org/t/self-destructing-python-script/898/3