#!/usr/bin/env dub
/+ dub.sdl:
name "android-research-exec-probe"
platforms "linux"
dflags "-betterC"
targetPath "build"
buildType "checked" {
buildOptions "optimize" "inline" "debugInfo"
}
+/
// ci: run-always
/**
Libc-only E1–E4 payload: report the real app context, argv and executable;
optionally try execve or dlopen. See ../index.md#current-target-experiments.
No ADB calls, policy changes, namespace changes or persistent child processes.
Compile with -version=ExecProbeStatic to omit dynamic-loader calls for E4.
*/
module (module) exec_probeLibc-only E1–E4 payload: report the real app context, argv and executable;
optionally try execve or dlopen. See ../index.md#current-target-experiments.
No ADB calls, policy changes, namespace changes or persistent child processes.
Compile with -version=ExecProbeStatic to omit dynamic-loader calls for E4.
exec_probe;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.errnoD header file for C99.
pubs.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html, errno.h
Source
core/stdc/errno.d
errno : (alias) exec_probe.errno = int core.stdc.errno.__errno_location() nothrow @nogc ref @trustederrno;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stdioD header file for C99 <stdio.h>
pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h
Source
core/stdc/stdio.d
stdio : (alias) exec_probe.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf, (alias) exec_probe.fflush = int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trustedfflush, (alias) exec_probe.fopen = shared(core.stdc.stdio._IO_FILE)* core.stdc.stdio.fopen(scope const(char*) filename, scope const(char*) mode) nothrow @nogcfopen, (alias) exec_probe.fclose = int core.stdc.stdio.fclose(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogcfclose, (alias) exec_probe.fgets = char* core.stdc.stdio.fgets(char* s, int n, shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogcfgets;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stringD header file for C99.
pubs.opengroup.org/onlinepubs/009695399/basedefs/string.h.html, string.h
Source
core/stdc/string.d
string : (alias) exec_probe.strcmp = int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogcstrcmp;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.unistdD header file for POSIX.
unistd : (alias) exec_probe.getuid = uint core.sys.posix.unistd.getuid() nothrow @nogc @trustedgetuid, (alias) exec_probe.getgid = uint core.sys.posix.unistd.getgid() nothrow @nogc @trustedgetgid, (alias) exec_probe.readlink = long core.sys.posix.unistd.readlink(scope const(char*), char*, ulong) nothrow @nogcreadlink, (alias) exec_probe.execve = int core.sys.posix.unistd.execve(scope const(char*), scope const(char**), scope const(char**)) nothrow @nogcexecve;
version (ExecProbeStaticExecProbeStatic) {} else
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.dlfcnD header file for POSIX.
dlfcn : (alias) exec_probe.dlopen = void* core.sys.posix.dlfcn.dlopen(scope const(char*), int) nothrow @nogcdlopen, (alias) exec_probe.dlclose = int core.sys.posix.dlfcn.dlclose(void*) nothrow @nogcdlclose, (alias) exec_probe.dlerror = char* core.sys.posix.dlfcn.dlerror() nothrow @nogcdlerror, (alias constant) exec_probe.RTLD_NOW = int core.sys.posix.dlfcn.RTLD_NOW = 2RTLD_NOW, (alias constant) exec_probe.RTLD_LOCAL = int core.sys.posix.dlfcn.RTLD_LOCAL = 0RTLD_LOCAL;
extern(C) extern __gshared char** (__gshared global) char** exec_probe.environenviron;
extern(C) int int exec_probe.main(int argc, char** argv) nothrow @nogc @systemmain(int (parameter) int argcargc, char** (parameter) char** argvargv) @system nothrow @nogc
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("uid=%u gid=%u\n", uint core.sys.posix.unistd.getuid() nothrow @nogc @trustedgetuid(), uint core.sys.posix.unistd.getgid() nothrow @nogc @trustedgetgid());
char[4096] (local variable) char[4096] bufferbuffer;
auto (local variable) shared(core.stdc.stdio._IO_FILE)* contextcontext = shared(core.stdc.stdio._IO_FILE)* core.stdc.stdio.fopen(scope const(char*) filename, scope const(char*) mode) nothrow @nogcfopen("/proc/self/attr/current", "r");
if ((local variable) shared(core.stdc.stdio._IO_FILE)* contextcontext is null)
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("context: errno=%d\n", int core.stdc.errno.__errno_location() nothrow @nogc ref @trustederrno);
else
{
if (char* core.stdc.stdio.fgets(char* s, int n, shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogcfgets((local variable) char[4096] bufferbuffer.(constant) char* char[4096].ptr = &bufferptr, cast(int) (local variable) char[4096] bufferbuffer.(constant) ulong char[4096].length = 4096LUlength, (local variable) shared(core.stdc.stdio._IO_FILE)* contextcontext) !is null)
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("context=%s\n", (local variable) char[4096] bufferbuffer.(constant) char* char[4096].ptr = &bufferptr);
int core.stdc.stdio.fclose(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogcfclose((local variable) shared(core.stdc.stdio._IO_FILE)* contextcontext);
}
const (local variable) const(long) sizesize = long core.sys.posix.unistd.readlink(scope const(char*), char*, ulong) nothrow @nogcreadlink("/proc/self/exe", (local variable) char[4096] bufferbuffer.(constant) char* char[4096].ptr = &bufferptr, (local variable) char[4096] bufferbuffer.(constant) ulong char[4096].length = 4096LUlength - 1);
if ((local variable) const(long) sizesize < 0)
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("readlink: errno=%d\n", int core.stdc.errno.__errno_location() nothrow @nogc ref @trustederrno);
else
{
(local variable) char[4096] bufferbuffer[(local variable) const(long) sizesize] = 0;
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("exe=%s\n", (local variable) char[4096] bufferbuffer.(constant) char* char[4096].ptr = &bufferptr);
}
foreach ((local variable) int ii; 0 .. (parameter) int argcargc)
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("argv[%d]=%s\n", (local variable) int ii, (parameter) char** argvargv[(local variable) int ii]);
if ((parameter) int argcargc == 3 && int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogcstrcmp((parameter) char** argvargv[1], "--exec") == 0)
{
const(char)*[2] (local variable) const(char)*[2] childArgschildArgs = [(parameter) char** argvargv[2], null];
int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trustedfflush(null);
int core.sys.posix.unistd.execve(scope const(char*), scope const(char**), scope const(char**)) nothrow @nogcexecve((parameter) char** argvargv[2], (local variable) const(char)*[2] childArgschildArgs.(constant) const(char)** const(char)*[2].ptr = &childArgsptr, cast(const(char)**) (__gshared global) char** exec_probe.environenviron);
const (local variable) const(int) errorerror = int core.stdc.errno.__errno_location() nothrow @nogc ref @trustederrno;
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("execve(%s): errno=%d\n", (parameter) char** argvargv[2], (local variable) const(int) errorerror);
return 1;
}
version (ExecProbeStaticExecProbeStatic) {} else
{
if ((parameter) int argcargc == 3 && int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogcstrcmp((parameter) char** argvargv[1], "--dlopen") == 0)
{
auto (local variable) void* handlehandle = void* core.sys.posix.dlfcn.dlopen(scope const(char*), int) nothrow @nogcdlopen((parameter) char** argvargv[2], (constant) int core.sys.posix.dlfcn.RTLD_NOW = 2RTLD_NOW | (constant) int core.sys.posix.dlfcn.RTLD_LOCAL = 0RTLD_LOCAL);
if ((local variable) void* handlehandle is null)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("dlopen: %s\n", char* core.sys.posix.dlfcn.dlerror() nothrow @nogcdlerror());
return 1;
}
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("dlopen: success\n");
return int core.sys.posix.dlfcn.dlclose(void*) nothrow @nogcdlclose((local variable) void* handlehandle) == 0 ? 0 : 1;
}
}
return 0;
}