Network Layer

A layer that enables the transmission of data between two nodes on the different networks. It handles routing and determining the path of data through a network.


Internet Protocol (IP)

A set of rules governing the routing and addressing packets (communication and exchange) of data over the internet


Internet Protocol Address V4 (IPv4)

A network address that is used to locate the device; it has 32-bit numbers represented as strings of 0s and 1s

Binary

11000000.10101000.00000001.00000001

Decimal

192.168.1.1


IPv4 Addresses Classification


IPv4 Addresses Classes

Note: Class A also has 127.0.0.0 to 127.255.255.255 are reserved for loopback and diagnostic (Those addresses cannot be used)


Subnet 

A method of creating a smaller network inside a large network


Internet Protocol Address V4 (IPv4) Example

192.168.1.0/25, the first node starts at 0, and the last one is 126


Router

A physical or virtual device that forward data packets between computer networks (Uses IP addresses and stores that in a routing table)


VLAN Interconnection

A technique that used to allow routing between VLANs


VLAN Interconnection (Router on stick - Trunk port)

A technique that used to allow routing between VLANs using a single interface


Cyberattacks


PCAP Example

The web server here uses 0.0.0.0 IP; this is a placeholder that means listen to all, it accepts incoming connections from all network adapters (If this was 127.0.0.1, it would only be accessible to processes running on the device itself). A client can connect to this web server using the network adapter IP, in this case, the network adapter IP is 10.0.0.2 as shown in the Wireshark image

from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer
from io import BytesIO
from gzip import GzipFile
from datetime import datetime
from contextlib import suppress

with suppress(Exception):
    from netifaces import gateways, ifaddresses, AF_INET, AF_LINK
    print("The default network interface is: ",gateways()['default'][AF_INET][1])
    print("The default network interface mac address is: ",ifaddresses(gateways()['default'][AF_INET][1])[AF_LINK])

class Server(SimpleHTTPRequestHandler):
    def do_GET(self):
        compressed = False
        content = b'<HTML><h1>Hello World!</h1></HTML>'
        if len(content) > 0:
            if 'accept-encoding' in self.headers:
                if 'gzip' in self.headers['accept-encoding']:
                    bytes_ = BytesIO()
                    with GzipFile(fileobj=bytes_, mode='w', compresslevel=5) as f:
                        f.write(content)
                        f.close()
                        content = bytes_.getvalue()
                        compressed = True
        self.send_response(200)
        if compressed:
            self.send_header('content-encoding', 'gzip')
        self.send_header('content-length', len(content))
        self.end_headers()
        self.wfile.write(content)

    def log_message(self, format, *args):
        print("[{}] - {}:{} - {} {}".format(datetime.now().strftime("%m/%d/%Y %H:%M:%S"), self.client_address[0],self.client_address[1],args[0],args[1]))

TCPServer(('0.0.0.0', 80), Server).serve_forever()

Clint/Server IP Addresses

The IPs are added to each packet

Layer Protocol PDU Info Ports IPs MACs
Transport Layer TCP Segments 3 Way handshake Process (SYN) Src Port: 35310
Dst Port: 80
Network Layer IP Packets 3 Way handshake Process (SYN) Src Port: 35310
Dst Port: 80
Src IP: 10.0.0.3
Dst IP: 10.0.0.2
Data Link Layer Ethernet Frames 3 Way handshake Process (SYN) Src Port: 35310
Dst Port: 80
Src IP: 10.0.0.3
Dst IP: 10.0.0.2

Src MAC: bc:35:db:cf:1b:03
Dst MAC: bc:f2:b8:57:86:02

Physical Layer Coax Bits 01001000 01010100 01010100 01001000 01010100 01001000 01010100 01001000 01010100