This article was compiled by the editor of Downcodes and introduces in detail the commonly used port scanning methods in penetration testing, including SYN scanning, ACK scanning, UDP scanning, full connection scanning, covert scanning, and service and version detection. The article provides an in-depth explanation of the principles, steps and characteristics of each scanning method, and analyzes its advantages, disadvantages and potential risks. In addition, the article also provides relevant FAQs to help readers better understand and apply this knowledge. I hope this article can provide a reference for those engaged in network security work.

Port scanning methods in penetration testing mainly include SYN scanning, ACK scanning, UDP scanning, full connection scanning, covert scanning, and service and version detection. Each of these methods has its own characteristics, but in practical applications, SYN scanning is often used first. SYN scanning, also known as semi-open scanning, uses the handshake process of the TCP protocol to determine the status of the target port. It will not complete the TCP three-way handshake. After sending, it will only judge the port status based on the response, thereby reducing the possibility of being logged by the target system and having high concealment and efficiency.
The process of SYN scanning involves sending a SYN packet to the target port. If the response is SYN-ACK, it indicates that the port is open. Then the scanner no longer sends an ACK packet to complete the handshake, but sends an RST to reset the connection. This This method does not establish a complete connection on the target system, thereby reducing the risk of detection.
A detailed SYN scanning step is as follows:
Packet sending: The scanner sends a SYN packet to the target port. Monitoring response: The scanner receives a response, usually in the following three situations: (1) SYN-ACK packet is received, indicating that the port is open; (2) RST packet is received, and the port is closed; (3) Not received In response, the port may be filtered by the firewall. Result analysis: Analyze the status of the port based on the received response. Send RST packet: For the port that responds to SYN-ACK, send RST packet to terminate the connection.ACK scanning is often used to determine the firewall rules on the target host. This scanning method is to send packets based on TCP's ACK flag bit, with the purpose of observing the target port's response to the ACK detection packet, thereby inferring the filtering rules.
The key points of ACK scanning are:
Send a TCP packet with the ACK flag to the target port. If an RST packet is returned, it indicates that the target port responded to the ACK packet, and the firewall rules can be further analyzed. If there is no response or other type of response, further analysis by other techniques is required.UDP scan is used to detect open UDP ports. Since UDP is a connectionless protocol, this scanning method is different from TCP scanning.
The operation steps of UDP scanning mainly include:
Send a UDP packet to the destination port. If the target port is open, there will usually be no response, whereas if the port is closed, the target will send an ICMP port unreachable message. Analyze the response to determine the port status.Full connection scan, also known as TCP Connect scan, is the most direct port scanning method. It determines whether the port is open through the complete TCP three-way handshake process.
The steps for full connection scan are as follows:
Initiate a normal TCP connection and completely follow the standard TCP three-way handshake process. If the target port is open, the entire handshake process will be completed, and the scanner needs to send a RST packet to terminate the connection. Although full connectivity scan is easy to detect, it can provide very accurate scan results.Covert scanning methods include XMAS scanning, FIN scanning, NULL scanning, etc. These scanning techniques are designed to evade the detection of intrusion detection systems.
The key points of covert scanning are:
Send abnormal TCP flag combinations, such as FIN, URG, and PSH, to trigger non-standard responses from the target system. Different systems and firewall configurations may have different responses to abnormal packets sent, so a lot of trial and error and analysis are involved. By studying anomalous responses, covert scanning may bypass some security monitoring tools.Service and version detection not only focuses on whether the port is open, but also studies the services running on the open port and their version information in more detail.
Service and version detection includes:
Use specific detection techniques (such as sending special data packets, etc.) to obtain the banner information of the service. Combined with the known service and version vulnerability database, this information is analyzed to provide a basis for subsequent penetration testing. Through this in-depth exploration, penetration testers can target vulnerabilities for attack.In summary, port scanning is a critical step in penetration testing, which provides necessary information for subsequent more in-depth attack operations. Penetration testers need to choose the appropriate port scanning method based on the specific target environment and testing requirements, and be aware that each scanning method may bring the risk of discovery. Therefore, the invisibility of the scan is equally important as the cleanup after the test.
How to perform port scanning in penetration testing?
Port scanning in penetration testing is used to detect which ports in the target system are open or accessible. Here are some common port scanning methods in penetration testing:
Port scanning tool: Use a specialized port scanning tool such as Nmap to scan the ports of the target system. These tools can check the status of a port by sending TCP or UDP requests. Based on the response or lack of response, the open or closed status of the port can be determined.
Manual port scanning: Penetration testers can check the status of target systems by manually connecting to different ports on them. This requires some skill and experience, but can provide more detailed and precise results.
Port scanning technology: Use different types of port scanning technologies such as TCP full connection scanning, semi-open scanning, UDP scanning, etc. to detect open ports in the target system. Each technology has its advantages and limitations. Choose the appropriate technology for scanning based on your needs.
How to choose the appropriate port scanning technology?
Choosing the appropriate port scanning technique during penetration testing is important because different techniques are suitable for different situations. Here are some suggestions for choosing appropriate port scanning technology:
Target system type: Different operating systems and services may respond differently to port scanning techniques. Knowing the type and version of the target system can help select the appropriate technology.
Scan Purpose: Determine whether the purpose of the scan is to find open ports or to detect the system's response to a malicious scan. Depending on the purpose, appropriate technologies are selected to avoid triggering safety devices or causing system failures.
Scan performance: Some technologies may require longer scan times, and some may generate greater network traffic. Select the appropriate technology based on time and performance constraints.
Does port scanning pose a security risk to the target system?
Port scanning itself does not pose a security risk to the target system because it simply detects the port status by sending network requests. However, if the results of port scanning are not handled properly, it may lead to some security risks.
Information leakage: Port scanning can expose vulnerability information or unauthorized services in the target system. If this information is exploited by hackers, it could lead to further attacks.
Network congestion: Some port scanning techniques may generate large amounts of network traffic, causing network congestion or service interruption on the target system.
Countermeasures: Certain port scanning techniques may be detected by the target system's security equipment, triggering defense mechanisms such as blocking IP addresses or recording the attacker's behavior.
Therefore, when conducting port scans, penetration testers should follow ethical principles and security best practices and ensure that scan results are handled appropriately to mitigate any possible security risks.
I hope this summary by the editor of Downcodes can help you better understand the port scanning technology in penetration testing. Remember, in practice, always abide by ethical and legal regulations and ensure authorization before conducting any penetration testing activities.