summarylogtreecommitdiffstats
path: root/spoof_homedir.c
diff options
context:
space:
mode:
authorXiretza2019-06-11 21:56:08 +0200
committerXiretza2019-06-19 00:22:35 +0200
commitc8ba3b03b4d4b5e1bb219fe340b59607778b9f20 (patch)
treec4c470de5cd62c8611e9b481b9510242f2ec21af /spoof_homedir.c
downloadaur-c8ba3b03b4d4b5e1bb219fe340b59607778b9f20.tar.gz
Initial commit
Diffstat (limited to 'spoof_homedir.c')
-rw-r--r--spoof_homedir.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/spoof_homedir.c b/spoof_homedir.c
new file mode 100644
index 00000000000..caee9b033b2
--- /dev/null
+++ b/spoof_homedir.c
@@ -0,0 +1,28 @@
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <pwd.h>
+#include <sys/types.h>
+
+/* shared library that replaces the home directory for root in a `getpwuid()` call
+ * with a specific location
+ *
+ * inspired by https://rafalcieslak.wordpress.com/2013/04/02/dynamic-linker-tricks-using-ld_preload-to-cheat-inject-features-and-investigate-programs/
+ *
+ * Usage:
+ * gcc -shared -fPIC -D 'FAKE_HOME="/path/to/fake/directory"' spoof_homedir.c -o spoof_homedir.so -ldl
+ * LD_PRELOAD="./spoof_homedir.so" binary_to_spoof
+ */
+
+typedef struct passwd *(*orig_getpwuid_f_type)(uid_t uid);
+
+struct passwd *getpwuid(uid_t uid) {
+ orig_getpwuid_f_type orig_getpwuid;
+ orig_getpwuid = (orig_getpwuid_f_type)dlsym(RTLD_NEXT, "getpwuid");
+
+ struct passwd *result = orig_getpwuid(uid);
+ if (uid == 0) {
+ result->pw_dir = FAKE_HOME;
+ }
+
+ return result;
+}