diff options
| author | jvoisin | 2013-01-15 21:31:40 +0100 |
|---|---|---|
| committer | jvoisin | 2013-01-15 21:31:40 +0100 |
| commit | 808069c906a036f3b8c5de51e302245154131584 (patch) | |
| tree | c8e046626973ee28a793c24faba312ace286c8c1 /detect/various.c | |
First commit with an ugly makefile !
Diffstat (limited to 'detect/various.c')
| -rw-r--r-- | detect/various.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/detect/various.c b/detect/various.c new file mode 100644 index 0000000..3689a8a --- /dev/null +++ b/detect/various.c | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | /* | ||
| 2 | * Detection of various tricks | ||
| 3 | * | ||
| 4 | */ | ||
| 5 | |||
| 6 | |||
| 7 | #include <stdio.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | |||
| 12 | |||
| 13 | /* | ||
| 14 | * Dead simple try to detect the LD_PRELOAD trick by looking | ||
| 15 | * into environnement variables of the program. | ||
| 16 | */ | ||
| 17 | int various_ldpreload(){ | ||
| 18 | return (getenv("LD_PRELOAD") != NULL); | ||
| 19 | } | ||
| 20 | |||
| 21 | /* | ||
| 22 | * Try to detect the LD_PRELOAD trick when used with a custom | ||
| 23 | * gentenv() function. Feel free to expand it using the same principe. | ||
| 24 | */ | ||
| 25 | int various_ldpreload_custom_getenv(){ | ||
| 26 | if(!various_ldpreload()){ | ||
| 27 | putenv("LD_PRELOAD=hello"); | ||
| 28 | return (strcmp(getenv("LD_PRELOAD"), "hello")); | ||
| 29 | } | ||
| 30 | return 1; | ||
| 31 | } | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Timiming attack, useful for detecting breakpoints | ||
| 35 | */ | ||
| 36 | int various_rdtsc(){ | ||
| 37 | clock_t t = clock(); | ||
| 38 | |||
| 39 | int i; //Time-consuming crap | ||
| 40 | for(i=2; i<7137001; i++) | ||
| 41 | if (7137001 % i == 0) | ||
| 42 | break; | ||
| 43 | |||
| 44 | return (clock() - t > 0xffff); //adjust this | ||
| 45 | } | ||
| 46 | |||
