Protocols and Networking
Protocols and Networking
7 - Application Software
6 - Presentation Software
5 - Session Software
The bottom 3 layers are typically implemented in hardware within devices on
the network, e.g. Switches, Routers and Firewalls:
Layer Where it is implemented
1 - Physical Hardware
Layer 4, the Transport layer, connects the software with the hardware layers.
SDN ("Software Defined Networking") is technology which allows more layers
of the hardware to be implemented via software.
ADVERTISEMENT
Layer 4 - Transport
The layer which allows applications to be represented on the network.
Some well known applications on this layer:
TCP ("Transmission Control Protocol") - Used for many applications,
ensuring stability, control of how much data can be sent at any given
time, reliability and more.
UDP ("User Datagram Protocol") - Lightweight and quick protocol use
for many services.
QUIC ("Quick UDP Internet Connections") - A protocol designed for
faster connections and goes hand-in-hand with the version 2 of the HTTP
protocol.
Layer 3 - Network
A layer responsible of routing packets between networks via routers.
On this layer, the following protocols reside:
IP ("Internet Protocol") - Used everyday when accessing the Internet.
Comes in two versions, IP version 4 and 6.
ICMP ("Internet Control Message Protocol") - Used by network devices
and network operators, to diagnose network connections or for devices to
send and respond to error conditions and more.
IPSec ("Internet Protocol Security") - Allows encrypted and secure
connections between two network devices.
Layer 2 - Link
Link networks, as the name implies, consist of protocols designed to send
packets through the actual links (physical connections) that network nodes are
connected to. A simpler way of thinking of it is that the Link Layer is
responsible for moving data from physical over to logical (to the network layer).
Protocols on this layer include:
Ethernet - An essential protocol used by most operating systems when
connecting to networks using a physical cable.
Wi-Fi ("Wireless Fidelity") - For accessing networks via radio signals. It
uses a family of protocols called IEEE 802.11.xx
NDP ("Neighbor Discovery Protocol") - IP version 6(IPv6) uses this
protocol on the Link Layer to gather information required to
communicate via IPv6
Layer 1 - Physical
Physical layer represents the signaling which allows bits and bytes to transfer
between a physical medium. It can be transferred via radio or signals over a
cable, using electrical signals or light, for example fiber.
Examples of the Physical Layer protocols includes:
CAN Bus ("Controller Area Network") - Used in microcontrollers and
other devices to communicate to other similar devices, not involving a
computer. Often used in ICS ("Industrial Control Systems").
Ethernet Physical Layer - Used by Ethernet on the physical layer to send
signals with speeds up to many gigabits of traffic per second.
Bluetooth Physical Layer - Bluetooth also has its own specifications on
how radio signals should be sent and received.
Different Networks
Let us take a look at different networks within RFC1918 and how large the
networks are:
10.0.0.0/8 - More than 16 million IP addresses
172.16.0.0/12 - About 1 million IP addresses
192.168.0.0/16 - 65534 IP addresses
IP segments can be further broken up into smaller and more granular networks.
Each network has a reserved address for broadcasting traffic to every host in the
network, this is called the broadcast address. Broadcasting data means sending
data to everyone on the network instead of sending to just a single host. There
are many applications and protocols which rely on broadcasting traffic in order
for them to work.
For each network segment the broadcast is always last IP address in the
network. For example in the network 192.168.0.0/24 network, the broadcast
address is 192.168.0.255.
The smallest netmask possible is 255.255.255.255, represented as /32. This
network only has one IP address.
If traffic needs to be sent back to the host, e.g. for communications between
applications, it is sent to the localhost address. This address is always 127.0.0.1
and is a /8 network.
In IP networks the traffic is routed by a router. A router is a networking device
which understands the IP format and can forward packets between networks.
This is different than a switch as the switch forwards data within a network,
while the router forwards between networks.
Packets on the network has headers which describe many of the important
details we already discussed within the IP protocol. IPv4 Header looks like this:
Image Credits: By Michel Bakni - Postel, J. (September 1981) RFC 791,
Internet Protocol, DARPA Internet Program Protocol Specification, The
Internet Society, p. 11 DOI: 10.17487/RFC0791., CC BY-SA
4.0, https://commons.wikimedia.org/w/index.php?curid=79949694
The Source Address is the IP address of the system who is sending the packet,
and destination is to whom the packet is intended. There are also other fields in
the header which is used by the many features of the IP protocol, but which are
outside the scope of this introduction class.
You can check your IP address on Windows by running the
command ipconfig within a Command Line Window. On Linux this is done
with the ip addr show or ifconfig command.
When a computer needs to communicate to something which can not be found
on the LAN, it sends traffic to the default gateway as per how the system is
configured. The default gateway being a router which is capable of forwarding
the traffic to the destination IP address.
IPv6 - IP Version 6
IP version 6 is the latest standard for IP and was made to support more IP
addresses. Instead of using 32 bits of addressing for IP addresses, 128 bits is
used. This allows for enough IP addresses for the foreseeable future while IPv4
has already run out.
IPv6 addresses uses 8 groups of of 4 hexadecimal numbers. An IPv6 address
look like this: 2a00:1450:400f:80a::200e:. Notice it does not have have the 8
groups of 4 hexadecimal numbers. This is because IPv6 addresses can be
shortened via simple rules:
Leading 0's can be shortened
Double colon (::) can be used to represent a continuous string of 0's.
The expanded IPv6 address is: 2a00:1450:400f:080a:0000:0000:0000:200e.
The localhost can be reduced into ::1 and ::.
IPv6 has networks, i.e. subnets, just like IPv4 has.
The IPv6 header looks like this:
We can see a much simpler header with a lot more room for IP addressing.
IPv6 is used more and more, and there is built in support for this protocol in
many tools. For example with ping we can switch between IPv4 and IPv6 with
the -4 and -6 flag respectively.
Run ipconfig and see if you see any IPv6 addresses. If you have IPv6 enabled,
try ping -6 google.com and ping -4 google.com. See how the command allows
us to use either IPv4 or IPv6?
Note: If you do not have IPv6 today, there are many public cloud services
which will grant you a public IPv6 address today which you can use to
experiment and explore with.
ICMP
ICMP is often associated with Ping and Traceroute. ICMP can be used for other
things, such as ask a node for its time referred to as an ICMP Timestamp
request. An ICMP Timestamp request simply allows e.g. a Router to ask
another Router to synchronize their time, an important attribute in network
communications.
A common tactic for attackers to check if systems are available on a network, is
to conduct a Ping Sweep. The goal of such activity is to make the target device
in a network range reply to ping requests so that the attacker knows it is
available. This approach is naive as many systems by default block incoming
pings.
Traceroute
Tracerouting is a way to determine which routers are involved in sending a
packet from system A to B. Knowing which routers our packets take can be
useful both better understanding our networks and also in understanding the
attack surface. A router is responsible for routing the package in the right
direction. Imagine this as driving on a road, where road signs at intersections
guide you to the destination. These signs at intersections represent routers.
Traceroute identify these signs and intersections and tells you how far away
they are, measured in milliseconds (ms).
The IPv4 TTL and IPv6 Hop Limit headers have the same function. Every
router who routes a packet will decrement this value by 1, and if the value
reaches 0 the router will discard the packet and return an ICMP Time Exceeded
packet to the sender.
To perform a traceroute on Windows:
tracert google.com
To perform a traceroute on Linux (not installed by default):
traceroute google.com
The process of tracerouting via these tools is simple:
1. The operating system sends a packet google.com, the TTL value is set to
1.
2. The packet is routed on the network, and the first router decrements the
TTL by 1, leaving it at 0. This causes the router to drop the packet and
send "ICMP Time Exceeded" back to the source.
3. The client increases the TTL 1, allowing the packet to be routed through
one additional hop.
This process is repeated, increasing the TTL with 1 until the destination has
been reached.
TCP 3-Way-Handshake
TCP uses a three-way handshake to allow two systems to engage in
communications. The handshake uses 32 bits of PRNG ("Pseudo Random
Number Generator") numbers to establish the handshake. The handshake
enforces that both parties intends to communicate.
Here is a graphic to illustrate:
The screenshot shows the tool Wireshark being used to capture and inspect
packets. Wireshark is a very good utility because it allows us to visualize
packets and inspect them more in-depth. The screenshot shows 3 packets
representing the 3-way handshake. Notice the source and destination columns
representing the two parties communicating. The Info field shows source and
destination port, including (within the square brackets) the SYN, SYN/ACK and
ACK.
The next screenshot shows data being communicated between the parties after
the 3-way handshake. The data inside of the TCP packet has been highlighted
near the bottom of the picture.
A message to W3School students is shown in the screenshot above. Can you see
it?
ADVERTISEMENT
Spoofing Traffic
There are few restrictions on networks today for anyone to create packets as
they desire. Anyone can create packets with any of the fields of the headers set
to whatever value they desire. This is called spoofing, allowing attackers to send
traffic on behalf of others.
TCP has security built into the protocol, but it relies on the strength of the
PRNG ("Pseudo Random Number Generator") number generators. If the
Sequence numbers of the communicating parties can be guessed, the security of
TCP can be compromised in the sense that an attacker can engage in spoofed
communications via TCP.
Many protocols are easily spoofed, but TCP offers some resiliency against this.
Protocols such as UDP and ICMP does not offer similar protection.
Spoofing packets is typically done by attackers with root / system capabilities,
i.e. the highest privileges on the Operating System. The reason being that
Operating Systems enforces the use of API's which forces the user to conform
to the rules of communications as specified in RFC's ("Request For
Comments"). If the attacker does not have the highest privileges, they will not
be able to craft their own packets on the network.
Because UDP does not have features such as the 3-Way-Handshake, UDP can
be easily spoofed.
Switched Networks
Systems are connected to a LAN ("Local Area Network") through a Switch.
Switches uses MAC ("Media Access Control") addresses for addressing, not the
more well-known IP address. Switches forward traffic across Local Area
Networks, i.e. your home-network or within branches of your organization.
MAC Addresses are designed to be unique, but anyone can change their MAC
Address as long as they have administrator rights.
The MAC address defined by 6 octets, for example: FC:F8:AE:12:34:56
The first three octets represent the organization which manufactured the device
communicating, called OUI ("Organizational Unique Identifier"). The above
MAC address is assigned to Intel Corporate. You can search for MAC
Addresses in many places, for example: https://www.adminsub.net/mac-
address-finder/intel.
The last three octets is determined by the manufacturer.
ARP
ARP ("Address Resolution Protocol") is the protocol which allows computer
systems to know which MAC address belongs to which IP address. If the traffic
has to be routed, the computer system will forward traffic to the Default
Gateway configured on the system.
ARP, like DNS, is a protocol which resolves one address into another. Every
time a system tries to communicate to an IP address which is on the LAN it will
check its ARP cache to see if has recently been resolved.
You can inspect your own ARP. Simply run the command arp -a on both Linux
or Windows. This reveals which systems your system has recently
communicated with.
Alice: Does anyone know the MAC address of 192.168.10.10?
Bob: Sure thing Alice, here is my MAC Address.
Layer 4 Firewall
The traditional Firewall is a Layer 4 Firewall with features such as:
NAT
Routing
Blocking or Allowing traffic
Track active network connections
Support VPN connections
Note: These Firewalls are typically cheaper and offers more throughput on the
network than a more modern Next-Generation Firewall.
Note: Which features your NGFW comes with often greatly depends on which
licenses have been purchased and the capacity of the hardware running the
Firewall.
Firewall Administration
A Firewall can typically be administered via a proprietary management
application, or via a web-browser accessing the Firewalls management via
HTTP.
Management ports to Firewalls, including other management services of an
organization, should ideally be segmented away from regular user access.
Ideally the segmentation of management services is connected to an
organizations user directory, for example Active Directory for Windows
environments.
Segmentation
Firewalls can segment traffic between hosts and systems into segments,
sometimes called zones. Each segment holds services which are allowed to
communicate between one another.
The best and most secure kind of segmentation is called zero-trust architecture,
forcing all systems on the network to explicitly be allowed to communicate to
different services.
To ease management of Firewall rules, the Firewall management is ideally
connected to the organizations user directory. This can allow Firewall
administrators to create careful rules based on employee responsibilities,
allowing the organization to add and remove permissions which are applied on
the network without asking the Firewall administrators for changes anytime
there is a role change. This is sometimes called user-based policy control.
Examples include:
IT-Administrators should be able to use management protocols to the
different services.
HR employees should be allowed to access HTTPS to the HR platforms.
Helpdesk employees can only access helpdesk related services.
Unrecognizable users can be identified and provisioned accordingly.
Note: A very common user directory is Microsoft's Windows Active Directory.
It holds information about which users, computers and groupings the
organization holds.
In this course the term IDS and IPS is used interchangeably as the difference
between them is often just a matter of configuration of how they operate. An
IPS system is positioned in such a way it can detect and block threats, while an
IDS system is only capable of detecting threats.
IPS systems can be used to detect and block attackers and often rely on frequent
updates and inspection in encrypted traffic.
Note: A very useful feature of IDS and IPS is the frequent updates of new
signatures of developing threats from the vendors. This allows defenders some
reassurance that new threats will be blocked as the firewall is updated with new
updates.
Elements such as domain age and validity could also be checked, preventing
users from visiting domains which has recently been created and not yet
categorized, or checking for fraudulent activities by analyzing the content of the
domain.
Instead of rejecting access to websites, the Firewall could intercept the request
and send the user to what is called a captive web portal. On this portal the user
could be warned about immediate danger or the violation of company policy in
e.g. visiting unacceptable content. In some cases you could allow the user to
provide a reason why they need to access the content, then let them continue if
they have provided a reason.
Categories within domains can be many, for example websites hosting content
related to:
Hacking
Nudity
Violence
Phishing
Dating
Instant Messaging
Entertainment
Anonymizing services
Applications
The Firewall can try to determine which applications are in use, not just the
protocols. Many protocols are capable of carrying other applications, for
example HTTP can hold thousands of different applications. A Firewall can try
to decode the network streams on Layer 4 and try to determine the content
which is presented on Layer 7.
A screenshot shows what a user could see when an application has been
blocked.
Content Control
As Applications are being identified, the Firewall could try to reveal specific
content within the applications, for example content being downloaded:
Word documents
Executables
Source-code
Scripts
In such files, the Firewall can try to identify malware, proprietary and
confidential information not supposed to leave the network and much more.
The Firewall could support many different protocols and the content running
through them, for example:
HTTP
SMB
FTP
IMAP & POP3
SMTP
Sandboxing
In this context, sandboxing means to have a platform execute files, which are
may be malicious. The sandbox records and monitors the activity of the file to
see if it is malicious or not.
Decrypting Traffic
Many Firewalls support installing certificates which allows for decryption of
traffic. If content is decrypted, content can then be inspected for threats.
Decryption can take place on Egress or Ingress traffic, or both. For Ingress
traffic the Firewall could protect servers against incoming traffic. Egress traffic
allows the Firewall to protect users and systems needing to communicate
outbound.
The Firewall will often avoid decrypting traffic such as health care and financial
data as this may have privacy and other implications. Decryption of traffic
requires more effort from the organization to distribute keys to clients which is
used by the firewall to decrypt traffic.
Note: Remember Egress and Ingress traffic? Egress means traffic leaving the
network, while Ingress means traffic arriving to the network.
Unknown Traffic
Some traffic can not be decrypted or understood fully by the Firewall. Many
reasons can apply, for example a proprietary application sends data which the
Firewall does not know of. Such traffic can also be categorized as Unknown. A
Firewall administrator should consider blocking such applications, especially
from networks which are considered high-risk.
HTTP Headers
The HTTP protocol uses many headers, some custom to the application and
others well defined and accepted by the technology.
Example request to http://google.com
GET /search?q=w3schools+cyber+security&ie=UTF-8 HTTP/1.1
Host: google.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88
Safari/537.36
Accept: image/avif,image/webp,image/apng,image/*,*/*;q=0.8
Referer: https://w3schools.com/
Accept-Encoding: gzip, deflate
Cookie: cookie1=value1;cookie2=value2
The request header specifies what the client wants to perform on the target
webserver. It also has information regarding if it accepts compression, what
kind of client is accessing and any cookies the server has told the client to
present. The HTTP request headers are explained here:
Header Explanation
Set-Cookie: Any special values the client should remember and return
in the next request
HTTP Verbs
When accessing a web application the client is instructed on how to send data to
the web application. There are many verbs which can be accepted by the
application.
!Verb Used for
POST Used to send data to a script via values in the body of the
Request sent to the webserver. Typically it involves creating,
uploading or sending large quantities of data
404 The client tried to access a resource which does not exist
REST
Rest services, sometimes called RESTful services, employ the full force of
HTTP Verbs and HTTP Response Codes to facilitate the use of the web
application. RESTful services often uses parts of the URL as a query parameter
to determine what happens on the web application. REST is typically used by
API's ("Application Programming Interfaces").
REST URLs will invoke functionality based on the different elements of the
URL.
An example REST URL: http://example.com/users/search/w3schools
This URL will invoke functionality as part of the URL instead of Query
Parameters. We can decipher the URL as:
Parameter Comment
Here are some common Cookie examples which allows the application on the
webserver to control sessions and state:
PHPSESSID
JSESSIONID
ASP.NET_SessionID
These values represent a certain state, often called a session, on the server. This
state represents things like:
What user you have logged in as
Privileges and authorizations
It is important that session value, sent to the Client, can not be easily guessed or
otherwise identified by others. If they could, an attacker could then present
themselves as other users on the web application.
State can also be saved on the client. This involves the server sending all the
states to the client and relies on the client sending back all the items. Such
implementations relies on encryption to check the integrity of the state the client
is claiming. Examples of implementations using this is listed below:
JWT ("JSON Web Tokens")
ASP.Net ViewState
You are using cookies to take this class! You can inspect these cookies in your
web browser by opening up the developer tools. This is done by
hitting F12 within the browser, opening up the developer tools window. Within
this window you should be able to find the correct place where your cookies are
stored.
In Google Chrome, the cookies were identified in the Application tab above.
Note: Can you think of why the cookies have been masked away in the
screenshot so you cannot read them?
Virtual Hosts
One webserver can process many applications via Virtual Hosts, often
abbreviated as Vhosts. To facilitate access to other Virtual Hosts the web server
typically reads off the Host header of the client request, and based on this value
sends the request to the correct application.
URL Encoding
For an application to safely transfer content between the server and client, some
characters must be encoded to ensure they do not impact the protocol. To
preserve the integrity of the communications, URL encoding is used.
URL Encoding replaces unsafe characters with a % and two hexadecimal digits.
For example:
Percentage is replaced with %25
Space is replaced with %20
Quote is replaced with %22
An excellent tool to perform text analysis and run operations such as URL
Decoding is CyberChef. You can try it out in your browser
here: https://gchq.github.io/CyberChef/
Note: Play around with Cyber Chef and see if you can reveal what the following
message in URL encoded characters hold: %48 %65 %6c %6c %6f %20 %64
%65 %61 %72 %20 %77 %33 %73 %63 %68 %6f %6f %6c %73 %20 %73
%74 %75 %64 %65 %6e %74 %2e %20 %48 %6f %70 %65 %20 %79 %6f
%75 %20 %61 %72 %65 %20 %6c %65 %61 %72 %6e %69 %6e %67 %20
%73 %6f %6d %65 %74 %68 %69 %6e %67 %20 %74 %6f %64 %61 %79
%21
JavaScript
To support dynamic content, browsers use the scripting language JavaScript.
This enables developers to program solutions which will run on the client,
enabling more interactive and "alive" web-content.
JavaScript is also involved in many attacks against web-applications and client
applications such as browsers.