summaryrefslogtreecommitdiff
path: root/detect/various.c
blob: 3689a8a8c56b590397c48f78057fdde4c13f7e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Detection of various tricks
 *
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


/*
 * Dead simple try to detect the LD_PRELOAD trick by looking
 * into environnement variables of the program.
 */
int various_ldpreload(){
    return (getenv("LD_PRELOAD") != NULL);
}

/*
 * Try to detect the LD_PRELOAD trick when used with a custom
 * gentenv() function. Feel free to expand it using the same principe.
 */
int various_ldpreload_custom_getenv(){
    if(!various_ldpreload()){
        putenv("LD_PRELOAD=hello");
        return (strcmp(getenv("LD_PRELOAD"), "hello"));
    }
    return 1;
}

/*
 * Timiming attack, useful for detecting breakpoints
 */
int various_rdtsc(){
    clock_t t = clock();

    int i; //Time-consuming crap
    for(i=2; i<7137001; i++)
        if (7137001 % i == 0)
            break;

    return (clock() - t > 0xffff); //adjust this
}