0Pricing
Reverse Engineering & Binary Analysis Basics · Урок

Выявление уязвимостей двоичных файлов

Научитесь распознавать распространённые уязвимости, такие как переполнение буфера, ошибки форматных строк и переполнение целых чисел, в двоичных файлах.

«Выявление уязвимостей двоичных файлов» — бесплатный урок Reverse Engineering & Binary Analysis Basics на CoddyKit. Это урок 1 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Reverse Engineering & Binary Analysis Basics, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Reverse Engineering & Binary Analysis Basics содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

Intro to Binary Vulnerabilities

Welcome! In reverse engineering, understanding vulnerabilities is key. These are flaws in software that an attacker can exploit to gain control or cause damage.

We'll explore common types found in compiled binaries, focusing on how they arise and what they look like.

Buffer Overflows Explained

A buffer is a contiguous block of memory allocated to hold data, like an array or a string. Think of it as a fixed-size container.

  • Buffer Overflow: Happens when a program tries to write more data into a buffer than it can hold.
  • This extra data "overflows" into adjacent memory regions, potentially corrupting other data or even overwriting critical program instructions.

Simple Buffer in C

Here's a basic C program using a fixed-size buffer. Notice the char buffer[10]; line, which reserves 10 bytes for our string.

Run this code to see how a string fits into the buffer.

#include <stdio.h>
#include <string.h>

int main() {
  char buffer[10]; // A buffer of 10 characters
  strcpy(buffer, "Hello"); // Copy "Hello" into buffer
  printf("Buffer content: %s\n", buffer);
  return 0;
}

Triggering a Buffer Overflow

What happens if we try to copy a string longer than 10 characters into our buffer? The strcpy function doesn't check bounds, so it will just keep writing.

This can lead to:

  • Program crashes (segmentation faults).
  • Corruption of adjacent data.
  • Potential execution of malicious code (advanced exploitation).

Modern compilers and OSes have protections, but the core vulnerability remains.

Format String Bugs

Format string vulnerabilities occur when a program uses user-supplied input as the format string argument in functions like printf() or sprintf().

The format string (e.g., "%s", "%d") tells printf how to interpret and print subsequent arguments. If an attacker controls this string, they can:

  • Read data from the stack.
  • Write arbitrary data to arbitrary memory locations.

Format String Vulnerability

This example shows how an attacker could use format specifiers to peek at stack memory. The printf function expects arguments matching its format string.

If the format string comes from untrusted input, it can be abused.

#include <stdio.h>
#include <string.h>

int main() {
  char input[20];
  strcpy(input, "%p %p %p %p"); // Malicious input

  printf("User input as format string:\n");
  printf(input); // Vulnerable call: no format string provided by developer
  printf("\n");
  return 0;
}

Understanding Integer Overflows

Computers store numbers using a fixed number of bits. An integer overflow happens when an arithmetic operation tries to create a numeric value that is too large to be represented within the available storage space.

  • For unsigned integers, the value "wraps around" to zero.
  • For signed integers, it can wrap around to a large negative number.

This can lead to unexpected behavior, buffer overflows (e.g., if a calculated size is too small), or security bypasses.

Integer Overflow in Action

Watch what happens when we add 1 to the maximum possible value for an unsigned int. It "overflows" and wraps back to zero.

This unexpected behavior can be exploited if the result is used for memory allocation or loop counters.

#include <stdio.h>
#include <limits.h> // For UINT_MAX

int main() {
  unsigned int max_val = UINT_MAX; // Maximum unsigned int value
  unsigned int overflow_val = max_val + 1;

  printf("Max unsigned int: %u\n", max_val);
  printf("Max unsigned int + 1: %u\n", overflow_val); // Will be 0
  return 0;
}

Preventing Vulnerabilities

These vulnerabilities often stem from unsafe programming practices, especially in languages like C/C++ that offer direct memory access.

  • Buffer Overflows: Use bounds-checking functions (e.g., strncpy, snprintf) or higher-level languages/libraries.
  • Format String Bugs: Always provide a constant format string literal to printf-like functions, never user input.
  • Integer Overflows: Validate input, perform range checks, and use larger data types or arbitrary-precision arithmetic when necessary.

Vulnerability Check

Which of the following scenarios describe a common binary vulnerability?

Recap & Next Steps

Great job! You've now been introduced to three fundamental binary vulnerabilities:

  • Buffer Overflows: Writing past a buffer's allocated memory.
  • Format String Bugs: Misusing format specifiers in print functions.
  • Integer Overflows: Numbers exceeding their storage capacity and wrapping around.

Understanding these is crucial for analyzing binaries and identifying potential weak points. Next, we'll look at how to find these bugs using automated tools!

Часто задаваемые вопросы

Урок «Выявление уязвимостей двоичных файлов» бесплатный?

Да — полный текст урока «Выявление уязвимостей двоичных файлов» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Reverse Engineering & Binary Analysis Basics, подпишись на CoddyKit PRO. Курс Reverse Engineering & Binary Analysis Basics содержит 4 уроков всего.

Чему я научусь в уроке «Выявление уязвимостей двоичных файлов»?

Научитесь распознавать распространённые уязвимости, такие как переполнение буфера, ошибки форматных строк и переполнение целых чисел, в двоичных файлах. Ты практикуешь Reverse Engineering & Binary Analysis Basics с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Reverse Engineering & Binary Analysis Basics?

Предыдущий опыт не требуется. Reverse Engineering & Binary Analysis Basics на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 1 из 4.

Сколько времени занимает урок «Выявление уязвимостей двоичных файлов»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Reverse Engineering & Binary Analysis Basics?

Да. Каждый урок Reverse Engineering & Binary Analysis Basics включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Выявление уязвимостей двоичных файлов
  2. Введение в фаззинг
  3. Обзор примитивов эксплойтов
  4. Современные средства защиты от эксплуатации и их обход
← Назад к Reverse Engineering & Binary Analysis Basics