This repository contains Python scripts related to networking, demonstrating various concepts and practical applications.
- UDP Client
- TCP Client
- TCP Server
- SSH Server
- SSH Command Executor
- SSH Remote Command Executor
- Packet Sniffer (IP Header Decoder)
- TCP Proxy
- Netcat Clone
- Traceroute Script
- Email Validator
- String to Reversed Hex Converter
- Subdomain Finder using crt.sh
A simple UDP client script that:
- Sends a message (
AAABBBCCC) to a target host and port. - Receives a response from the server.
- Utilizes the
socketlibrary for UDP communication. - Configures the target host (
127.0.0.1) and port (9997). - Demonstrates basic send and receive operations in UDP.
- Make sure a corresponding UDP server is running on the target host and port.
- Run the script:
python udp_client.py
- View the server's response in the console.
Response from server: Hello, Client!
A simple TCP client script that:
- Connects to a specified host and port.
- Sends a message (
ABCDEF) to the server. - Receives and prints the server's response.
- Utilizes the
socketlibrary for TCP communication. - Configures the target host (
0.0.0.0) and port (9998). - Demonstrates basic connect, send, and receive operations in TCP.
- Ensure a corresponding TCP server is running on the target host and port.
- Run the script:
python tcp_client.py
- View the server's response in the console.
Response from server: Welcome to the server!
A multi-threaded TCP server script that:
- Listens for incoming connections on a specified host and port.
- Accepts connections from multiple clients.
- Receives messages from clients and sends an acknowledgment (
ACK).
- Utilizes the
socketlibrary for TCP communication. - Employs the
threadingmodule to handle multiple client connections concurrently. - Configures the server to listen on
0.0.0.0and port9998.
- Run the script to start the server:
python tcp_server.py
- The server will listen for incoming connections and log connection details.
- Connect to the server using a TCP client (e.g.,
tcp_client.py).
[*] Listening on 0.0.0.0:9998
[*] Accepted connection from 127.0.0.1:12345
[*] Received: ABCDEF
A custom SSH server script that:
- Implements SSH server functionalities using the
paramikolibrary. - Authenticates users based on predefined credentials (
username: kali,password: root). - Listens for incoming SSH connections on a specified host and port.
- Accepts commands from authenticated clients and sends responses.
- Utilizes
paramikofor SSH transport and authentication. - Configures the server to listen on
192.168.0.108and port2222. - Employs threading to handle multiple client connections concurrently.
- Generate an RSA private key file (e.g.,
test_rsa.key) and place it in the same directory as the script.ssh-keygen -t rsa -f test_rsa.key
- Run the script to start the SSH server:
python ssh_server.py
- Connect to the server using an SSH client (e.g.,
sshcommand-line tool):ssh kali@192.168.0.108 -p 2222
- Authenticate with the password
rootand interact with the server.
[+] Listening for connection ...
[+] Got a connection! <socket object> ('192.168.0.105', 56789)
[+] Authenticated!
Welcome to bh_ssh
A script for executing commands on a remote SSH server:
- Connects to an SSH server using provided credentials.
- Executes a specified command and prints the output.
- Utilizes the
paramikolibrary for SSH communication. - Prompts the user for server IP, port, username, password, and command.
- Handles authentication and command execution over SSH.
- Run the script:
python ssh_cmd.py
- Enter the required details when prompted (IP, port, username, password, command).
- View the command output in the console.
Username: kali
Password:
Enter server IP: 192.168.0.106
Enter port or <CR>: 2222
Enter command or <CR>: id
--- Output ---
uid=1000(kali) gid=1000(kali) groups=1000(kali)
A script for executing remote commands via SSH and receiving their output:
- Connects to a remote SSH server using provided credentials.
- Sends and receives commands interactively.
- Utilizes the
paramikolibrary for SSH communication. - Handles interactive command execution through a custom SSH session.
- Uses
subprocessandshlexto execute commands on the server.
- Run the script:
python ssh_rcmd.py
- Enter the required details when prompted (IP, port, username, password).
- Interact with the server by sending commands and receiving their output.
Enter User: kali
Password:
Enter server IP: 192.168.0.106
Enter port: 2222
--- Output ---
ClientConnected
ls
file1.txt file2.txt
exit
A script for sniffing and decoding IP headers from network packets:
- Captures raw network packets.
- Extracts and decodes IP header information such as source and destination addresses, protocol type, etc.
- Utilizes the
socketlibrary for raw packet capture. - Handles IP header parsing using the
structlibrary. - Maps common protocol numbers to protocol names (e.g., TCP, UDP, ICMP).
- Run the script:
If no host is specified, the default is
python sniffer_ip_header_decoder.py <host>
192.168.0.103. - The script will continuously sniff packets on the specified host and display their IP header details.
- Press
Ctrl+Cto stop the script.
Protocol: TCP 192.168.0.105 -> 192.168.0.1
Protocol: UDP 192.168.0.106 -> 192.168.0.2
- Requires administrative/root privileges to run.
- Behavior may differ on Windows vs. Unix-based systems due to socket options.
A flexible TCP proxy script that:
- Forwards traffic between a local and a remote host.
- Logs and modifies traffic in both directions.
- Uses
socketfor low-level network operations. - Implements
hexdumpto inspect data streams. - Includes customizable
request_handlerandresponse_handlerfor traffic manipulation.
- Run the script with the required arguments:
Example:
python proxy.py [localhost] [localport] [remotehost] [remoteport] [receive_first]
python proxy.py 127.0.0.1 9000 10.12.132.1 9000 True
- The proxy will listen on
localhost:localportand forward traffic toremotehost:remoteport. - Use the
receive_firstflag (TrueorFalse) to control whether the proxy waits for data from the remote host before forwarding traffic.
- Traffic logging and hexdumping in both directions.
- Traffic modification using
request_handlerandresponse_handlerfunctions.
- Useful for testing and debugging network applications.
- Requires basic Python and networking knowledge to customize effectively.
A Python-based Netcat clone that:
- Supports both client and server modes for TCP communication.
- Provides functionalities to send and receive files, execute commands, and create reverse shells.
- Uses
argparsefor command-line argument parsing. - Utilizes
socketfor TCP communication. - Implements threading for concurrent server operations.
- Handles different modes of operation:
send,receive,execute, andshell.
-
Run the script with the appropriate arguments:
python netcat.py -t <target_host> -p <port> -l -c
-l: Listen mode (server mode).-c: Command shell.-t: Target host.-p: Port number.
-
Example Usage:
- Start a Netcat server:
python netcat.py -t 0.0.0.0 -p 5555 -l -c
- Connect to the server as a client:
python netcat.py -t 127.0.0.1 -p 5555
- Start a Netcat server:
-
Additional options can be used for file transfers or command execution.
- Requires Python 3 and basic networking knowledge to operate.
- Ensure proper firewall settings to allow communication.
Here's the README section for traceroute.py:
A Python script that replicates the functionality of the traceroute network diagnostic tool:
- Determines the route packets take to a specified destination.
- Reports the IP address, hostname, and round-trip time (RTT) for each hop along the path.
- Uses
socketfor sending and receiving packets. - Implements a
create_socketfunction to configure ICMP and UDP sockets with varying TTL values. - Calculates RTT for each hop and handles host resolution.
- Provides an option to save traceroute results to a file.
-
Run the script:
python traceroute.py
-
Enter the required parameters when prompted:
- Destination: Hostname or IP address of the target.
- Maximum Hops: Maximum number of hops to trace (default is 30).
- Timeout: Timeout in seconds for each hop (default is 2 seconds).
-
Example Input:
Enter destination host/IP: google.com Enter maximum hops (default 30): 20 Enter timeout in seconds (default 2): 1 -
Example Output:
Traceroute to google.com Hop IP Hostname Time ------------------------------------------------------------ 1 192.168.1.1 myrouter.home 1.23ms 2 10.0.0.1 - 2.45ms ... 10 142.250.72.14 fra15s30-in-f14.1e100.net 20.31ms -
Optionally, save the results to a file:
- When prompted, type
yand provide a filename, or leave it blank to auto-generate.
- When prompted, type
- Displays hop-by-hop details with RTT.
- Resolves IP addresses to hostnames when possible.
- Saves results to a timestamped text file for later reference.
- Requires administrative/root privileges to run.
- May behave differently depending on network and operating system configurations.
A Python script that checks the validity of an email address through multiple verification steps. This script helps ensure that an email address is properly formatted, belongs to a valid domain, and actually exists.
- Email Format Validation: Ensures the email address is in the correct format.
- Domain Validation: Verifies that the domain name is valid and not from a disposable email provider.
- MX Record Check: Retrieves and checks the domain's MX (Mail Exchange) records.
- Mailbox Verification: Attempts to connect to the email server to verify the existence of the email address.
The script follows these steps to validate an email address:
- Check for Email Format: Uses a regular expression to ensure the email address is formatted correctly.
- Validate Domain: Checks if the domain name is valid and not from a known disposable email provider.
- Check MX Records: Resolves the MX records for the domain.
- Simulate Email Delivery: Connects to the email server and simulates sending an email to verify if the email address exists.
python email_validator.py user@example.comOutput:
Valid email address
A Python script to convert string to reversed hex.
python conv.py /bin/shOutput:
0x68732f
0x6e69622f
A simple Python script uses the crt.sh API to find unique subdomains for any given domain.
- Queries
crt.shfor any subdomains of your target domain. - Handles subdomains returned in the
name_valuefield. - Supports timeout configuration for the request.
- Optionally saves the output to a file.
- Outputs a clean, sorted list of subdomains.
python crt.pyExample workflow:
- Enter the target domain when prompted.
- Specify a timeout in seconds (or press Enter for the default of 10 seconds).
- View the unique subdomains found.
- Choose whether to save them to a file.
Enter the domain (e.g., example.com): example.com
Enter timeout in seconds (default: 10):
[*] Fetching subdomains for: example.com with timeout 10s
[+] Found 8 unique subdomains:
example.com
www.example.com
mail.example.com
dev.example.com
...
Do you want to save the results to a file? (y/n): y
Enter filename (e.g., subdomains.txt): example_subdomains.txt
[+] Subdomains saved to: example_subdomains.txt
More Scripts are Comming soon!!!