Open blackcon opened 2 years ago
Create a VM overlay in a dedicated overlays folder: (Use the absolute path of windows.qcow2!) ./hAFL2/qemu-6.0.0/build/qemu-img create -f qcow2 -b windows.qcow2 overlay_0.qcow2 Run the VM overlay: ./hAFL2/qemu-6.0.0/build/x86_64-softmmu/qemu-system-x86_64 -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+intel-pt,-hypervisor,+vmx -usbdevice tablet -m 16384 -bios /root/hAFL2/OVMF_CODE-pure-efi.fd -drive file=overlay_0.qcow2 -machine q35
Click on the Capture Menu, then click on Capture Kernel.
C:\devcon.exe install CPHarness.inf root\CPHarness
PoolVNC is OK + Channel is OK: [ADDRESS]
Note
If you don't see these log lines, you need to make sure you modified the ourName variable within the CPHarness driver according to the NDIS.sys offset of the Child Partition VM as stated before (explained in the one of the previous section.)
Occured issue
bcdedit.exe
for debugging to kernel
~
~bcdedit /dbgsettings serial DEBUGPORT:2 BAUDRATE:115200~ ~bcdedit /debug on~
- Just Update Windows least Versin, and should modify miniportChannel offset at CPHarness sourcecode (and build)
Within the Child Partition VM, open a command prompt as an Administrator and execute C:\loader.exe
This will create a snapshot to which the fuzzer will return after crashes.
C:loader.exe
whithin Child Partition VM
for f in overlay_{1..X}.qcow2; do cp overlay_0.qcow2 $f; done
python3 /root/hAFL2/kAFL-Fuzzer/kafl_info.py \
-work_dir /root/work \
-vm_dir /root/hAFL_qcow2_dir \
-bios /root/hAFL2/OVMF_CODE-pure-efi.fd \
-mem 16384 \
-agent hAFL2/targets/windows_x86_64/bin/info/info.exe \
-v
ptr = (PUINT8)KernelGetProcAddress(vmbkclBaseAddress, (PCHAR)&vmbDllInitialize);
DbgPrintEx(DPFLTR_IHVDRIVER_ID, DEBUG_LEVEL, "CPHarness: DllInitialize Address: %p\n", ptr);
if (ptr)
{
//Looking for first existing "lea rax, SOMETHING" code snippet, SOMETHING should be pointing at KmclChannelList
for (int x = 0; x < 0x200; x++)
{
ptr++;
if (ptr[0] == 0x48 && ptr[1] == 0x8d && ptr[2] == 0x05 && ptr[3] == 0x3c && ptr[4] == 0x90 && ptr[5] == 0xff && ptr[6] == 0xff) // (vmbkmcl.sys in guest)
{
kmclChannelListLocation = (PVOID)((UINT64)ptr + 0xFFFFFFFF00000007 + *((PUINT32)(ptr + 3)));
DbgPrintEx(DPFLTR_IHVDRIVER_ID, DEBUG_LEVEL, "CPHarness: kmclChannelListLocation: %p\n", kmclChannelListLocation);
break;
}
}
}
LONG WPP_MAIN_CB_OFFSET = 0x130E0; // vmbkmcl.sys build 10.0.19044.1526, offset 0x130E0 ==> vmbkmcl!WPP_MAIN_CB
if (vmbkclBaseAddress)
{
//kmclChannelListLocation =poi(vmbkmcl+0x130e0+WPP_MAIN_CB_OFFSET)+0x20
kmclChannelListLocation = (PVOID)((UINT64)vmbkclBaseAddress + WPP_MAIN_CB_OFFSET); // vmbkmcl!WPP_MAIN_CB
kmclChannelListLocation = (PVOID)((UINT64)kmclChannelListLocation + 0xA0); // vmbkmcl!WPP_MAIN_CB.DeviceQueue
kmclChannelListLocation = (PVOID)(*(PUINT64)kmclChannelListLocation + 0x20); // vmbkmcl!WPP_MAIN_CB.DeviceQueue.kmclChannelListLocation
}
without hAFL2
whithin hAFL2
Execute fuzzer
python3 /root/hAFL2/kAFL-Fuzzer/kafl_fuzz.py \
-work_dir ./work \
--purge \
-vm_dir /root/hAFL_qcow2_dir \
-bios ./hAFL2/OVMF_CODE-pure-efi.fd \
-mem 16384 \
-agent /root/hAFL2/targets/windows_x86_64/bin/fuzzer/packet_sender.exe\
-p 1 \
-ip0 0xfffff80749d10000-0xfffff8054cb52000 \
--debug \
-v \
-seed_dir /root/hAFL2/kAFL-Fuzzer/seed/hv/
View Log
tail -f work/debug.log
Display kAFL-GUI
python3 hAFL2/kAFL-Fuzzer/kafl_gui.py ~/work
Sanity Check
1. Execute fuzzer * Command ``` python3 /root/hAFL2/kAFL-Fuzzer/kafl_fuzz.py \ -work_dir ./work \ --purge \ -vm_dir /root/hAFL_qcow2_dir \ -bios ./hAFL2/OVMF_CODE-pure-efi.fd \ -mem 16384 \ -agent /root/hAFL2/targets/windows_x86_64/bin/fuzzer/packet_sender.exe\ -p 1 \ -ip0 0xfffff80749d10000-0xfffff8054cb52000 \ --debug \ -v \ -seed_dir /root/hAFL2/kAFL-Fuzzer/seed/hv/ ``` * Image ![image](https://user-images.githubusercontent.com/6852711/156588482-000d40e7-92a4-40a1-b69f-88cc11745c5a.png) 2. View Log * Command: `tail -f work/debug.log` * Image ![image](https://user-images.githubusercontent.com/6852711/156588608-f3f26e6d-84cf-4647-bec9-11f23bc1b11b.png) 3. Display kAFL-GUI * Command ``` python3 hAFL2/kAFL-Fuzzer/kafl_gui.py ~/work ``` * Image ![image](https://user-images.githubusercontent.com/6852711/156588407-3bfee4ed-74f0-42f2-be4a-6fb541576ac6.png)
Sanity Check
- What the..
UINT NVSP_RNDIS_PKT_SIZE = 0x28;
pNvspRndisPkt = ExAllocatePool2(POOL_FLAG_NON_PAGED, NVSP_RNDIS_PKT_SIZE , HARNESS_POOL_TAG); // for NDIS.sys
...
status = SendPacket(pNvspRndisPkt, (UINT32)NVSP_RNDIS_PKT_SIZE , pFuzzPayload, (ULONG)fuzzPayloadSize);
UINT TARGET_PKT_SIZE = 0x40;
pNvspRndisPkt = ExAllocatePool2(POOL_FLAG_NON_PAGED, TARGET_PKT_SIZE , HARNESS_POOL_TAG); // for TARGET.sys
...
status = SendPacket(pNvspRndisPkt, (UINT32)TARGET_PKT_SIZE , pFuzzPayload, (ULONG)fuzzPayloadSize);
Run kAFL.py
tail -f ~/work/debug.log
/dev/sdb6
)
root@hafl-System-Product-Name:/# du -sh /var
173G /var
root@hafl-System-Product-Name:/var# du -sh /var/log/
170G /var/log/
root@hafl-System-Product-Name:/var/log# ll -SS
total 173792960
-rw-r----- 1 syslog adm 88837206016 3월 8 17:27 syslog
-rw-r----- 1 syslog adm 88827826176 3월 8 17:06 kern.log
-rw-r----- 1 syslog adm 277410057 3월 8 02:21 kern.log.1
root@hafl-System-Product-Name:/home/hafl# df -l Filesystem 1K-blocks Used Available Use% Mounted on udev 32859736 0 32859736 0% /dev tmpfs 6578420 1968 6576452 1% /run /dev/sdb6 199523664 15565984 173752752 9% /
Desktop Image
WinVer
kAFL hprintf Log
kAFL Debug LOG
1. install kernel as hAFL2
2. install qemu6.0.0
3. install WindowsOS as level0 on QEMU
4. Setup Level2 VM within Level1
Turn off Level2 and Execute command using powershell within Level1
Run the following command from within PowerShell:
Turn on Level1 and Configuring
bcdedit.exe
whtin Level25. Compile Necessary Binaries
Compile hAFL2’s fuzzing binaries by executing the following within bash:
Use Visual Studio to compile both drivers from within the hAFL2\drivers folder.
Within VS:
6. Optimizing the Crash Monitoring and Disabling DSE for Root Partition VM
Execute the Root Partition VM:~
In order to make the crash monitoring functionality operate faster, open PowerShell (within the root partition VM) as an Administrator and execute the following command:
Disable Driver Signature Enforcement from within an elevated command prompt (Restart the root partition VM once you're done):
7. Preparing the Root and Child Partition VMs for Fuzzing