Part II : Network Security

Introduction

The functionalities of OSI layers are briefly described as follows:

  1. The application layer serves as an interface between applications and network programs. It supports application programs and end-user processing. Common application-layer programs include remote logins, file transfer, email, and Web browsing.
  2. The presentation layer is responsible for dealing with data that is formed differently. This protocol layer allows application-layer programs residing on different sides of a communication channel with different platforms to understand each other's data formats regardless of how they are presented.
  3. The session layer is responsible for creating, managing, and closing a communication connection.
  4. The transport layer is responsible for providing reliable connections, such as packet sequencing, traffic control, and congestion control.
  5. The network layer is responsible for routing device-independent data packets from the current hop to the next hop.
  6. The data-link layer is responsible for encapsulating device-independent data packets into device-dependent data frames. It has two sublayers: logical link control and media access control.
  7. The physical layer is responsible for transmitting device-dependent frames through some physical media.

  8. Starting from the application layer, data generated from an application program is passed down layer-by-layer to the physical layer. Data from the previous layer is enclosed in a new envelope at the current layer, where the data from the previous layer is also just an envelope containing the data from the layer before it. This is similar to enclosing a smaller envelope in a larger one. The envelope added at each layer contains sufficient information for handling the packet. Application-layer data are divided into blocks small enough to be encapsulated in an envelope at the next layer.

  9. Application data blocks are “dressed up” in the TCP/IP architecture according to the following basic steps. At the sending side, an application data block is encapsulated in a TCP packet when it is passed down to the TCP layer. In other words, a TCP packet consists of a header and a payload, where the header corresponds to the TCP envelope and the payload is the application data block. Likewise, the TCP packet will be encapsulated in an IP packet when it is passed down to the IP layer. An IP packet consists of a header and a payload, which is the TCP packet passed down from the TCP layer. The IP packet will be encapsulated in a device-dependent frame (e.g., an Ethernet frame) when it is passed down to the data-link layer. A frame has a header, and it may also have a trailer. For example, in addition to having a header, an Ethernet frame also has a 32-bit cyclic redundancy check (CRC) trailer. When it is passed down to the physical layer, a frame will be transformed to a sequence of media signals for transmission

    image15 Flow Diagram of a Packet Generation

  10. At the destination side, the medium signals are converted by the physical layer into a frame, which is passed up to the data-link layer. The data-link layer passes the frame payload (i.e., the IP packet encapsulated in the frame) up to the IP layer. The IP layer passes the IP payload, namely, the TCP packet encapsulated in the IP packet, up to the TCP layer. The TCP layer passes the TCP payload, namely, the application data block, up to the application layer. When a packet arrives at a router, it only goes up to the IP layer, where certain fields in the IP header are modified (e.g., the value of TTL is decreased by 1). This modified packet is then passed back down layer-by-layer to the physical layer for further transmission.

Public Key Infrastructure

IPsec: A Security Protocol at the Network Layer

PGP & S/MIME : Email Security

PGP

GPG (GnuPG)

S/MIME

SSL/TLS

Network Perimeter Security

Let us see how we keep a check on the perimeter i.e the edges, the first layer of protection

General Firewall Framework

Packet Filters

Circuit Gateways

Application Gateways(ALG)

Trusted Systems & Bastion Hosts


Common Techniques & Scannings, Packet Capturing

Scanning Ports with Nmap

image16

Nmap uses 6 different port states:

Types of Nmap Scan:

  1. TCP Connect
  2. TCP Connect scan completes the 3-way handshake.
  3. If a port is open, the operating system completes the TCP three-way handshake and the port scanner immediately closes the connection to avoid DOS. This is “noisy” because the services can log the sender IP address and might trigger Intrusion Detection Systems.
  4. UDP Scan
  5. This scan checks to see if there are any UDP ports listening.
  6. Since UDP does not respond with a positive acknowledgment like TCP and only responds to an incoming UDP packet when the port is closed,

  7. SYN Scan

  8. SYN scan is another form of TCP scanning.
  9. This scan type is also known as “half-open scanning” because it never actually opens a full TCP connection.
  10. The port scanner generates a SYN packet. If the target port is open, it will respond with an SYN-ACK packet. The scanner host responds with an RST packet, closing the connection before the handshake is completed.
  11. If the port is closed but unfiltered, the target will instantly respond with an RST packet.
  12. SYN scan has the advantage that the individual services never actually receive a connection.

  13. FIN Scan

  14. This is a stealthy scan, like the SYN scan, but sends a TCP FIN packet instead.

  15. ACK Scan

  16. Ack scanning determines whether the port is filtered or not.
  17. Null Scan
  18. Another very stealthy scan that sets all the TCP header flags to off or null.
  19. This is not normally a valid packet and some hosts will not know what to do with this.
  20. XMAS Scan
  21. Similar to the NULL scan except for all the flags in the TCP header is set to on
  22. RPC Scan
  23. This special type of scan looks for machine answering to RPC (Remote Procedure Call) services
  24. IDLE Scan
  25. It is a super stealthy method whereby the scan packets are bounced off an external host.
  26. You don’t need to have control over the other host but it does have to set up and meet certain requirements. You must input the IP address of our “zombie” host and what port number to use. It is one of the more controversial options in Nmap since it really only has a use for malicious attacks.

Scan Techniques

A couple of scan techniques which can be used to gain more information about a system and its ports. You can read more at https://medium.com/infosec-adventures/nmap-cheatsheet-a423fcdda0ca

OpenVAS

WireShark

A simple demo of wireshark

  1. Capture only udp packets:
  2. Capture filter = “udp”

  3. Capture only tcp packets

  4. Capture filter = “tcp”

  5. TCP/IP 3 way Handshake image17

  6. Filter by IP address: displays all traffic from IP, be it source or destination

  7. ip.addr == 192.168.1.1
  8. Filter by source address: display traffic only from IP source
  9. ip.src == 192.168.0.1

  10. Filter by destination: display traffic only form IP destination

  11. ip.dst == 192.168.0.1

  12. Filter by IP subnet: display traffic from subnet, be it source or destination

  13. ip.addr = 192.168.0.1/24

  14. Filter by protocol: filter traffic by protocol name

  15. dns
  16. http
  17. ftp
  18. arp
  19. ssh
  20. telnet
  21. icmp

  22. Exclude IP address: remove traffic from and to IP address

  23. !ip.addr ==192.168.0.1

  24. Display traffic between two specific subnet

    • ip.addr == 192.168.0.1/24 and ip.addr == 192.168.1.1/24
  25. Display traffic between two specific workstations

    • ip.addr == 192.168.0.1 and ip.addr == 192.168.0.2
  26. Filter by MAC

    • eth.addr = 00:50:7f:c5:b6:78
  27. Filter TCP port

    • tcp.port == 80
  28. Filter TCP port source
    • tcp.srcport == 80
  29. Filter TCP port destination
    • tcp.dstport == 80
  30. Find user agents
    • http.user_agent contains Firefox
    • !http.user_agent contains || !http.user_agent contains Chrome
  31. Filter broadcast traffic
    • !(arp or icmp or dns)
  32. Filter IP address and port

    • tcp.port == 80 && ip.addr == 192.168.0.1
  33. Filter all http get requests

    • http.request
  34. Filter all http get requests and responses
    • http.request or http.response
  35. Filter three way handshake
    • tcp.flags.syn==1 or (tcp.seq==1 and tcp.ack==1 and tcp.len==0 and tcp.analysis.initial_rtt)
  36. Find files by type
    • frame contains “(attachment|tar|exe|zip|pdf)”
  37. Find traffic based on keyword
    • tcp contains facebook
    • frame contains facebook
  38. Detecting SYN Floods
    • tcp.flags.syn == 1 and tcp.flags.ack == 0

Wireshark Promiscuous Mode - By default, Wireshark only captures packets going to and from the computer where it runs. By checking the box to run Wireshark in Promiscuous Mode in the Capture Settings, you can capture most of the traffic on the LAN.

DumpCap

DaemonLogger

NetSniff-NG

netsniff-ng –i eth1 –o data.pcap

Netflow

IDS

A security solution that detects security-related events in your environment but does not block them. IDS sensors can be software and hardware based used to collect and analyze the network traffic. These sensors are available in two varieties, network IDS and host IDS.

Signature Based IDS

Policy Based IDS

Anomaly Based IDS

Host Based IDS & Network Based IDS

Honeypots


Chinks In The Armour (TCP/IP Security Issues)

image18

IP Spoofing

IP Spoofing Detection Techniques

Covert Channel

IP Fragmentation Attack

TCP Flags

SYN FLOOD

FIN Attack

Connection Hijacking

image22

STEPS:

  1. The attacker examines the traffic flows with a network monitor and notices traffic from Employee X to a web server.
  2. The web server returns or echoes data back to the origination station (Employee X).
  3. Employee X acknowledges the packet.
  4. The cracker launches a spoofed packet to the server.
  5. The web server responds to the cracker. The cracker starts verifying SEQ/ACK numbers to double-check success. At this time, the cracker takes over the session from Employee X, which results in a session hanging for Employee X.
  6. The cracker can start sending traffic to the web server.
  7. The web server returns the requested data to confirm delivery with the correct ACK number.
  8. The cracker can continue to send data (keeping track of the correct SEQ/ACK numbers) until eventually setting the FIN flag to terminate the session.

Buffer Overflow

Mechanism:

CounterMeasure:

More Spoofing

Address Resolution Protocol Spoofing

DNS Spoofing