Jugaad Linux Thread Injection Kit. By Aseem Jakhar

Similar documents
Win32 API Emulation on UNIX for Software DSM

User Mode Linux Linux inside Linux inside Linux inside...

Syscall Proxying - Simulating remote execution Maximiliano Caceres <maximiliano.caceres@corest.com> Copyright 2002 CORE SECURITY TECHNOLOGIES

Stack Overflows. Mitchell Adair

For a 64-bit system. I - Presentation Of The Shellcode

Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail

Operating Systems and Networks

Assembly Language: Function Calls" Jennifer Rexford!

Buffer Overflows. Security 2011

W4118 Operating Systems. Junfeng Yang

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

The Linux Kernel: Process Management. CS591 (Spring 2001)

Software Vulnerabilities

Hotpatching and the Rise of Third-Party Patches

Format string exploitation on windows Using Immunity Debugger / Python. By Abysssec Inc

VICE Catch the hookers! (Plus new rootkit techniques) Jamie Butler Greg Hoglund

Linux/UNIX System Programming. POSIX Shared Memory. Michael Kerrisk, man7.org c February 2015

esrever gnireenigne tfosorcim seiranib

COS 318: Operating Systems

Linux exploit development part 2 (rev 2) - Real app demo (part 2)

Betriebssysteme KU Security

HTC Windows Phone 7 Arbitrary Read/Write of Kernel Memory 10/11/2011

Off-by-One exploitation tutorial

Exploiting nginx chunked overflow bug, the undisclosed attack vector

Software security. Buffer overflow attacks SQL injections. Lecture 11 EIT060 Computer Security

How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes

IOActive Security Advisory

C Programming Review & Productivity Tools

1 Posix API vs Windows API

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Intel P6 Systemprogrammering 2007 Föreläsning 5 P6/Linux Memory System

Reverse Engineering and Computer Security

Defense in Depth: Protecting Against Zero-Day Attacks

WLSI Windows Local Shellcode Injection. Cesar Cerrudo Argeniss (

64 Bit File Access. 1.0 Introduction. 2.0 New Interfaces. 2.1 New User Visible Types. Adam Sweeney

There s a kernel security researcher named Dan Rosenberg whose done a lot of linux kernel vulnerability research

CS61: Systems Programing and Machine Organization

Title: Bugger The Debugger - Pre Interaction Debugger Code Execution

64-Bit NASM Notes. Invoking 64-Bit NASM

telnetd exploit FreeBSD Telnetd Remote Exploit Für Compass Security AG Öffentliche Version 1.0 Januar 2012

Bypassing Browser Memory Protections in Windows Vista

OPERATING SYSTEMS STRUCTURES

Jorix kernel: real-time scheduling

Attacking Host Intrusion Prevention Systems. Eugene Tsyrklevich

Programmation Systèmes Cours 9 Memory Mapping

Shared Memory Introduction

Carnegie Mellon Virtual Memory of a Linux Process Process-specific data structs (ptables, Different for

Stealth Secrets of the Malware Ninjas. By Nick Harbour

The Plan Today... System Calls and API's Basics of OS design Virtual Machines

NDK: NOVELL NSS AUDIT

Testing for Security

Exploiting Trustzone on Android

Bypassing Windows Hardware-enforced Data Execution Prevention

PCI-SIG ENGINEERING CHANGE REQUEST

TitanMist: Your First Step to Reversing Nirvana TitanMist. mist.reversinglabs.com

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

Vista and ActiveX control

Hydra. Advanced x86 polymorphic engine. Incorporates existing techniques and introduces new ones in one package. All but one feature OS-independent

Web Application Security Payloads. Andrés Riancho Director of Web Security OWASP AppSec USA Minneapolis

Advanced IBM AIX Heap Exploitation. Tim Shelton V.P. Research & Development HAWK Network Defense, Inc. tshelton@hawkdefense.com

Where s the FEEB? The Effectiveness of Instruction Set Randomization

Removing Sentinel SuperPro dongle from Applications and details on dongle way of cracking Shub-Nigurrath of ARTeam Version 1.

CSC 2405: Computer Systems II

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Operating Systems Design 16. Networking: Sockets

Operating System Structures

Persist It Using and Abusing Microsoft s Fix It Patches

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Keil Debugger Tutorial

Lab 4: Socket Programming: netcat part

From SQL Injection to MIPS Overflows

Libmonitor: A Tool for First-Party Monitoring

Using fuzzing to detect security vulnerabilities

Sandy. The Malicious Exploit Analysis. Static Analysis and Dynamic exploit analysis. Garage4Hackers

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2005

Boost SQL Server Performance Buffer Pool Extensions & Delayed Durability

Attacking x86 Windows Binaries by Jump Oriented Programming

Systems Design & Programming Data Movement Instructions. Intel Assembly

Virtual Private Systems for FreeBSD

Bypassing Memory Protections: The Future of Exploitation

System Calls Related to File Manipulation

Making Linux Safe for Virtual Machines

OLD WIN32 CODE FOR A MODERN, SUPER-STEALTH TROJAN

風 水. Heap Feng Shui in JavaScript. Alexander Sotirov.

System/Networking performance analytics with perf. Hannes Frederic Sowa

Linux Kernel Rootkit : Virtual Terminal Key Logger

Real-time Debugging using GDB Tracepoints and other Eclipse features

A Tiny Guide to Programming in 32-bit x86 Assembly Language

PuttyRider. With great power comes great responsibility. # Pivoting from Windows to Linux in a penetration test. Adrian Furtunã, PhD adif2k8@gmail.

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Application-Level Debugging and Profiling: Gaps in the Tool Ecosystem. Dr Rosemary Francis, Ellexus

Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code

CS3600 SYSTEMS AND NETWORKS

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

Transcription:

Jugaad Linux Thread Injection Kit By Aseem Jakhar

$whoami A Big Hello from India. Founder null The open security community. Organizer nullcon security conference. Chief researcher Payatu Labs http://www.payatu.com Speaker at various security conferences Blackhat, Xcon, Gnunify, ISACA Blore, Cocon, Clubhack, Blore Cyber security Summit.

null Registered Non-Profit organization. The largest security community in India. Focus security research, knowledge sharing. 6 chapters in India. Monthly meets in all chapters. Security awareness camps. nullcon The Favorite go-to destination for hackers and security professionals in the Indian subcontinent.

Agenda What is Jugaad What Jugaad is not Code Injection Windows Linux ptrace() Primer Library Injection Jugaad Conclusion

What is Jugaad Jugaad Hindi word, means workaround/hack. Code injection technique. Threading capability. Customized payload. Jugaad in it's true sense.

Agenda What is Jugaad What Jugaad is not Code Injection Windows Linux ptrace() Primer Library Injection Jugaad Conclusion

What Jugaad is not Zero day. Vulnerability. Privilege escalation technique.

Agenda What is Jugaad What Jugaad is not Code Injection Windows Linux ptrace() Primer Library Injection Jugaad Conclusion

Code Injection Injecting executable instructions/code. Altering the default flow of execution. Buffer overflow SQLi XSS XML APIs

Agenda What is Jugaad What Jugaad is not Code Injection Windows Linux ptrace() Primer Library Injection Jugaad Conclusion

Windows Allows code injection via a defined API. CreateRemoteThread and family. HANDLE WINAPI CreateRemoteThread( in HANDLE hprocess, in LPSECURITY_ATTRIBUTES lpthreadattributes, in SIZE_T dwstacksize, in LPTHREAD_START_ROUTINE lpstartaddress, in LPVOID lpparameter, in DWORD dwcreationflags, out LPDWORD lpthreadid);

Windows hprocess A handle to the process in which the thread is to be created. dwstacksize The initial size of the stack, in bytes. lpstartaddress A pointer to the application-defined function to be executed by the thread and represents the starting address of the thread in the remote process. The function must exist in the remote process. Source: http://msdn.microsoft.com/en-us/library/ms682437%28v=vs.85%29.aspx

Agenda What is Jugaad What Jugaad is not Code Injection Windows Linux ptrace() Primer Library Injection Jugaad Conclusion

Linux No remote code injection API. No CreateRemoteThread equivalent. How do we inject code into remote process? Wait a minute... what does gdb do? Awesomeness of ptrace().

Agenda What is Jugaad What Jugaad is not Code Injection Windows Linux ptrace() Primer Library Injection Jugaad Conclusion

ptrace() primer Tracing API a.k.a Debugging. Powerful API Single function, multiple operations. long ptrace( enum ptrace_request request, pid_t pid, void *addr, void *data); request The operation to be performed on the traced process. pid The process identifier of the process being traced. addr and data The values depend on the type of operation.

ptrace() primer request parameter. PTRACE_ATTACH - Attaches to the process specified in pid. PTRACE_CONT - Restarts the stopped child process. PTRACE_DETACH - Restarts the stopped child as for PTRACE_CONT, but first detaches from the process. PTRACE_PEEKTEXT - Reads a word at the location addr in the child's memory.

ptrace() primer PTRACE_POKETEXT - Copies the word data to location addr in the child's memory. PTRACE_GETREGS - Copies the child's general purpose to location data in the parent. PTRACE_SETREGS - Copies the child's general purpose or floating-point registers, respectively, from location data in the parent.

ptrace() primer Getting the control back after executing specific instructions. Breakpoints. Int3 instruction (0xcc).

Agenda What is Jugaad What Jugaad is not Code Injection Windows Linux ptrace() Primer Library Injection Jugaad Conclusion

Library Injection Injecting shared libraries into running processes. Open source tool injectso. Awesome!!! Read/write fds, intercept IO, functions. But wait... Whats that in /proc?

Library Injection cat /proc/1234/maps 00d74000-00f63000 r-xp 00000000 08:01 8698 /home/victim/evil.so

Library Injection Demo

Agenda What is Jugaad What Jugaad is not Code Injection Windows Linux ptrace() Primer Library Injection Jugaad Conclusion

Jugaad Thread injection kit. In-memory injection. Stealthier. No more library traces in maps. Awesomeness?? Custom Payload.

Jugaad Memory Allocation and Execution Threadification Payload (Evil code) Implementation Demo

Jugaad Memory Allocation and Execution Threadification Payload (Evil code) Implementation details Demo

Jugaad Backup memory location and registers. Overwrite with shellcode. Set EIP to point to the overwritten memory location. Execute the code. Upon executing int3 instruction we get the control back.

Jugaad Allocate memory using mmap2 system call. void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); length Length of the mapping. prot Desired memory protection of the mapping. flags mapping specific flags.

Jugaad Sample shellcode "\x31\xdb" // xor %ebx,%ebx # Zero out ebx "\xb9\x10\x27\x00\x00" // mov $0x2710,%ecx # memory size 10000 bytes "\xba\x07\x00\x00\x00" // mov $0x7,%edx # page permissions R W E = 7 "\xbe\x22\x00\x00\x00" // mov $0x22,%esi #flags MAP_PRIVATE MAP_ANONYMOUS "\x31\xff" // xor %edi,%edi # Zero out edi "\x31\xed" // xor %ebp,%ebp # Zero out ebp "\xb8\xc0\x00\x00\x00" // mov $0xc0,%eax # mmap2 sys call no. 192 "\xcd\x80" // int $0x80 # s/w interrupt "\xcc"; // int3 # breakpoint interrupt

Jugaad Memory Allocation and Execution Threadification Payload (Evil code) Implementation Demo

Jugaad Clone system call wrapper. int clone(int (*fn)(void *), void *child_stack, int flags, void *arg,... /* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ ); fn Function application to execute. child_stack location of the stack used by the child process. Stack bottom (highest memory) address. flags specify what is shared between the calling process and the child process.

Jugaad Execute clone shellcode. Get the control back from the remote process in main thread by int3 instruction. The injected thread starts execution and becomes independent of the ptrace caller and the traced process main thread.

Jugaad Memory Allocation and Execution Threadification Payload (Evil code) Implementation Demo

Jugaad Custom payload. Thread aware. The payload is injected as a combined threading payload for relative addressing and jumping to thread code from the clone code. Kind of a sandwich. [CLONE_HEAD] [PAYLOAD] [CLONE_TAIL] CLONE_HEAD clone syscall. PAYLOAD The evil code. CLONE_TAIL exit syscall.

Jugaad Memory Allocation and Execution Threadification Payload (Evil code) Implementation Demo

Jugaad Shellcode mmap2, clone, exit, evil code. Shellcode Stubs for mmap2 and clone. Actual shellcode generated on the fly based on caller requirements.

Jugaad struct shellcode {unsigned char * payload, size_t psize}; struct shellcode * shellcode_mmap2(size_t length, int prot, int flags); struct shellcode * shellcode_thread(unsigned char * tpayload, size_t tpsize, void * child_stack, int flags);

Jugaad libjugaad API int create_remote_thread(pid_t pid, int stack_size, unsigned char * tpayload, size_t tpsize, int thread_flags, int mmap_prot, int mmap_flags, void * bkpaddr);

Jugaad Memory Allocation and Execution Threadification Payload (Evil code) Implementation Demo

Agenda What is Jugaad What Jugaad is not Code Injection Windows Linux Ptrace() Primer Library Injection Jugaad Conclusion

Conclusion Stealthy CreateRemoteThread now possible. Simple debugging functionality can be abused for injection purposes. Injecting library is not that stealthy, shared object name in maps file. Disable ptrace functionality in your linux boxes via SELinux/apparmor.

Project details section/projects Version 1 contains 32 bit support. Next release will include 64 bit support, library injection (possibly without the trace in maps file).

Contribution null local Chapters. null projects. null Jobs http://jobs.nullcon.net nullcon security conference http://nullcon.net Mailing list http://groups.google.com/group/null-co-in

Thanks? &. Contact aseemjakhar at gmail.com null at null.co.in I'll be around if you feel like contributing to null or if you have any queries.