Add MySQL Cache Manager & code cleanup

This commit is contained in:
Brendan LE GLAUNEC
2016-05-21 11:17:08 +02:00
committed by Brendan Le Glaunec
parent faa2570883
commit 8a8e4faa42
29 changed files with 844 additions and 69 deletions
+4 -13
View File
@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <configuration.h> // configuration
#include <fstream> // std::ifstream
#include <unistd.h> // access, F_OK
#include <configuration.h> // configuration
namespace etix {
@@ -22,9 +22,9 @@ namespace cameradar {
const std::string configuration::name_ = "configuration";
// read a file at the path "path"
// if the file is available we return the whole content as an std::string inside
// a pair
// Read a file at the path "path"
// If the file is available we return the whole content as
// an std::string inside a pair
// otherwise return false and an empty string inside a pair
std::pair<bool, std::string>
read_file(const std::string& path) {
@@ -107,14 +107,6 @@ configuration::load_url() {
auto root = Json::Value();
auto reader = Json::Reader();
reader.parse(content, root);
// auto result = tool::json::check_fields(
// {{"urls", Json::arrayValue, root["urls"]}}, "general
// configuration");
// if (not result.first) {
// LOG_ERR_(result.second, "general configuration");
// return false;
// }
for (unsigned int i = 0; i < root["urls"].size(); i++) {
if (not root["urls"][i].isString()) {
@@ -194,7 +186,6 @@ load(const std::string& path) {
}
// Deserialize the json to a configuration struct
// and return
// REPLACE THIS WITH JSONCPP
std::pair<bool, configuration> conf = serialize(root);
conf.second.raw_conf = root;
conf.first &= conf.second.load_url();
+13 -4
View File
@@ -20,12 +20,20 @@ namespace cameradar {
// The main loop of the binary
void
dispatcher::run() {
if (not(*cache)->configure(std::make_shared<configuration>(conf))) {
LOG_ERR_(
"There was a problem with the cache manager, Cameradar can't work properly without "
"cache management",
"dispatcher");
return;
}
std::thread worker(&dispatcher::do_stuff, this);
using namespace std::chrono_literals;
// catch CTRL+C signal
// Catch CTRL+C signal
signal_handler::instance();
// wait for event or end
// Wait for event or end
while (signal_handler::instance().should_stop() not_eq stop_priority::stop &&
current != task::finished) {
std::this_thread::sleep_for(30ms);
@@ -36,7 +44,7 @@ dispatcher::run() {
LOG_INFO_("Press CTRL+C again to force stop", "dispatcher");
}
// waiting for task to cleanup / force stop command
// Waiting for task to cleanup / force stop command
while ((signal_handler::instance().should_stop() not_eq stop_priority::force_stop) and
doing_stuff()) {
std::this_thread::sleep_for(std::chrono::milliseconds(30));
@@ -76,7 +84,8 @@ dispatcher::do_stuff() {
if (queue.front()->run())
queue.pop_front();
else {
LOG_ERR_("An error occured in one of the tasks, Cameradar will now stop.", "dispatcher");
LOG_ERR_("An error occured in one of the tasks, Cameradar will now stop.",
"dispatcher");
break;
}
}
+4 -4
View File
@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <fs.h> // fs::home
#include <opt_parse.h> // parsing opt
#include <dispatcher.h> // program loop
#include <iostream> // iostream
#include "version.h" // versionning
#include <dispatcher.h> // program loop
#include <fs.h> // fs::home
#include <iostream> // iostream
#include <opt_parse.h> // parsing opt
namespace cmrdr = etix::cameradar;
+8 -8
View File
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <tasks/brutelogs.h>
#include <cachemanager.h>
#include <tasks/brutelogs.h>
namespace etix {
namespace cameradar {
@@ -36,10 +36,10 @@ brutelogs::test_ids(const etix::cameradar::stream_model& stream,
std::string path = stream.service_name + "://";
if (username != "" || password != "") { path += username + ":" + password + "@"; }
path += stream.address + ":" + std::to_string(stream.port);
LOG_DEBUG_("Testing ids : " + path, "bruteforce");
LOG_DEBUG_("Testing ids : " + path, "brutelogs");
try {
if (curl_describe(path, true)) {
LOG_DEBUG_("[FOUND IDS] : " + path, "bruteforce");
LOG_DEBUG_("[FOUND IDS] : " + path, "brutelogs");
found = true;
stream_model newstream{
stream.address, stream.port, username, password,
@@ -55,7 +55,7 @@ brutelogs::test_ids(const etix::cameradar::stream_model& stream,
(*cache)->update_stream(newstream);
}
} catch (const std::runtime_error& e) {
LOG_DEBUG_("Ids already tested : " + std::string(e.what()), "bruteforce");
LOG_DEBUG_("Ids already tested : " + std::string(e.what()), "brutelogs");
}
return found;
}
@@ -75,7 +75,7 @@ brutelogs::run() const {
LOG_INFO_(
"Beginning bruteforce of the usernames and passwords task, it may "
"take a while.",
"bruteforce");
"brutelogs");
std::vector<etix::cameradar::stream_model> streams = (*cache)->get_streams();
bool doubleskip;
size_t found = 0;
@@ -88,7 +88,7 @@ brutelogs::run() const {
" : This camera's ids were already discovered in "
"the database. Skipping to "
"the next camera.",
"bruteforce");
"brutelogs");
++found;
} else {
for (const auto& username : conf.usernames) {
@@ -110,12 +110,12 @@ brutelogs::run() const {
}
}
if (!found) {
LOG_WARN_(no_ids_warning_, "bruteforce");
LOG_WARN_(no_ids_warning_, "brutelogs");
return false;
} else
LOG_INFO_("Found " + std::to_string(found) + " ids for " + std::to_string(streams.size()) +
" cameras",
"bruteforce");
"brutelogs");
return true;
}
}
+7 -3
View File
@@ -28,9 +28,12 @@ namespace cameradar {
//! problem.
bool
nmap_is_ok() {
return (launch_command("test `dpkg -l | cut -c 5-9 | grep nmap` = nmap")
// && launch_command("test `nmap --version | cut -c 14-18 | head -n2 | tail -n1` = 6.47")
&& launch_command("mkdir -p scans")); // Creates the directory in which the scans will be stored
return (
launch_command("test `dpkg -l | cut -c 5-9 | grep nmap` = nmap")
// && launch_command("test `nmap --version | cut -c 14-18 | head -n2 | tail -n1` = 6.47")
&&
launch_command(
"mkdir -p scans")); // Creates the directory in which the scans will be stored
}
//! Launches and checks the return of the nmap command
@@ -44,6 +47,7 @@ mapping::run() const {
LOG_INFO_("Beginning mapping task. This may take a while.", "mapping");
std::string cmd =
"nmap -T4 -A " + subnets + " -p " + this->conf.ports + " -oX " + nmap_output;
LOG_DEBUG_("Launching nmap : " + cmd, "mapping");
bool ret = launch_command(cmd);
if (ret)
LOG_INFO_("Nmap XML output successfully generated in file: " + nmap_output, "mapping");