Last active
April 22, 2017 15:36
-
-
Save Freeaqingme/b2a7b452c22f8e8a95e898751308c478 to your computer and use it in GitHub Desktop.
modsecurity v3 linked to Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
#cgo CPPFLAGS: -I/usr/local/modsecurity/include | |
#cgo LDFLAGS: /usr/local/modsecurity/lib/libmodsecurity.so | |
#include "modsecurity/modsecurity.h" | |
#include "modsecurity/transaction.h" | |
#include "modsecurity/rules.h" | |
char main_rule_uri[] = "basic_rules.conf"; | |
int foobar () | |
{ | |
int ret; | |
ModSecurity *modsec = NULL; | |
Transaction *transaction = NULL; | |
Rules *rules = NULL; | |
modsec = msc_init(); | |
rules = msc_create_rules_set(); | |
const char *error = NULL; | |
ret = msc_rules_add_file(rules, main_rule_uri, &error); | |
if (ret < 0) { | |
fprintf(stderr, "Problems loading the rules --\n"); | |
fprintf(stderr, "%s\n", error); | |
return *error; | |
} | |
transaction = msc_new_transaction(modsec, rules, NULL); | |
msc_process_connection(transaction, "127.0.0.1", 80, "127.0.0.1", 80); | |
//msc_process_uri(transaction, "http://www.modsecurity.org/test?key1=value1&key2=value2&key3=value3&test=args&test=test", "GET", "1.1"); | |
msc_process_uri(transaction, "http://www.modsecurity.org/test?key1=value1&key2=value2&key3=value3&test=args&test=test", "CONNECT", "1.1"); | |
msc_process_request_headers(transaction); | |
msc_process_request_body(transaction); | |
msc_process_response_headers(transaction, 200, "HTTP 1.!"); | |
msc_process_response_body(transaction); | |
ModSecurityIntervention intervention; | |
intervention.status = 200; | |
intervention.url = NULL; | |
intervention.log = NULL; | |
intervention.disruptive = 0; | |
if (msc_intervention(transaction, &intervention) == 0) { | |
fprintf(stderr, "No intervention required!\n"); | |
return 0; | |
} else { | |
fprintf(stderr, "We should intervene...!\n"); | |
} | |
return 0; | |
} | |
*/ | |
import "C" | |
import ( | |
"fmt" | |
) | |
func main() { | |
fmt.Println(C.foobar()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment