â˜ ī¸
smadi0x86 Playground
  • 💀Welcome to smadi0x86 Playground
    • 🍷Resources
    • đŸšŦProjects
    • 🎓Certifications
    • 📌Pinned
    • ❓Questions
    • 📞Contact
  • đŸžī¸Cloud Native
    • Docker
      • Quick Reference
      • Introduction
      • Containers
      • Images
      • Storage & Volumes
      • Security
      • Cheatsheet
    • Git
    • Serverless Framework
    • YAML
  • 🔨Software Engineering
    • System Design
    • Environment Variables
    • JSON Web Tokens
  • 👾Architecture
    • C Language
      • Introduction
      • GCC Compilation
      • Libraries & Linking
      • I/O
      • Files
      • Pointers
      • Dynamic Memory Allocation
      • Data Types
      • Strings Manipulation
      • Bit Manipulation
      • Pre-processors
      • Macros
      • Type Qualifiers
    • C/C++ Build Systems
      • Fundamentals for Linking
      • Symbolic Linking
      • Cross-Platform Compilation
      • CMake for Building and Linking
      • Shared Libraries
      • Dynamic Linking and Dependency Management
    • Operating Systems
      • OS & Architecture
      • Processes
      • CPU Scheduling
      • Memory Management
  • đŸ›Šī¸Cyber Warfare
    • Flight Physics
    • Communication
      • PWM & PPM
      • MAVLink
  • đŸ´â€â˜ ī¸Offensive Security
    • Active Directory
      • Introduction
    • Web Attacks
      • Server Side
        • OS Command Injection
        • Information Disclosure
        • Directory Traversal
        • Business Logic
        • Authentication
        • File Upload
        • SSRF
      • Client Side
        • CSRF
        • XSS
    • Recon
      • Active
        • Host discovery
        • Nmap
        • Mass Scan
      • Passive
        • Metadata
      • Web Applications
        • Discovery
        • Subdomains & Directories
        • SSL Certs
        • CMS
        • WAF Detection
      • Firewall Evasion
  • Binary Exploitation
    • Stack Smashing
      • x86
      • x86_64
    • pwntools
      • Processes and Communication
      • Logging and Context
      • Cyclic
      • Packing
      • ELF
      • ROP
  • 😈Advanced Persistent Threat
    • C2
      • Sliver
    • Malware
      • Windows Internals
        • PEB
      • Academy
        • Basics
      • Sektor7
        • Essentials
  • 💌Certifications
    • AWS Certified Cloud Practitioner (CLF-C01)
      • Cloud Foundations
      • Domain 1: Cloud Concepts
      • Domain 2: Security and Compliance
      • Domain 3: Technology
      • Domain 4: Billing and Pricing
    • AWS Certified Solutions Architect - Associate (SAA-C03)
      • Foundation
    • Certified Kubernetes Administrator (CKA)
      • Core Concepts
      • Scheduling
      • Logging & Monitoring
      • Application Lifecycle Management
      • Cluster Maintenance
      • Security
      • Storage
      • Networking
      • Design Kubernetes Cluster
      • Kubernetes The Kubeadm Way
      • Troubleshooting
      • JSONPATH
      • Lightning Lab
      • Mock Exams
      • Killer Shell
    • Certified Kubernetes Security (CKS)
      • Foundation
      • Cluster Setup
      • Cluster Hardening
      • Supply Chain Security
      • Runtime Security
      • System Hardening
      • Killer Shell
    • (KGAC-101) Kong Gateway Foundations
      • Introduction to APIs and API Management
      • Introduction to Kong Gateway
      • Getting Started with Kong Enterprise
      • Getting Started with Kong Konnect
      • Introduction to Kong Plugins
  • 📜Blog Posts
    • Modern Solutions For Preventing Ransomware Attacks
Powered by GitBook
On this page
  • Steps to Use Pwn Cyclic
  • Step 1: Generate a Unique Pattern
  • Step 2: Input the Pattern into the Program
  • Step 3: Analyze the Crash Dump
  • Step 4: Identify the Offset
  • Full Example
  • Step-by-Step Process
  1. Binary Exploitation
  2. pwntools

Cyclic

👀 What ?

Pwn cyclic is a technique used in cybersecurity for exploiting buffer overflow vulnerabilities. Buffer overflow is a common security issue where a program writes more data to a buffer than it can handle, which can overwrite adjacent memory areas. Pwn cyclic is a tool that can generate, search and slice cyclic patterns, which are patterns of distinct values that can be used to identify the exact location of buffer overflow.

🧐 Why ?

Understanding Pwn cyclic is crucial for both cybersecurity professionals and software developers. For cybersecurity professionals, it's a powerful tool for identifying and exploiting vulnerabilities in software systems. For developers, understanding this technique can help them write more secure code by identifying potential buffer overflow vulnerabilities and ensuring their programs handle input data correctly. This knowledge is essential for anyone interested in maintaining secure systems.

â›ī¸ How ?

To use Pwn cyclic, you first need to generate a cyclic pattern with a specified length. You can do this with the 'cyclic' function in the Pwn library. After an overflow occurs, you can use the 'cyclic_find' function to identify the exact location of the overflow. This allows you to pinpoint the exact place in the code where the overflow happened, making it easier to develop an exploit or fix the vulnerability.

âŗ When ?

Pwn cyclic has been around for several years, and it has become an important tool in the toolkit of many cybersecurity professionals. Its use is particularly common in the field of penetration testing, where it is used to identify and exploit vulnerabilities in software systems.

Pwn cyclic is a tool used in exploit development to identify the exact location of a buffer overflow. It generates a sequence of unique patterns, which can be inputted into a program. If the program crashes due to a buffer overflow, the crash dump will contain part of this unique pattern.

By analyzing the crash dump, you can pinpoint the exact offset where the buffer overflow occurred. This method is effective because each subset of the cyclic pattern is unique, allowing precise identification of the overflow point.

Steps to Use Pwn Cyclic

Step 1: Generate a Unique Pattern

The first step is to generate a unique pattern using cyclic from the pwntools library. This pattern is designed so that every subset is unique.

from pwn import *

pattern = cyclic(100)
print(pattern)

This generates a 100-byte long pattern.

Step 2: Input the Pattern into the Program

Next, you input the generated pattern into the vulnerable program. This can be done by various means depending on the program's input method (e.g., command-line argument, environment variable, network input).

./vulnerable_program $(python -c 'from pwn import *; print(cyclic(100))')

Step 3: Analyze the Crash Dump

When the program crashes, the crash dump (e.g., core dump) will contain part of the cyclic pattern. You need to locate the exact part of the pattern present in the crash dump.

Step 4: Identify the Offset

Using the pattern found in the crash dump, you can determine the exact offset of the buffer overflow using cyclic_find.

from pwn import *

# Example pattern from crash dump
crash_pattern = b'aaab'

offset = cyclic_find(crash_pattern)
print(f"The offset is {offset}")

This will output the exact offset where the buffer overflow occurred.

Full Example

Consider a vulnerable program that reads input into a fixed-size buffer without checking the length. Here is a simplified example:

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

void vulnerable_function(char *input) {
    char buffer[64];
    strcpy(buffer, input);  // Vulnerable to buffer overflow
}

int main(int argc, char *argv[]) {
    if (argc > 1) {
        vulnerable_function(argv[1]);
    }
    return 0;
}

Step-by-Step Process

  1. Compile the Program:

    gcc -o vulnerable_program vulnerable_program.c -fno-stack-protector -z execstack
    
  2. Generate a Unique Pattern:

    from pwn import *
    
    pattern = cyclic(100)
    print(pattern)
    
  3. Run the Program with the Pattern:

    ./vulnerable_program $(python -c 'from pwn import *; print(cyclic(100))')
    
  4. Analyze the Crash Dump:

    • The program will crash, and you need to find the pattern in the crash dump. Assuming the crash dumps the EIP register:

      Segmentation fault at EIP: 0x61616162
      
  5. Identify the Offset:

    from pwn import *
    
    crash_pattern = 0x61616162  # The value from the crash dump
    offset = cyclic_find(crash_pattern)
    print(f"The offset is {offset}")
    
    • This will output:

      The offset is 64
      
  6. Develop the Exploit:

    • With the offset known, you can craft a payload to exploit the buffer overflow, for example, by overwriting the return address.

    from pwn import *
    
    offset = 64
    new_return_address = p32(0xdeadbeef)  # Example address
    
    payload = cyclic(offset) + new_return_address
    print(payload)
    

  • Run the program with the crafted payload:

./vulnerable_program $(python -c 'from pwn import *; print(cyclic(64) + p32(0xdeadbeef))')
PreviousLogging and ContextNextPacking

Last updated 1 month ago

Page cover image