Pentesting Notes
Protocols and Servers

Protocols and Servers
| Protocol | TCP Port | Application(s) | Data Security |
|---|---|---|---|
| FTP | 21 | File Transfer | Cleartext |
| FTPS | 990 | File Transfer | Encrypted |
| HTTP | 80 | Worldwide Web | Cleartext |
| HTTPS | 443 | Worldwide Web | Encrypted |
| IMAP | 143 | Email (MDA) | Cleartext |
| IMAPS | 993 | Email (MDA) | Encrypted |
| POP3 | 110 | Email (MDA) | Cleartext |
| POP3S | 995 | Email (MDA) | Encrypted |
| SFTP | 22 | File Transfer | Encrypted |
| SSH | 22 | Remote Access and File Transfer | Encrypted |
| SMTP | 25 | Email (MTA) | Cleartext |
| SMTPS | 465 | Email (MTA) | Encrypted |
| Telnet | 23 | Remote Access | Cleartext |
Telnet
- The Telnet protocol allows users to remotely access and control another computer's terminal. It works by connecting to a virtual terminal on the target machine.
Pros:
- Simple to use: Users connect, enter credentials, and gain access to a command prompt.
- Fast connection: Offers quick access to the remote system.
Cons:
- Unsecure: All communication (including username and password) is sent in plain text, making it vulnerable to eavesdropping.
- Limited functionality: Primarily used for command-line access, not ideal for graphical interfaces.
Security Risk:
Telnet poses a security risk because passwords and other sensitive data are not encrypted. Anyone monitoring network traffic can easily capture login credentials.
Alternative:
The document recommends using SSH (Secure Shell) as a secure alternative to Telnet. SSH encrypts communication, protecting usernames and passwords from unauthorized access.
Hypertext Transfer Protocol
HTTP is the fundamental protocol used for transferring web pages and other data on the internet.
Key Points:
- Client-Server Model: HTTP operates in a client-server model where a client (web browser) requests resources from a server (web server).
- Data Transfer: HTTP transfers data in plain text format, making it susceptible to eavesdropping.
- Request-Response Cycle: Clients send requests to servers, and servers respond with the requested data or error messages.
- Common Requests: Common HTTP requests include GET (retrieve data), POST (submit data), and HEAD (get header information).
- Status Codes: Servers respond with status codes to indicate the outcome of a request (e.g., 200 OK, 404 Not Found).
Components:
- HTTP Servers: Software that handles HTTP requests and serves web content (e.g., Apache, Nginx, IIS).
- HTTP Clients: Software that sends HTTP requests and processes responses (e.g., web browsers).
Example:
A user types a URL into a web browser. The browser sends an HTTP GET request to the web server. The server processes the request, retrieves the requested web page, and sends it back to the browser. The browser then displays the page.
Security Considerations:
Since HTTP transmits data in plain text, it's essential to use HTTPS (HTTP Secure) for sensitive information like passwords and credit card details. HTTPS encrypts data using SSL/TLS, making it more secure.
File Transfer Protocol
FTP (File Transfer Protocol) is a network protocol used to transfer files between computers.
Key Points:
- Client-Server Model: FTP operates in a client-server model where a client (FTP client) connects to a server (FTP server) to transfer files.
- Data Transfer: FTP transfers data in plain text format, making it susceptible to eavesdropping.
- Control and Data Connections: FTP establishes two separate connections: a control connection for commands and a data connection for file transfers.
- File Transfer Modes: FTP supports ASCII and binary modes for transferring different types of files.
- FTP Commands: Common FTP commands include USER (login), PASS (password), LIST (list files), GET (download), PUT (upload), and QUIT (exit).
Security Considerations:
Since FTP transmits data in plain text, it's essential to use secure FTP protocols like SFTP (SSH File Transfer Protocol) or FTPS (FTP over SSL/TLS) to protect sensitive data during file transfers.
FTP Servers and Clients:
- FTP Servers: Software that handles FTP connections and file transfers (e.g., vsftpd, ProFTPD, uFTP).
- FTP Clients: Software that connects to FTP servers and performs file transfers (e.g., FileZilla, command-line FTP clients).
Simple Mail Transfer Protocol
Email is a widely used communication method that involves the exchange of messages between different users. The process of sending and receiving emails involves several key components and protocols.
Components:
- Mail User Agent (MUA): The email client used by users to compose, send, and receive emails (e.g., Outlook, Gmail).
- Mail Submission Agent (MSA): A component that accepts emails from MUAs and forwards them to MTAs.
- Mail Transfer Agent (MTA): A server responsible for routing and delivering emails to their intended recipients.
- Mail Delivery Agent (MDA): A component that receives emails from MTAs and stores them in user mailboxes.
Email Delivery Process:
- User composes an email: A user creates an email using their MUA.
- MUA sends email to MSA: The MUA connects to an MSA and sends the email message.
- MSA forwards email to MTA: The MSA checks the email for errors and forwards it to an MTA.
- MTA routes email to recipient's MTA: The MTA determines the recipient's MTA and routes the email accordingly.
- Recipient's MTA receives email: The recipient's MTA receives the email and stores it in their MDA.
- Recipient retrieves email: The recipient uses their MUA to connect to their MDA and retrieve the email.
Protocols:
- Simple Mail Transfer Protocol (SMTP): Used for sending emails between MTAs.
- Post Office Protocol (POP3) or Internet Message Access Protocol (IMAP): Used by MUAs to retrieve emails from MDAs.
SMTP Example:
The provided example demonstrates basic SMTP communication using Telnet. A user connects to an SMTP server, sends email commands (helo, mail from, rcpt to, data), and types the email message. The SMTP server queues the email for delivery.
Post Office Protocol 3
POP3 (Post Office Protocol version 3) is a protocol used to retrieve emails from a mail server.
Key Points:
- Client-Server Model: POP3 operates in a client-server model where a client (email client) connects to a server (POP3 server) to retrieve emails.
- Authentication: POP3 requires authentication to access a user's mailbox.
- Email Retrieval: Clients can download emails from the server, often deleting them from the server in the process.
- Plain Text Communication: POP3 transmits data in plain text, making it susceptible to eavesdropping.
POP3 Commands:
- USER: Specifies the username.
- PASS: Specifies the password.
- STAT: Retrieves the number of messages and inbox size.
- LIST: Lists the available messages.
- RETR: Retrieves a specific message.
- QUIT: Terminates the connection.
Security Considerations:
Since POP3 transmits data in plain text, it's essential to use secure POP3 (POP3 over SSL/TLS) to protect login credentials and email content during transmission.
Limitations:
- Email Deletion: POP3 typically deletes emails from the server after downloading them, which can be inconvenient if you access your email from multiple devices.
- Synchronization: POP3 doesn't provide real-time synchronization between multiple devices, making it difficult to manage read and unread messages across different clients.
Alternatives:
To overcome the limitations of POP3, consider using IMAP (Internet Message Access Protocol), which allows you to synchronize emails across multiple devices and access them from different locations without deleting them from the server.
Internet Message Access Protocol
IMAP (Internet Message Access Protocol) is a protocol used to retrieve and manage emails on a mail server. It offers more advanced features compared to POP3, particularly for users who access their email from multiple devices.
Key Features:
- Synchronization: IMAP allows emails to be synchronized across multiple devices, ensuring consistent access and management across different clients.
- Folder Structure: IMAP supports a hierarchical folder structure, enabling users to organize their emails into different categories.
- Message Management: IMAP provides features like flagging, labeling, and searching messages, allowing for better organization and management.
- Offline Access: IMAP supports offline access, allowing users to download and view emails even when they are not connected to the internet.
IMAP Commands:
- LOGIN: Authenticates the user to the IMAP server.
- LIST: Retrieves a list of available folders.
- EXAMINE: Selects a specific folder for further operations.
- SEARCH: Searches for messages based on criteria like sender, recipient, subject, or keywords.
- FETCH: Retrieves a specific message or part of a message.
- STORE: Modifies message attributes like flags or labels.
- LOGOUT: Terminates the connection.
Security Considerations:
Similar to POP3, IMAP transmits data in plain text, making it susceptible to eavesdropping. It's essential to use secure IMAP (IMAP over SSL/TLS) to protect login credentials and email content during transmission.
Comparison to POP3:
- Synchronization: IMAP provides synchronization across multiple devices, while POP3 typically deletes emails from the server after downloading them.
- Folder Structure: IMAP supports a hierarchical folder structure, while POP3 has a simpler folder structure.
- Message Management: IMAP offers more advanced features for managing messages, while POP3 has limited message management capabilities.
- Offline Access: IMAP supports offline access, while POP3 may have limited offline capabilities.
Conclusion:
IMAP is a more sophisticated protocol than POP3, offering better synchronization, folder management, and message management features. It's particularly suitable for users who access their email from multiple devices and require advanced email management capabilities.
Sniffing Attack
Sniffing attacks involve capturing network traffic to gather information about a target system. This is particularly effective when protocols are used in cleartext, as data can be intercepted and analyzed without encryption.
Tools for Sniffing:
- Tcpdump: A command-line tool for capturing and analyzing network packets.
- Wireshark: A graphical user interface tool for capturing and analyzing network packets.
- Tshark: A command-line alternative to Wireshark.
Example: Capturing POP3 Credentials
The provided example demonstrates how to use Tcpdump to capture POP3 credentials. By filtering traffic on port 110 (the default POP3 port) and displaying the packet contents in ASCII format, the username and password can be extracted from the captured packets.
Requirements:
- Network Access: The attacker needs to be on the same network as the target system or have access to a switch with port mirroring.
- Root or Administrator Privileges: Elevated privileges are required to capture network packets.
Mitigation:
To protect against sniffing attacks, it's crucial to encrypt network traffic using protocols like HTTPS, FTPS, SFTP, or SSH. These protocols provide a secure layer of encryption, preventing unauthorized access to data.
Man-in-the-Middle Attack
MITM attacks occur when an attacker intercepts communication between two parties, modifying or eavesdropping on the data exchanged. This can lead to various consequences, such as unauthorized access, data theft, or fraudulent transactions.
Example:
The provided example demonstrates how an attacker can intercept a payment transaction and modify the amount to be transferred. This attack is possible when the parties involved do not verify the authenticity and integrity of the messages being exchanged.
Vulnerable Protocols:
- HTTP: Browsing over HTTP is particularly vulnerable to MITM attacks due to its lack of encryption.
- FTP: File transfers over FTP can be intercepted and modified if not secured.
- SMTP, POP3: Email communication can be compromised if not protected against MITM attacks.
Tools for MITM Attacks:
- Ettercap: A powerful tool for network sniffing and MITM attacks.
- Bettercap: Another popular tool for network analysis and MITM attacks.
Mitigation:
To protect against MITM attacks, it's essential to use protocols that provide encryption and authentication. TLS (Transport Layer Security) is a widely used protocol that offers both encryption and authentication using PKI and trusted root certificates. By enabling TLS, you can significantly reduce the risk of MITM attacks.
Transport Layer Security
SSL/TLS (Secure Sockets Layer/Transport Layer Security) is a cryptographic protocol that provides security for network communication. It protects against password sniffing and MITM attacks by encrypting data and verifying the authenticity of communicating parties.
How SSL/TLS Works:
- TCP Connection: A TCP connection is established between the client and server.
- SSL/TLS Handshake:
- The client sends a ClientHello message, indicating supported algorithms.
- The server responds with a ServerHello, selecting parameters and providing its certificate.
- The client generates a master key and sends a ClientKeyExchange message.
- Both parties switch to using encryption.
- Encrypted Communication: Subsequent data is exchanged using the agreed-upon encryption.
Benefits of SSL/TLS:
- Confidentiality: Protects data from unauthorized access.
- Integrity: Ensures data is not modified during transmission.
- Authentication: Verifies the identity of communicating parties.
Applications:
- HTTPS: Secure web browsing.
- FTPS: Secure file transfers.
- SMTPS: Secure email transmission.
- POP3S: Secure email retrieval.
- IMAPS: Secure IMAP communication.
Key Components:
- Certificates: Digital files that contain information about the server's identity and public key.
- Certificate Authorities (CAs): Trusted organizations that issue and manage certificates.
Conclusion:
SSL/TLS is a fundamental security protocol that plays a crucial role in protecting online communication. By encrypting data and verifying identities, it helps prevent various security threats and ensures the confidentiality and integrity of network traffic.
Secure Shell
SSH (Secure Shell) is a protocol designed for secure remote system administration. It provides confidentiality, integrity, and authentication to ensure secure communication.
Key Features:
- Authentication: SSH supports various authentication methods, including username/password and public key-based authentication.
- Encryption: All communication is encrypted using strong cryptographic algorithms, protecting data from unauthorized access.
- Integrity: SSH verifies the integrity of messages to prevent tampering or modification.
- Man-in-the-Middle Protection: SSH protects against MITM attacks by verifying the authenticity of the remote server using public key cryptography.
SSH Commands:
- ssh username@MACHINE_IP: Connects to an SSH server using the specified username and password.
- scp: Transfers files securely between systems using SSH.
SSH and Security:
SSH provides a secure alternative to Telnet, which transmits data in cleartext. By using SSH, you can protect your login credentials, commands, and data from being intercepted or modified.
SSH vs. FTP:
- Security: SSH is inherently more secure than FTP, which transmits data in cleartext by default.
- Functionality: SSH provides a wider range of functionalities, including remote command execution and file transfer.
- Port: SSH uses port 22, while FTP uses port 21.
Conclusion:
SSH is an essential tool for secure remote administration. It offers robust security features, making it a reliable choice for connecting to remote systems and managing them securely.
Password Attack
Password attacks aim to compromise a user's login credentials to gain unauthorized access to systems or accounts. Common types of password attacks include:
- Password Guessing: Using personal information or common patterns to guess passwords.
- Dictionary Attacks: Trying words from a dictionary or wordlist.
- Brute Force Attacks: Exhaustively trying all possible combinations of characters.
Password Cracking Tools:
- Hydra: A versatile tool for cracking passwords against various protocols.
- John the Ripper: A popular password cracking tool with support for various hashing algorithms.
Password Security Measures:
- Strong Password Policies: Enforce strong password requirements, such as using a combination of uppercase, lowercase, numbers, and symbols.
- Password Managers: Use password managers to securely store and manage complex passwords.
- Multi-Factor Authentication (MFA): Require additional verification factors, such as a code sent to your phone or a biometric scan.
- Account Lockout: Lock accounts after multiple failed login attempts to prevent brute force attacks.
- Rate Limiting: Limit the number of login attempts within a specific timeframe.
Additional Considerations:
- Password Reuse: Avoid using the same password for multiple accounts.
- Phishing Awareness: Be cautious of phishing attempts that trick users into revealing their passwords.
- Regular Password Updates: Encourage users to change their passwords periodically.
- Security Training: Educate users about password security best practices.
الملف في مستودعي: Protocols and Servers.md