Now that we have a target service up and running, it's time to dive into SYN scans. SYN scans are a crucial part of network security testing, allowing us to discover open ports on a target system. In this section, we'll learn about how SYN scans work and then use Nmap, a powerful network scanning tool, to perform a SYN scan against our HTTP server.
What is a SYN Scan?
Before we start the actual scan, it's essential to understand the underlying mechanism of a SYN scan. To do that, let's first look at how a normal TCP connection is established.
Normal TCP Connection
In a normal TCP connection, a three - way handshake takes place. This is a fundamental process for establishing a reliable connection between a client and a server:
- Step 1: SYN Packet from Client
The client initiates the connection by sending a SYN (synchronize) packet to the server. This packet is like a request to start a conversation, asking the server if it's ready to communicate.
- Step 2: SYN - ACK Packet from Server
Upon receiving the SYN packet, if the server is available and willing to communicate, it responds with a SYN - ACK (synchronize - acknowledge) packet. This packet acknowledges the client's request and also indicates that the server is ready to start the connection.
- Step 3: ACK Packet from Client
Finally, the client sends an ACK (acknowledge) packet to complete the three - way handshake. After this step, the TCP connection is fully established, and data can be exchanged between the client and the server.
SYN Scan Process
A SYN scan, on the other hand, has a different approach:
- Step 1: SYN Packet from Nmap
Nmap, our scanning tool, sends the initial SYN packet to the target port. This is similar to the first step in a normal TCP connection.
- Step 2: SYN - ACK Response from Target
If the target port is open, it will respond with a SYN - ACK packet, just like in a normal TCP connection.
- Step 3: Connection Termination by Nmap
Instead of sending the final ACK packet to complete the handshake, Nmap terminates the connection. This makes the scan less detectable because the full connection is never established. Additionally, it is faster than a full connect scan, which completes the entire three - way handshake for each port being scanned.
Step 1: Navigate to the Project Directory
First, we need to make sure we are in the correct project directory. This is important because we'll be saving the scan results in a file within this directory. To navigate to the project directory, run the following command in your terminal:
cd /home/labex/project
Step 2: Execute the SYN Scan
Now, we're ready to perform the SYN scan using Nmap. Run the following command in your terminal:
sudo nmap -sS localhost -p 8080 > /home/labex/project/nmap-syn-scan-results.txt
Let's break down this command to understand what each part does:
sudo
: This command is used to run the subsequent command with elevated privileges. SYN scans require root privileges because they involve sending raw network packets, so we need to use sudo
to execute the nmap
command.
nmap
: This is the network scanning tool we are using. Nmap is widely used for network exploration and security auditing.
-sS
: This option specifies that we want to perform a SYN scan.
localhost
: This is the target of our scan. In this case, we are scanning our own machine.
-p 8080
: This option tells Nmap to only scan port 8080. We are interested in checking if this specific port is open on our local machine.
> /home/labex/project/nmap-syn-scan-results.txt
: This part of the command redirects the output of the nmap
scan to a file named nmap - syn - scan - results.txt
in the project directory. This way, we can review the results later.
Step 3: View the Scan Results
After the scan is complete, we can view the results. Run the following command in your terminal:
cat /home/labex/project/nmap-syn-scan-results.txt
You should see output similar to the following:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-18 12:00 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000097s latency).
PORT STATE SERVICE
8080/tcp open http-proxy
Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds
This output provides valuable information. It confirms that port 8080 is open on your local machine and that it is running an HTTP service. This information can be used for further security analysis or network troubleshooting.