Buffer Overflow Prep - Beginner friendly note
Buffer Overflow Prep (Beginner friendly - I hope)
I know this topic is extremely important for people who is into OSCP preparation like I am. I take this seriously. Although I have zero programming language knowledge, I still manage to put together Buffer Overflow (BOF) to some certain extend.
Tryhackme ALSO SAID:
PLEASE NOTE THAT THIS ROOM DOES NOT TEACH BUFFER OVERFLOWS FROM SCRATCH. IT IS INTENDED TO HELP OSCP STUDENTS AND ALSO BRING TO THEIR ATTENTION SOME FEATURES OF MONA WHICH WILL SAVE TIME IN THE OSCP EXAM.For context: (To be honest, I struggle tremendously on what Tryhackme is trying to do in these task below, it take a good chunk of my time to realized that they are mimics vulnerable applications on the victims machine. These vulnerable applications then listen for output from the network.) We will take advantage of the fact that they are vulnerable to BOF and exploit them from there.
Note: I will try to keep this note as newbie friendly as possible. Because I'm a newbie myself at the time of writing this note, I will try to also explain to myself what is going on.
xfreerdp3 /u:admin /p:password /v:10.10.15.213 /cert:ignore /workarea /sec:rdpTask 1: oscp.exe - OVERFLOW1
Step 1: Run Immunity Debugger as Admin


Step 2: Open oscp.exe with Immunity Debugger
oscp.exe with Immunity Debugger
Step 3: The binary will open in a "paused" state, so click the red play icon or choose Debug -> Run. In a terminal window, the oscp.exe binary should be running, and tells us that it is listening on port 1337.


Step 4: On your Kali box, connect to port 1337 on 10.10.15.213 using netcat:
Step 5: Mona Configuration
IN THE NEXT FEW STEPS OUR STEPS CAN BE SUM UP AS THESE:
Sigh
Anyway, confusingly enough, let's continue with the steps.
Step 6: Fuzzing
Step 7: Crash Replication & Controlling EIP

Step 8: Finding Bad Characters
What is this for? - You asked?
Answer: The purpose of this step is to identify bad characters — bytes that break our payload — by comparing what we sent versus what actually landed in memory. We keep trimming both our payload and the Mona-generated bytearray until we know exactly which characters are safe.
Why are we doing this so many times ? - You asked?
Answer: Every time a bad character is hit, Mona stops analyzing the rest of the payload — because it thinks the string is over. That’s why we often have to do this step multiple times, trimming as we go.


PAY REALLY CLOSE ATTENTION FOR WHAT TRYHACKME SAID ABOVE!
Because our line of bytes payload may not all corrupted, we might as well slowly remove each bytes, not call them all corrupted, that's wrong! So if you found consecutive byte like 01 02 03 a1 a2 a3, may be start removing 01, a1 first.


Step 9: Finding a Jump Point
✅ What We’re Looking For:



Step 10: Generate Payload
Step 11: Prepend NOPs
Step 12: Exploit!
Task 9: oscp.exe - OVERFLOW9
In this task something interesting happens

Q&A with a friend
[1] In Task 1, what does: !mona config -set workingfolder c:\mona\%p do?
[1] In Task 1, what does: !mona config -set workingfolder c:\mona\%p do?Answer:
🔧 !mona config -set workingfolder c:\mona\%p — What does it do?
!mona config -set workingfolder c:\mona\%p — What does it do?🧠 What is %p?
%p?💾 Why is this important?
✅ Summary:
Command
Meaning
[2] In a hypothesis environment, all that will be done by the victim, not the hacker right?
[2] In a hypothesis environment, all that will be done by the victim, not the hacker right?🧠 In Real Life (Not the TryHackMe Lab), Who Does What?
💻 In TryHackMe / OSCP / CTF:
🌐 In Real World / Hypothetical Attack:
🔬 This Is Called "Developing an Exploit Locally"
🧨 Think Like This:
✅ TL;DR:
Action
Who Does It
Where
[3]: So the attacker have to understand things thoroughly to be able to spot the similarity between a vuln app in the lab and vuln app in the wild right?
[3]: So the attacker have to understand things thoroughly to be able to spot the similarity between a vuln app in the lab and vuln app in the wild right?🔎 Why Deep Understanding Matters:
🧠 It's Like Street Fighting vs. Dojo Sparring
🛠️ What You’re Actually Learning When You Do BOF Labs:
Lab Skill
Real World Benefit
🧬 Final Truth
[4] What is EIP?
[4] What is EIP?🔹 EIP = Extended Instruction Pointer
🔥 That’s how you hijack a program.
[5] Why ESP?
[5] Why ESP?[6] What is a "jump point"?
[6] What is a "jump point"?[7] Why not jump straight to the shellcode address?
[7] Why not jump straight to the shellcode address?[8] 🔧 In exploit.py, what is retn?
[8] 🔧 In exploit.py, what is retn?[BONUS] How can multiple JMP ESP addresses work if there’s only one ESP (top of the stack)?
[BONUS] How can multiple JMP ESP addresses work if there’s only one ESP (top of the stack)?[BONUS 2]: How can JMP ESP addresses work across different machines running the same vulnerable app?
[BONUS 2]: How can JMP ESP addresses work across different machines running the same vulnerable app?I hope you enjoy this guide as much as I enjoy writing it. Have a good day!
PreviousTryhackme - Internal - THE HARD WAYNextHướng dẫn chi tiết bằng tiếng Việt - Tryhackme - Brainstorm
Last updated