Task Automation
Stop doing repetitive tasks. Let Python handle the boring stuff.
1. File Organization Script
This script automatically sorts files in a folder into subfolders based on their file extension (e.g., images go to /Images, PDFs go to /Documents).
import os
import shutil
def organize_folder(folder_path):
extensions = {
'Images': ['.jpg', '.jpeg', '.png', '.gif', '.bmp'],
'Documents': ['.pdf', '.docx', '.txt', '.xlsx'],
'Videos': ['.mp4', '.mkv', '.avi'],
'Archives': ['.zip', '.rar', '.7z']
}
for filename in os.listdir(folder_path):
file_path = os.path.join(folder_path, filename)
if os.path.isdir(file_path): continue
_, ext = os.path.splitext(filename)
ext = ext.lower()
for folder_name, ext_list in extensions.items():
if ext in ext_list:
target_dir = os.path.join(folder_path, folder_name)
if not os.path.exists(target_dir): os.makedirs(target_dir)
shutil.move(file_path, os.path.join(target_dir, filename))
print(f"Moved: {filename} -> {folder_name}/")
break
# Usage:
# organize_folder("/path/to/messy/folder")
Network Defense
Protect infrastructure. Understand how data flows and how to secure it.
1. Port Scanner (Defensive Check)
Before attackers find your open ports, find them yourself. This basic script checks if specific ports are open on a server.
import socket
def scan_ports(target, ports):
print(f"Scanning Target: {target}")
for port in ports:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1.0)
result = s.connect_ex((target, port))
if result == 0:
print(f"[+] Port {port} is OPEN")
else:
print(f"[-] Port {port} is CLOSED")
s.close()
# Usage:
# scan_ports("127.0.0.1", [21, 22, 80, 443, 3306])
Offensive Security
Think like an attacker to build better defenses.
⚠️ ETHICAL DISCLAIMER
The techniques and simulations shown here are strictly for educational purposes. Never test these on systems you do not own or have explicit permission to test. Unauthorized hacking is illegal.
Interactive Lab 1: SQL Injection Simulation
SQL Injection happens when a website fails to validate user input, allowing attackers to run database commands. Try to bypass this login form using a classic SQL payload.
Hint: Try typing ' OR 1=1 -- as the username.
// TARGET: VULNERABLE_LOGIN
Interactive Lab 2: Brute Force Simulator
Brute forcing is the act of trying every possible combination until the correct one is found. Start the attack and watch the terminal try to guess the 4-digit PIN.
// TARGET: PIN_CRACKER
Interactive Lab 3: Capture The Flag (CTF)
In cybersecurity, a "Flag" is a hidden string of text placed inside a system to prove you've compromised it. Check the Source Code (Right-click -> View Page Source) or press F12 and look through the HTML. Find the hidden flag and submit it below.
// CHALLENGE: FIND_THE_FLAG
Cryptography
The mathematics of secrecy and integrity.
1. Hashing Passwords (SHA-256)
Never store passwords in plaintext. Hashing is a one-way function.
import hashlib
def hash_password(password):
encoded_pw = password.encode('utf-8')
hash_obj = hashlib.sha256(encoded_pw)
return hash_obj.hexdigest()
# Usage:
# print(hash_password("mySuperSecretPassword123"))
OSINT & Recon
Open Source Intelligence. Information is power.
1. IP Geolocation Lookup
Use public APIs to find out where an IP address is located. This uses the free ip-api.com service.
import requests
def ip_lookup(ip_address):
url = f"http://ip-api.com/json/{ip_address}"
try:
response = requests.get(url)
data = response.json()
if data['status'] == 'success':
print(f"--- Info for {ip_address} ---")
print(f"Country: {data['country']}")
print(f"City: {data['city']}")
print(f"ISP: {data['isp']}")
except Exception as e:
print(f"Error: {e}")
# Usage:
# ip_lookup("8.8.8.8")