📔
Cyber Security Notes
  • Introduction
  • CVEs
    • CVE-2022-33106
  • Paper Reviews
    • Imperfect Forward Secrecy: How Diffie-Hellman Fails in Practice
  • Security Basics Notes
    • Identification, Authentication and Authorization
  • Enumeration and Initial Compromise
    • Methodology
    • Footprinting
    • Network Protocols
      • FTP
      • SMB
      • DNS
      • NFS
      • SMTP
      • IMAP/POP3
      • SNMP
      • MySQL
      • MSSQL
      • Oracle TNS
      • IPMI
    • Nifty One Liners
    • Brute-Force Web Pages
      • Hydra
    • Network Pentest
      • Quick SMB cheatsheet
      • SSH keypair basics
      • Compromise using SSH Key
      • Networking fundamentals Interview topics
      • nmap quick cheatsheet
      • Metasploit Quick Reference
    • Web Pentest
      • Web Pentest Interview top topics
      • Wordpress Exploitation
      • Joomla Exploitation
      • Login Bypass using Cookie Tampering/Poisoning
      • Subdomain Enumeration
      • CSRF mitigation
      • XSS mitigation
      • CSP bypass with JSONP
      • PHP Vulnerabilities
      • Python Serialization Vulnerabilities - Pickle
      • SQL Injections
        • SQLmap
      • SSTI
      • XSS
    • Buffer Overflow Prep
      • Understanding CPUs
      • Virtual Memory and Paging
      • Syscalls
      • Theorem Proving
      • Stripping readable function names
      • Insecure C functions
      • Stack Canaries
      • Linking - GOT,PLT
      • Return Oriented Programming
    • Active Directory - Basics
      • AD DS
      • Managing OUs
      • Group Policies
      • Authentications
      • Trees, Forests and Trusts
      • Kerberos
      • Attacking Kerberos
      • Priv Esc (Post Exploitation)
    • DNS/Domain Enum Masterguide
  • Post Exploitation
    • Shell Escape Techniques
    • Getting stable shell after compromise
    • Linux Privilege Escalation
      • Sudoers file
      • Sudoers entry - Yum
      • Wildcards - Basics
      • Wildcards - Chown
      • Wildcards - Tar
      • Linux Permissions & SUID/SGID/Sticky Bit
      • SUID - nmap
      • SUID - bash
      • SUID - man
      • NFS no_root_squash
      • SUID - pkexec
      • Bad permissions
    • Windows Privilege Escalation
      • SeImpersonatePrivilege Token Impersonation
      • Firefox Creds
      • Potatoes
      • Print Spooler Basics
      • Print Spooler CVE 2020-1030
      • SpoolFool
    • Data Exfiltration Post Exploitation
  • Port Forwarding Cheatsheet
  • Powershell Essentials
    • Powershell Basics
    • Powershell Enumeration
    • Powershell Port Scanner
    • Powershell One Liner Port Scanning
    • Powershell Port Scan in a given CIDR
  • Application Security
    • System Calls in Linux
    • Buffer Overflow Defenses
    • Format string vulnerabilities
    • Sample Github Actions
    • Basic Bugs in Demo Application
    • Using AFL++
  • Linux 64-bit Assembly
    • GDB Basics
      • My relevant GDB cheatsheet
      • Task 1 - Tamper strcmp logic
      • Breakpoints
      • Always starting with intel flavor
      • GDB TUI Mode
    • Basic Hello World Program
    • Registers in 64-bit
    • global directive
    • Reducing instructions and Removing NULL-> Optimizing memory in Assembly
    • Data Types
    • Endianness
    • Moving Data
    • push, pop, and the stack
    • Analysis - Writing data on memory location and referencing
    • Arithmetic Operations
    • Bitwise Logical Operations
    • Bit-Shifting Operations
    • Control Instructions
    • Loops
    • Procedures
    • Stack-Frames and Procedures
    • String Operations
    • Shellcoding basics
      • Introduction and Common Rules
      • Basic Shellcodes->Exit
      • Testing shellcode->Skeleton Code
      • Techniques-> JMP,CALL,POP
      • Techniques-> Stack
      • Techniques-> (64-bit only) RIP Relative Addressing
      • Shellcode 1 -> execve(/bin/sh) STACK PUSH
      • Shellcode 1 -> execve(/bin/sh) JMP CALL POP
      • Techniques-> XOR-Encoder
  • Cloud Security
    • Foundational Technology
    • Learning Through Project Omega
    • IAM Essentials
      • Deep dive into IAM - Part 1
    • Amazon S3
    • Risk Management & Data Controls
    • Enumeration
      • S3 - Enum Basics - PwnedLabs
      • S3 - Identify the AWS Account ID from a Public S3 Bucket
      • EBS - Loot Public EBS Volumes
      • S3- Exploit Weak Bucket Policies for Privileged Access
  • API Security
    • WSDL
  • Reverse Engineering
    • Some string Operations
    • Numbers and Inputs
    • Address inputs
    • Recursive Function
    • Crackme: level1
    • Crackme: level2
    • CTF: Memory Dereferencing
    • CTF: Monty Python
  • CTF Challenge Learnings
    • vsCTF 2024
      • Sanity Check
      • not-quite-caesar
      • Intro to reversing
    • NCL Individual 2024
      • Web Challenges
        • PiratePals
        • Pierre's Store
    • Pico CTF 2024
      • Web Exploitation
        • Bookmarklet
        • WebDecode
        • Unminify
        • Trickster
      • General Skills
        • Commitment Issues
        • Time Machine
        • Blame Game
        • Collaborative Development
        • Binary Search
        • Dont-you-love-banners
    • Sunshine CTF
      • Knowledge Repository
    • Amazon WiCys CTF
      • I am Lazy
      • Password Locker on the Web
      • Happy Birthday Card Generator
      • Bloggergate
      • simple offer
      • Bad Actor
      • Secret Server
      • Simple PCAP
      • Hidden Message
    • C code using getenv()
    • Command Injection with filter
    • Pwning
      • Shoddy_CMP
      • PLT_PlayIT
  • Applied Cryptography
    • Linear Congruential Generator
  • Tools for everything
Powered by GitBook
On this page

Was this helpful?

  1. CTF Challenge Learnings
  2. Pwning

PLT_PlayIT

Deals with GOT overwrite by utlizing Write-What-where primitive

PreviousShoddy_CMPNextApplied Cryptography

Last updated 1 year ago

Was this helpful?

In this binary, we can see in line 18, local_28 bariable (which is only 8 bytes) is allowed to write 24 bytes in the memroy. What this will essentially do is overwrite local_20 and local_18 variables too which are the subsequent 8 bytes each variable in memory (making total 24 bytes).

But we see that local_18 is a pointer. So we can overwrite it's value with an address.

Now in line 20, we see the value of local_18 is assigned as local_28. So at the address pointed by local_18, local_28 will be written to. And look at line 21, at the address pointed by local_18[1] (as in local_18 + 8 bytes) local_20 is being written to.

This allows us to utilize the "Write What Where" exploit primitive. We can write essentially 2 values in memory.

local_28 -> Written in addr (*local_18)

local_20 -> Written in addr + 8 (local_18[1])

Input would be: local_28 (8 bytes) + local_20 (8 bytes) + local_18 (8 bytes)

So, essentially we have to craft a payload which would:

  1. Write a malicious shellcode (or shell giving string) to a location

  2. Have it called using system()

  3. Overwrite GOT of a function by system. SHould be a function which comes after the initialization of local_28, local_20 and local_18

Let's write "/bin/sh" somewhere in memory whose next 8 bytes and should be overwritten by system's PLT stub function.

This makes it simple. Only puts comes after initialization and is operating on local_28. So, local_28 becomes "/bin/sh". puts() is to be replcaced with system()'s PLT stub address

Upon exploring Ghidra I see one such prominent location at address 00601010:

So, the payload becomes: "/bin/sh" + PLT STUB address of System() + 0x00601010

This would mean that 00601010 would be written with "/bin/sh"

00601010 + 8 (which is puts()) would be overwritten by PLT stub of system()

Essentially when puts(local_28) will be called, system(local_28) will execute.

System@plt is at:

The same could be done using pwntools:

So, exploit becomes: "/bin/sh" + 0x00000000004005d0 + 0x0000000000601010

I am representing the addresses in 64 bit value (8 byte addresses)

Let's whip up pwntools in python3 and let me guide you through my exploit dev

  1. Made the payload but only interacting with binary intially to see how it reacts first before sending in the payload. Adding a \x00 terminated the string (/bin/sh) and is exactly 8 bytes long too.

  1. It is taking input after it says "to save: ". Let's incorporate that in code

  1. After it says that, I have to give an input. I use sendline to provide payload as an input.

  1. But where is the shell? The process breaks the execution after input so we can use interactive() to interact with the process after our input.

But let me first set a SUID bit on this binary and run the exploit as a low priv user, so that when exploit works, I get a root shell. I'll also add a flag.txt file that can only be read by the root user.

Let me also set SUID on local.py

  1. Now it looks like this:

  1. Cool, let's give it a whirl.

Let's run this on our remote server with a few alterations

There we go. That's how I pwned playit using write-what-where primitive to overwrite GOT for puts and replace by system() to get the flag eventually!