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
  • Initial Analysis
  • Identifying Anti-Debugging Techniques
  • Manual Patching
  • Sleep
  • Program Termination
  • Sandbox
  • Time & Date
  • Environment
  • File Check
  • Solution
  1. CTF Writeups
  2. Reverse Engineering

SiberSiaga 2023: Obstacles

The best satisfaction always comes after overcoming many annoying obstacles. Overcome this challenge to gain the satisfaction of a flag!

PreviousACS 2023: MazeNextSiberSiaga 2023: Packed

Last updated 1 year ago

TL;DR

Bypass anti-debugging techniques via manual patching to circumvent branching controls.

Initial Analysis

Running the executable doesn't seem to be doing anything at all.

 ┌──(kali💀JesusCries)-[~/…/CTF/SiberSiaga2023 (Finals)/Rev/Obstacles]
 └─$ wine Obstacles.exe                      
 ^C   

Importing the executable in any debugger/disassembler of choice shows that it is written in Go Lang. Luckily for us, most of the function names are resolved automatically without needing to rename them.

Identifying Anti-Debugging Techniques

At a glance, there seem to be several anti-debugging techniques such as time.Sleep and main.isDebuggerPresent implemented. This is then followed by a series of decryption routines.

Further down, there are even checks to verify if the executable is currently running in a sandbox based on the presence of specific processes.

We can verify the process names by going back a few lines.

data_50dbb8 is a pointer that points to 0x4dde33, so we'll take a look at that address instead.

This reveals the process ollydbg.exe and procmon.exe. In the meantime, take note of notepad.exe as well.

The last anti-debugging technique seems to be checking the current date against a specific point of time.

Manual Patching

As the challenge description suggests, we need to overcome these obstacles, a.k.a anti-debugging techniques via assembly patching, while leaving all the decryption routine untouched. I am going to use BinaryNinja for patching due to it's intuitiveness.

Sleep

When trying to run the executable, it will go to sleep indefinitely due to time.Sleep. We can patch this out easily with Skip and Return Zero:

Program Termination

Next, we will need a way to prevent the program from terminating. Right click on os.Exit and select Patch -> Edit Current Line:

Instead of terminating, we can neutralize it by jumping to the nearest block. Obtain the address of the nearest block with Copy Address:

This way, it will continue execution on the same block, regardless of the comparison test rax, rax made on top.

Sandbox

Up until this point, we have defeated time.Sleep and os.Exit, but we are met with sandbox checks.

To neutralize this, select Invert Branch to turn je into jne. Do note that the sandbox checks are still in place since main.sandboxFilepath remains intact. However, any positive detection will not trigger anything since we have flipped the decision tree.

Sandbox detection is now gone.

Time & Date

Apply the same technique as patching time.Sleep for all date-time equivalent function calls.

Recall that we received the error message panic: time: missing Location in call to Date on runtime. This matches with the following function call.

We can bypass this with a simple Invert Patch:

However, we now encounter a different problem.

A little below, we can find the culprit for that problem.

Patch the instructions with a Return Zeroand Invert Patch respectively.

Environment

An environment issue.

A little below, we can find the code block responsible for this via data_50c300 strings.

Perform an Invert Patch on the jump above, so it changes from jg to jle:

File Check

Once that is completed, we have a final part to fix before our flag gets fully decrypted.

We can either patch jne or os.Exit here, both methods will lead to the same result.

Solution

Once the flag is fully decrypted, it will be injected into an existing process, as verified with the usage of API calls:

OpenProcess -> VirtualAllocEx -> WriteProcessMemory -> CreateRemoteThreadEx

Since OpenProcess is invoked (instead of CreateProcessW), the process injection must be targeting an existing process on the system. Before this, we knew that notepad.exe was somehow involved in this challenge, so it must've been the one! To solve this challenge, open a new instance of notepad.exe and run the executable.

Flag: sibersiaga{G0_GO_G0L4NG_0BST4ClES}

🚩