For this project you will implement a basic network port scanner in C or C++. Port scanning software can analyze a machine for open network ports. They are an invaluable tool for network administrators and security analysts in verifying the security of machines in their network and proving proper implementation of firewall technologies. They are also one of the first tools used by attackers once they have identified a target as it allows them to quickly enumerate possible entry points and methods to escalate their access. An example of a well-known, open source port scanner is Nmap. In this project you will create a stripped-down port scanner, written for network administrators interested in ensuring that machines on their network run only expected services. During this project, you will also gain experience with basic socket programming.
Note: A malleable port scanning tool can be an excellent resource in network assessments and could be a very useful tool for you in the future, so make sure that you do a good job at writing this one.
The basic idea behind a port scanner is simple: Given the IP address of a machine and a list of ports to scan, the scanner will connect on each port using TCP sockets, make a determination of whether or not the port is open based on success of the connection request and close the socket before moving on to the next port to scan (send a TCP RST command). For this project, you will NOT allow for "half-open" scans (connection requests without a corresponding close) as it can lead to network failures (though you may want to consider this ability for your own use later on). Also, It will then similarly scan UDP sockets to attempt to enumerate closed ports there. For this exercise, you will simply make a UDP determination based on whether or not you receive an ICMP Destination Unreachable message.
Your scanner should run on the CSE Linux machines and you must write it in C/C++. An administrator would invoke it as: "./portScan [option1, ..., optionN]". Implement the following options:
You may also wish to allow for "shortcut" variations (-p for ports) but this is not a requirement.
Details of each option are given below:
Output: After each invocation, the portScan should output a succinct summary of the list of open TCP and UDP ports on each IP address. Additionally, for each open port from 1 to 1024, it will include the name of the service that is likely running. To find services associated with ports [1-1024], visit http://www.iana.org/assignments/port-numbers.
started Mon Nov 19 20:14:15 CST 2018 .
--------------------------------- .
192.168.1.1 .
No Open Ports or Host Down .
--------------------------------- .
192.168.1.2 .
No Open Ports or Host Down .
--------------------------------- .
192.168.1.3 .
No Open Ports or Host Down .
--------------------------------- .
192.168.1.4 .
TCP PORT STATE SERVICE .
21 closed ftp .
22 closed ssh .
80 open http .
139 open netbios-ssn .
443 open http protocol over TLS/SSL .
445 open microsoft-ds .
8081 open Unknown .
.
UDP PORT STATE SERVICE . 53 open DNS .
--------------------------------- .
192.168.1.5 .
No Open Ports or Host Down .
--------------------------------- .
END OF LIST
Getting Started: Begin by familiarizing yourself with the Nmap software. This is pre-installed on Kali Linux. A simple starting point is to scan your machine, aka, localhost, via "nmap 127.0.0.1". Another useful resource is telnet which will allow you to interact with a server using a plain text command line. (try telnet towel.blinkenlights.nl for fun!)
Other Resources: As always, you are encouraged to research using Internet resources and Linux manual pages when completing the assignment. Socket tutorials such as, https://www.tutorialspoint.com/unix_sockets/ will be helpful in understanding socket programming. Another great place to start is by reviewing the RFC for the protocols themselves: https://tools.ietf.org/html/rfc793 and https://tools.ietf.org/html/rfc768