Skip to content

Commit cb3363c

Browse files
author
Felipe Zimmerle
committed
Adds support for the exec action
1 parent 7bec78a commit cb3363c

File tree

9 files changed

+1026
-722
lines changed

9 files changed

+1026
-722
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
v3.0.????? - ?
33
---------------------------
44

5+
- Adds support for the exec action.
6+
[Issue #1050 - @zimmerle]
57
- Adds support for transformations inside Lua engine
68
[Issue #994 - @zimmerle]
79
- Adds initial support for Lua engine.

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,5 @@ TESTS+=test/test-cases/regression/misc-variable-under-quotes.json
287287
TESTS+=test/test-cases/regression/operator-fuzzyhash.json
288288
TESTS+=test/test-cases/regression/collection-resource.json
289289
TESTS+=test/test-cases/regression/operator-inpectFile.json
290+
TESTS+=test/test-cases/regression/action-exec.json
290291

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ ACTIONS = \
121121
actions/disruptive/deny.cc \
122122
actions/disruptive/redirect.cc \
123123
actions/disruptive/pass.cc \
124+
actions/exec.cc \
124125
actions/init_col.cc \
125126
actions/log.cc \
126127
actions/log_data.cc \
@@ -273,6 +274,7 @@ libmodsecurity_la_SOURCES = \
273274
macro_expansion.cc \
274275
rule.cc \
275276
rule_message.cc \
277+
rule_script.cc \
276278
unique_id.cc \
277279
rules_exceptions.cc \
278280
${BODY_PROCESSORS} \

src/actions/exec.cc

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address security@modsecurity.org.
13+
*
14+
*/
15+
16+
#include "src/actions/exec.h"
17+
18+
#include <iostream>
19+
#include <string>
20+
21+
#include "modsecurity/actions/action.h"
22+
#include "modsecurity/transaction.h"
23+
#include "modsecurity/rule.h"
24+
#include "src/macro_expansion.h"
25+
#include "src/utils/system.h"
26+
#include "src/engine/lua.h"
27+
28+
29+
namespace modsecurity {
30+
namespace actions {
31+
32+
33+
bool Exec::init(std::string *error) {
34+
std::string err;
35+
36+
m_script = utils::find_resource(m_parser_payload, "", &err);
37+
38+
if (m_script.size() == 0) {
39+
error->assign("exec: Script not found: " + err);
40+
return false;
41+
}
42+
43+
if (engine::Lua::isCompatible(m_script, &m_lua, &err) == false) {
44+
error->assign("exec: " + err);
45+
return false;
46+
}
47+
48+
return true;
49+
}
50+
51+
52+
bool Exec::evaluate(Rule *rule, Transaction *t) {
53+
t->debug(8, "Running script... " + m_script);
54+
55+
m_lua.run(t);
56+
return true;
57+
}
58+
59+
60+
} // namespace actions
61+
} // namespace modsecurity

src/actions/exec.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address security@modsecurity.org.
13+
*
14+
*/
15+
16+
#include <string>
17+
18+
#include "modsecurity/actions/action.h"
19+
#include "src/engine/lua.h"
20+
21+
#ifndef SRC_ACTIONS_EXEC_H_
22+
#define SRC_ACTIONS_EXEC_H_
23+
24+
class Transaction;
25+
26+
namespace modsecurity {
27+
class Transaction;
28+
namespace actions {
29+
30+
31+
class Exec : public Action {
32+
public:
33+
explicit Exec(std::string action)
34+
: Action(action),
35+
m_script("") { }
36+
37+
~Exec() { }
38+
39+
bool evaluate(Rule *rule, Transaction *transaction) override;
40+
bool init(std::string *error) override;
41+
42+
private:
43+
std::string m_script;
44+
engine::Lua m_lua;
45+
};
46+
47+
48+
} // namespace actions
49+
} // namespace modsecurity
50+
51+
#endif // SRC_ACTIONS_EXEC_H_

0 commit comments

Comments
 (0)