Hacker Disassembling Uncovered (Second Edition) : (Draft, For Internal Usage ONLY)
Hacker Disassembling Uncovered (Second Edition) : (Draft, For Internal Usage ONLY)
Preface
I've been obsessed by computers since childhood. I specialize in reverse engineering (disas-
sembling), finding vulnerabilities (holes) in existing protection mechanisms, and developing
my own protection systems. I was inspired to write this book by a natural curiosity in
"what's under the hood" of a computer and a desire to crack something using a crowbar or
hammer (figuratively, of course). Without doing so, is it possible to understand how this
thing works? If hackers are individuals obsessed by understanding the universe, then I am a
hacker.
Hacking is a natural need of many sentient beings. They pass along the thorny path of un-
derstanding the true essence of surrounding things, bent on destruction. Just look around:
Nuclear physicists split atoms, analysts separate long molecules into lots of smaller ones,
and mathematicians actively use decomposition. And not one of them deserves reproach!
Strangely, code diggers, who try to do the same things with software, are often censured.
Are accusations against them justified? Is hacking in general, and disassembling in particu-
lar, illegal?
Preface 2
Hacking is not the same thing as vandalism. Hacking is the demonstration of natural curios-
ity and the desire to understand the surrounding world. Disassembled listings, machine com-
mands, black screens of SoftIce that are reminders of the early days of MS-DOS—all these
are interesting and captivating. Among them is the entire world of hidden mechanisms and
protection code. Do not look for them on maps; this world exists only in fragments of print-
outs, technical manuals automatically opening at the most interesting positions, and sleep-
less nights spent at the monitor.
Hackers and developers of protection mechanisms are not just opponents but also col-
leagues. If you assume that hackers are parasitic, exploiting programmers' inability to build
high-quality protection mechanisms, then you have to realize that programmers are also par-
asitic, exploiting users' inability to write programs.
Hacking and programming have much in common. Creating high-quality and reliable pro-
tection mechanisms requires low-level programming skills; the ability to work with the op-
erating system, drivers, and equipment; and knowledge of the architecture of contemporary
processors, the specific features of code generation typical for specific compilers, and the
"biology" of the libraries being used. At this level of programming, the distinction between
programming and hacking becomes so slight that I won't even try to draw a line between
them.
To develop protection mechanisms, the programmer must have at least a general idea about
the working methods and technical tools used by an opponent. To master this technical arse-
nal at a level no lower than that of the opponent is even better. Practical experience (in
cracking programs) is highly desirable because it allows the programmer to study the tactics
and strategy of the offensive party carefully, thus allowing the organization of an optimal de-
fense. It simply allows the programmer to detect and reinforce the most probable targets
against hacker attacks, concentrating on them the maximum available intellectual resources.
This means that a developer of protection mechanisms must be inspired by hacker psychol-
ogy and must start thinking like a hacker.
Thus, mastering the information-protection technology assumes mastering the cracking tech-
nology. If you don't know how protection mechanisms are cracked, are unaware of their vul-
nerabilities, and have no information about the hacker's arsenal, you won't be able to create
a strong protection mechanism that is inexpensive and easy to implement. Books about se-
curity that consider this subject exclusively from the protection point of view have the same
drawback as storage devices that can only write information—they have no practical appli-
cation.
This book is neither a manual on cracking nor a manual on antihacker protection. Such
books are already available in abundance. Rather, it contains the "travel notes" of a code
digger. You'll examine Intel's compilers, look inside the protection mechanisms of commer-
cial programs, and learn how disassemblers and debuggers work and how to work with them
expertly. If you are not so afraid that you immediately close this book and throw it away,
you'll learn many new and interesting facts.
Preface 3
Book Structure
The second edition is divided into four parts: Part I, "Introduction to Hacking Tools"; Part
II, "Basic Hacking Techniques"; Part III, "Advanced Disassembling Techniques"; and Part
IV, "Practical Code Investigation."
The book contains the following chapters:
Chapter 1 provides a brief overview of the most popular hacking tools for Windows, in-
cluding debuggers, disassemblers, decompilers, hex editors, unpackers, and dumpers. In
addition, it provides a list of must-read books, which would allow you to gain the mini-
mum level of knowledge required for jumping into the area of hacking.
Chapter 2 describes available hacking tools for UNIX and Linux.
Chapter 3 concentrates on a popular and interesting topic—emulating debuggers and
emulators, which offer practically unlimited possibilities for code diggers. In addition to
describing the most popular emulators and areas of their application, this chapter pro-
Preface 4
vides a comparative analysis of existing emulators and describes the recent technological
advances in this area.
Chapter 4 is dedicated to an overview of available assemblers, their advantages, and
their drawbacks. This topic is of special importance because a hacker that hasn't mas-
tered assembly languages is not a hacker. How can you disassemble anything if your
knowledge is limited to high-level programming languages? Special attention is paid to
the problem of choosing an assembly translator, which is crucial not only for beginners
but also for professional programmers.
Chapter 5, which opens Part II, provides an overview of protection mechanisms, their
strong and weak points, and the most common implementation errors of the existing pro-
tection mechanisms. It also provides recommendations for protection developers, which
should help you strengthen your protection without causing inconveniences for legal
users.
Chapter 6 introduces the basic techniques that hackers use to crack protection mecha-
nisms. It illustrates the basic techniques of working with a hex editor, an API spy, and a
disassembler (on the example of IDA Pro), and it provides simple and illustrative exam-
ples of practical hacking.
Chapter 7 introduces application debugging. Although this book concentrates on disas-
sembling, analysis of the disassembled listing of an entire program is often inefficient.
Debuggers are most popular hacking tools, and they often are used with disassemblers.
This chapter illustrates the techniques of efficiently locating protection mechanisms us-
ing a debugger and illustrates them with a practical example.
Chapter 8 is a logical continuation of the previous chapter, covering specific features of
debugging under UNIX and Linux. It discusses the efficient techniques of working with
one of the most powerful debuggers in the UNIX world—GDB. Special attention is
drawn to debugging binary files without symbolic information.
Chapter 9 covers the topic of kernel debugging on the example of Linice, the debugger
suitable for hacking protected applications.
Chapter 10, which concludes Part II, covers advanced debugging topics and prepares
you for serious code investigations. This chapter acquaints you with various hacking
tricks that allow more efficient hacking, including efficient techniques of working with
breakpoints, using SoftIce as a logger, using debuggers and disassemblers in combina-
tion, and quickly locating protection mechanisms within large programs.
Chapter 11 is dedicated to disassembling 32-bit PE files. It describes the PE file struc-
ture and discusses various techniques of inserting foreign code into such files. This topic
is highly important for understanding further materials provided in this book, because
the techniques of code insertion are widely used by worms, viruses, shellcode, as well as
by protection mechanisms.
Chapter 12 discusses the issues of disassembling ELF files, covers various techniques
of inserting foreign code into ELF files, and provides practical disassembling examples.
Chapter 13 covers the issues of disassembling 64-bit executable files on the example of
the AMD 64 architecture.
Preface 5