mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 03:34:29 +03:00
Adds all variables to the 'Variables' name space
This commit is contained in:
49
src/variables/duration.cc
Normal file
49
src/variables/duration.cc
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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 "variables/duration.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <chrono>
|
||||
#include <utility>
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace Variables {
|
||||
|
||||
std::list<std::pair<std::string, std::string>>
|
||||
Duration::evaluate(Assay *assay) {
|
||||
std::list<std::pair<std::string, std::string>> resl;
|
||||
std::string res;
|
||||
std::pair<std::string, std::string> pair;
|
||||
|
||||
auto e = std::chrono::high_resolution_clock::now() - assay->start;
|
||||
|
||||
res = std::to_string(
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(e).count());
|
||||
|
||||
pair = std::make_pair(std::string("DURATION"), std::string(res));
|
||||
resl.push_back(pair);
|
||||
|
||||
return resl;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
44
src/variables/duration.h
Normal file
44
src/variables/duration.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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 <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
#ifndef SRC_VARIABLES_DURATION_H_
|
||||
#define SRC_VARIABLES_DURATION_H_
|
||||
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
class Assay;
|
||||
namespace Variables {
|
||||
|
||||
class Duration : public Variable {
|
||||
public:
|
||||
explicit Duration(std::string _name)
|
||||
: Variable(_name) { }
|
||||
|
||||
std::list<std::pair<std::string, std::string>>
|
||||
evaluate(Assay *assay) override;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
||||
|
||||
#endif // SRC_VARIABLES_DURATION_H_
|
69
src/variables/env.cc
Normal file
69
src/variables/env.cc
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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 "variables/env.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
#include <map>
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
#include "src/utils.h"
|
||||
|
||||
extern char **environ;
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace Variables {
|
||||
|
||||
std::list<std::pair<std::string, std::string>>
|
||||
Env::evaluate(Assay *assay) {
|
||||
std::list<std::pair<std::string, std::string>> resl;
|
||||
|
||||
std::map<std::string, std::string> envs;
|
||||
for (char **current = environ; *current; current++) {
|
||||
std::string env = std::string(*current);
|
||||
std::vector<std::string> key_value = split(env, '=');
|
||||
envs.insert(std::pair<std::string, std::string>("ENV:" + key_value[0],
|
||||
key_value[1]));
|
||||
if ("env:" + key_value[0] == name) {
|
||||
std::pair<std::string, std::string> pair;
|
||||
pair = std::make_pair(name, key_value[1]);
|
||||
resl.push_back(pair);
|
||||
return resl;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& x : envs) {
|
||||
if ((x.first.substr(0, name.size() + 1).compare(name + ":") != 0)
|
||||
&& (x.first != name)) {
|
||||
continue;
|
||||
}
|
||||
std::pair<std::string, std::string> pair;
|
||||
pair = std::make_pair(x.first, x.second);
|
||||
resl.push_back(pair);
|
||||
}
|
||||
|
||||
return resl;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
44
src/variables/env.h
Normal file
44
src/variables/env.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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 <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
#ifndef SRC_VARIABLES_ENV_H_
|
||||
#define SRC_VARIABLES_ENV_H_
|
||||
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
class Assay;
|
||||
namespace Variables {
|
||||
|
||||
class Env : public Variable {
|
||||
public:
|
||||
explicit Env(std::string _name)
|
||||
: Variable(_name) { }
|
||||
|
||||
std::list<std::pair<std::string, std::string>>
|
||||
evaluate(Assay *assay) override;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
||||
|
||||
#endif // SRC_VARIABLES_ENV_H_
|
43
src/variables/highest_severity.cc
Normal file
43
src/variables/highest_severity.cc
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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 "variables/highest_severity.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace Variables {
|
||||
|
||||
std::list<std::pair<std::string, std::string>>
|
||||
HighestSeverity::evaluate(Assay *assay) {
|
||||
std::list<std::pair<std::string, std::string>> resl;
|
||||
std::pair<std::string, std::string> pair;
|
||||
|
||||
pair = std::make_pair(std::string("HIGHEST_SEVERITY"),
|
||||
std::to_string(assay->highest_severity));
|
||||
resl.push_back(pair);
|
||||
|
||||
return resl;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
44
src/variables/highest_severity.h
Normal file
44
src/variables/highest_severity.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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 <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
#ifndef SRC_VARIABLES_HIGHEST_SEVERITY_H_
|
||||
#define SRC_VARIABLES_HIGHEST_SEVERITY_H_
|
||||
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
class Assay;
|
||||
namespace Variables {
|
||||
|
||||
class HighestSeverity : public Variable {
|
||||
public:
|
||||
explicit HighestSeverity(std::string _name)
|
||||
: Variable(_name) { }
|
||||
|
||||
std::list<std::pair<std::string, std::string>>
|
||||
evaluate(Assay *assay) override;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
||||
|
||||
#endif // SRC_VARIABLES_HIGHEST_SEVERITY_H_
|
49
src/variables/modsec_build.cc
Normal file
49
src/variables/modsec_build.cc
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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 "variables/modsec_build.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
#include "modsecurity/modsecurity.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace Variables {
|
||||
|
||||
std::list<std::pair<std::string, std::string>>
|
||||
ModsecBuild::evaluate(Assay *assay) {
|
||||
std::list<std::pair<std::string, std::string>> resl;
|
||||
std::pair<std::string, std::string> pair;
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << std::setw(2) << std::setfill('0') << MODSECURITY_MAJOR;
|
||||
ss << std::setw(2) << std::setfill('0') << MODSECURITY_MINOR;
|
||||
ss << std::setw(2) << std::setfill('0') << MODSECURITY_PATCHLEVEL;
|
||||
ss << std::setw(2) << std::setfill('0') << MODSECURITY_TAG_NUM;
|
||||
|
||||
pair = std::make_pair(std::string("MODSEC_BUILD"), ss.str());
|
||||
resl.push_back(pair);
|
||||
|
||||
return resl;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
44
src/variables/modsec_build.h
Normal file
44
src/variables/modsec_build.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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 <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
#ifndef SRC_VARIABLES_MODSEC_BUILD_H_
|
||||
#define SRC_VARIABLES_MODSEC_BUILD_H_
|
||||
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
class Assay;
|
||||
namespace Variables {
|
||||
|
||||
class ModsecBuild : public Variable {
|
||||
public:
|
||||
explicit ModsecBuild(std::string _name)
|
||||
: Variable(_name) { }
|
||||
|
||||
std::list<std::pair<std::string, std::string>>
|
||||
evaluate(Assay *assay) override;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
||||
|
||||
#endif // SRC_VARIABLES_MODSEC_BUILD_H_
|
@@ -22,7 +22,7 @@
|
||||
#ifndef SRC_VARIABLES_TIME_H_
|
||||
#define SRC_VARIABLES_TIME_H_
|
||||
|
||||
#include "src/variable.h"
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef SRC_VARIABLES_TIME_DAY_H_
|
||||
#define SRC_VARIABLES_TIME_DAY_H_
|
||||
|
||||
#include "src/variable.h"
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef SRC_VARIABLES_TIME_EPOCH_H_
|
||||
#define SRC_VARIABLES_TIME_EPOCH_H_
|
||||
|
||||
#include "src/variable.h"
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef SRC_VARIABLES_TIME_HOUR_H_
|
||||
#define SRC_VARIABLES_TIME_HOUR_H_
|
||||
|
||||
#include "src/variable.h"
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef SRC_VARIABLES_TIME_MIN_H_
|
||||
#define SRC_VARIABLES_TIME_MIN_H_
|
||||
|
||||
#include "src/variable.h"
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef SRC_VARIABLES_TIME_MON_H_
|
||||
#define SRC_VARIABLES_TIME_MON_H_
|
||||
|
||||
#include "src/variable.h"
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef SRC_VARIABLES_TIME_SEC_H_
|
||||
#define SRC_VARIABLES_TIME_SEC_H_
|
||||
|
||||
#include "src/variable.h"
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef SRC_VARIABLES_TIME_WDAY_H_
|
||||
#define SRC_VARIABLES_TIME_WDAY_H_
|
||||
|
||||
#include "src/variable.h"
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef SRC_VARIABLES_TIME_YEAR_H_
|
||||
#define SRC_VARIABLES_TIME_YEAR_H_
|
||||
|
||||
#include "src/variable.h"
|
||||
#include "variables/variable.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
51
src/variables/variable.cc
Normal file
51
src/variables/variable.cc
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 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 "variables/variable.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace Variables {
|
||||
|
||||
std::list<std::pair<std::string, std::string>>
|
||||
Variable::evaluate(Assay *assay) {
|
||||
return assay->resolve_variable(this->name);
|
||||
}
|
||||
|
||||
std::string Variable::to_s(
|
||||
std::vector<Variable *> *variables) {
|
||||
std::string ret;
|
||||
for (int i = 0; i < variables->size() ; i++) {
|
||||
std::string name = variables->at(i)->name;
|
||||
|
||||
if (i == 0) {
|
||||
ret = ret + name;
|
||||
} else {
|
||||
ret = ret + "|" + name;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
44
src/variables/variable.h
Normal file
44
src/variables/variable.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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 <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
#ifndef SRC_VARIABLES_VARIABLE_H_
|
||||
#define SRC_VARIABLES_VARIABLE_H_
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
class Assay;
|
||||
namespace Variables {
|
||||
|
||||
class Variable {
|
||||
public:
|
||||
explicit Variable(std::string _name)
|
||||
: name(_name) { }
|
||||
|
||||
static std::string to_s(std::vector<Variable *> *variables);
|
||||
virtual std::list<std::pair<std::string, std::string>>
|
||||
evaluate(Assay *assay);
|
||||
std::string name;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Variables
|
||||
} // namespace ModSecurity
|
||||
|
||||
#endif // SRC_VARIABLES_VARIABLE_H_
|
Reference in New Issue
Block a user