mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Initial support for Lua script engine
This commit is contained in:
@@ -28,6 +28,7 @@ namespace operators {
|
||||
bool InspectFile::init(const std::string ¶m2, std::string *error) {
|
||||
std::istream *iss;
|
||||
std::string err;
|
||||
std::string err_lua;
|
||||
|
||||
m_file = utils::find_resource(m_param, param2, &err);
|
||||
iss = new std::ifstream(m_file, std::ios::in);
|
||||
@@ -38,37 +39,45 @@ bool InspectFile::init(const std::string ¶m2, std::string *error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (engine::Lua::isCompatible(m_file, &m_lua, &err_lua) == true) {
|
||||
m_isScript = true;
|
||||
}
|
||||
|
||||
delete iss;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool InspectFile::evaluate(Transaction *transaction, const std::string &str) {
|
||||
FILE *in;
|
||||
char buff[512];
|
||||
std::stringstream s;
|
||||
std::string res;
|
||||
std::string openstr;
|
||||
if (m_isScript) {
|
||||
return m_lua.run(transaction);
|
||||
} else {
|
||||
FILE *in;
|
||||
char buff[512];
|
||||
std::stringstream s;
|
||||
std::string res;
|
||||
std::string openstr;
|
||||
|
||||
openstr.append(m_param);
|
||||
openstr.append(" ");
|
||||
openstr.append(str);
|
||||
openstr.append(m_param);
|
||||
openstr.append(" ");
|
||||
openstr.append(str);
|
||||
if (!(in = popen(openstr.c_str(), "r"))){
|
||||
return false;
|
||||
}
|
||||
|
||||
while (fgets(buff, sizeof(buff), in) != NULL) {
|
||||
s << buff;
|
||||
}
|
||||
|
||||
pclose(in);
|
||||
|
||||
res.append(s.str());
|
||||
if (res.size() > 1 && res.at(0) == '1') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(in = popen(openstr.c_str(), "r"))){
|
||||
return false;
|
||||
}
|
||||
|
||||
while (fgets(buff, sizeof(buff), in) != NULL) {
|
||||
s << buff;
|
||||
}
|
||||
|
||||
pclose(in);
|
||||
|
||||
res.append(s.str());
|
||||
if (res.size() > 1 && res.at(0) == '1') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "src/operators/operator.h"
|
||||
#include "src/engine/lua.h"
|
||||
|
||||
|
||||
namespace modsecurity {
|
||||
@@ -29,15 +30,19 @@ class InspectFile : public Operator {
|
||||
/** @ingroup ModSecurity_Operator */
|
||||
InspectFile(std::string o, std::string p, bool n)
|
||||
: Operator(o, p, n),
|
||||
m_file("") { }
|
||||
m_file(""),
|
||||
m_isScript(false) { }
|
||||
explicit InspectFile(std::string param)
|
||||
: Operator("InspectFile", param),
|
||||
m_file("") { }
|
||||
m_file(""),
|
||||
m_isScript(false) { }
|
||||
|
||||
bool init(const std::string ¶m, std::string *error) override;
|
||||
bool evaluate(Transaction *transaction, const std::string &str) override;
|
||||
private:
|
||||
std::string m_file;
|
||||
bool m_isScript;
|
||||
engine::Lua m_lua;
|
||||
};
|
||||
|
||||
} // namespace operators
|
||||
|
Reference in New Issue
Block a user