Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Ethical Hacking Workshop

You're reading from   Ethical Hacking Workshop Explore a practical approach to learning and applying ethical hacking techniques for effective cybersecurity

Arrow left icon
Product type Paperback
Published in Oct 2023
Publisher Packt
ISBN-13 9781804612590
Length 220 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Rishalin Pillay Rishalin Pillay
Author Profile Icon Rishalin Pillay
Rishalin Pillay
Mohammed Abutheraa Mohammed Abutheraa
Author Profile Icon Mohammed Abutheraa
Mohammed Abutheraa
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Part 1:Network Fundamentals
2. Chapter 1: Networking Primer FREE CHAPTER 3. Chapter 2: Capturing and Analyzing Network Traffic 4. Chapter 3: Cryptography Primer 5. Part 2: Breaking and Entering
6. Chapter 4: Reconnaissance 7. Chapter 5: Scanning 8. Chapter 6: Gaining Access 9. Part 3: Total Immersion
10. Chapter 7: Post-Exploitation 11. Index 12. Other Books You May Enjoy

Code-based attacks

Code-based attacks imply using vulnerabilities or weak/unsecure coding practices that can lead to exploitable applications. These exploits can allow attackers to modify or run executables or commands that result in gaining access to the system, reading data, modifying data, and more. In this section, we will discuss two very common types of attacks: buffer overflow and format string attacks.

Buffer overflow

Buffer overflow is one of the most common code-based attacks. It simply sends more or additional data into applications that don’t parse inputs. It works by moving data into memory if the applications don’t have a proper way to do limit checking and parsing on data. A simple example of a buffer overflow attack is a login page that is expecting an input of 8 bytes. If you send more than 8 bytes of data, the additional data will be written to an overflow buffer. This overflow buffer would be a piece of memory that is allocated to a different program, thereby allowing the attacker to influence how the program works.

Note

If you are interested in doing a deeper dive into shellcode and memory attacks, please read Offensive Shellcode from Scratch, by Rishalin Pillay.

These types of attacks are popular in both Linux and Windows-based environments.

Buffer overflow allows you to perform a few escalation techniques within the network:

  • Escalate privileges: This involves gaining elevated access to resources on the target system
  • Execute arbitrary commands: This allows you to run any commands or code of your choice on the target system

Usually, you have two options when using buffer overflow for exploitations:

  • Use already developed tools such as Bed, a tool that we will discuss later in this chapter, or other tools that include payloads for buffer overflow, such as Metasploit
  • Develop a new exploit for a vulnerability

The process of using buffer overflow is as follows:

  1. Find a potential buffer overflow.
  2. Push the right executable code into memory so that it can be executed.
  3. Place the return pointer so that it points to the stack and the code can be run.

Buffer overflow is one of the most common code-based techniques that’s used. Here, we have provided a high-level overview of it and the process involved. We won’t cover this in more detail in this book but having a general understanding of this technique and any relevant tools are useful in the gaining access phase of any ethical hacking exercise.

Format string attacks

Format string is the second most common code-based attack. These attacks are based on the misuse of printf and related commands. It uses these commands to change information anywhere in memory to take control. This allows you to do the following:

  • Read data from memory
  • Change data anywhere in memory

Now that you have an understanding of code-based attacks, let’s add into your knowledge repository with the additional methods of attacks.

printf example

printf is one of the functions that’s commonly used in format string attacks. The right method to execute or use printf is by using printf("%s", buffer), where "%s" is the format string. Programmers may mistakenly use printf(buffer), which is the wrong method as it will compile without errors and run successfully. For this example, if we submit a value of %d, which means decimal, the program will search the memory looking for an integer. But similar to the aforementioned example, you can use this to input hexadecimal information and read the memory stack.

Bed

Bed is an open source tool that is used to scan for potential buffer overflows and format strings against apps. By default, the tool is not installed in Kali Linux. To install the Bed tool, you must run the following command:

$ sudo apt install bed

To list the options available for Bed, as well as a high-level description, all you need to do is run the bed -h command, as shown in the following screenshot:

Figure 6.3 – Bed command-line options

Figure 6.3 – Bed command-line options

The following command shows an example of using the HTTP plugin to fuzz the Metasploitable 2 virtual machine:

$ bed -s HTTP -t192.168.1.102

Here’s the output:

Figure 6.4 – Bed command-line example

Figure 6.4 – Bed command-line example

In this section, we provided a high-level overview of code-based attacks. Usually, these types of attacks are not covered during ethical hacking attacks, but knowing about them and some of the available tools can prove useful. Next, we will focus on exploiting services using different techniques and tools.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime