mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Adds support to https audit log output
This functionality was built for test only.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "audit_log/writer/https.h"
|
||||
#include "audit_log/writer/parallel.h"
|
||||
#include "audit_log/writer/serial.h"
|
||||
#include "utils/regex.h"
|
||||
@@ -184,6 +185,9 @@ bool AuditLog::init() {
|
||||
if (m_type == SerialAuditLogType) {
|
||||
m_writer = new audit_log::writer::Serial(this);
|
||||
}
|
||||
if (m_type == HttpsAuditLogType) {
|
||||
m_writer = new audit_log::writer::Https(this);
|
||||
}
|
||||
m_writer->refCountIncrease();
|
||||
|
||||
if (m_writer == NULL || m_writer->init() == false) {
|
||||
|
@@ -42,6 +42,7 @@ class AuditLog {
|
||||
enum AuditLogType {
|
||||
SerialAuditLogType,
|
||||
ParallelAuditLogType,
|
||||
HttpsAuditLogType
|
||||
};
|
||||
|
||||
enum AuditLogStatus {
|
||||
|
61
src/audit_log/writer/https.cc
Normal file
61
src/audit_log/writer/https.cc
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "audit_log/writer/https.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <mutex>
|
||||
|
||||
#include "audit_log/audit_log.h"
|
||||
#include "modsecurity/transaction.h"
|
||||
#include "src/utils.h"
|
||||
#include "utils/md5.h"
|
||||
#include "utils/https_client.h"
|
||||
|
||||
namespace modsecurity {
|
||||
namespace audit_log {
|
||||
namespace writer {
|
||||
|
||||
|
||||
Https::~Https() {
|
||||
}
|
||||
|
||||
|
||||
bool Https::init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Https::write(Transaction *transaction, int parts) {
|
||||
Utils::HttpsClient m_http_client;
|
||||
transaction->debug(7, "Sending logs to: " + m_audit->m_path1);
|
||||
|
||||
std::string log = transaction->toJSON(parts);
|
||||
m_http_client.setRequestType("application/json");
|
||||
m_http_client.setRequestBody(log.c_str());
|
||||
m_http_client.download(m_audit->m_path1);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace writer
|
||||
} // namespace audit_log
|
||||
} // namespace modsecurity
|
64
src/audit_log/writer/https.h
Normal file
64
src/audit_log/writer/https.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#ifndef SRC_AUDIT_LOG_WRITER_HTTPS_H_
|
||||
#define SRC_AUDIT_LOG_WRITER_HTTPS_H_
|
||||
|
||||
#include "audit_log/writer.h"
|
||||
#include "modsecurity/transaction.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace modsecurity {
|
||||
namespace audit_log {
|
||||
namespace writer {
|
||||
|
||||
/** @ingroup ModSecurity_CPP_API */
|
||||
class Https : public audit_log::Writer {
|
||||
public:
|
||||
explicit Https(audit_log::AuditLog *audit)
|
||||
: audit_log::Writer(audit) { }
|
||||
|
||||
~Https() override;
|
||||
|
||||
void refCountIncrease() override {
|
||||
m_refereceCount++;
|
||||
}
|
||||
|
||||
|
||||
void refCountDecreaseAndCheck() override {
|
||||
m_refereceCount--;
|
||||
if (m_refereceCount == 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
bool init() override;
|
||||
bool write(Transaction *transaction, int parts) override;
|
||||
|
||||
};
|
||||
|
||||
} // namespace writer
|
||||
} // namespace audit_log
|
||||
} // namespace modsecurity
|
||||
#endif
|
||||
|
||||
#endif // SRC_AUDIT_LOG_WRITER_HTTPS_H_
|
Reference in New Issue
Block a user