|
|
|
|
|
|
|
|
#include "../CodeDweller/threading.hpp"
|
|
|
#include "../CodeDweller/threading.hpp"
|
|
|
#include "../SNFMulti/snf_xci.hpp"
|
|
|
#include "../SNFMulti/snf_xci.hpp"
|
|
|
|
|
|
|
|
|
using namespace std; // Introduce standard namespace.
|
|
|
|
|
|
|
|
|
namespace cd = codedweller;
|
|
|
|
|
|
|
|
|
const char* VERSION_INFO = "SNF Client Version 3.1 Build: " __DATE__ " " __TIME__;
|
|
|
|
|
|
|
|
|
const char* VERSION_INFO = "SNF Client Version 3.2 Build: " __DATE__ " " __TIME__;
|
|
|
|
|
|
|
|
|
time_t Timestamp() { // Get an ordinary timestamp.
|
|
|
time_t Timestamp() { // Get an ordinary timestamp.
|
|
|
time_t rawtime; // Grab raw time from
|
|
|
time_t rawtime; // Grab raw time from
|
|
|
|
|
|
|
|
|
return rawtime;
|
|
|
return rawtime;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
string Timestamp(time_t t) { // Convert time_t to a timestamp.
|
|
|
|
|
|
char TimestampBfr[20]; // Create a small buffer.
|
|
|
|
|
|
|
|
|
std::string Timestamp(time_t t) { // Convert time_t to a timestamp.
|
|
|
|
|
|
char TimestampBfr[16]; // Create a small buffer.
|
|
|
tm* gmt; // Get a ptr to a tm structure.
|
|
|
tm* gmt; // Get a ptr to a tm structure.
|
|
|
gmt = gmtime(&t); // Fill it with UTC.
|
|
|
gmt = gmtime(&t); // Fill it with UTC.
|
|
|
sprintf(TimestampBfr,"%04d%02d%02d%02d%02d%02d", // Format yyyymmddhhmmss
|
|
|
|
|
|
|
|
|
size_t l = snprintf(
|
|
|
|
|
|
TimestampBfr,
|
|
|
|
|
|
sizeof(TimestampBfr),
|
|
|
|
|
|
"%04d%02d%02d%02d%02d%02d", // Format yyyymmddhhmmss
|
|
|
gmt->tm_year+1900,
|
|
|
gmt->tm_year+1900,
|
|
|
gmt->tm_mon+1,
|
|
|
gmt->tm_mon+1,
|
|
|
gmt->tm_mday,
|
|
|
gmt->tm_mday,
|
|
|
|
|
|
|
|
|
gmt->tm_min,
|
|
|
gmt->tm_min,
|
|
|
gmt->tm_sec
|
|
|
gmt->tm_sec
|
|
|
);
|
|
|
);
|
|
|
return string(TimestampBfr); // Return a string.
|
|
|
|
|
|
|
|
|
const size_t TimestampLength = 4+2+2+2+2+2;
|
|
|
|
|
|
if(TimestampLength == l) return std::string(TimestampBfr); // Return a string.
|
|
|
|
|
|
else return std::string("00000000000000");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
string ErrorMessage(int argc, char** argv, string ErrorText) { // Create an error message.
|
|
|
|
|
|
|
|
|
std::string ErrorMessage(int argc, char** argv, std::string ErrorText) { // Create an error message.
|
|
|
|
|
|
|
|
|
ostringstream FailurePreamble; // Setup a stringstream for formatting.
|
|
|
|
|
|
|
|
|
std::ostringstream FailurePreamble; // Setup a stringstream for formatting.
|
|
|
|
|
|
|
|
|
string TimestampString = Timestamp(Timestamp()); // Get the UTC timestamp.
|
|
|
|
|
|
|
|
|
std::string TimestampString = Timestamp(Timestamp()); // Get the UTC timestamp.
|
|
|
|
|
|
|
|
|
FailurePreamble << TimestampString << ", "; // Start with the timestamp and
|
|
|
FailurePreamble << TimestampString << ", "; // Start with the timestamp and
|
|
|
for(int a = 1; a < argc; a++) { // then roll in all of the command
|
|
|
for(int a = 1; a < argc; a++) { // then roll in all of the command
|
|
|
FailurePreamble << "arg" << a << "=" << argv[a]; // line parameters. Follow that with
|
|
|
|
|
|
|
|
|
FailurePreamble << "arg" << a << "=" << argv[a]; // line parameters. Follow that with
|
|
|
if(a < argc-1) { FailurePreamble << ", "; } // a colon and the error itself.
|
|
|
if(a < argc-1) { FailurePreamble << ", "; } // a colon and the error itself.
|
|
|
else { FailurePreamble << " : "; }
|
|
|
else { FailurePreamble << " : "; }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
FailurePreamble << ErrorText << endl; // Tack on the error text.
|
|
|
|
|
|
|
|
|
FailurePreamble << ErrorText << std::endl; // Tack on the error text.
|
|
|
|
|
|
|
|
|
return FailurePreamble.str(); // Return the completed string.
|
|
|
return FailurePreamble.str(); // Return the completed string.
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// Figure out what we're going to do and create a suitable RequestString.
|
|
|
// Figure out what we're going to do and create a suitable RequestString.
|
|
|
|
|
|
|
|
|
bool DebugMode = false; // This will be our debug mode.
|
|
|
bool DebugMode = false; // This will be our debug mode.
|
|
|
string argv0(argv[0]); // Capture how we were called.
|
|
|
|
|
|
|
|
|
std::string argv0(argv[0]); // Capture how we were called.
|
|
|
if(
|
|
|
if(
|
|
|
string::npos != argv0.find("Debug") || // If we find "Debug" or
|
|
|
|
|
|
string::npos != argv0.find("debug") // "debug" in our command path
|
|
|
|
|
|
|
|
|
std::string::npos != argv0.find("Debug") || // If we find "Debug" or
|
|
|
|
|
|
std::string::npos != argv0.find("debug") // "debug" in our command path
|
|
|
) { // then we are in DebugMode.
|
|
|
) { // then we are in DebugMode.
|
|
|
DebugMode = true; // Set the flag and tell the
|
|
|
DebugMode = true; // Set the flag and tell the
|
|
|
cout << "Debug Mode" << endl; // watchers.
|
|
|
|
|
|
|
|
|
std::cout << "Debug Mode" << std::endl; // watchers.
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
string FileToScan; // What will we be scanning?
|
|
|
|
|
|
string RequestString; // What will we send to the server?
|
|
|
|
|
|
|
|
|
std::string FileToScan; // What will we be scanning?
|
|
|
|
|
|
std::string RequestString; // What will we send to the server?
|
|
|
bool ItIsACommand = false; // Is it a command?
|
|
|
bool ItIsACommand = false; // Is it a command?
|
|
|
bool ItIsAScan = false; // Is it a scan?
|
|
|
bool ItIsAScan = false; // Is it a scan?
|
|
|
bool GetXHDRs = false; // GetXHDRs with scan?
|
|
|
bool GetXHDRs = false; // GetXHDRs with scan?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
} else
|
|
|
|
|
|
|
|
|
if(0 == FileToScan.find("-shutdown")) { // If argv1 is -shutdown:
|
|
|
|
|
|
ItIsACommand = true; // Set the command flag.
|
|
|
|
|
|
if(DebugMode) { cout << "Command: shutdown" << endl; } // In debug - tell what we are doing.
|
|
|
|
|
|
|
|
|
if(0 == FileToScan.find("-shutdown")) { // If argv1 is -shutdown:
|
|
|
|
|
|
ItIsACommand = true; // Set the command flag.
|
|
|
|
|
|
if(DebugMode) { std::cout << "Command: shutdown" << std::endl; } // In debug - tell what we are doing.
|
|
|
|
|
|
|
|
|
// Format the request.
|
|
|
// Format the request.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if('-' == FileToScan.at(0)) { // If argv1 still looks like -something
|
|
|
if('-' == FileToScan.at(0)) { // If argv1 still looks like -something
|
|
|
goto BadCommandLine; // Complain and show the help text.
|
|
|
goto BadCommandLine; // Complain and show the help text.
|
|
|
|
|
|
|
|
|
} else { // If it does not then it is a file.
|
|
|
|
|
|
ItIsAScan = true; // Set the scan flag.
|
|
|
|
|
|
if(DebugMode) { cout << "Scan: " << FileToScan << endl; } // In debug - tell what we are doing.
|
|
|
|
|
|
|
|
|
} else { // If it does not then it is a file.
|
|
|
|
|
|
ItIsAScan = true; // Set the scan flag.
|
|
|
|
|
|
if(DebugMode) { std::cout << "Scan: " << FileToScan << std::endl; } // In debug - tell what we are doing.
|
|
|
|
|
|
|
|
|
// Format the request.
|
|
|
// Format the request.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
case 3: { // Special Scan Mode
|
|
|
case 3: { // Special Scan Mode
|
|
|
string CommandString = argv[1]; // -command
|
|
|
|
|
|
|
|
|
std::string CommandString = argv[1]; // -command
|
|
|
FileToScan = argv[2]; // What file to scan?
|
|
|
FileToScan = argv[2]; // What file to scan?
|
|
|
|
|
|
|
|
|
// XHeader Scan? ---------------------------------------------------
|
|
|
// XHeader Scan? ---------------------------------------------------
|
|
|
|
|
|
|
|
|
ItIsAScan = true; // Set the scan flag.
|
|
|
ItIsAScan = true; // Set the scan flag.
|
|
|
GetXHDRs = true; // Turn on XHDRs for the scan.
|
|
|
GetXHDRs = true; // Turn on XHDRs for the scan.
|
|
|
if(DebugMode) {
|
|
|
if(DebugMode) {
|
|
|
cout << "(xhdr)Scan: " << FileToScan << endl; // In debug - tell what we are doing.
|
|
|
|
|
|
|
|
|
std::cout << "(xhdr)Scan: " << FileToScan << std::endl; // In debug - tell what we are doing.
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// Format the request.
|
|
|
// Format the request.
|
|
|
|
|
|
|
|
|
ItIsAScan = true; // Set the scan flag.
|
|
|
ItIsAScan = true; // Set the scan flag.
|
|
|
|
|
|
|
|
|
const int SourceIPIndex = CommandString.find("=") + 1; // Find source after "-source="
|
|
|
const int SourceIPIndex = CommandString.find("=") + 1; // Find source after "-source="
|
|
|
IP4Address SourceIP = CommandString.substr(SourceIPIndex); // Extract the source IP.
|
|
|
|
|
|
|
|
|
cd::IP4Address SourceIP = CommandString.substr(SourceIPIndex); // Extract the source IP.
|
|
|
|
|
|
|
|
|
if(DebugMode) {
|
|
|
if(DebugMode) {
|
|
|
cout << "([" << (string) SourceIP // In debug - tell what we are doing.
|
|
|
|
|
|
<< "])Scan: " << FileToScan << endl;
|
|
|
|
|
|
|
|
|
std::cout << "([" << (std::string) SourceIP // In debug - tell what we are doing.
|
|
|
|
|
|
<< "])Scan: " << FileToScan << std::endl;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// Format the request.
|
|
|
// Format the request.
|
|
|
|
|
|
|
|
|
RequestString = "<snf><xci><scanner><scan file=\'";
|
|
|
RequestString = "<snf><xci><scanner><scan file=\'";
|
|
|
RequestString.append(FileToScan);
|
|
|
RequestString.append(FileToScan);
|
|
|
RequestString.append("\' ip=\'");
|
|
|
RequestString.append("\' ip=\'");
|
|
|
RequestString.append((string) SourceIP);
|
|
|
|
|
|
|
|
|
RequestString.append((std::string) SourceIP);
|
|
|
RequestString.append("\'/></scanner></xci></snf>\n");
|
|
|
RequestString.append("\'/></scanner></xci></snf>\n");
|
|
|
|
|
|
|
|
|
} else
|
|
|
} else
|
|
|
|
|
|
|
|
|
ItIsAScan = true; // Set the scan flag.
|
|
|
ItIsAScan = true; // Set the scan flag.
|
|
|
FileToScan = argv[2]; // Grab the message_file_name for
|
|
|
FileToScan = argv[2]; // Grab the message_file_name for
|
|
|
if(DebugMode) { // a compatability scan and if
|
|
|
if(DebugMode) { // a compatability scan and if
|
|
|
cout << "(compat)Scan: " << FileToScan << endl; // debugging then announce it.
|
|
|
|
|
|
|
|
|
std::cout << "(compat)Scan: " << FileToScan << std::endl; // debugging then announce it.
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// Format the request.
|
|
|
// Format the request.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 4: {
|
|
|
case 4: {
|
|
|
|
|
|
|
|
|
string Command1String = argv[1]; // -command1
|
|
|
|
|
|
string Command2String = argv[2]; // -command2
|
|
|
|
|
|
|
|
|
std::string Command1String = argv[1]; // -command1
|
|
|
|
|
|
std::string Command2String = argv[2]; // -command2
|
|
|
FileToScan = argv[3]; // What file to scan?
|
|
|
FileToScan = argv[3]; // What file to scan?
|
|
|
|
|
|
|
|
|
// XHeader Scan W/ Source IP? --------------------------------------
|
|
|
// XHeader Scan W/ Source IP? --------------------------------------
|
|
|
|
|
|
|
|
|
if(0 == Command1String.find("-source=")) { // If things are reversed
|
|
|
if(0 == Command1String.find("-source=")) { // If things are reversed
|
|
|
string tmp = Command2String; // swap them to the order we
|
|
|
|
|
|
|
|
|
std::string tmp = Command2String; // swap them to the order we
|
|
|
Command2String = Command1String; // are expecting. If we're wrong
|
|
|
Command2String = Command1String; // are expecting. If we're wrong
|
|
|
Command1String = tmp; // then that case will be handled
|
|
|
Command1String = tmp; // then that case will be handled
|
|
|
} // next step.
|
|
|
} // next step.
|
|
|
|
|
|
|
|
|
GetXHDRs = true; // Turn on XHDRs for the scan.
|
|
|
GetXHDRs = true; // Turn on XHDRs for the scan.
|
|
|
|
|
|
|
|
|
const int SourceIPIndex = Command2String.find("=") + 1; // Find source after "-source="
|
|
|
const int SourceIPIndex = Command2String.find("=") + 1; // Find source after "-source="
|
|
|
IP4Address SourceIP = Command2String.substr(SourceIPIndex); // Extract the source IP.
|
|
|
|
|
|
|
|
|
cd::IP4Address SourceIP = Command2String.substr(SourceIPIndex); // Extract the source IP.
|
|
|
|
|
|
|
|
|
if(DebugMode) {
|
|
|
if(DebugMode) {
|
|
|
cout << "(xhdr [" << (string) SourceIP // In debug - tell what we are doing.
|
|
|
|
|
|
<< "])Scan: " << FileToScan << endl;
|
|
|
|
|
|
|
|
|
std::cout << "(xhdr [" << (std::string) SourceIP // In debug - tell what we are doing.
|
|
|
|
|
|
<< "])Scan: " << FileToScan << std::endl;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// Format the request.
|
|
|
// Format the request.
|
|
|
|
|
|
|
|
|
RequestString = "<snf><xci><scanner><scan file=\'";
|
|
|
RequestString = "<snf><xci><scanner><scan file=\'";
|
|
|
RequestString.append(FileToScan);
|
|
|
RequestString.append(FileToScan);
|
|
|
RequestString.append("\' xhdr=\'yes\' ip=\'");
|
|
|
RequestString.append("\' xhdr=\'yes\' ip=\'");
|
|
|
RequestString.append((string) SourceIP);
|
|
|
|
|
|
|
|
|
RequestString.append((std::string) SourceIP);
|
|
|
RequestString.append("\'/></scanner></xci></snf>\n");
|
|
|
RequestString.append("\'/></scanner></xci></snf>\n");
|
|
|
|
|
|
|
|
|
} else
|
|
|
} else
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
case 6: { // GBUdb set mode.
|
|
|
case 6: { // GBUdb set mode.
|
|
|
string CommandString = argv[1]; // -command
|
|
|
|
|
|
|
|
|
std::string CommandString = argv[1]; // -command
|
|
|
|
|
|
|
|
|
// GBUdb set? ------------------------------------------------------
|
|
|
// GBUdb set? ------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: { // If we don't know: show help.
|
|
|
default: { // If we don't know: show help.
|
|
|
BadCommandLine: // Shortcut for others.
|
|
|
BadCommandLine: // Shortcut for others.
|
|
|
cout
|
|
|
|
|
|
<< endl
|
|
|
|
|
|
<< VERSION_INFO << endl
|
|
|
|
|
|
<< endl
|
|
|
|
|
|
<< "Help:" << endl
|
|
|
|
|
|
<< endl
|
|
|
|
|
|
<< " To scan a message file use: " << endl
|
|
|
|
|
|
<< " SNFClient.exe [-xhdr] [-source=<IP4Address>] <FileNameToScan>" << endl
|
|
|
|
|
|
<< " or: SNFClient.exe <Authenticationxx> <FileNameToScan>" << endl
|
|
|
|
|
|
<< endl
|
|
|
|
|
|
<< " To test an IP with GBUdb use: " << endl
|
|
|
|
|
|
<< " SNFClient.exe -test <IP4Address>" << endl
|
|
|
|
|
|
<< endl
|
|
|
|
|
|
<< " To update GBUdb records use: " << endl
|
|
|
|
|
|
<< " SNFClient.exe -set <IP4Address> <flag> <bad> <good>" << endl
|
|
|
|
|
|
<< " or: SNFClient.exe -drop <IP4Address>" << endl
|
|
|
|
|
|
<< " or: SNFClient.exe -good <IP4Address>" << endl
|
|
|
|
|
|
<< " or: SNFClient.exe -bad <IP4Address>" << endl
|
|
|
|
|
|
<< endl
|
|
|
|
|
|
<< " To check SNFServer status use: " << endl
|
|
|
|
|
|
<< " SNFClient.exe -status.second" << endl
|
|
|
|
|
|
<< " or: SNFClient.exe -status.minute" << endl
|
|
|
|
|
|
<< " or: SNFClient.exe -status.hour" << endl
|
|
|
|
|
|
<< endl
|
|
|
|
|
|
<< " To shut down the SNFServer use: " << endl
|
|
|
|
|
|
<< " SNFClient.exe -shutdown" << endl
|
|
|
|
|
|
<< endl
|
|
|
|
|
|
<< " For more information see www.armresearch.com" << endl
|
|
|
|
|
|
<< " (C) 2007-2019 Arm Research Labs, LLC." << endl;
|
|
|
|
|
|
|
|
|
std::cout
|
|
|
|
|
|
<< std::endl
|
|
|
|
|
|
<< VERSION_INFO << std::endl
|
|
|
|
|
|
<< std::endl
|
|
|
|
|
|
<< "Help:" << std::endl
|
|
|
|
|
|
<< std::endl
|
|
|
|
|
|
<< " To scan a message file use: " << std::endl
|
|
|
|
|
|
<< " SNFClient.exe [-xhdr] [-source=<IP4Address>] <FileNameToScan>" << std::endl
|
|
|
|
|
|
<< " or: SNFClient.exe <Authenticationxx> <FileNameToScan>" << std::endl
|
|
|
|
|
|
<< std::endl
|
|
|
|
|
|
<< " To test an IP with GBUdb use: " << std::endl
|
|
|
|
|
|
<< " SNFClient.exe -test <IP4Address>" << std::endl
|
|
|
|
|
|
<< std::endl
|
|
|
|
|
|
<< " To update GBUdb records use: " << std::endl
|
|
|
|
|
|
<< " SNFClient.exe -set <IP4Address> <flag> <bad> <good>" << std::endl
|
|
|
|
|
|
<< " or: SNFClient.exe -drop <IP4Address>" << std::endl
|
|
|
|
|
|
<< " or: SNFClient.exe -good <IP4Address>" << std::endl
|
|
|
|
|
|
<< " or: SNFClient.exe -bad <IP4Address>" << std::endl
|
|
|
|
|
|
<< std::endl
|
|
|
|
|
|
<< " To check SNFServer status use: " << std::endl
|
|
|
|
|
|
<< " SNFClient.exe -status.second" << std::endl
|
|
|
|
|
|
<< " or: SNFClient.exe -status.minute" << std::endl
|
|
|
|
|
|
<< " or: SNFClient.exe -status.hour" << std::endl
|
|
|
|
|
|
<< std::endl
|
|
|
|
|
|
<< " To shut down the SNFServer use: " << std::endl
|
|
|
|
|
|
<< " SNFClient.exe -shutdown" << std::endl
|
|
|
|
|
|
<< std::endl
|
|
|
|
|
|
<< " For more information see www.armresearch.com" << std::endl
|
|
|
|
|
|
<< " (C) 2007-2020 Arm Research Labs, LLC." << std::endl;
|
|
|
|
|
|
|
|
|
return 0; // Return 0 on help.
|
|
|
return 0; // Return 0 on help.
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If we're in debug mode this is a good time to emit our request string
|
|
|
// If we're in debug mode this is a good time to emit our request string
|
|
|
|
|
|
|
|
|
if(DebugMode) { cout << RequestString << endl; } // If debugging, show our request.
|
|
|
|
|
|
|
|
|
if(DebugMode) { std::cout << RequestString << std::endl; } // If debugging, show our request.
|
|
|
|
|
|
|
|
|
// Since we're gonna do this -- prepare for an error
|
|
|
// Since we're gonna do this -- prepare for an error
|
|
|
|
|
|
|
|
|
string ERRFname; // The default error log name will
|
|
|
|
|
|
|
|
|
std::string ERRFname; // The default error log name will
|
|
|
ERRFname = argv[0]; // be the program file name with
|
|
|
ERRFname = argv[0]; // be the program file name with
|
|
|
ERRFname.append(".err"); // .err tagged on the end.
|
|
|
ERRFname.append(".err"); // .err tagged on the end.
|
|
|
const int FailSafeResult = 0; // Fail Safe result code.
|
|
|
const int FailSafeResult = 0; // Fail Safe result code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Connect to the server and get the result...
|
|
|
// Connect to the server and get the result...
|
|
|
|
|
|
|
|
|
string ResultString; // We need our result string.
|
|
|
|
|
|
|
|
|
std::string ResultString; // We need our result string.
|
|
|
bool ConnectSuccess = false; // We need our success flag.
|
|
|
bool ConnectSuccess = false; // We need our success flag.
|
|
|
|
|
|
|
|
|
// Max time in this loop should be (100*50ms) = 5 seconds per try times
|
|
|
// Max time in this loop should be (100*50ms) = 5 seconds per try times
|
|
|
|
|
|
|
|
|
memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Set the entire thing to nulls.
|
|
|
memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Set the entire thing to nulls.
|
|
|
|
|
|
|
|
|
const int Tries = 20; // How many times to try this.
|
|
|
const int Tries = 20; // How many times to try this.
|
|
|
Sleeper SleepAfterAttempt(100); // How long to sleep between attempts.
|
|
|
|
|
|
|
|
|
cd::Sleeper SleepAfterAttempt(100); // How long to sleep between attempts.
|
|
|
|
|
|
|
|
|
const int OpenTries = 90; // How many tries at opening.
|
|
|
const int OpenTries = 90; // How many tries at opening.
|
|
|
Sleeper WaitForOpen(10); // How long to wait for an open cycle.
|
|
|
|
|
|
|
|
|
cd::Sleeper WaitForOpen(10); // How long to wait for an open cycle.
|
|
|
|
|
|
|
|
|
const int ReadTries = 900; // How many tries at reading.
|
|
|
const int ReadTries = 900; // How many tries at reading.
|
|
|
Sleeper SleepBeforeReading(10); // How long to pause before reading.
|
|
|
|
|
|
|
|
|
cd::Sleeper SleepBeforeReading(10); // How long to pause before reading.
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
** 20 * 100ms = 2 seconds for all tries.
|
|
|
** 20 * 100ms = 2 seconds for all tries.
|
|
|
|
|
|
|
|
|
for(int tryagain = Tries; (0<tryagain) && (!ConnectSuccess); tryagain--) { // Try a few times to get this done.
|
|
|
for(int tryagain = Tries; (0<tryagain) && (!ConnectSuccess); tryagain--) { // Try a few times to get this done.
|
|
|
try {
|
|
|
try {
|
|
|
ResultString = ""; // Clear our result string.
|
|
|
ResultString = ""; // Clear our result string.
|
|
|
TCPHost SNFServer(9001); // Create connection to server.
|
|
|
|
|
|
|
|
|
cd::TCPHost SNFServer(9001); // Create connection to server.
|
|
|
SNFServer.makeNonBlocking(); // Make it non-blocking.
|
|
|
SNFServer.makeNonBlocking(); // Make it non-blocking.
|
|
|
|
|
|
|
|
|
for(int tries = OpenTries; 0 < tries; tries--) { // Wait & Watch for a good connection.
|
|
|
for(int tries = OpenTries; 0 < tries; tries--) { // Wait & Watch for a good connection.
|
|
|
|
|
|
|
|
|
memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Clear the buffer.
|
|
|
memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Clear the buffer.
|
|
|
SNFServer.receive(ResultBuffer, ResultBufferSize); // Receive the answer.
|
|
|
SNFServer.receive(ResultBuffer, ResultBufferSize); // Receive the answer.
|
|
|
ResultString.append(ResultBuffer);
|
|
|
ResultString.append(ResultBuffer);
|
|
|
if(string::npos ==
|
|
|
|
|
|
|
|
|
if(std::string::npos ==
|
|
|
ResultString.rfind("</snf>",ResultString.length())) { // If we don't have the end yet.
|
|
|
ResultString.rfind("</snf>",ResultString.length())) { // If we don't have the end yet.
|
|
|
continue; // Try again.
|
|
|
continue; // Try again.
|
|
|
} else { // If we got to end of line
|
|
|
} else { // If we got to end of line
|
|
|
|
|
|
|
|
|
if(!ConnectSuccess) { // If no connection success complain!
|
|
|
if(!ConnectSuccess) { // If no connection success complain!
|
|
|
|
|
|
|
|
|
if(DebugMode) {
|
|
|
if(DebugMode) {
|
|
|
cout << FileToScan << ": ";
|
|
|
|
|
|
cout << "Could Not Connect!" << endl;
|
|
|
|
|
|
|
|
|
std::cout << FileToScan << ": ";
|
|
|
|
|
|
std::cout << "Could Not Connect!" << std::endl;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
ofstream ERRF(ERRFname.c_str(), ios::out | ios::ate | ios::app);
|
|
|
|
|
|
|
|
|
std::ofstream ERRF(ERRFname.c_str(), std::ios::out | std::ios::ate | std::ios::app);
|
|
|
ERRF << ErrorMessage(argc, argv, "Could Not Connect!");
|
|
|
ERRF << ErrorMessage(argc, argv, "Could Not Connect!");
|
|
|
ERRF.close();
|
|
|
ERRF.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// At this point we should have a usable result.
|
|
|
// At this point we should have a usable result.
|
|
|
|
|
|
|
|
|
if(DebugMode) { cout << ResultString << endl; } // In debug, show the result string.
|
|
|
|
|
|
|
|
|
if(DebugMode) { std::cout << ResultString << std::endl; } // In debug, show the result string.
|
|
|
|
|
|
|
|
|
snf_xci Reader(ResultString); // Interpret the data and check for
|
|
|
snf_xci Reader(ResultString); // Interpret the data and check for
|
|
|
if(Reader.bad()) { // a proper read. If it was bad then
|
|
|
if(Reader.bad()) { // a proper read. If it was bad then
|
|
|
|
|
|
|
|
|
if(DebugMode) {
|
|
|
if(DebugMode) {
|
|
|
cout << FileToScan << ": ";
|
|
|
|
|
|
cout << "Bad result from server!" << endl;
|
|
|
|
|
|
cout << ResultString << endl;
|
|
|
|
|
|
|
|
|
std::cout << FileToScan << ": ";
|
|
|
|
|
|
std::cout << "Bad result from server!" << std::endl;
|
|
|
|
|
|
std::cout << ResultString << std::endl;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
ofstream ERRF(ERRFname.c_str(), ios::out | ios::ate | ios::app);
|
|
|
|
|
|
|
|
|
std::ofstream ERRF(ERRFname.c_str(), std::ios::out | std::ios::ate | std::ios::app);
|
|
|
|
|
|
|
|
|
ERRF << ErrorMessage(argc, argv, // complain and spit out what we got
|
|
|
ERRF << ErrorMessage(argc, argv, // complain and spit out what we got
|
|
|
"Bad result from server! " + ResultString); // for debugging purposes.
|
|
|
"Bad result from server! " + ResultString); // for debugging purposes.
|
|
|
return FailSafeResult; // Return our failsafe value.
|
|
|
return FailSafeResult; // Return our failsafe value.
|
|
|
|
|
|
|
|
|
if(0 < Reader.xci_error_message.length()) { // If the result was a general error
|
|
|
if(0 < Reader.xci_error_message.length()) { // If the result was a general error
|
|
|
|
|
|
|
|
|
if(DebugMode) {
|
|
|
if(DebugMode) {
|
|
|
cout << FileToScan << ": ";
|
|
|
|
|
|
cout << "XCI Error!: " << Reader.xci_error_message << endl;
|
|
|
|
|
|
|
|
|
std::cout << FileToScan << ": ";
|
|
|
|
|
|
std::cout << "XCI Error!: " << Reader.xci_error_message << std::endl;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
ofstream ERRF(ERRFname.c_str(), ios::out | ios::ate | ios::app);
|
|
|
|
|
|
|
|
|
std::ofstream ERRF(ERRFname.c_str(), std::ios::out | std::ios::ate | std::ios::app);
|
|
|
ERRF << ErrorMessage(argc, argv,
|
|
|
ERRF << ErrorMessage(argc, argv,
|
|
|
"XCI Error!: " + Reader.xci_error_message); // then spit that out
|
|
|
"XCI Error!: " + Reader.xci_error_message); // then spit that out
|
|
|
return FailSafeResult; // and return the failsafe.
|
|
|
return FailSafeResult; // and return the failsafe.
|
|
|
|
|
|
|
|
|
// If we got here we've successfully parsed the results.
|
|
|
// If we got here we've successfully parsed the results.
|
|
|
|
|
|
|
|
|
if(ItIsACommand) { // If it was a command then
|
|
|
if(ItIsACommand) { // If it was a command then
|
|
|
cout << " [Server Says: " << Reader.xci_server_response << "]" << endl; // show the response.
|
|
|
|
|
|
|
|
|
std::cout
|
|
|
|
|
|
<< " [Server Says: " << Reader.xci_server_response << "]" // show the response.
|
|
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
else if(ItIsAScan) { // If it was a scan then
|
|
|
else if(ItIsAScan) { // If it was a scan then
|
|
|
int ResultCode = Reader.scanner_result_code; // grab the result code.
|
|
|
int ResultCode = Reader.scanner_result_code; // grab the result code.
|
|
|
|
|
|
|
|
|
if(0 < Reader.scanner_result_xhdr.length()) { // If we have xheaders show them.
|
|
|
|
|
|
cout << endl << Reader.scanner_result_xhdr << endl;
|
|
|
|
|
|
|
|
|
if(GetXHDRs) { // If we want xheaders show them.
|
|
|
|
|
|
std::cout << std::endl << Reader.scanner_result_xhdr << std::endl;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if(DebugMode) { cout << "(" << ResultCode << ")"; }
|
|
|
|
|
|
|
|
|
if(DebugMode) { std::cout << "(" << ResultCode << ")"; }
|
|
|
|
|
|
|
|
|
if( (0 < ResultCode) && (64 > ResultCode) ) { // If the result code means SPAM
|
|
|
if( (0 < ResultCode) && (64 > ResultCode) ) { // If the result code means SPAM
|
|
|
if(DebugMode) { cout << "[spam]" << endl; }
|
|
|
|
|
|
|
|
|
if(DebugMode) { std::cout << "[spam]" << std::endl; }
|
|
|
return ResultCode; // Return the result code.
|
|
|
return ResultCode; // Return the result code.
|
|
|
} else
|
|
|
} else
|
|
|
if(0 == ResultCode) {
|
|
|
if(0 == ResultCode) {
|
|
|
if(DebugMode) { cout << "[clean]" << endl; }
|
|
|
|
|
|
|
|
|
if(DebugMode) { std::cout << "[clean]" << std::endl; }
|
|
|
return 0;
|
|
|
return 0;
|
|
|
} else {
|
|
|
} else {
|
|
|
if(DebugMode) { cout << "[Fail Safe!]" << endl; }
|
|
|
|
|
|
|
|
|
if(DebugMode) { std::cout << "[Fail Safe!]" << std::endl; }
|
|
|
return FailSafeResult;
|
|
|
return FailSafeResult;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
else if(ItIsAGBUdb) { // If it was a GBUdb function then show
|
|
|
else if(ItIsAGBUdb) { // If it was a GBUdb function then show
|
|
|
cout // the results to whomever is watching.
|
|
|
|
|
|
<< "GBUdb Record for " << Reader.gbudb_result_ip << endl
|
|
|
|
|
|
<< " Type Flag: " << Reader.gbudb_result_type << endl
|
|
|
|
|
|
<< " Bad Count: " << Reader.gbudb_result_bad_count << endl
|
|
|
|
|
|
<< " Good Count: " << Reader.gbudb_result_good_count << endl
|
|
|
|
|
|
<< "Probability: " << Reader.gbudb_result_probability << endl
|
|
|
|
|
|
<< " Confidence: " << Reader.gbudb_result_confidence << endl
|
|
|
|
|
|
<< " Range: " << Reader.gbudb_result_range << endl
|
|
|
|
|
|
<< " Code: " << Reader.gbudb_result_code << endl
|
|
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
std::cout // the results to whomever is watching.
|
|
|
|
|
|
<< "GBUdb Record for " << Reader.gbudb_result_ip << std::endl
|
|
|
|
|
|
<< " Type Flag: " << Reader.gbudb_result_type << std::endl
|
|
|
|
|
|
<< " Bad Count: " << Reader.gbudb_result_bad_count << std::endl
|
|
|
|
|
|
<< " Good Count: " << Reader.gbudb_result_good_count << std::endl
|
|
|
|
|
|
<< "Probability: " << Reader.gbudb_result_probability << std::endl
|
|
|
|
|
|
<< " Confidence: " << Reader.gbudb_result_confidence << std::endl
|
|
|
|
|
|
<< " Range: " << Reader.gbudb_result_range << std::endl
|
|
|
|
|
|
<< " Code: " << Reader.gbudb_result_code << std::endl
|
|
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
|
return Reader.gbudb_result_code;
|
|
|
return Reader.gbudb_result_code;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
else if(ItIsAReport) { // If it was a report request then
|
|
|
else if(ItIsAReport) { // If it was a report request then
|
|
|
cout // output the report. Add a handy
|
|
|
|
|
|
<< endl << "<!-- Status Report -->" << endl // XML comment to help humans.
|
|
|
|
|
|
<< Reader.report_response << endl;
|
|
|
|
|
|
|
|
|
std::cout // output the report. Add a handy
|
|
|
|
|
|
<< std::endl << "<!-- Status Report -->" << std::endl // XML comment to help humans.
|
|
|
|
|
|
<< Reader.report_response << std::endl;
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// You can't get here from there.
|
|
|
// You can't get here from there.
|
|
|
if(DebugMode) { cout << "End Of Logic [Fail Safe!!]" << endl; }
|
|
|
|
|
|
|
|
|
if(DebugMode) { std::cout << "End Of Logic [Fail Safe!!]" << std::endl; }
|
|
|
return FailSafeResult;
|
|
|
return FailSafeResult;
|
|
|
}
|
|
|
}
|