|
|
|
|
|
|
|
|
#include "../CodeDweller/faults.hpp"
|
|
|
#include "../CodeDweller/faults.hpp"
|
|
|
#include "../SNFMulti/GBUdb.hpp"
|
|
|
#include "../SNFMulti/GBUdb.hpp"
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
namespace cd = codedweller;
|
|
|
|
|
|
|
|
|
const string VersionInfo = "V0.1";
|
|
|
|
|
|
|
|
|
const std::string VersionInfo = "V0.1";
|
|
|
const int ErrorResultCode = 1;
|
|
|
const int ErrorResultCode = 1;
|
|
|
const int SuccessResultCode = 0;
|
|
|
const int SuccessResultCode = 0;
|
|
|
|
|
|
|
|
|
struct Configuration {
|
|
|
struct Configuration {
|
|
|
string GBXFile;
|
|
|
|
|
|
|
|
|
std::string GBXFile;
|
|
|
double Probability;
|
|
|
double Probability;
|
|
|
double Confidence;
|
|
|
double Confidence;
|
|
|
bool findBlack;
|
|
|
bool findBlack;
|
|
|
|
|
|
|
|
|
showDetails(false) {}
|
|
|
showDetails(false) {}
|
|
|
} myConfig;
|
|
|
} myConfig;
|
|
|
|
|
|
|
|
|
class BadArguments : public RuntimeFault {public: BadArguments(string s):RuntimeFault(s){}};
|
|
|
|
|
|
|
|
|
class BadArguments : public cd::RuntimeFault {public: BadArguments(std::string s):RuntimeFault(s){}};
|
|
|
const BadArguments BadArgumentCount("Wrong number of arguments");
|
|
|
const BadArguments BadArgumentCount("Wrong number of arguments");
|
|
|
const BadArguments BadSwitch("Bad command line switch");
|
|
|
const BadArguments BadSwitch("Bad command line switch");
|
|
|
|
|
|
|
|
|
void setConfiguration(Configuration &conf, int argc, char* argv[]) {
|
|
|
void setConfiguration(Configuration &conf, int argc, char* argv[]) {
|
|
|
BadArgumentCount(argc > 6 || argc < 1);
|
|
|
BadArgumentCount(argc > 6 || argc < 1);
|
|
|
for(int i = 1; i < argc; i++) {
|
|
|
for(int i = 1; i < argc; i++) {
|
|
|
string thisArgument(argv[i]);
|
|
|
|
|
|
|
|
|
std::string thisArgument(argv[i]);
|
|
|
|
|
|
|
|
|
if(0 == thisArgument.find("-black")) {
|
|
|
if(0 == thisArgument.find("-black")) {
|
|
|
conf.findBlack = true;
|
|
|
conf.findBlack = true;
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void displayHelp() {
|
|
|
void displayHelp() {
|
|
|
cerr << "GBUDBTool " << VersionInfo << endl;
|
|
|
|
|
|
cerr << "Use: GBUDBTool [-black | -white] [-p=<value>] [-c=<value>] <gbx file>" << endl;
|
|
|
|
|
|
cerr << " -black prints out blacklist IPs based on p & c" << endl;
|
|
|
|
|
|
cerr << " -white prints out whitelist IPs based on p & c" << endl;
|
|
|
|
|
|
cerr << " -details prints out counts, confidence, and probability" << endl;
|
|
|
|
|
|
cerr << " -c=<value> sets the confidence figure for the list" << endl;
|
|
|
|
|
|
cerr << " -p=<value> sets the probability figure for the list" << endl;
|
|
|
|
|
|
cerr << " <gbx file> is the path to a GBUdb snapshot" << endl;
|
|
|
|
|
|
|
|
|
std::cerr << "GBUDBTool " << VersionInfo << std::endl;
|
|
|
|
|
|
std::cerr << "Use: GBUDBTool [-black | -white] [-p=<value>] [-c=<value>] <gbx file>" << std::endl;
|
|
|
|
|
|
std::cerr << " -black prints out blacklist IPs based on p & c" << std::endl;
|
|
|
|
|
|
std::cerr << " -white prints out whitelist IPs based on p & c" << std::endl;
|
|
|
|
|
|
std::cerr << " -details prints out counts, confidence, and probability" << std::endl;
|
|
|
|
|
|
std::cerr << " -c=<value> sets the confidence figure for the list" << std::endl;
|
|
|
|
|
|
std::cerr << " -p=<value> sets the probability figure for the list" << std::endl;
|
|
|
|
|
|
std::cerr << " <gbx file> is the path to a GBUdb snapshot" << std::endl;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
class Reporter : public GBUdbOperator {
|
|
|
class Reporter : public GBUdbOperator {
|
|
|
private:
|
|
|
private:
|
|
|
Configuration myConfig;
|
|
|
Configuration myConfig;
|
|
|
|
|
|
|
|
|
string toIP4String(unsigned int IP) {
|
|
|
|
|
|
|
|
|
std::string toIP4String(unsigned int IP) {
|
|
|
int a, b, c, d;
|
|
|
int a, b, c, d;
|
|
|
d = IP & 0x000000ff; IP >>= 8;
|
|
|
d = IP & 0x000000ff; IP >>= 8;
|
|
|
c = IP & 0x000000ff; IP >>= 8;
|
|
|
c = IP & 0x000000ff; IP >>= 8;
|
|
|
b = IP & 0x000000ff; IP >>= 8;
|
|
|
b = IP & 0x000000ff; IP >>= 8;
|
|
|
a = IP;
|
|
|
a = IP;
|
|
|
ostringstream S;
|
|
|
|
|
|
|
|
|
std::ostringstream S;
|
|
|
S << a << "." << b << "." << c << "." << d;
|
|
|
S << a << "." << b << "." << c << "." << d;
|
|
|
return S.str();
|
|
|
return S.str();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if(myConfig.findBlack) goodProbability = (myConfig.Probability <= R.Probability());
|
|
|
if(myConfig.findBlack) goodProbability = (myConfig.Probability <= R.Probability());
|
|
|
else goodProbability = (myConfig.Probability <= R.Probability());
|
|
|
else goodProbability = (myConfig.Probability <= R.Probability());
|
|
|
if(goodProbability && goodConfidence) {
|
|
|
if(goodProbability && goodConfidence) {
|
|
|
cout << toIP4String(IP);
|
|
|
|
|
|
|
|
|
std::cout << toIP4String(IP);
|
|
|
if(myConfig.showDetails) {
|
|
|
if(myConfig.showDetails) {
|
|
|
cout << "\t"
|
|
|
|
|
|
|
|
|
std::cout << "\t"
|
|
|
<< "g=" << R.Good()
|
|
|
<< "g=" << R.Good()
|
|
|
<< ", b=" << R.Bad()
|
|
|
<< ", b=" << R.Bad()
|
|
|
<< ", c=" << R.Confidence()
|
|
|
<< ", c=" << R.Confidence()
|
|
|
<< ", p=" << R.Probability();
|
|
|
<< ", p=" << R.Probability();
|
|
|
}
|
|
|
}
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
}
|
|
|
}
|
|
|
return R;
|
|
|
return R;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
DB.doForAllRecords(R);
|
|
|
DB.doForAllRecords(R);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
catch(exception &e) {
|
|
|
|
|
|
|
|
|
catch(const std::exception &e) {
|
|
|
displayHelp();
|
|
|
displayHelp();
|
|
|
cerr << endl << "Exception: " << e.what() << endl;
|
|
|
|
|
|
|
|
|
std::cerr << std::endl << "Exception: " << e.what() << std::endl;
|
|
|
return ErrorResultCode;
|
|
|
return ErrorResultCode;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|