📝
Home
Pentesting
  • 📝Home
  • ⚒️PENTESTING
    • Foundational
      • Gaining Access
      • Session Hijacking
      • Buffer Overflows
        • Finding the Offset
        • Spiking
        • Fuzzing
      • Attack Basics
        • Brute Force Attacks
        • Credential Stuffing and Password Spraying
        • Netcat Shell Stabilization
        • Reverse Shells vs Bind Shells
        • Staged vs Non-Staged Payloads
      • Footprinting
    • Reconnaissance
      • Discovering Email Addresses
      • Hunting Subdomains
    • Scanning and Enumeration
      • Banner Grabbing
      • Enumerating HTTP and HTTPS
      • Enumerating SMB
      • Enumerating SSH
      • NetBIOS Enumeration
      • SNMP Enumeration
      • Sniffing
    • Privilege Escalation
      • 🐧Linux Privilege Escalation
      • 🪟Windows Privilege Escalation
        • Initial Enumeration
    • Defense Evasion
      • Hiding Files and Covering Tracks
      • Network Evasion
    • Attacking Services
      • Attacking Kerberos
      • Attacking VPNs
      • Denial of Service
      • Exploiting FTP
      • Exploiting NFS
      • Exploiting SMTP
      • Exploiting Telnet
    • Attacking Active Directory
      • Initial Attack Vectors
        • Gaining Shell Access
        • LLMNR Poisoning
        • SMB Relay
        • Passback Attacks
        • IPv6 Attacks
      • Post-Compromise Enumeration
        • Bloodhound
        • ldapdomaindump
        • PowerView
        • PlumHound
      • Post-Compromise Attacks
        • GPP Attacks
        • Print Nightmare
        • Token Impersonation using Incognito
        • URL File Attack
        • Pass Attacks
        • Kerberoasting
        • LNK File Attacks
        • Mimikatz
      • Post-Domain Compromise Attacks
        • Dumping the NTDS.dit
        • Golden Ticket Attacks
      • Post Exploitation
    • Toolkit
      • Burp Suite
        • Intruder
      • Hping
        • Crafting TCP and UDP Packets
      • Metasploit
        • Meterpreter
        • Shell Handler
        • Gather Information
        • Gaining Root
    • Web Application Hacking
      • Attack Methodology
      • Attacking Web Applications
      • Authentication Bypass
      • Cross-Site Scripting
      • Cross-Site Request Forgery
      • File Inclusion
      • Server-Side Request Forgery
      • Injection
        • Command Injection
        • LDAP Injection
        • SQL Injection
  • 👽MALWARE ANALYSIS
    • Malware Analysis Primer
    • Malware Types
      • Rootkits
      • Viruses
      • WannaCry
    • Analyzing Malicious Windows Programs
    • Static Analysis
      • Basic Static Techniques
      • Advanced Static Analysis
    • Reverse Engineering
      • Crash Course in x86 Disassembly
      • Recognizing Code in Assembly Language
    • Dynamic Analysis
    • Detecting Malware
      • Evasion Techniques
      • Detecting Mimikatz
      • Hunting Malware
      • Hunting Metasploit
      • Hunting Persistence
  • 🏹THREAT HUNTING
    • Foundational
      • ATT&CK Framework
      • CIA Triad
    • APTs
  • 🐍PROGRAMMING & SCRIPTING
    • Foundational
      • Computer Memory
    • C Programming
    • Assembly Language
      • Assembly File Structure
      • Debugging with gdb
    • Bash
    • Python
      • Foundational
        • Booleans and Operators
        • Comprehensions
        • Conditionals
        • Dictionaries
        • Exceptions and Error Handling
        • Functions
        • Lambdas
        • Lists
        • Loops
        • Modules
        • Numbers
        • Reading and Writing Files
        • Sets
        • Sockets
        • String Formatting
        • Tuples
        • User Input
        • Variables
      • Extending Python
        • Virtual Environments
        • Sys Module
        • Requests
        • pwntools
    • Regular Expressions
    • SQL
  • 🕵️DIGITAL FORENSICS
    • Anti-Forensic Techniques
    • 🪟Windows Security Internals
      • Windows Security Internals
        • Kernel
          • Security Reference Monitor (SRM)
          • Object Manager
            • System Calls
            • NTSTATUS Codes
            • Object Handles
            • Query and Set Information System Calls
          • The I/O Manager & The Process and Thread Manager
          • The Memory Manager
          • The Configuration Manager
  • 💼GRC (CISSP Notes)
    • Security Assessment and Testing
    • Security Governance Principles
    • Security Policies Standards and Procedures
    • Preventing and Responding to Incidents
    • Organizational Roles and Responsibilities
    • Organizational Processes
  • 📦Networking
    • Foundational
      • DHCP
      • DNS Basics
      • HTTP Protocol
      • IPSec
      • IPv6 Fundamentals
    • Wireless Technologies
      • 802.11
      • Bluetooth
      • Wireless Authentication
      • Wireless Encryption
Powered by GitBook
On this page
  • Recognizing Code in Assembly Language
  • Disassembling Arithmetic Operations
  • Recognizing if Statements
  • Recognizing nested if statements
  • Recognizing Loops
  • Finding while loops
  • Understanding Function Call Conventions
  • Analyzing switch statements
  • Disassembling Arrays
  • Identifying Structs
  • Analyzing Linked List Traversal
  1. MALWARE ANALYSIS
  2. Reverse Engineering

Recognizing Code in Assembly Language

PreviousCrash Course in x86 DisassemblyNextDynamic Analysis

Last updated 1 year ago

Recognizing Code in Assembly Language

Notice that x is changed in memory when eax is moved into dword_40CF60

Disassembling Arithmetic Operations

int a = 0; 
int b = 1;
a = a + 11;
a = a - b; 
a--;
b++;
b = a % 3; 

This can be broken down and translated back to C

Recognizing if Statements

Recognizing nested if statements

Recognizing Loops

  • The for loop can be recognized by locating the four components

    • Initialization

    • Comparison

    • Execution instructions

    • Increment/decrement

Finding while loops

Understanding Function Call Conventions

  • The calling convention used depends on the compiler

  • Three most common calling conventions

    • cdecl

      • parameters are pushed onto the stack from right to left

      • caller cleans up the stack when the function is complete

      • return value is stored in EAX

  • stdcall

    • requires the callee to clean up the stack when the function is complete

    • function called would be responsible for cleaning up the stack

    • standard calling convention for the Windows API

    • Any code calling these functions will not need to clean up the stack, that responsibility falls to the DLLs that implement the code for the API function

  • fastcall

    • first few arguments are passed in registers with the most commonly used registers being EDX and ECX

    • the calling function is usually responsible for cleaning up the stack

    • more efficient because the code doesn't need to involve the stack as much

  • Push vs. Move

    • adder function adds two arguments and returns the result

    • main function calls adder and prints the result using printf

Analyzing switch statements

  • Compiled in two common ways

    • using the if style

    • using jump tables

  • A compiled switch statement looks like a group of if statements

  • There may be multiple ways to represent the same code constructs in assembly

Using a jump table

  • defines offsets to additional memory locations

  • switch variable is used as an index into the jump table

Disassembling Arrays

  • Used by programmer to define an ordered set of similar data items

  • Malware sometimes uses array of pointers to strings that contain multiple hostname that are used as options for connections

  • In assembly, arrays are accessed using a base address as a starting point

  • ecx is used as the index, which is multiplied by 4 to account for the size of the elements

  • The resulting value is added to the base address of the array to access the proper array element

Identifying Structs

  • Similar to arrays

  • Comprise elements of different types

  • Commonly used by malware authors to group information

  • Accessed with a base address used as a starting pointer

Analyzing Linked List Traversal

  • Linked list

    • A data structure that consists of a sequence of data records

    • Each record includes a field that contains a reference (link) to the next record in the sequence

    • Benefits over arrays - order of linked items can be different from the order in which data items are stored in memory or disk

    • To recognize a linked list, you have to recognize that some object contains a pointer that points to another of the same type

  • To recognize a linked list - you have to first recognize that some object contains a pointer that points to another object of the same type

👽