{ "cells": [ { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" }, "tags": [] }, "source": [ "# Mutation-Based Fuzzing\n", "\n", "Most [randomly generated inputs](Fuzzer.ipynb) are syntactically _invalid_ and thus are quickly rejected by the processing program. To exercise functionality beyond input processing, we must increase chances to obtain valid inputs. One such way is so-called *mutational fuzzing* – that is, introducing small changes to existing inputs that may still keep the input valid, yet exercise new behavior. We show how to create such mutations, and how to guide them towards yet uncovered code, applying central concepts from the popular AFL fuzzer." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.183206Z", "iopub.status.busy": "2024-01-18T17:14:25.182707Z", "iopub.status.idle": "2024-01-18T17:14:25.247203Z", "shell.execute_reply": "2024-01-18T17:14:25.246851Z" }, "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from bookutils import YouTubeVideo\n", "YouTubeVideo('5ROhc_42jQU')" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "skip" } }, "source": [ "**Prerequisites**\n", "\n", "* You should know how basic fuzzing works; for instance, from the [\"Fuzzing\"](Fuzzer.ipynb) chapter.\n", "* You should understand the basics of [obtaining coverage](Coverage.ipynb)." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" } }, "source": [ "## Synopsis\n", "\n", "\n", "To [use the code provided in this chapter](Importing.ipynb), write\n", "\n", "```python\n", ">>> from fuzzingbook.MutationFuzzer import \n", "```\n", "\n", "and then make use of the following features.\n", "\n", "\n", "This chapter introduces a `MutationFuzzer` class that takes a list of _seed inputs_ which are then mutated:\n", "\n", "```python\n", ">>> seed_input = \"http://www.google.com/search?q=fuzzing\"\n", ">>> mutation_fuzzer = MutationFuzzer(seed=[seed_input])\n", ">>> [mutation_fuzzer.fuzz() for i in range(10)]\n", "['http://www.google.com/search?q=fuzzing',\n", " 'http://wwBw.google.com/searh?q=fuzzing',\n", " 'http8//wswgoRogle.am/secch?qU=fuzzing',\n", " 'ittp://www.googLe.com/serch?q=fuzzingZ',\n", " 'httP://wgw.google.com/seasch?Q=fuxzanmgY',\n", " 'http://www.google.cxcom/search?q=fuzzing',\n", " 'hFttp://ww.-g\\x7fog+le.com/s%arch?q=f-uzz#ing',\n", " 'http://www\\x0egoogle.com/seaNrch?q=fuZzing',\n", " 'http//www.Ygooge.comsarch?q=fuz~Ijg',\n", " 'http8//ww.goog5le.com/sezarc?q=fuzzing']\n", "```\n", "The `MutationCoverageFuzzer` maintains a _population_ of inputs, which are then evolved in order to maximize coverage.\n", "\n", "```python\n", ">>> mutation_fuzzer = MutationCoverageFuzzer(seed=[seed_input])\n", ">>> mutation_fuzzer.runs(http_runner, trials=10000)\n", ">>> mutation_fuzzer.population[:5]\n", "['http://www.google.com/search?q=fuzzing',\n", " 'http://wwv.oogle>co/search7Eq=fuzing',\n", " 'http://wwv\\x0eOogleb>co/seakh7Eq\\x1d;fuzing',\n", " 'http://wwv\\x0eoglebkooqeakh7Eq\\x1d;fuzing',\n", " 'http://wwv\\x0eoglekol=oekh7Eq\\x1d\\x1bf~ing']\n", "```\n", "![](PICS/MutationFuzzer-synopsis-1.svg)\n", "\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Fuzzing with Mutations\n", "\n", "On November 2013, the first version of [American Fuzzy Lop](http://lcamtuf.coredump.cx/afl/) (AFL) was released. Since then, AFL has become one of the most successful fuzzing tools and comes in many flavors, e.g., [AFLFast](https://github.com/mboehme/aflfast), [AFLGo](https://github.com/aflgo/aflgo), and [AFLSmart](https://github.com/aflsmart/aflsmart) (which are discussed in this book). AFL has made fuzzing a popular choice for automated vulnerability detection. It was the first to demonstrate that vulnerabilities can be detected automatically at a large scale in many security-critical, real-world applications.\n", "\n", "![American Fuzzy Lop Command Line User Interface](PICS/afl_screen.png)\n", "
Figure 1. American Fuzzy Lop Command Line User Interface
\n", "\n", "In this chapter, we are going to introduce the basics of mutational fuzz testing; the next chapter will then further show how to direct fuzzing towards specific code goals." ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Fuzzing a URL Parser\n", "\n", "Many programs expect their inputs to come in a very specific format before they would actually process them. As an example, think of a program that accepts a URL (a Web address). The URL has to be in a valid format (i.e., the URL format) such that the program can deal with it. When fuzzing with random inputs, what are our chances to actually produce a valid URL?" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "To get deeper into the problem, let us explore what URLs are made of. A URL consists of a number of elements:\n", "\n", " scheme://netloc/path?query#fragment\n", " \n", "where\n", "\n", "* `scheme` is the protocol to be used, including `http`, `https`, `ftp`, `file`...\n", "* `netloc` is the name of the host to connect to, such as `www.google.com`\n", "* `path` is the path on that very host, such as `search`\n", "* `query` is a list of key/value pairs, such as `q=fuzzing`\n", "* `fragment` is a marker for a location in the retrieved document, such as `#result`" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "In Python, we can use the `urlparse()` function to parse and decompose a URL into its parts." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.271452Z", "iopub.status.busy": "2024-01-18T17:14:25.271233Z", "iopub.status.idle": "2024-01-18T17:14:25.273609Z", "shell.execute_reply": "2024-01-18T17:14:25.273286Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "import bookutils.setup" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.275405Z", "iopub.status.busy": "2024-01-18T17:14:25.275282Z", "iopub.status.idle": "2024-01-18T17:14:25.277143Z", "shell.execute_reply": "2024-01-18T17:14:25.276823Z" }, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from typing import Tuple, List, Callable, Set, Any" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.278816Z", "iopub.status.busy": "2024-01-18T17:14:25.278699Z", "iopub.status.idle": "2024-01-18T17:14:25.280370Z", "shell.execute_reply": "2024-01-18T17:14:25.280124Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "from urllib.parse import urlparse" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.281948Z", "iopub.status.busy": "2024-01-18T17:14:25.281846Z", "iopub.status.idle": "2024-01-18T17:14:25.283952Z", "shell.execute_reply": "2024-01-18T17:14:25.283678Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "ParseResult(scheme='http', netloc='www.google.com', path='/search', params='', query='q=fuzzing', fragment='')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "urlparse(\"http://www.google.com/search?q=fuzzing\")" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "source": [ "We see how the result encodes the individual parts of the URL in different attributes." ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "Let us now assume we have a program that takes a URL as input. To simplify things, we won't let it do very much; we simply have it check the passed URL for validity. If the URL is valid, it returns True; otherwise, it raises an exception." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.285835Z", "iopub.status.busy": "2024-01-18T17:14:25.285701Z", "iopub.status.idle": "2024-01-18T17:14:25.288071Z", "shell.execute_reply": "2024-01-18T17:14:25.287722Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "def http_program(url: str) -> bool:\n", " supported_schemes = [\"http\", \"https\"]\n", " result = urlparse(url)\n", " if result.scheme not in supported_schemes:\n", " raise ValueError(\"Scheme must be one of \" + \n", " repr(supported_schemes))\n", " if result.netloc == '':\n", " raise ValueError(\"Host must be non-empty\")\n", "\n", " # Do something with the URL\n", " return True" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "Let us now go and fuzz `http_program()`. To fuzz, we use the full range of printable ASCII characters, such that `:`, `/`, and lowercase letters are included." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.289766Z", "iopub.status.busy": "2024-01-18T17:14:25.289639Z", "iopub.status.idle": "2024-01-18T17:14:25.372467Z", "shell.execute_reply": "2024-01-18T17:14:25.372113Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from Fuzzer import fuzzer" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.374511Z", "iopub.status.busy": "2024-01-18T17:14:25.374369Z", "iopub.status.idle": "2024-01-18T17:14:25.376771Z", "shell.execute_reply": "2024-01-18T17:14:25.376492Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "'\"N&+slk%h\\x7fyp5o\\'@[3(rW*M5W]tMFPU4\\\\P@tz%[X?uo\\\\1?b4T;1bDeYtHx #UJ5w}pMmPodJM,_'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fuzzer(char_start=32, char_range=96)" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "Let's try to fuzz with 1000 random inputs and see whether we have some success." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.378354Z", "iopub.status.busy": "2024-01-18T17:14:25.378252Z", "iopub.status.idle": "2024-01-18T17:14:25.404657Z", "shell.execute_reply": "2024-01-18T17:14:25.404372Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "for i in range(1000):\n", " try:\n", " url = fuzzer()\n", " result = http_program(url)\n", " print(\"Success!\")\n", " except ValueError:\n", " pass" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "What are the chances of actually getting a valid URL? We need our string to start with `\"http://\"` or `\"https://\"`. Let's take the `\"http://\"` case first. These are seven very specific characters we need to start with. The chance of producing these seven characters randomly (with a character range of 96 different characters) is $1 : 96^7$, or" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.406546Z", "iopub.status.busy": "2024-01-18T17:14:25.406451Z", "iopub.status.idle": "2024-01-18T17:14:25.409149Z", "shell.execute_reply": "2024-01-18T17:14:25.408856Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "75144747810816" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "96 ** 7" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "The odds of producing a `\"https://\"` prefix are even worse, at $1 : 96^8$:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.411176Z", "iopub.status.busy": "2024-01-18T17:14:25.411009Z", "iopub.status.idle": "2024-01-18T17:14:25.413657Z", "shell.execute_reply": "2024-01-18T17:14:25.413353Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "7213895789838336" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "96 ** 8" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "source": [ "which gives us a total chance of" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.415395Z", "iopub.status.busy": "2024-01-18T17:14:25.415279Z", "iopub.status.idle": "2024-01-18T17:14:25.417537Z", "shell.execute_reply": "2024-01-18T17:14:25.417187Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "1.344627131107667e-14" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "likelihood = 1 / (96 ** 7) + 1 / (96 ** 8)\n", "likelihood" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "And this is the number of runs (on average) we'd need to produce a valid URL scheme:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.419292Z", "iopub.status.busy": "2024-01-18T17:14:25.419171Z", "iopub.status.idle": "2024-01-18T17:14:25.421364Z", "shell.execute_reply": "2024-01-18T17:14:25.421078Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "74370059689055.02" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 / likelihood" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "Let's measure how long one run of `http_program()` takes:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.423203Z", "iopub.status.busy": "2024-01-18T17:14:25.423080Z", "iopub.status.idle": "2024-01-18T17:14:25.424818Z", "shell.execute_reply": "2024-01-18T17:14:25.424469Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from Timer import Timer" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.426434Z", "iopub.status.busy": "2024-01-18T17:14:25.426315Z", "iopub.status.idle": "2024-01-18T17:14:25.453841Z", "shell.execute_reply": "2024-01-18T17:14:25.453550Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "2.451037500577513e-05" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "trials = 1000\n", "with Timer() as t:\n", " for i in range(trials):\n", " try:\n", " url = fuzzer()\n", " result = http_program(url)\n", " print(\"Success!\")\n", " except ValueError:\n", " pass\n", "\n", "duration_per_run_in_seconds = t.elapsed_time() / trials\n", "duration_per_run_in_seconds" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "That's pretty fast, isn't it? Unfortunately, we have a lot of runs to cover." ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.455824Z", "iopub.status.busy": "2024-01-18T17:14:25.455627Z", "iopub.status.idle": "2024-01-18T17:14:25.458517Z", "shell.execute_reply": "2024-01-18T17:14:25.457986Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "1822838052.1806188" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "seconds_until_success = duration_per_run_in_seconds * (1 / likelihood)\n", "seconds_until_success" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "source": [ "which translates into" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.460570Z", "iopub.status.busy": "2024-01-18T17:14:25.460430Z", "iopub.status.idle": "2024-01-18T17:14:25.463022Z", "shell.execute_reply": "2024-01-18T17:14:25.462730Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "57.76225226825294" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hours_until_success = seconds_until_success / 3600\n", "days_until_success = hours_until_success / 24\n", "years_until_success = days_until_success / 365.25\n", "years_until_success" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "source": [ "Even if we parallelize things a lot, we're still in for months to years of waiting. And that's for getting _one_ successful run that will get deeper into `http_program()`." ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "What basic fuzzing will do well is to test `urlparse()`, and if there is an error in this parsing function, it has good chances of uncovering it. But as long as we cannot produce a valid input, we are out of luck in reaching any deeper functionality." ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Mutating Inputs\n", "\n", "The alternative to generating random strings from scratch is to start with a given _valid_ input, and then to subsequently _mutate_ it. A _mutation_ in this context is a simple string manipulation - say, inserting a (random) character, deleting a character, or flipping a bit in a character representation. This is called *mutational fuzzing* – in contrast to the _generational fuzzing_ techniques discussed earlier.\n", "\n", "Here are some mutations to get you started:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.464877Z", "iopub.status.busy": "2024-01-18T17:14:25.464630Z", "iopub.status.idle": "2024-01-18T17:14:25.466444Z", "shell.execute_reply": "2024-01-18T17:14:25.466158Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "import random" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.468342Z", "iopub.status.busy": "2024-01-18T17:14:25.468210Z", "iopub.status.idle": "2024-01-18T17:14:25.470338Z", "shell.execute_reply": "2024-01-18T17:14:25.470000Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "def delete_random_character(s: str) -> str:\n", " \"\"\"Returns s with a random character deleted\"\"\"\n", " if s == \"\":\n", " return s\n", "\n", " pos = random.randint(0, len(s) - 1)\n", " # print(\"Deleting\", repr(s[pos]), \"at\", pos)\n", " return s[:pos] + s[pos + 1:]" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.472075Z", "iopub.status.busy": "2024-01-18T17:14:25.471964Z", "iopub.status.idle": "2024-01-18T17:14:25.474089Z", "shell.execute_reply": "2024-01-18T17:14:25.473834Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "'A uick brown fox'\n", "'A quic brown fox'\n", "'A quick brown fo'\n", "'A quic brown fox'\n", "'A quick bown fox'\n", "'A quick bown fox'\n", "'A quick brown fx'\n", "'A quick brown ox'\n", "'A quick brow fox'\n", "'A quic brown fox'\n" ] } ], "source": [ "seed_input = \"A quick brown fox\"\n", "for i in range(10):\n", " x = delete_random_character(seed_input)\n", " print(repr(x))" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.476522Z", "iopub.status.busy": "2024-01-18T17:14:25.476160Z", "iopub.status.idle": "2024-01-18T17:14:25.478640Z", "shell.execute_reply": "2024-01-18T17:14:25.478340Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "def insert_random_character(s: str) -> str:\n", " \"\"\"Returns s with a random character inserted\"\"\"\n", " pos = random.randint(0, len(s))\n", " random_character = chr(random.randrange(32, 127))\n", " # print(\"Inserting\", repr(random_character), \"at\", pos)\n", " return s[:pos] + random_character + s[pos:]" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.480288Z", "iopub.status.busy": "2024-01-18T17:14:25.480138Z", "iopub.status.idle": "2024-01-18T17:14:25.482295Z", "shell.execute_reply": "2024-01-18T17:14:25.481967Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "'A quick brvown fox'\n", "'A quwick brown fox'\n", "'A qBuick brown fox'\n", "'A quick broSwn fox'\n", "'A quick brown fvox'\n", "'A quick brown 3fox'\n", "'A quick brNown fox'\n", "'A quick brow4n fox'\n", "'A quick brown fox8'\n", "'A equick brown fox'\n" ] } ], "source": [ "for i in range(10):\n", " print(repr(insert_random_character(seed_input)))" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.484112Z", "iopub.status.busy": "2024-01-18T17:14:25.483870Z", "iopub.status.idle": "2024-01-18T17:14:25.486283Z", "shell.execute_reply": "2024-01-18T17:14:25.485988Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "def flip_random_character(s):\n", " \"\"\"Returns s with a random bit flipped in a random position\"\"\"\n", " if s == \"\":\n", " return s\n", "\n", " pos = random.randint(0, len(s) - 1)\n", " c = s[pos]\n", " bit = 1 << random.randint(0, 6)\n", " new_c = chr(ord(c) ^ bit)\n", " # print(\"Flipping\", bit, \"in\", repr(c) + \", giving\", repr(new_c))\n", " return s[:pos] + new_c + s[pos + 1:]" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.487845Z", "iopub.status.busy": "2024-01-18T17:14:25.487736Z", "iopub.status.idle": "2024-01-18T17:14:25.489949Z", "shell.execute_reply": "2024-01-18T17:14:25.489590Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "'A quick bRown fox'\n", "'A quici brown fox'\n", "'A\"quick brown fox'\n", "'A quick brown$fox'\n", "'A quick bpown fox'\n", "'A quick brown!fox'\n", "'A 1uick brown fox'\n", "'@ quick brown fox'\n", "'A quic+ brown fox'\n", "'A quick bsown fox'\n" ] } ], "source": [ "for i in range(10):\n", " print(repr(flip_random_character(seed_input)))" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "Let us now create a random mutator that randomly chooses which mutation to apply:" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.492390Z", "iopub.status.busy": "2024-01-18T17:14:25.492221Z", "iopub.status.idle": "2024-01-18T17:14:25.494416Z", "shell.execute_reply": "2024-01-18T17:14:25.494069Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "def mutate(s: str) -> str:\n", " \"\"\"Return s with a random mutation applied\"\"\"\n", " mutators = [\n", " delete_random_character,\n", " insert_random_character,\n", " flip_random_character\n", " ]\n", " mutator = random.choice(mutators)\n", " # print(mutator)\n", " return mutator(s)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.496011Z", "iopub.status.busy": "2024-01-18T17:14:25.495887Z", "iopub.status.idle": "2024-01-18T17:14:25.497895Z", "shell.execute_reply": "2024-01-18T17:14:25.497660Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "'A qzuick brown fox'\n", "' quick brown fox'\n", "'A quick Brown fox'\n", "'A qMuick brown fox'\n", "'A qu_ick brown fox'\n", "'A quick bXrown fox'\n", "'A quick brown fx'\n", "'A quick!brown fox'\n", "'A! quick brown fox'\n", "'A quick brownfox'\n" ] } ], "source": [ "for i in range(10):\n", " print(repr(mutate(\"A quick brown fox\")))" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "The idea is now that _if_ we have some valid input(s) to begin with, we may create more input candidates by applying one of the above mutations. To see how this works, let's get back to URLs." ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Mutating URLs" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "source": [ "Let us now get back to our URL parsing problem. Let us create a function `is_valid_url()` that checks whether `http_program()` accepts the input." ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.499552Z", "iopub.status.busy": "2024-01-18T17:14:25.499435Z", "iopub.status.idle": "2024-01-18T17:14:25.501301Z", "shell.execute_reply": "2024-01-18T17:14:25.501032Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "def is_valid_url(url: str) -> bool:\n", " try:\n", " result = http_program(url)\n", " return True\n", " except ValueError:\n", " return False" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.502823Z", "iopub.status.busy": "2024-01-18T17:14:25.502722Z", "iopub.status.idle": "2024-01-18T17:14:25.504358Z", "shell.execute_reply": "2024-01-18T17:14:25.504076Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "assert is_valid_url(\"http://www.google.com/search?q=fuzzing\")\n", "assert not is_valid_url(\"xyzzy\")" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "Let us now apply the `mutate()` function on a given URL and see how many valid inputs we obtain." ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.506147Z", "iopub.status.busy": "2024-01-18T17:14:25.506019Z", "iopub.status.idle": "2024-01-18T17:14:25.508305Z", "shell.execute_reply": "2024-01-18T17:14:25.507933Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "seed_input = \"http://www.google.com/search?q=fuzzing\"\n", "valid_inputs = set()\n", "trials = 20\n", "\n", "for i in range(trials):\n", " inp = mutate(seed_input)\n", " if is_valid_url(inp):\n", " valid_inputs.add(inp)" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "source": [ "We can now observe that by _mutating_ the original input, we get a high proportion of valid inputs:" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.510191Z", "iopub.status.busy": "2024-01-18T17:14:25.510008Z", "iopub.status.idle": "2024-01-18T17:14:25.512347Z", "shell.execute_reply": "2024-01-18T17:14:25.512058Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "0.8" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(valid_inputs) / trials" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "What are the odds of also producing a `https:` prefix by mutating a `http:` sample seed input? We have to insert ($1 : 3$) the right character `'s'` ($1 : 96$) into the correct position ($1 : l$), where $l$ is the length of our seed input. This means that on average, we need this many runs:" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.513989Z", "iopub.status.busy": "2024-01-18T17:14:25.513874Z", "iopub.status.idle": "2024-01-18T17:14:25.516058Z", "shell.execute_reply": "2024-01-18T17:14:25.515807Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "10944" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "trials = 3 * 96 * len(seed_input)\n", "trials" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "We can actually afford this. Let's try:" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.517678Z", "iopub.status.busy": "2024-01-18T17:14:25.517529Z", "iopub.status.idle": "2024-01-18T17:14:25.519236Z", "shell.execute_reply": "2024-01-18T17:14:25.518972Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from Timer import Timer" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.520757Z", "iopub.status.busy": "2024-01-18T17:14:25.520644Z", "iopub.status.idle": "2024-01-18T17:14:25.528570Z", "shell.execute_reply": "2024-01-18T17:14:25.528309Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Success after 3656 trials in 0.0055189170088851824 seconds\n" ] } ], "source": [ "trials = 0\n", "with Timer() as t:\n", " while True:\n", " trials += 1\n", " inp = mutate(seed_input)\n", " if inp.startswith(\"https://\"):\n", " print(\n", " \"Success after\",\n", " trials,\n", " \"trials in\",\n", " t.elapsed_time(),\n", " \"seconds\")\n", " break" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "source": [ "Of course, if we wanted to get, say, an `\"ftp://\"` prefix, we would need more mutations and more runs – most important, though, we would need to apply _multiple_ mutations." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Multiple Mutations\n", "\n", "So far, we have only applied one single mutation on a sample string. However, we can also apply _multiple_ mutations, further changing it. What happens, for instance, if we apply, say, 20 mutations on our sample string?" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.530327Z", "iopub.status.busy": "2024-01-18T17:14:25.530203Z", "iopub.status.idle": "2024-01-18T17:14:25.531860Z", "shell.execute_reply": "2024-01-18T17:14:25.531587Z" }, "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "seed_input = \"http://www.google.com/search?q=fuzzing\"\n", "mutations = 50" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.533560Z", "iopub.status.busy": "2024-01-18T17:14:25.533236Z", "iopub.status.idle": "2024-01-18T17:14:25.535574Z", "shell.execute_reply": "2024-01-18T17:14:25.535330Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 mutations: 'http://www.google.com/search?q=fuzzing'\n", "5 mutations: 'http:/L/www.googlej.com/seaRchq=fuz:ing'\n", "10 mutations: 'http:/L/www.ggoWglej.com/seaRchqfu:in'\n", "15 mutations: 'http:/L/wwggoWglej.com/seaR3hqf,u:in'\n", "20 mutations: 'htt://wwggoVgle\"j.som/seaR3hqf,u:in'\n", "25 mutations: 'htt://fwggoVgle\"j.som/eaRd3hqf,u^:in'\n", "30 mutations: 'htv://>fwggoVgle\"j.qom/ea0Rd3hqf,u^:i'\n", "35 mutations: 'htv://>fwggozVle\"Bj.qom/eapRd[3hqf,u^:i'\n", "40 mutations: 'htv://>fwgeo6zTle\"Bj.\\'qom/eapRd[3hqf,tu^:i'\n", "45 mutations: 'htv://>fwgeo]6zTle\"BjM.\\'qom/eaR[3hqf,tu^:i'\n" ] } ], "source": [ "inp = seed_input\n", "for i in range(mutations):\n", " if i % 5 == 0:\n", " print(i, \"mutations:\", repr(inp))\n", " inp = mutate(inp)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "As you see, the original seed input is hardly recognizable anymore. By mutating the input again and again, we get a higher variety in the input." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "To implement such multiple mutations in a single package, let us introduce a `MutationFuzzer` class. It takes a seed (a list of strings) as well as a minimum and a maximum number of mutations. " ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.537538Z", "iopub.status.busy": "2024-01-18T17:14:25.537105Z", "iopub.status.idle": "2024-01-18T17:14:25.538997Z", "shell.execute_reply": "2024-01-18T17:14:25.538720Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from Fuzzer import Fuzzer" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.541238Z", "iopub.status.busy": "2024-01-18T17:14:25.541080Z", "iopub.status.idle": "2024-01-18T17:14:25.543516Z", "shell.execute_reply": "2024-01-18T17:14:25.543268Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "class MutationFuzzer(Fuzzer):\n", " \"\"\"Base class for mutational fuzzing\"\"\"\n", "\n", " def __init__(self, seed: List[str],\n", " min_mutations: int = 2,\n", " max_mutations: int = 10) -> None:\n", " \"\"\"Constructor.\n", " `seed` - a list of (input) strings to mutate.\n", " `min_mutations` - the minimum number of mutations to apply.\n", " `max_mutations` - the maximum number of mutations to apply.\n", " \"\"\"\n", " self.seed = seed\n", " self.min_mutations = min_mutations\n", " self.max_mutations = max_mutations\n", " self.reset()\n", "\n", " def reset(self) -> None:\n", " \"\"\"Set population to initial seed.\n", " To be overloaded in subclasses.\"\"\"\n", " self.population = self.seed\n", " self.seed_index = 0" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "In the following, let us develop `MutationFuzzer` further by adding more methods to it. The Python language requires us to define an entire class with all methods as a single, continuous unit; however, we would like to introduce one method after another. To avoid this problem, we use a special hack: Whenever we want to introduce a new method to some class `C`, we use the construct\n", "\n", "```python\n", "class C(C):\n", " def new_method(self, args):\n", " pass\n", "```\n", "\n", "This seems to define `C` as a subclass of itself, which would make no sense – but actually, it introduces a new `C` class as a subclass of the _old_ `C` class, and then shadowing the old `C` definition. What this gets us is a `C` class with `new_method()` as a method, which is just what we want. (`C` objects defined earlier will retain the earlier `C` definition, though, and thus must be rebuilt.)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Using this hack, we can now add a `mutate()` method that actually invokes the above `mutate()` function. Having `mutate()` as a method is useful when we want to extend a `MutationFuzzer` later." ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.545175Z", "iopub.status.busy": "2024-01-18T17:14:25.545071Z", "iopub.status.idle": "2024-01-18T17:14:25.546830Z", "shell.execute_reply": "2024-01-18T17:14:25.546594Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "class MutationFuzzer(MutationFuzzer):\n", " def mutate(self, inp: str) -> str:\n", " return mutate(inp)" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "Let's get back to our strategy, maximizing _diversity in coverage_ in our population. First, let us create a method `create_candidate()`, which randomly picks some input from our current population (`self.population`), and then applies between `min_mutations` and `max_mutations` mutation steps, returning the final result:" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.548224Z", "iopub.status.busy": "2024-01-18T17:14:25.548131Z", "iopub.status.idle": "2024-01-18T17:14:25.550073Z", "shell.execute_reply": "2024-01-18T17:14:25.549814Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "class MutationFuzzer(MutationFuzzer):\n", " def create_candidate(self) -> str:\n", " \"\"\"Create a new candidate by mutating a population member\"\"\"\n", " candidate = random.choice(self.population)\n", " trials = random.randint(self.min_mutations, self.max_mutations)\n", " for i in range(trials):\n", " candidate = self.mutate(candidate)\n", " return candidate" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "The `fuzz()` method is set to first pick the seeds; when these are gone, we mutate:" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.551606Z", "iopub.status.busy": "2024-01-18T17:14:25.551504Z", "iopub.status.idle": "2024-01-18T17:14:25.553509Z", "shell.execute_reply": "2024-01-18T17:14:25.553260Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "class MutationFuzzer(MutationFuzzer):\n", " def fuzz(self) -> str:\n", " if self.seed_index < len(self.seed):\n", " # Still seeding\n", " self.inp = self.seed[self.seed_index]\n", " self.seed_index += 1\n", " else:\n", " # Mutating\n", " self.inp = self.create_candidate()\n", " return self.inp" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Here is the `fuzz()` method in action. With every new invocation of `fuzz()`, we get another variant with multiple mutations applied. " ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.554994Z", "iopub.status.busy": "2024-01-18T17:14:25.554878Z", "iopub.status.idle": "2024-01-18T17:14:25.557250Z", "shell.execute_reply": "2024-01-18T17:14:25.556975Z" }, "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/plain": [ "'http://www.google.com/search?q=fuzzing'" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "seed_input = \"http://www.google.com/search?q=fuzzing\"\n", "mutation_fuzzer = MutationFuzzer(seed=[seed_input])\n", "mutation_fuzzer.fuzz()" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.559126Z", "iopub.status.busy": "2024-01-18T17:14:25.558988Z", "iopub.status.idle": "2024-01-18T17:14:25.561336Z", "shell.execute_reply": "2024-01-18T17:14:25.561058Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "'http://www.gogl9ecom/earch?qfuzzing'" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mutation_fuzzer.fuzz()" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.562912Z", "iopub.status.busy": "2024-01-18T17:14:25.562790Z", "iopub.status.idle": "2024-01-18T17:14:25.564953Z", "shell.execute_reply": "2024-01-18T17:14:25.564719Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "'htotq:/www.googleom/yseach?q=fzzijg'" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mutation_fuzzer.fuzz()" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "source": [ "The higher variety in inputs, though, increases the risk of having an invalid input. The key to success lies in the idea of _guiding_ these mutations – that is, _keeping those that are especially valuable._" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Guiding by Coverage\n", "\n", "To cover as much functionality as possible, one can rely on either _specified_ or _implemented_ functionality, as discussed in the [\"Coverage\"](Coverage.ipynb) chapter. For now, we will not assume that there is a specification of program behavior (although it _definitely_ would be good to have one!). We _will_ assume, though, that the program to be tested exists – and that we can leverage its structure to guide test generation.\n", "\n", "Since testing always executes the program at hand, one can always gather information about its execution – the least is the information needed to decide whether a test passes or fails. Since coverage is frequently measured as well to determine test quality, let us also assume we can retrieve coverage of a test run. The question is then: _How can we leverage coverage to guide test generation?_" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "One particularly successful idea is implemented in the popular fuzzer named [American fuzzy lop](http://lcamtuf.coredump.cx/afl/), or *AFL* for short. Just like our examples above, AFL evolves test cases that have been successful – but for AFL, \"success\" means _finding a new path through the program execution_. This way, AFL can keep on mutating inputs that so far have found new paths; and if an input finds another path, it will be retained as well." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Let us build such a strategy. We start with introducing a `Runner` class that captures the coverage for a given function. First, a `FunctionRunner` class:" ] }, { "cell_type": "code", "execution_count": 44, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.566642Z", "iopub.status.busy": "2024-01-18T17:14:25.566526Z", "iopub.status.idle": "2024-01-18T17:14:25.568091Z", "shell.execute_reply": "2024-01-18T17:14:25.567845Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from Fuzzer import Runner" ] }, { "cell_type": "code", "execution_count": 45, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.569535Z", "iopub.status.busy": "2024-01-18T17:14:25.569451Z", "iopub.status.idle": "2024-01-18T17:14:25.572019Z", "shell.execute_reply": "2024-01-18T17:14:25.571740Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "class FunctionRunner(Runner):\n", " def __init__(self, function: Callable) -> None:\n", " \"\"\"Initialize. `function` is a function to be executed\"\"\"\n", " self.function = function\n", "\n", " def run_function(self, inp: str) -> Any:\n", " return self.function(inp)\n", "\n", " def run(self, inp: str) -> Tuple[Any, str]:\n", " try:\n", " result = self.run_function(inp)\n", " outcome = self.PASS\n", " except Exception:\n", " result = None\n", " outcome = self.FAIL\n", "\n", " return result, outcome" ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.573569Z", "iopub.status.busy": "2024-01-18T17:14:25.573451Z", "iopub.status.idle": "2024-01-18T17:14:25.575722Z", "shell.execute_reply": "2024-01-18T17:14:25.575351Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "(True, 'PASS')" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "http_runner = FunctionRunner(http_program)\n", "http_runner.run(\"https://foo.bar/\")" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "We can now extend the `FunctionRunner` class such that it also measures coverage. After invoking `run()`, the `coverage()` method returns the coverage achieved in the last run." ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.578378Z", "iopub.status.busy": "2024-01-18T17:14:25.578206Z", "iopub.status.idle": "2024-01-18T17:14:25.894243Z", "shell.execute_reply": "2024-01-18T17:14:25.893868Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from Coverage import Coverage, population_coverage, Location" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.896307Z", "iopub.status.busy": "2024-01-18T17:14:25.896138Z", "iopub.status.idle": "2024-01-18T17:14:25.898669Z", "shell.execute_reply": "2024-01-18T17:14:25.898416Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "class FunctionCoverageRunner(FunctionRunner):\n", " def run_function(self, inp: str) -> Any:\n", " with Coverage() as cov:\n", " try:\n", " result = super().run_function(inp)\n", " except Exception as exc:\n", " self._coverage = cov.coverage()\n", " raise exc\n", "\n", " self._coverage = cov.coverage()\n", " return result\n", "\n", " def coverage(self) -> Set[Location]:\n", " return self._coverage" ] }, { "cell_type": "code", "execution_count": 49, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.900133Z", "iopub.status.busy": "2024-01-18T17:14:25.900022Z", "iopub.status.idle": "2024-01-18T17:14:25.902464Z", "shell.execute_reply": "2024-01-18T17:14:25.902197Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "(True, 'PASS')" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "http_runner = FunctionCoverageRunner(http_program)\n", "http_runner.run(\"https://foo.bar/\")" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Here are the first five locations covered: " ] }, { "cell_type": "code", "execution_count": 50, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.904288Z", "iopub.status.busy": "2024-01-18T17:14:25.904168Z", "iopub.status.idle": "2024-01-18T17:14:25.906179Z", "shell.execute_reply": "2024-01-18T17:14:25.905855Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[('http_program', 3), ('urlparse', 394), ('urlparse', 400), ('_noop', 104), ('urlsplit', 460)]\n" ] } ], "source": [ "print(list(http_runner.coverage())[:5])" ] }, { "cell_type": "markdown", "metadata": { "run_control": {}, "slideshow": { "slide_type": "subslide" } }, "source": [ "Now for the main class. We maintain the population and a set of coverages already achieved (`coverages_seen`). The `fuzz()` helper function takes an input and runs the given `function()` on it. If its coverage is new (i.e. not in `coverages_seen`), the input is added to `population` and the coverage to `coverages_seen`." ] }, { "cell_type": "code", "execution_count": 51, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:25.907872Z", "iopub.status.busy": "2024-01-18T17:14:25.907756Z", "iopub.status.idle": "2024-01-18T17:14:25.910362Z", "shell.execute_reply": "2024-01-18T17:14:25.910102Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "class MutationCoverageFuzzer(MutationFuzzer):\n", " \"\"\"Fuzz with mutated inputs based on coverage\"\"\"\n", "\n", " def reset(self) -> None:\n", " super().reset()\n", " self.coverages_seen: Set[frozenset] = set()\n", " # Now empty; we fill this with seed in the first fuzz runs\n", " self.population = []\n", "\n", " def run(self, runner: FunctionCoverageRunner) -> Any: # type: ignore\n", " \"\"\"Run function(inp) while tracking coverage.\n", " If we reach new coverage,\n", " add inp to population and its coverage to population_coverage\n", " \"\"\"\n", " result, outcome = super().run(runner)\n", " new_coverage = frozenset(runner.coverage())\n", " if outcome == Runner.PASS and new_coverage not in self.coverages_seen:\n", " # We have new coverage\n", " self.population.append(self.inp)\n", " self.coverages_seen.add(new_coverage)\n", "\n", " return result" ] }, { "cell_type": "markdown", "metadata": { "run_control": {}, "slideshow": { "slide_type": "subslide" } }, "source": [ "Let us now put this to use:" ] }, { "cell_type": "code", "execution_count": 52, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:25.911859Z", "iopub.status.busy": "2024-01-18T17:14:25.911749Z", "iopub.status.idle": "2024-01-18T17:14:26.628028Z", "shell.execute_reply": "2024-01-18T17:14:26.627727Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "['http://www.google.com/search?q=fuzzing',\n", " 'http://www.goog.com/search;q=fuzzilng',\n", " 'http://ww.6goog\\x0eoomosearch;/q=f}zzilng',\n", " 'http://uv.Lboo.comoseakrch;q=fuzilng',\n", " 'http://ww.6goog\\x0eo/mosarch;/q=f}z{il~g',\n", " 'http://www.googme.com/sear#h?q=fuzzing',\n", " 'http://www.oogcom/sa3rchq=fuzlnv|',\n", " 'http://ww.6goog*./mosarch;/q=f}Zz{ilel~g',\n", " 'http://uv.Lboo.comoseakch;q=fuzilng',\n", " 'http://www.goom^e.2com/s?ear#h?q=fuzzing',\n", " 'http://hwww.coole.com+search?R=fuzzig',\n", " 'http://ww.6g7oog*./mosarch; #/q;f}Zz{ilel~gL',\n", " \"http://ww.6'oog*R./mosarcx;/q=}Zz{ilel;~g\",\n", " 'http://www.goofme.com/sear#h?q=fuzzi*yng',\n", " \"http://sw.6'oog*R/msa'rcx;/qw?}Zz{ileRl;~g\",\n", " \"http://sw.6'oog*R/msa'rsx;/qw?}Zz{ileRUl;~g\",\n", " \"http://sw.6'oog*R/msa'rsx;qw?}Zz{ileRU;~g\",\n", " 'http://wgw.gooBm^e.2com/s?&eir#h?q=]fuzzing',\n", " \"http://sw.6'ooM*R/mDa'rsx;w?}Zz{ileU+~g\",\n", " \"http://sw.6L'ooM*R/mKD'rwx;w?}Z~{ileU#zg\",\n", " 'http://ww6g7ooVg:./mosarc; #/q;f}ZzF{ielW~gL',\n", " \"http://Jsw.6L'oM*R/mKD'r3w;w?~{ileU#zg\",\n", " \"http://sw.6'oog*R/msa'rsx;/qw?}Z#z{ileRYUl;~g\",\n", " \"http://sw6'oog*V/msa'rsx;/w\\x7f}Z#zileRUl;~g\",\n", " \"http://sw6'oog*/msa'rsx;/g\\x7fp}Z#zileRUl;~g\"]" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "seed_input = \"http://www.google.com/search?q=fuzzing\"\n", "mutation_fuzzer = MutationCoverageFuzzer(seed=[seed_input])\n", "mutation_fuzzer.runs(http_runner, trials=10000)\n", "mutation_fuzzer.population" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "Success! In our population, _each and every input_ now is valid and has a different coverage, coming from various combinations of schemes, paths, queries, and fragments." ] }, { "cell_type": "code", "execution_count": 53, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:26.629695Z", "iopub.status.busy": "2024-01-18T17:14:26.629584Z", "iopub.status.idle": "2024-01-18T17:14:26.632755Z", "shell.execute_reply": "2024-01-18T17:14:26.632449Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "all_coverage, cumulative_coverage = population_coverage(\n", " mutation_fuzzer.population, http_program)" ] }, { "cell_type": "code", "execution_count": 54, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:26.634189Z", "iopub.status.busy": "2024-01-18T17:14:26.634104Z", "iopub.status.idle": "2024-01-18T17:14:26.635771Z", "shell.execute_reply": "2024-01-18T17:14:26.635517Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "import matplotlib.pyplot as plt # type: ignore" ] }, { "cell_type": "code", "execution_count": 55, "metadata": { "button": false, "execution": { "iopub.execute_input": "2024-01-18T17:14:26.637184Z", "iopub.status.busy": "2024-01-18T17:14:26.637104Z", "iopub.status.idle": "2024-01-18T17:14:26.746285Z", "shell.execute_reply": "2024-01-18T17:14:26.745920Z" }, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAHHCAYAA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VJr22effYYWLVrAzs4Obm5uGDJkCK5fv661T+fOndG4cWOcOHECHTt2hL29PWbOnAkA+O6779C7d28olUooFAoEBQXh/fffR0lJSZnHX7VqFerUqQM7Ozu0bt0aBw4cQOfOndG5c2et/QoKCjB79mzUrVsXCoUCfn5+ePvtt7We55N8/fXXmufk4eGBV155BX/99ZfW84mKigIAtGrVCpIkPXE8w+PGF8yZMweSJGltkyQJ48ePx+eff45GjRpBoVAgLi6u3OOq73/hwgVERkbC2dkZ7u7uePPNN5Gfn6+17/r169GlSxd4eXlBoVCgYcOGWL16dZljBgQEoE+fPti1axdatmwJOzs7/Pe//wUA7N69Gx06dICrqyscHR3RoEEDzeuoVtFzv23bNgQEBCAoKKhMDeqWsO+++67c5602efJkuLu7Qwih2TZhwgRIkoQVK1Zott24cQOSJGme76NjbkaMGIFVq1YBKD3/6q9HrV27VvO706pVK/z2229PrA8ANmzYAEmSsH//fowdOxZeXl6oVasWAODq1asYO3YsGjRoADs7O7i7u2PQoEG4cuVKuceIj4/H5MmT4enpCQcHBwwYMAC3bt3S2lcIgfnz56NWrVqwt7fH888/j7Nnz5Zb2+XLlzFo0CC4ubnB3t4ebdq0KfPP0L59+yBJEjZv3oy5c+eiZs2acHJywksvvYSsrCwUFBRg4sSJ8PLygqOjI1599dUK/Z49+jvx8Nimp53nESNGwNHREZcvX0b37t3h4OAApVKJefPmab0X1LXv27dP6/66vv6bNm1CixYt4OTkBGdnZ4SGhmL58uVPfY5UOWy5IXz//feoU6cO2rVrV6H9R44ciY0bN+Kll17CW2+9haNHjyImJgbnz5/H1q1bAQCDBw/G8OHD8dtvv6FVq1aa+169ehVHjhzBBx98oNn273//G++99x4iIyMxcuRI3Lp1CytXrkTHjh1x6tQprVaNjIwM9OzZE0OGDMErr7wCb29vAKV/uB0dHTF58mQ4Ojril19+waxZs5Cdna31WKtXr8b48eMRHh6OSZMm4cqVK3jhhRdQo0YNzYcFUNrS0a9fPxw8eBCjR49GSEgI/vjjDyxbtgwXL17Etm3bnniONmzYgFdffRWtWrVCTEwMbty4geXLlyM+Pl7znN555x00aNAAa9euxbx58xAYGFjuh3Rl/fLLL9i8eTPGjx8PDw+Ppw68jIyMREBAAGJiYnDkyBGsWLECd+/exSeffKLZZ/Xq1WjUqBH69esHKysrfP/99xg7dixUKhXGjRundbzExEQMHToUY8aMwahRo9CgQQOcPXsWffr0QZMmTTBv3jwoFApcunQJ8fHxmvvpcu4PHTqE5557rtzn4+LigqCgIMTHx2PSpEmPfd7h4eFYtmwZzp49i8aNGwMADhw4AAsLCxw4cADR0dGabQDQsWPHco8zZswYpKamYvfu3fj000/L3eeLL75ATk4OxowZA0mSsHjxYrz44ou4fPlyhVohxo4dC09PT8yaNQv37t0DUNq1eejQIQwZMgS1atXClStXsHr1anTu3Bnnzp0r07I5YcIE1KhRA7Nnz8aVK1cQGxuL8ePH46uvvtLsM2vWLMyfPx+9evVCr169cPLkSXTr1g2FhYVax7px4wbatWuHvLw8REdHw93dHRs3bkS/fv2wZcsWDBgwQGv/mJgY2NnZYfr06bh06RJWrlwJa2trWFhY4O7du5gzZw6OHDmCDRs2IDAwELNmzXrqOanKeS4pKUGPHj3Qpk0bLF68GHFxcZg9ezaKi4sxb948nR7zSa//7t27MXToUHTt2hWLFi0CAJw/fx7x8fFa/ziSHgmq1rKysgQA0b9//wrtn5CQIACIkSNHam2fMmWKACB++eUXzXEVCoV46623tPZbvHixkCRJXL16VQghxJUrV4SlpaX497//rbXfH3/8IaysrLS2d+rUSQAQa9asKVNXXl5emW1jxowR9vb2Ij8/XwghREFBgXB3dxetWrUSRUVFmv02bNggAIhOnTpptn366afCwsJCHDhwQOuYa9asEQBEfHz8Y89RYWGh8PLyEo0bNxb379/XbP/hhx8EADFr1izNtvXr1wsA4rfffnvs8dSioqKEv79/me2zZ88Wj/4qAxAWFhbi7NmzZfYHIGbPnl3m/v369dPab+zYsQKAOH36tGZbeee5e/fuok6dOlrb/P39BQARFxentX3ZsmUCgLh169Zjn2dFz31RUZGQJKnM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VdKWqJiYla50gXNWrUKHf2Yn21BCUlJWm1DFy6dAkqlUrTqvX999+joKAA27dv1/rP+ElddOWxsLBA165d0bVrVyxduhQLFizAO++8g7179yIiIqLC597KygpBQUFlXueHpaSkoGnTpk+tSR1adu/ejd9++w3Tp08HUDp4ePXq1VAqlXBwcECLFi2eeJyqdFlV1pYtWxAVFYUlS5ZotuXn51d6pmv1+zMpKUmrVePWrVtlgqS/vz8SExPLHEPdFVzZ97qxqFQqXL58Wetvz8WLFwFA875Xt/o8ej7L+7170utvY2ODvn37om/fvlCpVBg7diz++9//4r333ivTmkxVx24pwttvvw0HBweMHDkSN27cKHN7cnKy5pLFXr16AQBiY2O19lH/l927d2+t7YMHD0Zqair+7//+D6dPn9bqkgKAF198EZaWlpg7d26Z/6qEEMjIyHhq/er/0h6+f2FhIT766COt/Vq2bAl3d3esW7dOqy//888/L/NHOzIyEn/99RfWrVtX5vHu37+vuVKlPC1btoSXlxfWrFmjdTnrzp07cf78+TLnqKKCgoKQlZWF33//XbMtLS1Nc4VaVakvY1VbuXIlAKBnz54Ayj/PWVlZWL9+fYUf486dO2W2NWvWDAA050qXc9+2bVscP3683MfKyspCcnJyha4CDAwMRM2aNbFs2TIUFRWhffv2AEpDT3JyMrZs2YI2bdpojdUqj3reGUMvofEwS0vLMr87K1eu1Kll4WERERGwtrbGypUrtY776O88UPr34NixY5quZ6B0/p21a9ciICBApzFfcvnwww813wsh8OGHH8La2hpdu3YFUBrQLC0tNWOy1B79+wI8/vV/9O+YhYWF5p+pik4tQbphyw0hKCgIX3zxBQYPHoyQkBCtGYoPHTqEr7/+WjP/StOmTREVFYW1a9dquoOOHTuGjRs34oUXXtBqEQFK//g5OTlhypQpsLS0xMCBA8s89vz58zFjxgzNZdlOTk5ISUnB1q1bMXr0aEyZMuWJ9bdr1w41atRAVFQUoqOjIUkSPv300zJ/8G1sbDBnzhxMmDABXbp0QWRkJK5cuYINGzYgKChI67+uf/7zn9i8eTP+9a9/Ye/evWjfvj1KSk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yckJu3fvxv37pR/SrVq1QnBwsF6LM2epfw8mVnIwMRERkV7pHG4yMjLQtWtX1K9fH7169UJaWhoA4PXXX8dbb72l9wLNVfrfg4l9OJiYiIhIr3QON5MmTYK1tTWuXbsGe3t7zfbBgwcjLi5Or8WZM80EfhxMTEREpFc6j7n56aefsGvXLtSqVUtre7169XgpuA7S2S1FRERkEDq33Ny7d0+rxUbtzp07UCh41U9FpbFbioiIyCB0Djfh4eGa5RcAQJIkqFQqLF68GM8//7xeizNnHFBMRERkGDp3Sy1evBhdu3bF8ePHUVhYiLfffhtnz57FnTt3EB8fb4gazU5hsQq3czmBHxERkSHo3HLTuHFjXLx4ER06dED//v1x7949vPjiizh16hSCgoIMUaPZuZGdDyEAG0sLuNnbyF0OERGRWdG55QYAXFxc8M477+i7lmpDvWCmjwsn8CMiItK3SoWbzMxMHDt2DDdv3oRKpdK6bfjw4XopzJxxMDEREZHh6Bxuvv/+ewwbNgy5ublwdnaGJD1oeZAkieGmAtI0g4kZboiIiPRN5zE3b731Fl577TXk5uYiMzMTd+/e1XzduXPHEDWaHfUcN76uvFKKiIhI33QON3/99Reio6PLneuGKib170UzfdlyQ0REpHc6h5vu3bvj+PHjhqil2lB3S/lyjhsiIiK903nMTe/evTF16lScO3cOoaGhsLa21rq9X79+eivOXD0IN2y5ISIi0jedw82oUaMAAPPmzStzmyRJKCkpqXpVZqyguOTBBH4MN0RERHqnc7h59NJv0s2NrNJgY2NlATcHTuBHRESkbzqPuaGqUc9x4+tiq3UZPREREelHhVpuVqxYgdGjR8PW1hYrVqx44r7R0dF6KcxccbwNERGRYVUo3CxbtgzDhg2Dra0tli1b9tj9JEliuHmKNK4GTkREZFAVCjcpKSnlfk+649ILREREhsUxN0aWmsnZiYmIiAypQi03kydPrvABly5dWuliqoP07NKWG64rRUREZBgVCjenTp2q0MF49c/Tpf3dcsNuKSIiIsOoULjZu3evoeuoFvKLSpBxrxAABxQTEREZCsfcGNGN7NJWG4WVBVztrZ+yNxEREVUGw40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w4cP4448/DPMkiKhC2HJDRBXi7++P9PR03LhxA/3794ckSTh79iwGDhwIX1/fp95/6tSpmD17NoKCgtCsWTOsX78eCQkJ+Pzzz41QPbBq1SrUq1cPISEhWLZsGe7evYvXXnsNABAWFgZ7e3vMnDkT0dHROHr0KDZs2KB1/4CAAKSkpCAhIQG1atWCk5MTvvzyS5SUlGju/9lnn8HOzu6Jl7ITkeGx5YaIKmzfvn1o1aoVbG1tcezYMdSqVatCwQYAoqOjMXnyZLz11lsIDQ1FXFwctm/fjnr16hm46lILFy7EwoUL0bRpUxw8eBDbt2/XjBFyc3PDZ599hh07diA0NBRffvllmUvRBw4ciB49euD555+Hp6cnvvzyS7i6umLdunVo3749mjRpgj179uD777+v0BVYRGQ4nKGYiMzalStXEBgYiFOnTj12SQciMi9suSEiIiKzwnBDREREZoXdUkRERGRW2HJDREREZoXhhoiIiMwKww0RERGZFYYbIiIiMisMN0RERGRWGG6IiIjIrDDcEBERkVlhuCEiIiKzwnBDREREZuX/Aem7iNwlxpCvAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt.plot(cumulative_coverage)\n", "plt.title('Coverage of urlparse() with random inputs')\n", "plt.xlabel('# of inputs')\n", "plt.ylabel('lines covered');" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "fragment" } }, "source": [ "The nice thing about this strategy is that, applied to larger programs, it will happily explore one path after the other – covering functionality after functionality. All that is needed is a means to capture the coverage." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Synopsis\n", "\n", "This chapter introduces a `MutationFuzzer` class that takes a list of _seed inputs_ which are then mutated:" ] }, { "cell_type": "code", "execution_count": 56, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:26.748082Z", "iopub.status.busy": "2024-01-18T17:14:26.747955Z", "iopub.status.idle": "2024-01-18T17:14:26.750813Z", "shell.execute_reply": "2024-01-18T17:14:26.750510Z" }, "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/plain": [ "['http://www.google.com/search?q=fuzzing',\n", " 'http://wwBw.google.com/searh?q=fuzzing',\n", " 'http8//wswgoRogle.am/secch?qU=fuzzing',\n", " 'ittp://www.googLe.com/serch?q=fuzzingZ',\n", " 'httP://wgw.google.com/seasch?Q=fuxzanmgY',\n", " 'http://www.google.cxcom/search?q=fuzzing',\n", " 'hFttp://ww.-g\\x7fog+le.com/s%arch?q=f-uzz#ing',\n", " 'http://www\\x0egoogle.com/seaNrch?q=fuZzing',\n", " 'http//www.Ygooge.comsarch?q=fuz~Ijg',\n", " 'http8//ww.goog5le.com/sezarc?q=fuzzing']" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "seed_input = \"http://www.google.com/search?q=fuzzing\"\n", "mutation_fuzzer = MutationFuzzer(seed=[seed_input])\n", "[mutation_fuzzer.fuzz() for i in range(10)]" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "The `MutationCoverageFuzzer` maintains a _population_ of inputs, which are then evolved in order to maximize coverage." ] }, { "cell_type": "code", "execution_count": 57, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:26.752355Z", "iopub.status.busy": "2024-01-18T17:14:26.752256Z", "iopub.status.idle": "2024-01-18T17:14:27.465316Z", "shell.execute_reply": "2024-01-18T17:14:27.465029Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "['http://www.google.com/search?q=fuzzing',\n", " 'http://wwv.oogle>co/search7Eq=fuzing',\n", " 'http://wwv\\x0eOogleb>co/seakh7Eq\\x1d;fuzing',\n", " 'http://wwv\\x0eoglebkooqeakh7Eq\\x1d;fuzing',\n", " 'http://wwv\\x0eoglekol=oekh7Eq\\x1d\\x1bf~ing']" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mutation_fuzzer = MutationCoverageFuzzer(seed=[seed_input])\n", "mutation_fuzzer.runs(http_runner, trials=10000)\n", "mutation_fuzzer.population[:5]" ] }, { "cell_type": "code", "execution_count": 58, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:27.466943Z", "iopub.status.busy": "2024-01-18T17:14:27.466819Z", "iopub.status.idle": "2024-01-18T17:14:27.468395Z", "shell.execute_reply": "2024-01-18T17:14:27.468152Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "# ignore\n", "from ClassDiagram import display_class_hierarchy" ] }, { "cell_type": "code", "execution_count": 59, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:27.469926Z", "iopub.status.busy": "2024-01-18T17:14:27.469827Z", "iopub.status.idle": "2024-01-18T17:14:27.920849Z", "shell.execute_reply": "2024-01-18T17:14:27.920493Z" }, "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "MutationCoverageFuzzer\n", "\n", "\n", "MutationCoverageFuzzer\n", "\n", "\n", "\n", "run()\n", "\n", "\n", "\n", "reset()\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "MutationFuzzer\n", "\n", "\n", "MutationFuzzer\n", "\n", "\n", "\n", "__init__()\n", "\n", "\n", "\n", "fuzz()\n", "\n", "\n", "\n", "create_candidate()\n", "\n", "\n", "\n", "mutate()\n", "\n", "\n", "\n", "reset()\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "MutationCoverageFuzzer->MutationFuzzer\n", "\n", "\n", "\n", "\n", "\n", "Fuzzer\n", "\n", "\n", "Fuzzer\n", "\n", "\n", "\n", "__init__()\n", "\n", "\n", "\n", "fuzz()\n", "\n", "\n", "\n", "run()\n", "\n", "\n", "\n", "runs()\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "MutationFuzzer->Fuzzer\n", "\n", "\n", "\n", "\n", "\n", "Legend\n", "Legend\n", "• \n", "public_method()\n", "• \n", "private_method()\n", "• \n", "overloaded_method()\n", "Hover over names to see doc\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# ignore\n", "display_class_hierarchy(MutationCoverageFuzzer,\n", " public_methods=[\n", " Fuzzer.run,\n", " Fuzzer.__init__,\n", " Fuzzer.runs,\n", " Fuzzer.fuzz,\n", " MutationFuzzer.__init__,\n", " MutationFuzzer.fuzz,\n", " MutationCoverageFuzzer.run,\n", " ],\n", " types={'Location': Location},\n", " project='fuzzingbook')" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Lessons Learned\n", "\n", "* Randomly generated inputs are frequently invalid – and thus exercise mostly input processing functionality.\n", "* Mutations from existing valid inputs have much higher chances to be valid, and thus to exercise functionality beyond input processing.\n" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Next Steps\n", "\n", "In the next chapter on [greybox fuzzing](GreyboxFuzzer.ipynb), we further extend the concept of mutation-based testing with _power schedules_ that allow spending more energy on seeds that exercise \"unlikely\" paths and seeds that are \"closer\" to a target location." ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Exercises\n" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "### Exercise 1: Fuzzing CGI decode with Mutations\n", "\n", "Apply the above _guided_ mutation-based fuzzing technique on `cgi_decode()` from the [\"Coverage\"](Coverage.ipynb) chapter. How many trials do you need until you cover all variations of `+`, `%` (valid and invalid), and regular characters?" ] }, { "cell_type": "code", "execution_count": 60, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:27.922814Z", "iopub.status.busy": "2024-01-18T17:14:27.922701Z", "iopub.status.idle": "2024-01-18T17:14:27.924667Z", "shell.execute_reply": "2024-01-18T17:14:27.924360Z" }, "run_control": {}, "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from Coverage import cgi_decode" ] }, { "cell_type": "code", "execution_count": 61, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:27.926143Z", "iopub.status.busy": "2024-01-18T17:14:27.926037Z", "iopub.status.idle": "2024-01-18T17:14:28.775067Z", "shell.execute_reply": "2024-01-18T17:14:28.774756Z" }, "run_control": {}, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "seed = [\"Hello World\"]\n", "cgi_runner = FunctionCoverageRunner(cgi_decode)\n", "m = MutationCoverageFuzzer(seed)\n", "results = m.runs(cgi_runner, 10000)" ] }, { "cell_type": "code", "execution_count": 62, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:28.776810Z", "iopub.status.busy": "2024-01-18T17:14:28.776722Z", "iopub.status.idle": "2024-01-18T17:14:28.779577Z", "shell.execute_reply": "2024-01-18T17:14:28.779241Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "['Hello World', 'he_<+llo(or" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "all_coverage, cumulative_coverage = population_coverage(\n", " m.population, cgi_decode)\n", "\n", "import matplotlib.pyplot as plt\n", "plt.plot(cumulative_coverage)\n", "plt.title('Coverage of cgi_decode() with random inputs')\n", "plt.xlabel('# of inputs')\n", "plt.ylabel('lines covered');" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "After 10,000 runs, we have managed to synthesize a `+` character and a valid `%xx` form. We can still do better." ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" }, "solution2": "hidden", "solution2_first": true }, "source": [ "### Exercise 2: Fuzzing bc with Mutations\n", "\n", "Apply the above mutation-based fuzzing technique on `bc`, as in the chapter [\"Introduction to Fuzzing\"](Fuzzer.ipynb).\n", "\n", "#### Part 1: Non-Guided Mutations\n", "\n", "Start with non-guided mutations. How many of the inputs are valid?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" }, "solution2": "hidden" }, "source": [ "**Solution.** This is just a matter of tying a `ProgramRunner` to a `MutationFuzzer`:" ] }, { "cell_type": "code", "execution_count": 65, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:28.958460Z", "iopub.status.busy": "2024-01-18T17:14:28.958315Z", "iopub.status.idle": "2024-01-18T17:14:28.962798Z", "shell.execute_reply": "2024-01-18T17:14:28.960917Z" }, "slideshow": { "slide_type": "skip" }, "solution2": "hidden" }, "outputs": [], "source": [ "from Fuzzer import ProgramRunner" ] }, { "cell_type": "code", "execution_count": 66, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:28.967373Z", "iopub.status.busy": "2024-01-18T17:14:28.967244Z", "iopub.status.idle": "2024-01-18T17:14:29.366158Z", "shell.execute_reply": "2024-01-18T17:14:29.365739Z" }, "slideshow": { "slide_type": "skip" }, "solution2": "hidden" }, "outputs": [], "source": [ "seed = [\"1 + 1\"]\n", "bc = ProgramRunner(program=\"bc\")\n", "m = MutationFuzzer(seed)\n", "outcomes = m.runs(bc, trials=100)" ] }, { "cell_type": "code", "execution_count": 67, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:29.368129Z", "iopub.status.busy": "2024-01-18T17:14:29.367997Z", "iopub.status.idle": "2024-01-18T17:14:29.370572Z", "shell.execute_reply": "2024-01-18T17:14:29.370290Z" }, "slideshow": { "slide_type": "skip" }, "solution2": "hidden" }, "outputs": [ { "data": { "text/plain": [ "[(CompletedProcess(args='bc', returncode=0, stdout='2\\n', stderr=''), 'PASS'),\n", " (CompletedProcess(args='bc', returncode=0, stdout='5\\n', stderr=''), 'PASS'),\n", " (CompletedProcess(args='bc', returncode=0, stdout='1000\\n', stderr=''),\n", " 'PASS')]" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "outcomes[:3]" ] }, { "cell_type": "code", "execution_count": 68, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:29.372262Z", "iopub.status.busy": "2024-01-18T17:14:29.372135Z", "iopub.status.idle": "2024-01-18T17:14:29.374399Z", "shell.execute_reply": "2024-01-18T17:14:29.374140Z" }, "slideshow": { "slide_type": "skip" }, "solution2": "hidden" }, "outputs": [ { "data": { "text/plain": [ "20" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sum(1 for completed_process, outcome in outcomes if completed_process.stderr == \"\")" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "#### Part 2: Guided Mutations\n", "\n", "Continue with _guided_ mutations. To this end, you will have to find a way to extract coverage from a C program such as `bc`. Proceed in these steps:\n", "\n", "First, get [GNU bc](https://www.gnu.org/software/bc/); download, say, `bc-1.07.1.tar.gz` and unpack it:" ] }, { "cell_type": "code", "execution_count": 69, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:29.376031Z", "iopub.status.busy": "2024-01-18T17:14:29.375926Z", "iopub.status.idle": "2024-01-18T17:14:30.691587Z", "shell.execute_reply": "2024-01-18T17:14:30.689809Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\r\n", " Dload Upload Total Spent Left Speed\r\n", "100 410k 100 410k 0 0 347k 0 0:00:01 0:00:01 --:--:-- 348k\r\n" ] } ], "source": [ "!curl -O mirrors.kernel.org/gnu/bc/bc-1.07.1.tar.gz" ] }, { "cell_type": "code", "execution_count": 70, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:30.700558Z", "iopub.status.busy": "2024-01-18T17:14:30.700023Z", "iopub.status.idle": "2024-01-18T17:14:30.866414Z", "shell.execute_reply": "2024-01-18T17:14:30.865180Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "!tar xfz bc-1.07.1.tar.gz" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Second, configure the package:" ] }, { "cell_type": "code", "execution_count": 71, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:30.872311Z", "iopub.status.busy": "2024-01-18T17:14:30.871884Z", "iopub.status.idle": "2024-01-18T17:14:35.218008Z", "shell.execute_reply": "2024-01-18T17:14:35.217472Z" }, "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "checking for a BSD-compatible install... /opt/homebrew/bin/ginstall -c\r\n", "checking whether build environment is sane... yes\r\n", "checking for a thread-safe mkdir -p... /opt/homebrew/bin/gmkdir -p\r\n", "checking for gawk... no\r\n", "checking for mawk... no\r\n", "checking for nawk... no\r\n", "checking for awk... awk\r\n", "checking whether make sets $(MAKE)... yes\r\n", "checking whether make supports nested variables... yes\r\n", "checking for gcc... gcc\r\n", "checking whether the C compiler works... yes\r\n", "checking for C compiler default output file name... a.out\r\n", "checking for suffix of executables... \r\n", "checking whether we are cross compiling... no\r\n", "checking for suffix of object files... o\r\n", "checking whether we are using the GNU C compiler... yes\r\n", "checking whether gcc accepts -g... yes\r\n", "checking for gcc option to accept ISO C89... none needed\r\n", "checking whether gcc understands -c and -o together... yes\r\n", "checking for style of include used by make... GNU\r\n", "checking dependency style of gcc... gcc3\r\n", "checking how to run the C preprocessor... gcc -E\r\n", "checking for grep that handles long lines and -e... /usr/bin/grep\r\n", "checking for egrep... /usr/bin/grep -E\r\n", "checking for ANSI C header files... yes\r\n", "checking for sys/types.h... yes\r\n", "checking for sys/stat.h... yes\r\n", "checking for stdlib.h... yes\r\n", "checking for string.h... yes\r\n", "checking for memory.h... yes\r\n", "checking for strings.h... yes\r\n", "checking for inttypes.h... yes\r\n", "checking for stdint.h... yes\r\n", "checking for unistd.h... yes\r\n", "checking minix/config.h usability... no\r\n", "checking minix/config.h presence... no\r\n", "checking for minix/config.h... no\r\n", "checking whether it is safe to define __EXTENSIONS__... yes\r\n", "checking for flex... flex\r\n", "checking lex output file root... lex.yy\r\n", "checking lex library... -ll\r\n", "checking whether yytext is a pointer... yes\r\n", "checking for ar... ar\r\n", "checking the archiver (ar) interface... ar\r\n", "checking for bison... bison -y\r\n", "checking for ranlib... ranlib\r\n", "checking whether make sets $(MAKE)... (cached) yes\r\n", "checking for stdarg.h... yes\r\n", "checking for stddef.h... yes\r\n", "checking for stdlib.h... (cached) yes\r\n", "checking for string.h... (cached) yes\r\n", "checking for errno.h... yes\r\n", "checking for limits.h... yes\r\n", "checking for unistd.h... (cached) yes\r\n", "checking for lib.h... no\r\n", "checking for an ANSI C-conforming const... yes\r\n", "checking for size_t... yes\r\n", "checking for ptrdiff_t... yes\r\n", "checking for vprintf... yes\r\n", "checking for _doprnt... no\r\n", "checking for isgraph... yes\r\n", "checking for setvbuf... yes\r\n", "checking for fstat... yes\r\n", "checking for strtol... yes\r\n", "Adding GCC specific compile flags.\r\n", "checking that generated files are newer than configure... done\r\n", "configure: creating ./config.status\r\n", "config.status: creating Makefile\r\n", "config.status: creating bc/Makefile\r\n", "config.status: creating dc/Makefile\r\n", "config.status: creating lib/Makefile\r\n", "config.status: creating doc/Makefile\r\n", "config.status: creating doc/texi-ver.incl\r\n", "config.status: creating config.h\r\n", "config.status: executing depfiles commands\r\n" ] } ], "source": [ "!cd bc-1.07.1; ./configure" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Third, compile the package with special flags:" ] }, { "cell_type": "code", "execution_count": 72, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:35.220818Z", "iopub.status.busy": "2024-01-18T17:14:35.220601Z", "iopub.status.idle": "2024-01-18T17:14:37.508290Z", "shell.execute_reply": "2024-01-18T17:14:37.507873Z" }, "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Applications/Xcode.app/Contents/Developer/usr/bin/make all-recursive\r\n", "Making all in lib\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT getopt.o -MD -MP -MF .deps/getopt.Tpo -c -o getopt.o getopt.c\r\n", "\u001b[1mgetopt.c:348:28: \u001b[0m\u001b[0;1;35mwarning: \u001b[0m\u001b[1mpassing arguments to 'getenv'\r\n", " without a prototype is deprecated in all versions of C and is not\r\n", " supported in C2x [-Wdeprecated-non-prototype]\u001b[0m\r\n", " posixly_correct = getenv (\"POSIXLY_CORRECT\");\r\n", "\u001b[0;1;32m ^\r\n", "\u001b[0mIn file included from getopt.c:106:\r\n", "\u001b[1m./../h/getopt.h:144:12: \u001b[0m\u001b[0;1;35mwarning: \u001b[0m\u001b[1ma function declaration\r\n", " without a prototype is deprecated in all versions of C and is treated as a\r\n", " zero-parameter prototype in C2x, conflicting with a subsequent definition\r\n", " [-Wdeprecated-non-prototype]\u001b[0m\r\n", "extern int getopt ();\r\n", "\u001b[0;1;32m ^\r\n", "\u001b[0m\u001b[1mgetopt.c:1135:1: \u001b[0m\u001b[0;1;30mnote: \u001b[0mconflicting prototype is here\u001b[0m\r\n", "getopt (int argc, char *const *argv, const char *optstring)\r\n", "\u001b[0;1;32m^\r\n", "\u001b[0m2 warnings generated.\r\n", "mv -f .deps/getopt.Tpo .deps/getopt.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT getopt1.o -MD -MP -MF .deps/getopt1.Tpo -c -o getopt1.o getopt1.c\r\n", "mv -f .deps/getopt1.Tpo .deps/getopt1.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT vfprintf.o -MD -MP -MF .deps/vfprintf.Tpo -c -o vfprintf.o vfprintf.c\r\n", "mv -f .deps/vfprintf.Tpo .deps/vfprintf.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT number.o -MD -MP -MF .deps/number.Tpo -c -o number.o number.c\r\n", "mv -f .deps/number.Tpo .deps/number.Po\r\n", "rm -f libbc.a\r\n", "ar cru libbc.a getopt.o getopt1.o vfprintf.o number.o \r\n", "ranlib libbc.a\r\n", "Making all in bc\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c\r\n", "In file included from main.c:34:\r\n", "\u001b[1m./../h/getopt.h:144:12: \u001b[0m\u001b[0;1;35mwarning: \u001b[0m\u001b[1ma function declaration\r\n", " without a prototype is deprecated in all versions of C and is treated as a\r\n", " zero-parameter prototype in C2x, conflicting with a previous declaration\r\n", " [-Wdeprecated-non-prototype]\u001b[0m\r\n", "extern int getopt ();\r\n", "\u001b[0;1;32m ^\r\n", "\u001b[0m\u001b[1m/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/unistd.h:509:6: \u001b[0m\u001b[0;1;30mnote: \u001b[0m\r\n", " conflicting prototype is here\u001b[0m\r\n", "int getopt(int, char * const [], const char *) __DARWIN_ALIAS(getopt);\r\n", "\u001b[0;1;32m ^\r\n", "\u001b[0m1 warning generated.\r\n", "mv -f .deps/main.Tpo .deps/main.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT bc.o -MD -MP -MF .deps/bc.Tpo -c -o bc.o bc.c\r\n", "mv -f .deps/bc.Tpo .deps/bc.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT scan.o -MD -MP -MF .deps/scan.Tpo -c -o scan.o scan.c\r\n", "mv -f .deps/scan.Tpo .deps/scan.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT execute.o -MD -MP -MF .deps/execute.Tpo -c -o execute.o execute.c\r\n", "mv -f .deps/execute.Tpo .deps/execute.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT load.o -MD -MP -MF .deps/load.Tpo -c -o load.o load.c\r\n", "mv -f .deps/load.Tpo .deps/load.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT storage.o -MD -MP -MF .deps/storage.Tpo -c -o storage.o storage.c\r\n", "mv -f .deps/storage.Tpo .deps/storage.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT util.o -MD -MP -MF .deps/util.Tpo -c -o util.o util.c\r\n", "mv -f .deps/util.Tpo .deps/util.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT warranty.o -MD -MP -MF .deps/warranty.Tpo -c -o warranty.o warranty.c\r\n", "\u001b[1mwarranty.c:56:1: \u001b[0m\u001b[0;1;35mwarning: \u001b[0m\u001b[1ma function definition without a\r\n", " prototype is deprecated in all versions of C and is not supported in C2x\r\n", " [-Wdeprecated-non-prototype]\u001b[0m\r\n", "warranty(prefix)\r\n", "\u001b[0;1;32m^\r\n", "\u001b[0m1 warning generated.\r\n", "mv -f .deps/warranty.Tpo .deps/warranty.Po\r\n", "echo '{0}' > libmath.h\r\n", "/Applications/Xcode.app/Contents/Developer/usr/bin/make global.o\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT global.o -MD -MP -MF .deps/global.Tpo -c -o global.o global.c\r\n", "mv -f .deps/global.Tpo .deps/global.Po\r\n", "gcc -g -O2 -Wall -funsigned-char --coverage -o libmath.h -o fbc main.o bc.o scan.o execute.o load.o storage.o util.o warranty.o global.o ../lib/libbc.a -ll \r\n", "./fbc -c ./libmath.b libmath.h\r\n", "./fix-libmath_h\r\n", "2655\r\n", "2793\r\n", "rm -f ./fbc ./global.o\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT global.o -MD -MP -MF .deps/global.Tpo -c -o global.o global.c\r\n", "mv -f .deps/global.Tpo .deps/global.Po\r\n", "gcc -g -O2 -Wall -funsigned-char --coverage -o bc main.o bc.o scan.o execute.o load.o storage.o util.o global.o warranty.o ../lib/libbc.a -ll \r\n", "Making all in dc\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I./.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT dc.o -MD -MP -MF .deps/dc.Tpo -c -o dc.o dc.c\r\n", "mv -f .deps/dc.Tpo .deps/dc.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I./.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT misc.o -MD -MP -MF .deps/misc.Tpo -c -o misc.o misc.c\r\n", "mv -f .deps/misc.Tpo .deps/misc.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I./.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT eval.o -MD -MP -MF .deps/eval.Tpo -c -o eval.o eval.c\r\n", "mv -f .deps/eval.Tpo .deps/eval.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I./.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT stack.o -MD -MP -MF .deps/stack.Tpo -c -o stack.o stack.c\r\n", "mv -f .deps/stack.Tpo .deps/stack.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I./.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT array.o -MD -MP -MF .deps/array.Tpo -c -o array.o array.c\r\n", "mv -f .deps/array.Tpo .deps/array.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I./.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT numeric.o -MD -MP -MF .deps/numeric.Tpo -c -o numeric.o numeric.c\r\n", "\u001b[1mnumeric.c:576:1: \u001b[0m\u001b[0;1;35mwarning: \u001b[0m\u001b[1ma function definition without a\r\n", " prototype is deprecated in all versions of C and is not supported in C2x\r\n", " [-Wdeprecated-non-prototype]\u001b[0m\r\n", "out_char (ch)\r\n", "\u001b[0;1;32m^\r\n", "\u001b[0m1 warning generated.\r\n", "mv -f .deps/numeric.Tpo .deps/numeric.Po\r\n", "gcc -DHAVE_CONFIG_H -I. -I.. -I./.. -I./../h -g -O2 -Wall -funsigned-char --coverage -MT string.o -MD -MP -MF .deps/string.Tpo -c -o string.o string.c\r\n", "mv -f .deps/string.Tpo .deps/string.Po\r\n", "gcc -g -O2 -Wall -funsigned-char --coverage -o dc dc.o misc.o eval.o stack.o array.o numeric.o string.o ../lib/libbc.a \r\n", "Making all in doc\r\n", "restore=: && backupdir=\".am$$\" && \\\r\n", "\tam__cwd=`pwd` && CDPATH=\"${ZSH_VERSION+.}:\" && cd . && \\\r\n", "\trm -rf $backupdir && mkdir $backupdir && \\\r\n", "\tif (makeinfo --no-split --version) >/dev/null 2>&1; then \\\r\n", "\t for f in bc.info bc.info-[0-9] bc.info-[0-9][0-9] bc.i[0-9] bc.i[0-9][0-9]; do \\\r\n", "\t if test -f $f; then mv $f $backupdir; restore=mv; else :; fi; \\\r\n", "\t done; \\\r\n", "\telse :; fi && \\\r\n", "\tcd \"$am__cwd\"; \\\r\n", "\tif makeinfo --no-split -I . \\\r\n", "\t -o bc.info bc.texi; \\\r\n", "\tthen \\\r\n", "\t rc=0; \\\r\n", "\t CDPATH=\"${ZSH_VERSION+.}:\" && cd .; \\\r\n", "\telse \\\r\n", "\t rc=$?; \\\r\n", "\t CDPATH=\"${ZSH_VERSION+.}:\" && cd . && \\\r\n", "\t $restore $backupdir/* `echo \"./bc.info\" | sed 's|[^/]*$||'`; \\\r\n", "\tfi; \\\r\n", "\trm -rf $backupdir; exit $rc\r\n", "/bin/sh: makeinfo: command not found\r\n", "make[3]: *** [bc.info] Error 127\r\n", "make[2]: *** [all-recursive] Error 1\r\n", "make[1]: *** [all] Error 2\r\n" ] } ], "source": [ "!cd bc-1.07.1; make CFLAGS=\"--coverage\"" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "The file `bc/bc` should now be executable..." ] }, { "cell_type": "code", "execution_count": 73, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:37.510452Z", "iopub.status.busy": "2024-01-18T17:14:37.510307Z", "iopub.status.idle": "2024-01-18T17:14:37.789361Z", "shell.execute_reply": "2024-01-18T17:14:37.786774Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4\r\n" ] } ], "source": [ "!cd bc-1.07.1/bc; echo 2 + 2 | ./bc" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "...and you should be able to run the `gcov` program to retrieve coverage information." ] }, { "cell_type": "code", "execution_count": 74, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:37.800332Z", "iopub.status.busy": "2024-01-18T17:14:37.799848Z", "iopub.status.idle": "2024-01-18T17:14:37.953766Z", "shell.execute_reply": "2024-01-18T17:14:37.952407Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "File 'main.c'\r\n", "Lines executed:52.55% of 137\r\n", "Creating 'main.c.gcov'\r\n", "\r\n" ] } ], "source": [ "!cd bc-1.07.1/bc; gcov main.c" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "As sketched in the [\"Coverage\" chapter](Coverage.ipynb), the file [bc-1.07.1/bc/main.c.gcov](bc-1.07.1/bc/main.c.gcov) now holds the coverage information for `bc.c`. Each line is prefixed with the number of times it was executed. `#####` means zero times; `-` means non-executable line." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Parse the GCOV file for `bc` and create a `coverage` set, as in `FunctionCoverageRunner`. Make this a `ProgramCoverageRunner` class that would be constructed with a list of source files (`bc.c`, `main.c`, `load.c`) to run `gcov` on." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "When you're done, don't forget to clean up:" ] }, { "cell_type": "code", "execution_count": 75, "metadata": { "execution": { "iopub.execute_input": "2024-01-18T17:14:37.969918Z", "iopub.status.busy": "2024-01-18T17:14:37.969645Z", "iopub.status.idle": "2024-01-18T17:14:38.129284Z", "shell.execute_reply": "2024-01-18T17:14:38.128087Z" }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "!rm -fr bc-1.07.1 bc-1.07.1.tar.gz" ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "### Exercise 3\n", "\n", "In this [blog post](https://lcamtuf.blogspot.com/2014/08/binary-fuzzing-strategies-what-works.html), the author of _American Fuzzy Lop_ (AFL), a very popular mutation-based fuzzer discusses the efficiency of various mutation operators. Implement four of them and evaluate their efficiency as in the examples above." ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "### Exercise 4\n", "\n", "When adding a new element to the list of candidates, AFL does actually not compare the _coverage_, but adds an element if it exercises a new _branch_. Using branch coverage from the exercises of the [\"Coverage\"](Coverage.ipynb) chapter, implement this \"branch\" strategy and compare it against the \"coverage\" strategy, above." ] }, { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "subslide" } }, "source": [ "### Exercise 5\n", "\n", "Design and implement a system that will gather a population of URLs from the Web. Can you achieve a higher coverage with these samples? What if you use them as initial population for further mutation?" ] } ], "metadata": { "ipub": { "bibliography": "fuzzingbook.bib", "toc": true }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.2" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": true, "title_cell": "", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true }, "toc-autonumbering": false }, "nbformat": 4, "nbformat_minor": 4 }