Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions docs/installation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,20 @@ kafl gui -w work

# 7. How to reproduce bugs <a name="section-7"></a>
----------------------------------
kAFL includes a replay utility to rerun a specific payload against your driver:
kAFL includes a replay utility to rerun a specific payload against your driver.
`replay.cpp` uses the Windows API (`CreateFileW`, `DeviceIoControl`), therefore it has to be
built as a Windows binary and executed inside the Windows guest, not on the Linux host:

```bash
# Build and run the replay tool
cd $kAFL/docs/installation
[you compiler] replay.cpp -o replay
# Install the MinGW-w64 C++ cross-compiler
sudo apt-get install g++-mingw-w64-x86-64

# Build the replay tool on the host
cd ~/kAFL/docs/installation
x86_64-w64-mingw32-g++ replay.cpp -o replay.exe -static

# Copy replay.exe into the guest, then run it there
# Usage:
./replay <SymbolicLinkName> <PayloadFile>
replay.exe <SymbolicLinkName> <PayloadFile>
```
![Fuzz Success](fuzzing.png?raw=true)
18 changes: 17 additions & 1 deletion docs/installation/replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

char* payload = NULL;
char* output = NULL;
DWORD outputSize = 0;
DWORD byteRead = NULL;

uint32_t u32(unsigned char* data) {
Expand Down Expand Up @@ -42,6 +43,11 @@ int wmain(int argc, wchar_t* argv[]) {

payload = (char*)VirtualAlloc(NULL, ((dFileSize + 0x1000 - 1) / 0x1000) * 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
output = (char*)VirtualAlloc(NULL, BUF_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (payload == NULL || output == NULL) {
printf("Buffer alloc fail..\n");
return 0;
}
outputSize = BUF_SIZE;

if (!ReadFile(hFile, payload, (DWORD)fileSize.QuadPart, &byteRead, NULL) || byteRead != fileSize.QuadPart) {
printf("File read fail..\n");
Expand All @@ -67,11 +73,21 @@ int wmain(int argc, wchar_t* argv[]) {

char* input = &payload[start + 16];

if (outbuffer_length > outputSize) {
VirtualFree(output, 0, MEM_RELEASE);
output = (char*)VirtualAlloc(NULL, outbuffer_length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (output == NULL) {
printf("Output buffer alloc fail..\n");
return 0;
}
outputSize = outbuffer_length;
}
memset(output, 0, outputSize);

NTSTATUS res = DeviceIoControl(hDriver, ioctl_code, input, inbuffer_length, output, outbuffer_length, &byteRead, 0);
printf("IOCTL: %lx, inputLen: %lx, outputLen: %lx success: %d\n", ioctl_code & 0xffffffff, inbuffer_length & 0xffffffff, outbuffer_length & 0xffffffff, res);

start = start + inbuffer_length + 16;
memset(output, 0, BUF_SIZE);
}

system("pause");
Expand Down