Skip to content

Commit 148d94e

Browse files
committed
*.*
0 parents  commit 148d94e

File tree

197 files changed

+37356
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+37356
-0
lines changed

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required (VERSION 2.6)
2+
project (vfuzz)
3+
add_definitions(-Wall -Wextra -std=c++17 -O3 -g -DNDEBUG)
4+
add_subdirectory(libvfuzz-core)
5+
add_subdirectory(libvfuzz-runtime)
6+
add_subdirectory(examples)

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Guido Vranken
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# vfuzz
2+
3+
(previously called VrankenFuzz).
4+
5+
I don't claim superiority over other engines in performance or efficiency out of the box, but this does implement some features that I felt where lacking elsewhere.
6+
7+
## Custom generators
8+
9+
Fetch any type of data from anywhere in your harness. The single byte array input provided by AFL/libFuzzer is a crude instrument for constructing complex objects in your harness. Protobufs are used to work around this, but there is no reason to not provide multiple data streams at the engine level.
10+
11+
## Custom sensors
12+
13+
Rather than just code coverage, use any quantifier. Code coverage is quite useful for most purposes, but not always sufficient for exploring specific corner cases.
14+
15+
You can use any ```uint64_t``` value in combination with one of several conditions (value higher than previous, value lower than previous, # of unique values) (which I call Processors) to add inputs to the corpus.
16+
17+
Custom sensors should make it easy to implement fuzzing non-LLVM-based languages, provided that you can extract a coverage signal from that language's interpreter or runtime. libFuzzer's equivalent of custom sensors is "extra counters", and I and several other people used this feature to implement libFuzzer support for [go-fuzz](https://github.com/dvyukov/go-fuzz) (which in turn made Go fuzzing on [OSS-Fuzz](https://github.com/google/oss-fuzz) possible) with minimal effort.
18+
19+
The library also comes bundled with some built-in sensors that are a bridge between instrumentation and system calls and the rest of the library:
20+
21+
### kSensorBuiltinCodeCoverage
22+
23+
Add to corpus if total of unique PC's observed is higher than before.
24+
25+
### kSensorBuiltinStackDepth
26+
27+
Add to corpus if stack pointer observed is lower than before. Useful for finding stack overflows.
28+
29+
### kSensorBuiltinStackUnique
30+
31+
Add to corpus if total of unique stack pointers observed is higher than before. Useful for finding stack overflows.
32+
33+
### kSensorBuiltinIntensity
34+
35+
Add to corpus if total of non-unique PC's observed is higher than before. Useful for finding slow inputs.
36+
37+
### kSensorBuiltinAllocSingleMax
38+
39+
Add to corpus if ```malloc()``` size from a particular location is higher than before. Useful for finding heap exhaustion inputs.
40+
41+
### kSensorBuiltinAllocGlobalMax
42+
43+
Add to corpus if peak concurrent heap usage is higher than before. Useful for finding heap exhaustion inputs.
44+
45+
### kSensorBuiltinAutoCodeIntensity
46+
47+
Add to corpus if the number of times a particular PC is executed during a single run is higher than before. Useful for finding slow inputs.
48+
49+
## Components
50+
51+
The library is split into two components.
52+
53+
### libvfuzz-core
54+
55+
This implements core fuzzer functionality like corpora, dictionaries, mutators, sensors and generators and is agnostic with respect to target-specific interfaces like instrumentation. You could use this to build new fuzzer engines, experiment with features like new mutators, implement fuzzing for other languages etc.
56+
57+
### libfuzzer-runtime
58+
59+
This is a bridge between both the user and the system (including instrumentation) one one hand, and libvfuzz-core on the other hand.
60+
61+
## State of the project
62+
63+
This is alpha-grade software. I can't provide much support but PR's are very welcome. This has only been tested and used on 64 bit Linux.
64+
65+
## Compilation
66+
67+
A recent version of Clang is required.
68+
69+
From the project's top-level directory:
70+
71+
```sh
72+
mkdir build/
73+
cd build/
74+
cmake -DCMAKE_CXX_COMPILER=clang++-8 -DCMAKE_C_COMPILER=clang-8 ..
75+
make -j$(nproc)
76+
```
77+
78+
## License
79+
80+
MIT

examples/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required (VERSION 2.6)
2+
project (examples)
3+
4+
include_directories(../include/)
5+
include_directories(../libvfuzz-core/src)
6+
7+
add_executable(nlohmann nlohmann.cpp)
8+
set_target_properties(nlohmann PROPERTIES COMPILE_FLAGS -fsanitize-coverage=trace-pc-guard)
9+
set_target_properties(nlohmann PROPERTIES LINK_FLAGS -fsanitize-coverage=trace-pc-guard)
10+
target_link_libraries(nlohmann vfuzz-runtime vfuzz-core)
11+
12+
add_executable(libvfuzz-core-example libvfuzz-core-example.cpp)
13+
target_link_libraries(libvfuzz-core-example vfuzz-core)

examples/libvfuzz-core-example.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <sensor/processor/highest.h>
2+
#include <logger/consolelogger.h>
3+
#include <container/corpus/corpus.h>
4+
#include <util/random.h>
5+
#include <iostream>
6+
7+
int main(void)
8+
{
9+
using namespace vfuzz;
10+
11+
auto Rand = std::make_shared<util::Random>(0);
12+
container::InputCluster ic(Rand, 10, 10);
13+
auto corpus = std::make_shared<container::corpus::Corpus>(Rand, ic);
14+
15+
auto loggers = std::make_shared<LoggerChain>();
16+
auto consolelogger = std::make_shared<ConsoleLogger>();
17+
loggers->AddLogger(consolelogger);
18+
19+
vfuzz::sensor::ProcessorHighest p(loggers);
20+
21+
consolelogger->Start();
22+
23+
for (const auto& v : {123, 999, 3}) {
24+
p.ReceiveInput(123, v);
25+
}
26+
27+
consolelogger->Stop();
28+
29+
std::cout << "Number of new values: " << p.GetNumValues() << std::endl;
30+
31+
std::cout << "Values are: " << std::endl;
32+
p.GetValues([](const uint64_t v) {
33+
std::cout << "\t" << v << std::endl;
34+
});
35+
36+
return 0;
37+
}

examples/nlohmann.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <vfuzz/vfuzz.h>
2+
#include "nlohmann/json.hpp"
3+
4+
extern "C" void VFuzzInit(int argc, char **argv) {
5+
(void)argc;
6+
(void)argv;
7+
8+
/* Experiment with uncommenting any of the following lines. */
9+
//sensor_enable(vfuzz::kSensorBuiltinCodeCoverage);
10+
//sensor_enable(vfuzz::kSensorBuiltinStackDepth);
11+
//sensor_enable(vfuzz::kSensorBuiltinStackUnique);
12+
//sensor_enable(vfuzz::kSensorBuiltinFlowtrace);
13+
//sensor_enable(vfuzz::kSensorBuiltinIntensity);
14+
//sensor_enable(vfuzz::kSensorBuiltinAllocSingleMax);
15+
//sensor_enable(vfuzz::kSensorBuiltinAllocGlobalMax);
16+
//sensor_enable(vfuzz::kSensorBuiltinAllocUnique);
17+
//sensor_enable(vfuzz::kSensorBuiltinValueProfile);
18+
//sensor_enable(vfuzz::kSensorBuiltinFuncEnter);
19+
//sensor_enable(vfuzz::kSensorBuiltinCMPDiff);
20+
//sensor_enable(vfuzz::kSensorBuiltinAutoCodeIntensity);
21+
}
22+
23+
extern "C" void VFuzzRun(void) {
24+
vfuzz::datasource::Datasource ds;
25+
26+
const auto s = ds.Get<std::string>();
27+
try {
28+
auto j = nlohmann::json::parse(s);
29+
} catch ( ... ) {
30+
/* Experiment with uncommenting the following line.
31+
* It prevents the input getting added to the corpus
32+
* if json parsing failed */
33+
//vfuzz_discard();
34+
}
35+
}

examples/nlohmann/LICENSE.MIT

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2013-2019 Niels Lohmann
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)