From: Tomas Mudrunka Date: Tue, 11 Feb 2014 02:28:06 +0000 (+0100) Subject: Troll23 test X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=5837f17e9368553bf13f094e0e62d8d38edf6589;p=mirrors%2FPrograms.git Troll23 test --- diff --git a/c/troll23/Makefile b/c/troll23/Makefile index d09d74f..c1d53dc 100644 --- a/c/troll23/Makefile +++ b/c/troll23/Makefile @@ -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 index 0000000..cd0f5e6 --- /dev/null +++ b/c/troll23/sshkeys.sh @@ -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 diff --git a/c/troll23/test.c b/c/troll23/test.c index 32cda63..a529f5b 100644 --- a/c/troll23/test.c +++ b/c/troll23/test.c @@ -1,3 +1,7 @@ +#include + int main() { + srand(time(NULL)); printf("%d\n", rand()); + return(0); } diff --git a/c/troll23/troll23.c b/c/troll23/troll23.c index 5ff84e1..f1822e0 100644 --- a/c/troll23/troll23.c +++ b/c/troll23/troll23.c @@ -1,21 +1,35 @@ #define _GNU_SOURCE +#include #include #include +#include #include #include +#include -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; +}