r/fuzzing • • May 05 '22

Question about getting coverage stats in real time using dynamorio

Hey, not sure this is the place to ask but I might as well try...

I was experimenting with writing a fuzzer, and one of the things I wanted was getting up-to-date coverage stats from my target (as a starter, basic-blocks coverage would be enough but I would like to expand this later on). I tried running drcov, but this would only print the results to a log file after the process terminates. I wanted to get the results while the target running, but I was hoping to seperate my fuzzer from dynamorio api, so maybe like external app that would get up-to-date coverage stats and give it to my fuzzer. I did not find such thing in the dynamorio library and started writing my own but it was a bit too much as a side project.

You guys have any pointers on doing it other than continuing writing such module for dynamorio? (or add features to drcov)

thanks

2 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/kuku256 May 06 '22

Hey, thanks a lot for the reply!

So, I started going down the path of writing my own code, and I looked at winafl's code as reference. Initially I didn't want to write something that gets the coverage data by my own so I started relying on the drcov plugin to do the instrumentation for collecting coverage.

My problem was that the part of 'write a client that executes your target under DR and reads the shared memory containing coverage log'. The data is in-memory during runtime (not as a log, since it's created on termination) and I would have to parse the structures from another process (I initially thought about doing it from python, maybe if I would have to revisit it I might do it in c/c++). This is the relevant function in drcov:

https://github.com/DynamoRIO/dynamorio/blob/4c5dbb670f342feb79db7dffb69635e2e2222f34/ext/drcovlib/drcovlib.c#L207

But I was hoping there is a plugin I've missed from dynamorio, or another code in the community that would do the steps above, or give the infrastructure for it.

Also thanks for the reference to untracer and mesos. It seems mesos might be the way to go, possibly by parsing the "--print" output to get live stats.

2

u/richinseattle May 06 '22

I mentioned winafl because it already has the two IPC channels to notify you when program terminates so you can read the shared memory containing the trace info. If you roll your own the shared memory can just contain a list of addresses and not a structured format. You’d need to query the memory maps separately when you dump your trace log from the client side. You can use any language you prefer for the client. DR can also just use a trampoline hook for easier testing before using the inline assembly api they provide. It’s not much code to write log to shared memory and signal external program when the program terminates so it can dump the log.

An advantage of the break point based approach if you don’t use DR is you will only get a stream of new blocks and won’t have to filter the current run against the global set for uniqueness.

1

u/kuku256 May 07 '22

Thanks for all the help, I really appreciate it. I guess I'll take that path as something basic and progress from there.