• Stars
    star
    405
  • Rank 106,656 (Top 3 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Binary coverage tool without binary modification for Windows

Bag of MesosBag of MesosBag of MesosBag of MesosBag of MesosBag of MesosBag of MesosBag of MesosBag of MesosBag of MesosBag of MesosBag of MesosBag of Mesos

Summary

Mesos is a tool to gather binary code coverage on all user-land Windows targets without need for source or recompilation. It also provides an automatic mechanism to save a full minidump of a process if it crashes under mesos.

Mesos is technically just a really fast debugger, capable of handling tens of millions of breakpoints. Using this debugger, we apply breakpoints to every single basic block in a program. These breakpoints are removed as they are hit. Thus, mesos converges to 0-cost coverage as gathering coverage only has a cost the first time the basic block is hit.

Why?

This is effectively the successor of my 5+ year old Chrome IPC fuzzer. It doesn't have any fuzz components in it, but it is a high-performance debugger. This debugger can apply millions of breakpoints to gather coverage, and handle thousands of breakpoints per second to modify memory to inject inputs.

This strategy has worked out well for me historically and still is my go-to tooling for fuzzing targets on live systems.

Out of the box it can be used to gather simple code coverage but it's designed to be easily modified to add fast breakpoint handlers to inject inputs. For example, put a breakpoint after NtReadFile() returns and modify the buffer in flight. I used this in Chrome to modify inbound IPC traffic in the browser.

Features

Code coverage

code coverage

Automatic full minidump saving

Crash being saved

IDA Coloring

IDA gettin colored up

Quick Usage Guide

Set %PATH% such that idat64.exe is in it:

path %PATH%;"C:\Program Files\IDA 7.2"

Generate mesos (the first time will be slow):

powershell .\offline_meso.ps1 <pid>
python generate_mesos.py process_ida

Gather coverage on target!

cargo build --release
target\release\mesos.exe <pid>

Applying 1.6 million breakpoints? No big deal.

C:\dev\mesos>target\release\mesos.exe 13828
mesos  is 64-bit: true
target is 64-bit: true
[      0.003783] Applied       5629 breakpoints (      5629 total breakpoints) notepad.exe
[      0.028071] Applied      61334 breakpoints (     66963 total breakpoints) ntdll.dll
[      0.035298] Applied      25289 breakpoints (     92252 total breakpoints) kernel32.dll
[      0.058815] Applied      55611 breakpoints (    147863 total breakpoints) kernelbase.dll
...
[      0.667417] Applied      11504 breakpoints (   1466344 total breakpoints) oleacc.dll
[      0.676151] Applied      19557 breakpoints (   1485901 total breakpoints) textinputframework.dll
[      0.705431] Applied      66650 breakpoints (   1552551 total breakpoints) coreuicomponents.dll
[      0.717276] Applied      25202 breakpoints (   1577753 total breakpoints) coremessaging.dll
[      0.720487] Applied       7557 breakpoints (   1585310 total breakpoints) ntmarta.dll
[      0.732045] Applied      28569 breakpoints (   1613879 total breakpoints) iertutil.dll

API

Currently this tool has a debugger lib you can easily bring in and start using to make custom debuggers. However this API is not finalized yet. I suggest not building anything using it yet as it may change very quickly. Once this message is removed it's probably stable :)

Performance

  • We can register (request breakpoints to be at module load) about ~6 million/second
  • We can apply them (actually install the breakpoints into the target at about ~3 million/second
  • We can clear breakpoints at about 15 million/second
  • We can hit and handle about 10k breakpoints/second

Given breakpoints are cleared as they're hit for coverage, that means you can observe 10k new blocks per second. Once you've hit a breakpoint they no longer have a performance cost!

C:\dev\mesos\examples\benchmark>cargo run --release
    Finished release [optimized + debuginfo] target(s) in 0.03s
     Running `target\release\benchmark.exe`
mesos  is 64-bit: true
target is 64-bit: true
Registered    1000000 breakpoints in   0.162230 seconds |  6164072.8 / second
Applied       1000000 breakpoints in   0.321347 seconds |  3111897.0 / second
Cleared       1000000 breakpoints in   0.067024 seconds | 14920028.6 / second
Hit            100000 breakpoints in  10.066440 seconds |     9934.0 / second

Usage

To use mesos there are 3 major steps. First, the modules of a running process are saved. Second, these modules are loaded in IDA which then outputs a list of all basic blocks into the meso format. And finally, mesos is run against a target process to gather coverage!

Creating meso_deps.zip

This step is the first thing we have to do. We create a ZIP file containing all of the modules loaded into a given PID.

This script requires no internet and is designed to be easily dropped onto new VMs so mesos can be generated for your target application. It depends on PowerShell v5.0 or later which is installed by default on Windows 10 and Windows Server 2016.

Run, with <pid> replaced with the process ID you want to gather coverage on:

C:\dev\mesos>powershell .\offline_meso.ps1 8484
Powershell is 64-bit: True
Target     is 64-bit: True

C:\dev\mesos>

Optionally you can supply -OutputZip <zipfile> to change the output zip file name

This will create a meso_deps.zip that if you look at contains all of the modules used in the process you ran the script targeting.

Example output:

C:\dev\mesos>powershell .\offline_meso.ps1 8484 -OutputZip testing.zip
Powershell is 64-bit: True                                                                                                                                         Target     is 64-bit: True                                                                                                                                                                                                                                                                                                            C:\dev\mesos>powershell Expand-Archive testing.zip -DestinationPath example                                                                                        
C:\dev\mesos>powershell Get-ChildItem example -rec -File -Name
cache\c_\program files\common files\microsoft shared\ink\tiptsf.dll
cache\c_\program files\intel\optaneshellextensions\iastorafsserviceapi.dll
cache\c_\program files\widcomm\bluetooth software\btmmhook.dll
cache\c_\program files (x86)\common files\adobe\coresyncextension\coresync_x64.dll
...

Generating meso files

To generate meso files we operate on the meso_deps.zip we created in the last step. It doesn't matter where this zip came from. This allows the zip to have come from a VM that the PowerShell script was run on.

Basic usage is:

python generate_mesos.py process_ida

This will use the meso_deps.zip file as an input, and use IDA to process all executables in the zip file and figure out where their basic blocks are.

This will create a cache folder with a bunch of files in it. These files are named based on the module name, the modules TimeDateStamp in the PE header, and the ImageSize field in the PE header. This is what DLLs are uniqued by in the PDB symbol store, so it should be good enough for us here too.

You'll see there are files with no extension (these are the original binaries), there are files with .meso extensions (the breakpoint lists), and .i64 files (the cached IDA database for the original binary).

Symbol resolution

There is no limitation on what can make these meso files. The quality of the symbol resolution depends on the tool you used to generate and it's ability to resolve symbols. For example with IDA if you have public/private symbols your _NT_SYMBOL_PATH should be configured correctly.

More advanced usage

Check the programs usage for the most recent usage. But there are _whitelist and _blacklist options that allow you to use a list of strings to filter the amount of mesos generated.

This is helpful as coverage outside of your target module is probably not relevant and just introduces overheads and unnecessary processing.

C:\dev\mesos>python generate_mesos.py
Usage:
    generate_mesos.py process_ida
        Processes all files in the meso_deps.zip file

    generate_mesos.py process_ida_whitelist <str 1> <str 2> <str ...>
        Processes files only containing one of the strings provided

    generate_mesos.py process_ida_blacklist <str 1> <str 2> <str ...>
        Processes files all files except for those containing one of the provided strings

Examples:

    python generate_mesos.py process_ida_whitelist system32
        Only processes files in `system32`

    python generate_mesos.py process_ida_blacklist ntdll.dll
        Process all files except for `ntdll.dll`

Path requirements for process_ida_*: must have `idat64.exe` in your PATH

Example usage

C:\dev\mesos>python generate_mesos.py process_ida_whitelist system32
Processing cache/c_/windows/system32/advapi32.dll
Processing cache/c_/windows/system32/bcryptprimitives.dll
Processing cache/c_/windows/system32/cfgmgr32.dll
...
Processing cache/c_/windows/system32/user32.dll
Processing cache/c_/windows/system32/uxtheme.dll
Processing cache/c_/windows/system32/win32u.dll
Processing cache/c_/windows/system32/windows.storage.dll
Processing cache/c_/windows/system32/wintypes.dll

Meso usage

Now we're onto the actual debugger. We've created meso files to tell it where to put breakpoints in each module.

First we need to build it with Rust!

cargo build --release

And then we can simply run it with a PID!

target\release\mesos.exe <pid>

Command-line options

Currently there are few options to mesos, run mesos without arguments to get the most recent list.

C:\dev\mesos>target\release\mesos.exe
Usage: mesos.exe <pid> [--freq | --verbose | --print] <explicit meso file 1> <explicit meso file ...>
    --freq               - Treats all breakpoints as frequency breakpoints
    --verbose            - Enables verbose prints for debugging
    --print              - Prints breakpoint info on every single breakpoint
    [explicit meso file] - Load a specific meso file regardless of loaded modules

Standard usage: mesos.exe <pid>

Example usage

C:\dev\mesos>target\release\mesos.exe 13828
mesos  is 64-bit: true
target is 64-bit: true
[      0.004033] Applied       5629 breakpoints (      5629 total breakpoints) notepad.exe
[      0.029248] Applied      61334 breakpoints (     66963 total breakpoints) ntdll.dll
[      0.037032] Applied      25289 breakpoints (     92252 total breakpoints) kernel32.dll
[      0.062844] Applied      55611 breakpoints (    147863 total breakpoints) kernelbase.dll
...
[      0.739059] Applied      66650 breakpoints (   1552551 total breakpoints) coreuicomponents.dll
[      0.750266] Applied      25202 breakpoints (   1577753 total breakpoints) coremessaging.dll
[      0.754485] Applied       7557 breakpoints (   1585310 total breakpoints) ntmarta.dll
[      0.766119] Applied      28569 breakpoints (   1613879 total breakpoints) iertutil.dll
...
[     23.544097] Removed 5968 breakpoints in imm32.dll
[     23.551529] Syncing code coverage database...
[     23.675103] Sync complete (169694 total unique coverage entries)
Detached from process 13828

Why not use cargo run?

When running in cargo run the Ctrl+C handler does not work correctly, and does not allow us to detach from the target program cleanly.

Limitations

Since this relies on a tool (IDA) to identify blocks, if the tool incorrectly identifies a block it could result in us inserting a breakpoint over data. Further it's possible to miss coverage if a block is not correctly found.

Why doesn't it do more?

Well. It really just allows fast breakpoints. Feel free to rip it apart and add your own hooks to functions. It could easily be used to fuzz things :)

Why IDA?

I tried a bunch of tools and IDA was the only one that seemed to work well. Binja probably would also work well but I don't have it installed and I'm not familiar with the API. I have a coworker who wrote a plugin for it and that'll probably get pull requested in soon.

The meso files are just simple files, anyone can generate them from any tool

Technical Details

Minidump autogenned filenames

The generated minidump filenames are designed to give a high-level of glance value at crashes. It includes things like the exception type, faulting address, and rough classification of the bug.

Currently if it's an access violation we apply the following classification:

  • Determine the access type (read, write, execute)
    • For reads the filename contains: "read"
    • For writes the filename contains: "WRITE"
    • For execute the filename contains: "DEP"
  • Determine if it's a non-canonical 64-bit address
    • For non-canonical addresses the filename contains: NONCANON
  • Otherwise determine if it's a NULL dereference (within 32 KiB +- of NULL)
    • Will put "null" in the filename
  • Otherwise it's considered a non-null deref and "HIGH" appears in the filename

It's intended that more severe things are in all caps to give higher glance value of prioritizing which crash dumps to look into more.

Example minidump filename for chrome:

crash_c0000005_chrome_child.dll+0x2c915c0_WRITE_null.dmp

Meso file format

Coming soon (once it's stable)

More Repositories

1

orange_slice

A research kernel and hypervisor attempting to get fully deterministic emulation with minimum performance cost
Rust
506
star
2

chocolate_milk

Pure Rust x86_64 bootloader and kernel
Rust
478
star
3

applepie

A hypervisor for fuzzing built with WHVP and Bochs
C++
361
star
4

mempeek

A command line tool that resembles a debugger as well as Cheat Engine, to search for values in memory
Rust
217
star
5

fzero_fuzzer

A fast Rust-based safe and thead-friendly grammar-based fuzz generator
Rust
208
star
6

elfloader

An architecture-agnostic ELF file flattener for shellcode
Rust
207
star
7

falkervisor_grilled_cheese

C
168
star
8

cookie_dough

A fuzzing introspection tool
Rust
161
star
9

proc_mem_ida_loader

A /proc/mem IDA loader to snapshot a running process
Python
149
star
10

fuzz_with_emus

Why fuzzing with emulators is amazing
Rust
129
star
11

nginx_shitpost

Nginx 0-day on latest nginx
C
116
star
12

rv32i_jit

A super simple RV32i JIT, designed for ease of understanding and modification
C
76
star
13

lemonade

A debugger for Linux in Rust
Rust
76
star
14

falkervisor_beta

Assembly
75
star
15

basic_mutator

About as basic of a mutator as you can get, but it does the trick in most situations
Rust
55
star
16

slime_tree

Worst Android kernel fuzzer
Rust
43
star
17

falkhash

Exotic Shitty Hash Maybe
C
43
star
18

guifuzz

A GUI fuzzing application set up to fuzz calc.exe right now
Rust
36
star
19

riscv

A div-less, mul-less, atomic-less `rv64i` compiler toolchain using purely clang, musl, and compiler-rt
C
27
star
20

whylol

Shhh
Rust
27
star
21

adventures_in_fuzzing

Here's the slides and audio for a talk I did at NYU on the 13th of November 2018
27
star
22

init

A super simple /sbin/init for Linux which allows running one and only one program
Rust
22
star
23

vectorized_mmu

Snapshot of the vectorized MMU that lines up with the vectorized MMU blog
Rust
22
star
24

rust_mips_nt4

Rust development environment for MIPS on NT4
Rust
19
star
25

aflbench

An AFL scaling benchmarking tool
Python
18
star
26

flounder

Flounder is an old corpus collector I wrote, but it still works. Just need a Bing API key
Python
18
star
27

pdblister

Faster version of `symchk /om` for generating PDB manifests of offline machines
Rust
18
star
28

gamozolabs.github.io

Apparently this maybe blogs or something?
Ruby
16
star
29

fuzzyneural

A neural network using fuzzing-style feedback rather than back-propagation
Rust
16
star
30

vectorized_emulation_recon_2019

Gave a talk on Vectorized emulation at Recon Montreal 2019, here are the slides
16
star
31

cuddly_kangaroo

A static website generator that embeds all images as base64, and thus can be used with a single resource.
Rust
15
star
32

snuffles

A high-performance graphics API designed mainly for data visualization
Rust
15
star
33

hellscape

Playground for testing feedback
Assembly
14
star
34

helicopter_game

This is uhh, a "clone" of the helicopter game
Rust
13
star
35

canon_pixma_mx492

Reverse engineering project on stream
Rust
13
star
36

coverage_highlight

A very simple coverage highlighter for VIM
Python
12
star
37

freetype_harness

Definitely not for fuzzing
Rust
11
star
38

qemu_chrooter

Take a QEMU binary, copy the dependencies into a chroot
Rust
11
star
39

bridengroom

Windows Heap Loggin'
Rust
11
star
40

statusbar

A DWM status that shows the MPD playing song and the current datetime in milliseconds
Rust
10
star
41

libprocmem

A simple /proc/<pid>/{mem,maps} library for Rust
Rust
9
star
42

fuzztheory

A project for simulating fuzzing such that analysis can be done on coverage/feedback/scaling mechanisms
Rust
9
star
43

safecast

Safe casting in Rust!
Rust
7
star
44

ffmpegged

Uhh, trying to make encoding actually use cores
Rust
7
star
45

coff_nm

`nm` and `addr2line` but for DI "debug-info" COFF files
Rust
7
star
46

streamwrite

Benchmarking sequential i32 stores
Rust
6
star
47

teraflopter420

A helicoptor game engine with perf
Rust
6
star
48

bochs_determinism_test

Used to run 2 Bochs instances in lockstep to verify they do the same things
C++
5
star
49

noodle

A non-procedrual Rust serialization and deserialization library
Rust
4
star
50

fork_benchmarking

I get asked about this a lot
Rust
4
star
51

lossless_compression_tutorial

An old tutorial I wrote during class about 10 years ago. It's probably bad, don't use it.
3
star
52

server_simulator_2020

Simulates servers to find the best server to run for the cost
Rust
3
star
53

OnorineAutoCandy

An automated WoW chocolate addon
Lua
3
star
54

simple_slope_viewer

A basic 3d model viewer with a fly-based model. Designed for exploring WoW collision maps
Rust
2
star
55

font_test

Font test do not use ever
Rust
2
star
56

gamlang

Some ancient programming language I thought was a good idea
C
2
star
57

wow_priest_theorycraftin

Here we use supercomputers to optimize WoW characters, why not
Rust
1
star
58

onorine_jumps

A WoW addon for helping with doing tricky jumps and exploring
Lua
1
star
59

triangle_test

Testing triangles
Rust
1
star
60

ErannaAuctions

Dumping ground for auction data harvesting
Lua
1
star
61

FishingBuddy

The FishingBuddy addon for Classic WoW, but with per-hour stat tracking
Lua
1
star
62

speculation_data

Just some random data from an observed speculative session on Kaby Lake
Gnuplot
1
star
63

wow_classic_manatick_reversing

Trying to figure out exactly how mana ticks work in WoW vanilla
Lua
1
star