Casual McDonald's Employee Scriptorium
BlogMemesGitHubAbout
  • root@JesusCries
  • ⛩️Red Teaming
    • Methodology
    • Red Team Infrastructure
    • Initial Access
    • Reconnaissance
    • Lateral Movement
    • Post-Exploitation
      • Credentials Dumping
    • Persistence
    • Evasion
      • Memory Scanner
      • Antimalware Scan Interface (AMSI)
      • Event Tracing for Windows (ETW)
      • Attack Surface Reduction (ASR)
      • Microsoft Windows Defender Application Control (WDAC)
      • EDR Evasion
    • Offensive Development
      • Process Injection & Shellcode Loader
      • Portable Executable (PE) Loader
      • User Defined Reflective Loader
      • Beacon Object Files
    • Command & Control (C2)
      • Cobalt Strike
      • Havoc
      • Mythic
      • Sliver
    • Miscellaneous
      • Interesting Read
      • Certification Reviews
        • Certified Red Team Lead (CRTL)
  • 🧊Active Directory & Pentest
    • Check List
  • 🚩CTF Writeups
    • Reverse Engineering
      • Wargames.MY 2024: World 3
      • Wargames.MY 2023: Defeat the boss!
      • ACS 2023: Licrackense Pt I
      • ACS 2023: babyrev
      • ACS 2023: expr
      • ACS 2023: rustarm
      • ACS 2023: Maze
      • SiberSiaga 2023: Obstacles
      • SiberSiaga 2023: Packed
      • SiberSiaga 2023: Malbot
      • SiberSiaga 2023: Vacine
      • ABOH 2023: MetalPipe
      • ABOH 2023: Grape
      • iCTF 2023: RemoteC4
    • Binary Exploitation
      • HTB Cyber Apocalypse 2024: SoundOfSilence
      • LACTF 2024: pizza
      • ACS 2023: Licrackense Pt II
      • ACS 2023: Shellcoding Test
      • ACS 2023: Coding Test
      • ACS 2023: register
      • Wargames.MY 2023: Pak Mat Burger
      • SiberSiaga 2023: Password Generator
      • NahamCON CTF 2023: nahmnahmnahm
      • NahamCON CTF 2023: Weird Cookie
      • TJCTF 2023: shelly
      • TJCTF 2023: formatter
      • ångstromCTF 2023: gaga2
      • ångstromCTF 2023: leek
      • Space Heroes 2023: Rope Dancer
      • corCTF 2022: babypwn
      • corCTF 2021: Cshell
      • HTB Cyber Apocalypse 2023: Void
      • HTB Cyber Santa CTF 2021: minimelfistic
      • HTB Challenge: pwnshop
  • 🤡Clown Chronicles
    • About Me
    • Blogs
      • How to Win A CTF by Overcomplicating Things
      • Exploring Dynamic Invocation for Process Injection in C# and Rust
    • Projects
    • Memes
    • Others
Powered by GitBook
On this page
  • TL;DR
  • Challenge Overview
  • Determine Start Address
  • Symbolic Memory
  • Determine Good & Bad Address
  • Solution
  • Final Script
  1. CTF Writeups
  2. Reverse Engineering

ACS 2023: babyrev

Peek-a-boo

PreviousACS 2023: Licrackense Pt INextACS 2023: expr

Last updated 1 year ago

TL;DR

Flag checker with library call path explosion designed to thwart Angr's symbolic execution. This pitfall can be resolved via Angr's Dynamic Memory implementation.

Challenge Overview

babyrev is yet another flag checker program, but connects over socket to increase its complexity.

Angr is known to struggle against library calls. The use of socket to receive user input is similar to one of the common roadblocks in Angr where library functions such as scanf are used.

Determine Start Address

To overcome this roadblock, we will try to avoid all instructions that are related to socket, and configure Angr's Simulation Manager to start directly from the flag-checking logic.

initial_state = project.factory.blank_state(addr=0x40CC5A)

Symbolic Memory

First, we create a symbolic bitvector flag that will substitute our input. In our case, the original input that recv() receives is stored in rbp-0xd0; hence we would also define our symbolic bitvector to store in the same memory address.

flag_chars = [claripy.BVS(f"c_{i}", 8) for i in range(FLAG_LEN)]
flag = claripy.Concat(*flag_chars)

initial_state.memory.store(initial_state.regs.rbp-0xd0, flag)
# Define the address at which the symbolic bitvector will be stored.

Determine Good & Bad Address

The rest is pretty much straightforward, which involves performing light-reversing to find good and bad addresses.

Solution

Angr solved this pretty quickly, taking only 4 minutes.

Flag: ACS{V2l0aCBncmVhdCBwb3dlciBjb21lcyBncmVhdCByZXNwb25zaWJpbGl0eS4gLSBTcGlkZXItbWFuIGZpbG1zCg==}

Final Script

#!/usr/bin/env python3

import angr
import claripy
import logging

FLAG_LEN = 88

find_addr  = 0x40CD50 # SUCCESS
avoid_addr = 0x40CCFA # FAILURE
start_addr = 0x40CC5A

project = angr.Project("babyrev", load_options={"auto_load_libs": False})
flag_chars = [claripy.BVS(f"c_{i}", 8) for i in range(FLAG_LEN)]
flag = claripy.Concat(*flag_chars)

logging.getLogger('angr').setLevel('INFO')
initial_state = project.factory.blank_state(
        stdin=flag,
        addr = start_addr,
        add_options={
        angr.options.SYMBOL_FILL_UNCONSTRAINED_MEMORY,
        angr.options.SYMBOL_FILL_UNCONSTRAINED_REGISTERS,
        angr.options.LAZY_SOLVES
    }
)

initial_state.memory.store(initial_state.regs.rbp-0xd0, flag)

# Add constraints that all characters are printable
for f in flag_chars:
    initial_state.solver.add(f >= 0x20)
    initial_state.solver.add(f < 0x7f)

sm = project.factory.simulation_manager(initial_state)
sm.explore(find=find_addr, avoid=avoid_addr)

if sm.found:
    solution_state = sm.found[0]
    solution = solution_state.solver.eval(flag, cast_to=bytes)
    print(solution)
else:
    raise Exception('Could not find the solution')

I came across this by Federico that uses Angr's symbolic memory to hook library calls.

🚩
tutorial