Troll23 test
authorTomas Mudrunka <tomas@mudrunka.cz>
Tue, 11 Feb 2014 02:28:06 +0000 (03:28 +0100)
committerTomas Mudrunka <tomas@mudrunka.cz>
Tue, 11 Feb 2014 02:28:06 +0000 (03:28 +0100)
c/troll23/Makefile
c/troll23/sshkeys.sh [new file with mode: 0755]
c/troll23/test.c
c/troll23/troll23.c

index d09d74ffb20fb1686d3083359b0ef4ce689c1465..c1d53dc649f5738d3688c038ac08832d720c9763 100644 (file)
@@ -6,3 +6,12 @@ $(proj).so: $(proj).c
        # To test:
        # export LD_PRELOAD=$(PWD)/$@
        # touch /tmp/deleteme; rm /tmp/deleteme
+       # Or:
+       # make go
+       # make ssh
+
+go: test $(proj).so
+       LD_PRELOAD=$(PWD)/$(proj).so ./test
+
+ssh: $(proj).so
+       LD_PRELOAD=$(PWD)/$(proj).so ./sshkeys.sh
diff --git a/c/troll23/sshkeys.sh b/c/troll23/sshkeys.sh
new file mode 100755 (executable)
index 0000000..cd0f5e6
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+ssh-keygen -P '' -f ssh-a.key >/dev/null
+ssh-keygen -P '' -f ssh-b.key >/dev/null
+md5sum ssh-?.key ssh-?.key.pub
+rm ssh-?.key ssh-?.key.pub
index 32cda6310e06c546acbc98701571066a0a9ae6a0..a529f5b1faba39dc485e0698a34a604c5c9768af 100644 (file)
@@ -1,3 +1,7 @@
+#include <stdio.h>
+
 int main() {
+       srand(time(NULL));
        printf("%d\n", rand());
+       return(0);
 }
index 5ff84e1186fe88e0a2a43b9d88776f793542e532..f1822e0e21f4f3815045293663a924faac89771c 100644 (file)
@@ -1,21 +1,35 @@
 #define _GNU_SOURCE
+#include <stdlib.h>
 #include <stdio.h>
 #include <sys/types.h>
+#include <sys/syscall.h>
 #include <dlfcn.h>
 #include <stdarg.h>
+#include <time.h>
 
-int rand(void) {       return 23; }
-int random(void) {     return 23; }
+//Catch rand() calls etc...
+time_t time(time_t *tloc) { srand(23); return (time_t)0; }
+int rand(void) {       srand(23); return 23; }
+long int random(void) {        srand(23); return 23; }
+int rand_r(unsigned int *seedp) { srand(23); return 23; }
+int random_r(struct random_data *buf, int32_t *result) { srand(23); return 23; }
 
+//Catch open() calls (while redirecting filename):
 static const char *redirect_name(const char *name)
 {
-       if(strcmp(name,"/dev/random") == 0) return "/dev/zero";
-       if(strcmp(name,"/dev/urandom") == 0) return "/dev/zero";
+       if(
+               (strcmp(name,"/dev/random") == 0) ||
+               (strcmp(name,"/dev/urandom") == 0)
+       ) {
+               printf("REDIRECT HIT: %s\n", name);
+               return "/dev/zero";
+       }
        return name;
 }
 
 int open(const char *filename, int flags, ...)
 {
+       //srand(23);
        static int (*open_orig)(const char *, int, mode_t);
        int ret;
        va_list ap;
@@ -30,8 +44,33 @@ int open(const char *filename, int flags, ...)
        va_end(ap);
 
        ret = open_orig(redirect_name(filename), flags, mode);
+       //ret = syscall(SYS_open,redirect_name(filename),flags,mode);
 
        printf("open(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
 
        return ret;
 }
+
+int open64(const char *filename, int flags, ...)
+{
+       //srand(23);
+       static int (*open64_orig)(const char *, int, mode_t);
+       int ret;
+       va_list ap;
+       mode_t mode;
+
+       if (!open64_orig) {
+               open64_orig = dlsym(RTLD_NEXT, "open64");
+       }
+
+       va_start(ap, flags);
+       mode = va_arg(ap, mode_t);
+       va_end(ap);
+
+       ret = open64_orig(redirect_name(filename), flags, mode);
+       //ret = syscall(SYS_open64,redirect_name(filename),flags,mode);
+
+       printf("open64(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
+
+       return ret;
+}
This page took 0.195619 seconds and 4 git commands to generate.