Hello again developers,
I don't fully expect anyone to be able to answer this question. At this
point, I am just looking for ideas to try.
I am still trying to get my module to make a POST request to an external
server (I am using a subrequest that bounces off of mod_proxy to the
external server). I have successfully created a subrequest using a "POST"
method, but:
(1) I can't seem to get the content of the POST (the post variables) written
to the subrequest body; I have tried a 'ap_rprintf(...)', but it appears
that the contents of this write becomes the beginning of the response
content
(2) Is the content of a subrequest expected to output directly to the
(super/parent)request?
int status code
if(is_request_a_honeypot_token(r) && string_matches(r->method, "GET"))
{
int status_code = OK;
request_rec* subr = NULL;
char newurl[2048];
// apr_snprintf(newurl, sizeof(newurl), "proxy:%s://%s:%d/%s",
"http", "192.168.3.104", 11000, "cgi/serve.php");
apr_snprintf(newurl, sizeof(newurl), "proxy:%s://%s:%d/%s", "http",
"192.168.3.104", 18000, "raw.html");
#if IS_DEBUG_MODE == 1
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: Handling Honeypot
Request");
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: New POST Request
URI: %s", newurl);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: POST Request
Parameters: %s", newparams);
#endif
if (ap_find_linked_module("mod_proxy.c") == NULL)
{
status = HTTP_INTERNAL_SERVER_ERROR;
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Access denied with
code 500%s "
"(Internal Error: proxy action to %s requested but
mod_proxy not found).",
newurl);
return status;
}
else
{
#if IS_DEBUG_MODE == 1
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: mod_proxy module
found successfully");
#endif
// Make a subrequest to mod_proxy, POSTing to the Honeypot
server and passing the resulting content as the content of the SuperRequest
subr = (request_rec*)ap_sub_req_method_uri("POST", "*", r,
NULL); // this MUST succeed!
subr->assbackwards = 0;
// build POST headers
char postparams[8192];
apr_snprintf(postparams, sizeof(postparams),
"k1=v1&k2=v2&k3=v3");
ap_set_content_type(subr, "application/x-www-form-urlencoded");
apr_table_set(subr->headers_in, "Content-Length",
strlen(postparams));
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "query constructed: %s
(%s)", newurl, postparams);
ap_rprintf(subr, "%s", postparams);
subr->filename = apr_pstrdup(r->pool, newurl);
subr->proxyreq = PROXYREQ_REVERSE;
subr->handler = "proxy-server";
status_code = ap_run_sub_req(subr);
#if IS_DEBUG_MODE == 1
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: Honeypot Response:
status code(%d)", status_code);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: Honeypot Response:
hostname - \"%s\"", subr->hostname);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "HTTPBL: Honeypot Response:
method - \"%s\"", subr->method);
#endif
if (status_code == 200)
{
// write from the subrequest results to the SuperRequest
ap_set_content_type(r, "text/html");
int bytes_sent = ap_rprintf(r, "<html>\n\t<head>\n<title>MY
FIRST HONEYPOT</title>\n\t</head>\n\t<body>\n\t\t<h1>My First
Honeypot</h1>\n\t</body>\n</html>");
}
ap_destroy_sub_req(subr);
// done processing content
status = OK;
}
}