When vulnerabilities exist, hackers can exploit flaws in computer networks. A person responsible for an organization’s network protection will have to patch vulnerable systems. It is also a good practice to shut down non-essential services running on systems. If systems are not properly managed or protected, they can be exploited by hackers. After cracking into a remote system, an attacker can take steps to entrench by setting up accounts and capturing and exfiltering information from the network. In this chapter, you will take a close look at buffer overflow and buffer overflow countermeasures.
- 1.
Define a buffer overflow.
- 2.
Identify a buffer overflow.
- 3.
Identify buffer overflow countermeasures.
Buffer Overflows
If an attacker can find a way of getting arbitrary code to the target system and getting that system to execute it, the attacker can gain access to the system and its resources. Contiguous blocks of memory are used to store data, and when data copied into a buffer exceeds the size of the buffer, a buffer overflow occurs. Vulnerabilities occur through human error such as programming errors by developers, programming languages that contain errors, and when good programming practices are not followed. Many programs are designed to allow input. The input fields can be used to send arbitrary code to the system.
Stack Buffer Overflow
A stack buffer overflow is caused when a program writes more data to a buffer located on the stack than was expected. This results in the corruption of data. For additional information, visit Stack Buffer Overflow (https://blog.rapid7.com/2019/02/19/stack-based-buffer-overflow-attacks-what-you-need-to-know/).
Heap-Based Buffer Overflow
Memory on the heap is dynamically allocated by an application. A lot of times the program data is contained on the heap. If an attacker can corrupt this data, the attacker can cause the application to overwrite internal structures . For more information, visit Heap-Based Buffer Overflow (https://cwe.mitre.org/data/definitions/122.html).
Detecting Buffer Overflow Vulnerabilities
Programs written in C are more susceptible to buffer overflows. The standard C library offers many functions that do not perform any boundary checks.

Detecting buffer overflow vulnerabilities
Defense Against Buffer Overflows
There are several things an application developer can do to eliminate buffer overflows including performing a manual audit of the code, disabling stack execution, using compiler techniques, and developing safer C library support.
Nmap
Nmap is free and operates on various platforms, like Microsoft Windows, Mac OS X, and Linux. It can be used to evaluate which hosts are on the network and then to identify the ports a remote system is running for the Transmission Control Protocol (TCP) and User Datagram Protocol (UDP). To determine what operating system the remote machine is operating, you can also execute an operating system scan. The results of the OS scan given by nmap may often be inconclusive, requiring the attacker to use other techniques to determine the remote OS accurately.

Nmap
TCP Scan

TCP scan
Fingerprint of the OS
Microsoft Windows 7 Professional
Microsoft Windows Vista SP0 or SP1
Windows Server 2008 SP1
Windows 7
Microsoft Windows Vista SP2
Windows Server 2008

OS fingerprint
Using Metasploit to Fingerprint

Metasploit auxiliary scan

Showing options

RHOSTS

Windows 2008 Standard without Hyper-V Service Pack 1
Searching for Exploits

Search using Metasploit
Meterpreter

Meterpreter
Summary
In this chapter, you learned about buffer overflows and how hackers can take advantage of weaknesses in computer systems due to vulnerabilities that may exist. You became familiar with intrusion detection techniques and various types of intrusion detection systems and firewalls. In addition, you learned what to look for in order to identify an attack on an internal network.
Resources
Stack Buffer Overflow: https://blog.rapid7.com/2019/02/19/stack-based-buffer-overflow-attacks-what-you-need-to-know/
Heap-Based Buffer Overflow: https://cwe.mitre.org/data/definitions/122.html