Code Monkey home page Code Monkey logo

windows-exploitation's Introduction

Windows exploitation

Types of Bugs

Uninitialized Stack Variable

  • References a local variable or buffer, which wasn’t previously properly initialized.
  • Usually mitigated by compiler warnings/errors, informing about potential security flaws present in the source code.
  • Challenge: how can one control the trash bytes present on the ring-0 stack, from within a ring-3 perspective?
  • How to exploit:
    • Find the kernel stack init address: !thread.
    • Find the offset of our callback from this init address
    • Spray the Kernel Stack with User controlled input from the user mode using NtMapUserPhysicalPages trick.

Null-Pointer Dereference

  • Happens when the value of the pointer is NULL, and is used by the application to point to a valid memory area.
  • How to exploit:
    • Map the NULL page in user space.
    • Place a fake data structure in it which will cause our shell code to be executed.
    • Trigger the dereference bug.

Symbolic links

  • Leverages two fundamental concepts in Windows:
    • object manager symbolic links.
    • NTFS junctions/mount points.
  • Requirements for exploitation:
    • A high privileged process writing to user controlled files or directories: C:\PownMe\Link.ex.
    • Reading permission to the referenced directory C:\Windows\System32\sysprep\ and writing permissions to the directory where the junction will be stored C:\PownMe.
    • directory where the junction will be stored must be empty: C:\PownMe before the reparse point is defined.
  • How to find them:
    • launch process monitor and filter by the process you are targeting.
    • look for CreateFile operations by the SYSTEM process.
    • then check if the target directory has the right access for the everyone group or username.

Payloads

Token Stealing Payload

  • The general algorithm for the token stealing shellcode is:
    • Save the drivers registers so we can restore them later and avoid crashing it.
    • Find the _KPRCB struct by looking in the fs segment register
    • Find the _KTHREAD structure corresponding to the current thread by indexing into_KPRCB.
    • Find the _EPROCESS structure corresponding to the current process by indexing into_KTHREAD.
    • Look for the _EPROCESS structure corresponding to the process with PID=4 (UniqueProcessId = 4) by walking the doubly linked list of all_EPROCESS structures that the_EPROCRESS structure contains a references to, this is the "System" process that always has SID ( Security Identifier) = NT AUTHORITY\SYSTEM SID.
    • Retrieve the address of the Token of that process.
    • Look for the _EPROCESS structure corresponding to the process we want to escalate (our process).
    • Replace the Token of the target process with the Token of the "System" process.
    • Clean up our stack and reset our registers before returning.

Mitigations

SMEP (Supervisor Mode Execution Prevention)

  • Introduced in 2011 in Intel processors based on the Ivy Bridge architecture and enabled by default since Windows 8.0.
  • SMEP restricts executing code that lies in usermode to be executed with Ring-0 privileges, attempts result in a crash. This basically prevents EoP exploits that rely on executing a usermode payload from ever executing it.
  • The SMEP bit is bit 20 of the CR4 register.
  • SMEP's goal is to block kernel exploit which:
    • Prepares a shellcode in user memory
    • Redirects execution to the prepared payload, by exploiting a kernel/driver security flaw.

SMEP Bypass

  • Craft a rop chain to disable SMEP (not possible with win10 vbs)
  • Modifying nt!MmUserProbeAddress
  • Windows Reserve Objects

windows-exploitation's People

Contributors

lordnoteworthy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.