Port Scanning Technique OSCP
Port Scanning Technique OSCP
Port Scanning Technique OSCP
Port scanning is a type of active information gathering. It is the process of scanning for
open ports on a particular host or network. It is worth to mention that this type of scanning
is illegal in several countries and should only be conducted on authorized systems. I will be
using the lab from the book to perform the scan.
The simpliest TCP port scanning technique is called CONNECT scanning and relied on 3-
way handshake. This can be done using netcat, telnet or even putty if you have installed.
The output below shows that we are able to connect to port 25 and the SMTP server
announced itself SLmail 5.5.0.4433.
UDP Scan:
As we know UDP is a stateless protocol. So it has no 3-way handshake and reliability. The
output below shows a manual port scan on port UDP 69.
NMAP:
Nmap is a free and open-source security scanner, originally written by Gordon Lyon, used
to discover hosts and services on a computer network, thus building a “map” of the
network. To accomplish its goal, Nmap sends specially crafted packets to the target host
and then analyzes the responses. The default nmap TCP scan will scan the 1000 most
popular ports on a given machine.
#nmap <host>
– Scanning a network:
#nmap <network>/<CIDR>
#nmap -iL <file> – Make sure the file is in the same directory you are running nmap.
A SYN scan (A.K.A. stealth scan) is a TCP scan that does not finish the TCP handshake. In
a SYN scan, Nmap sends the SYN and waits for the SYN-ACK if the
port is open but never sends the ACK to complete the connection. If the SYN packet
receives no SYN-ACK response, the port is not available; either it’s closed or the
connection is being filtered.
This way, Nmap finds out if a port is open without ever fully connecting to the target
machine. The syntax for a SYN scan is the -sS flag.
This the default scanning technique used.Unlike the TCP SYN scan, it completes the
normal TCP three way handshake process and requires the system to call connect(), which
is a part of the operating system.
Keep in mind that this technique is only applicable to find out the TCP ports, not the UDP
ports.
This technique is used to find an open UDP port of the target machine.
Just like a FIN scan, we can perform an xmas scan (-sX) and Null scan (-sN). The idea is
same but there is a difference between each type of scan. For example, the FIN scan sends
the packets containing only the FIN flag, where as the Null scan does not send any bit on
the packet, and the xmas sends FIN, PSH, and URG flags.
Ping scanning is unlike the other scan techniques because it is only used to find out whether
the host is alive or not, it is not used to discover open ports.
Version detection is the right technique that is used to find out what software version is
running on the target computer and on the respective ports. It is unlike the other scanning
techniques because it is not used to detect the open ports, but it requires the information
from open ports to detect the software version. In the first step of this scan technique,
version detection uses the TCP SYN scan to find out which ports are open.
Idle scan is an advance scan that provides complete anonymity while scanning. In idle scan,
Nmap doesn’t send the packets from your real IP address—instead of generating the
packets from the attacker machine, Nmap uses another host from the target network to
send the packets. Many people use -Pn w/Idlescan to prevent pings from their true IP.
OS Detection Nmap
One of the most important feature that Nmap has is the ability to detect remote operating
systems and software. It is very helpful during a penetration test to know about the
operating system and the software used by the remote computer because you can easily
predict the known vulnerabilities from this information.
Nmap has a database called nmap-os-db, the database contains information of more than
2,600 operating systems. Nmap sends TCP and UDP packets to the target machine and
then it examines the response by comparing the result with the database. The Nmap
operating system discovery technique is slightly slower then the scanning techniques
because OS detection involves the process of finding open ports.
#nmap -O <host>
If it the OS cannot be detected, we can use the option -osscan-guess and nmap will find the
nearest match of the target OS or –osscan-limit to skip the OS guessing.
When I ran just option -O nmap, it automatically tried to guess the OS.
Important Options:
-A: Enable OS detection, version detection, script scanning, and traceroute
-oA <basename>: Output in the three major formats at once (.gnmap, .nmap, .xml)
-v: Increase verbosity level (use -vv or more for greater effect)
-oG: saves the scan in a file in a Grepable format.
root@kali:~# ls -l scan*
-rw-r–r– 1 root root 936 Sep 25 21:21 scan.gnmap
-rw-r–r– 1 root root 3529 Sep 25 21:21 scan.nmap
-rw-r–r– 1 root root 14711 Sep 25 21:21 scan.xml
The Nmap Scripting Engine (NSE) is one of Nmap’s most powerful and flexible features. It
allows users to write (and share) simple scripts to automate a wide variety of networking
tasks. Those scripts are then executed in parallel with the speed and efficiency you expect
from Nmap. Users can rely on the growing and diverse set of scripts distributed with
Nmap, or write their own to meet custom needs. NSE is stored in the
/usr/share/nmap/scripts.
root@kali:/usr/share/nmap/scripts# pwd
/usr/share/nmap/scripts
root@kali:/usr/share/nmap/scripts#
root@kali:/usr/share/nmap/scripts# ls -l | wc -l
590
root@kali:/usr/share/nmap/scripts#
SCRIPT SCAN:
-sC: equivalent to –script=default
–script=<Lua scripts>: <Lua scripts> is a comma separated list of
directories, script-files or script-categories
–script-args=<n1=v1,[n2=v2,…]>: provide arguments to scripts
–script-args-file=filename: provide NSE script args in a file
–script-trace: Show all data sent and received
–script-updatedb: Update the script database.
–script-help=<Lua scripts>: Show help about scripts.
<Lua scripts> is a comma-separated list of script-files or
script-categories.
NSE is activated with the -sC option (or –script if you wish to specify a custom set of
scripts) and results are integrated into Nmap normal and XML output.
smb-os-discovery.nse
OR
root@kali:/usr/share/nmap/scripts# nmap -sC -p 139 192.168.0.112
Starting Nmap 7.70 ( https://nmap.org ) at 2018-09-25 22:17 -03
Nmap scan report for 192.168.0.112
Host is up (0.00095s latency).
whois-domain.nse script:
Banner grab: