Book Image

Learning Linux Binary Analysis

By : Ryan "elfmaster" O'Neill
Book Image

Learning Linux Binary Analysis

By: Ryan "elfmaster" O'Neill

Overview of this book

Learning Linux Binary Analysis is packed with knowledge and code that will teach you the inner workings of the ELF format, and the methods used by hackers and security analysts for virus analysis, binary patching, software protection and more. This book will start by taking you through UNIX/Linux object utilities, and will move on to teaching you all about the ELF specimen. You will learn about process tracing, and will explore the different types of Linux and UNIX viruses, and how you can make use of ELF Virus Technology to deal with them. The latter half of the book discusses the usage of Kprobe instrumentation for kernel hacking, code patching, and debugging. You will discover how to detect and disinfect kernel-mode rootkits, and move on to analyze static code. Finally, you will be walked through complex userspace memory infection analysis. This book will lead you into territory that is uncharted even by some experts; right into the world of the computer hacker.
Table of Contents (17 chapters)
Learning Linux Binary Analysis
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Demonstrating the code_inject tool


As we can see, our program injects and executes a shellcode that creates an executable memory mapping, where the payload program is then injected and executed:

  1. Run the host program (the one that you want to infect):

    ryan@elfmaster:~$ ./host &
    [1] 29656
    I am but a simple program, please don't infect me.
    
  2. Run code_inject and tell it to inject the program named payload into the process for the host:

    ryan@elfmaster:~$ ./code_inject `pidof host` payload
    I am the payload who has hijacked your process!
    [1]+ Done ./host
    

You may have noticed that there appears to be no traditional shellcode (byte code) in code_inject.c. That's because the uint64_t injection_code(void *) function is our shellcode. Since it is already compiled into machine instructions, we just calculated its length and passed its address to pid_write() in order to inject it into the process. This, in my opinion, is a more elegant way of doing things than the more common method of including an array...