git-svn-id: https://svn.microneil.com/svn/SNFMulti/trunk@4 dc71a809-1921-45c4-985c-09c81d0142d9wx
#include <sstream> | #include <sstream> | ||||
#include "SNFMulti.hpp" | #include "SNFMulti.hpp" | ||||
#include "timing.hpp" | |||||
#include "../CodeDweller/timing.hpp" | |||||
//#include "../nvwa-0.6/nvwa/debug_new.h" | //#include "../nvwa-0.6/nvwa/debug_new.h" | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <ctime> | #include <ctime> | ||||
#include <string> | #include <string> | ||||
#include "../CodeDweller/threading.hpp" | |||||
#include "GBUdb.hpp" | |||||
#include "FilterChain.hpp" | #include "FilterChain.hpp" | ||||
#include "snf_engine.hpp" | #include "snf_engine.hpp" | ||||
#include "snf_match.h" | #include "snf_match.h" | ||||
#include "threading.hpp" | |||||
#include "snfCFGmgr.hpp" | #include "snfCFGmgr.hpp" | ||||
#include "snfLOGmgr.hpp" | #include "snfLOGmgr.hpp" | ||||
#include "snfNETmgr.hpp" | #include "snfNETmgr.hpp" | ||||
#include "snfGBUdbmgr.hpp" | #include "snfGBUdbmgr.hpp" | ||||
#include "GBUdb.hpp" | |||||
#include "snfXCImgr.hpp" | #include "snfXCImgr.hpp" | ||||
#include <cassert> | #include <cassert> |
// MANGLER.CPP | |||||
// | |||||
// (C) 1984-2009 MicroNeil Research Corporation | |||||
// Derived from Version 1 of Mangler Encryption Algorythm, 1984. | |||||
// Derived from Version 2 of Mangler Encryption Algorythm, 1998. | |||||
// | |||||
// 20021008 _M | |||||
// Found and corrected range bug in ChaosDriver(void) where | |||||
// ~Position might access a location outside the fill. Replaced | |||||
// ~Position with Position^0xff which has the intended effect. | |||||
// 20020119 _M Version 3.0 | |||||
// | |||||
// Mangler encryption engine object. | |||||
// Using new optimized chaos driver for uniformity experiments. | |||||
// Important in this experiment is proof of highest possible entropy. | |||||
#include "mangler.hpp" | |||||
unsigned char MANGLER::ChaosDriver(void) { // Return the current | |||||
return Fill[Fill[Position]^Fill[Position^0xff]]; // chaos engine output | |||||
} // value. | |||||
// As of version 3 the output of the chaos driver was strengthened for | |||||
// cryptography and to increase the sensitivity of the output for use | |||||
// as a random number generator. In version 2, the software would simply | |||||
// return the fill value at the engine's current position. In the new | |||||
// version two distinct fill values are involved in abstracting the | |||||
// value of Position and determining the final output value and the Position | |||||
// value itself is used to add complexity to the output. | |||||
unsigned char MANGLER::Rotate(unsigned char i) { // Bitwise rotates i | |||||
return ( | |||||
(i & 0x80)? // This operation is | |||||
(i<<1)+1: // described without | |||||
(i<<1) // using asm. | |||||
); | |||||
} | |||||
void MANGLER::ChaosDriver(unsigned char i) { // Drives chaos engine. | |||||
// First we move our mixing position in the fill buffer forward. | |||||
Position=( // Move mixing position. | |||||
Position+1+ // Move at least 1, then | |||||
(Fill[Position]&0x0f) // maybe a few more. | |||||
)%256; // But stay within the fill. | |||||
// The fill position in version 2 was simply incremented. This allowed | |||||
// for an attacker to predict something important about the state of | |||||
// the chaos engine. The new method above uses abstraction through the | |||||
// fill buffer to introduce "jitter" when setting a new position based | |||||
// on data that is hidden from the outside. | |||||
// Next we abstract the incoming character through the fill buffer and | |||||
// use it to select fill data to rotate and swap. | |||||
unsigned char Swap = ((Fill[Position]^Fill[i])+Position+i)%256; | |||||
unsigned char Tmp; | |||||
Tmp = Fill[Swap]; | |||||
Fill[Swap]=Fill[Position]; | |||||
Fill[Position]=Rotate(Tmp); | |||||
// Whenever the Swap and Path positions are the same, the result is | |||||
// that no data is swapped in the chaos field. We resolve that by | |||||
// recalling the ChaosDriver. This has the added effect of increasing | |||||
// the complexity and making it more difficult to predict the state | |||||
// of the engine... particularly because the engine evloves to a new | |||||
// state under these conditions without having exposed that change | |||||
// to the outside world. | |||||
if(Position==Swap) ChaosDriver(Tmp); // If we didn't swap, recurse. | |||||
} | |||||
// The encryption / decryption scheme works by modulating an input data | |||||
// stream with a chaotic system and allowing the encrypted stream to drive | |||||
// the chaotic system of both the transmitter and receiver. This will | |||||
// synchronize the two chaotic systems and allow the receiving system to | |||||
// "predict" the state of the transmiting system so that it can properly | |||||
// demodulate the encrypted stream. Both chaotic systems must start in the | |||||
// same state with the same fill data characteristics or else the two | |||||
// chaotic systems evolve to further divergent states. | |||||
unsigned char MANGLER::Encrypt(unsigned char i) { | |||||
unsigned char g = ChaosDriver() ^ i; // Take the output of the | |||||
ChaosDriver(g); // chaos engine and use it | |||||
return g; // to moduleate the input. | |||||
} // Then drive the engine | |||||
// with the encrypted data. | |||||
unsigned char MANGLER::Decrypt(unsigned char i) { | |||||
unsigned char g = ChaosDriver() ^ i; // Take the output of the | |||||
ChaosDriver(i); // chaos engine and use it | |||||
return g; // to demodulate the input. | |||||
} // then drive the engine | |||||
// with the original input. | |||||
MANGLER::MANGLER(void) { | |||||
for(short c = 0;c<256;c++) // The default constructor sets | |||||
Fill[c]=(unsigned char) c; // the key to the root primary | |||||
Position = 0; // value and Position to 0. | |||||
} | |||||
// MANGLER.HPP | |||||
// | |||||
// (C) 1984-2009 MicroNeil Research Corporation | |||||
// Derived from Version 1 of Mangler Encryption Algorythm, 1984. | |||||
// Derived from Version 2 of Mangler Encryption Algorythm, 1998. | |||||
// | |||||
// 20020119 _M Mangler V3. | |||||
// Mangler object header file. | |||||
// If it's already been included, it doesn't need to be included again. | |||||
#ifndef _MANGLER_ | |||||
#define _MANGLER_ | |||||
class MANGLER { | |||||
private: | |||||
unsigned char Fill[256]; // Where to store the fill. | |||||
unsigned int Position; // Where to put position. | |||||
unsigned char Rotate(unsigned char); // Bitwise Rotate Utility. | |||||
unsigned char ChaosDriver(void); // Returns current chaos. | |||||
void ChaosDriver(unsigned char i); // Drives chaos forward. | |||||
public: | |||||
unsigned char Encrypt(unsigned char i); // Returns encrypted data. | |||||
unsigned char Decrypt(unsigned char i); // Returns decrypted data. | |||||
MANGLER(void); // Default. | |||||
}; | |||||
#endif | |||||
#include "GBUdb.hpp" | #include "GBUdb.hpp" | ||||
#include "snf_HeaderFinder.hpp" | #include "snf_HeaderFinder.hpp" | ||||
#include "configuration.hpp" | |||||
#include "threading.hpp" | |||||
#include "../CodeDweller/configuration.hpp" | |||||
#include "../CodeDweller/threading.hpp" | |||||
#include <string> | #include <string> | ||||
#include <set> | #include <set> | ||||
#ifndef snfGBUdbmgr_included | #ifndef snfGBUdbmgr_included | ||||
#define snfGBUdbmgr_included | #define snfGBUdbmgr_included | ||||
#include "threading.hpp" | |||||
#include "timing.hpp" | |||||
#include "../CodeDweller/threading.hpp" | |||||
#include "../CodeDweller/timing.hpp" | |||||
#include "snfCFGmgr.hpp" | #include "snfCFGmgr.hpp" | ||||
#include "snfLOGmgr.hpp" | #include "snfLOGmgr.hpp" | ||||
#include "GBUdb.hpp" | #include "GBUdb.hpp" |
// Log Manager implementations see snfLOGmgr.hpp for details. | // Log Manager implementations see snfLOGmgr.hpp for details. | ||||
#include "snfLOGmgr.hpp" | #include "snfLOGmgr.hpp" | ||||
#include "threading.hpp" | |||||
#include "timing.hpp" | |||||
#include "../CodeDweller/threading.hpp" | |||||
#include "../CodeDweller/timing.hpp" | |||||
#include <unistd.h> | #include <unistd.h> | ||||
using namespace std; | using namespace std; |
#include <ctime> | #include <ctime> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include "timing.hpp" | |||||
#include "threading.hpp" | |||||
#include "../CodeDweller/timing.hpp" | |||||
#include "../CodeDweller/threading.hpp" | |||||
#include "../CodeDweller/histogram.hpp" | |||||
#include "snf_match.h" | #include "snf_match.h" | ||||
#include "snfCFGmgr.hpp" | #include "snfCFGmgr.hpp" | ||||
#include "snfNETmgr.hpp" | #include "snfNETmgr.hpp" | ||||
#include "GBUdb.hpp" | #include "GBUdb.hpp" | ||||
#include "histogram.hpp" | |||||
class snfNETmgr; // Declare snfNETmgr | class snfNETmgr; // Declare snfNETmgr | ||||
extern const char* SNF_ENGINE_VERSION; // Declare the Engine Version Data | extern const char* SNF_ENGINE_VERSION; // Declare the Engine Version Data |
#include <sstream> | #include <sstream> | ||||
#include "snfNETmgr.hpp" | #include "snfNETmgr.hpp" | ||||
#include "snf_sync.hpp" | #include "snf_sync.hpp" | ||||
#include "mangler.hpp" | |||||
#include "base64codec.hpp" | |||||
#include "../CodeDweller/mangler.hpp" | |||||
#include "../CodeDweller/base64codec.hpp" | |||||
// #include "tcp_watchdog.hpp" No longer using TCPWatchdog -- see below _M | // #include "tcp_watchdog.hpp" No longer using TCPWatchdog -- see below _M | ||||
using namespace std; | using namespace std; |
#include <stdexcept> | #include <stdexcept> | ||||
#include <vector> | #include <vector> | ||||
#include "networking.hpp" | |||||
#include "timing.hpp" | |||||
#include "threading.hpp" | |||||
#include "../CodeDweller/networking.hpp" | |||||
#include "../CodeDweller/timing.hpp" | |||||
#include "../CodeDweller/threading.hpp" | |||||
#include "../CodeDweller/mangler.hpp" | |||||
#include "snfCFGmgr.hpp" | #include "snfCFGmgr.hpp" | ||||
#include "snfLOGmgr.hpp" | #include "snfLOGmgr.hpp" | ||||
#include "snfGBUdbmgr.hpp" | #include "snfGBUdbmgr.hpp" | ||||
#include "mangler.hpp" | |||||
class snfScanData; // Declare snfScanData; | class snfScanData; // Declare snfScanData; | ||||
class snfLOGmgr; // Declare snfLOGmgr; | class snfLOGmgr; // Declare snfLOGmgr; |
#include <string> | #include <string> | ||||
#include <queue> | #include <queue> | ||||
#include "timing.hpp" | |||||
#include "threading.hpp" | |||||
#include "networking.hpp" | |||||
#include "../CodeDweller/timing.hpp" | |||||
#include "../CodeDweller/threading.hpp" | |||||
#include "../CodeDweller/networking.hpp" | |||||
#include "snf_xci.hpp" | #include "snf_xci.hpp" | ||||
using namespace std; | using namespace std; |
#include <fstream> | #include <fstream> | ||||
#include <iostream> | #include <iostream> | ||||
#include <string> | #include <string> | ||||
#include "mangler.hpp" | |||||
#include "../CodeDweller/mangler.hpp" | |||||
#include "snf_engine.hpp" | #include "snf_engine.hpp" | ||||
using namespace std; | using namespace std; |
#include <iostream> | #include <iostream> | ||||
#include <string> | #include <string> | ||||
#include <exception> | #include <exception> | ||||
#include "mangler.hpp" | |||||
#include "../CodeDweller/mangler.hpp" | |||||
//#include "../nvwa-0.6/nvwa/debug_new.h" | //#include "../nvwa-0.6/nvwa/debug_new.h" | ||||
using namespace std; | using namespace std; |
#include <list> | #include <list> | ||||
#include <cstring> | #include <cstring> | ||||
#include "GBUdb.hpp" | #include "GBUdb.hpp" | ||||
#include "networking.hpp" | |||||
#include "configuration.hpp" | |||||
#include "../CodeDweller/networking.hpp" | |||||
#include "../CodeDweller/configuration.hpp" | |||||
class GBUAlertHandler : public Configurator { | class GBUAlertHandler : public Configurator { | ||||
public: | public: |
#ifndef snf_xci_included | #ifndef snf_xci_included | ||||
#define snf_xci_included | #define snf_xci_included | ||||
#include "configuration.hpp" | |||||
#include "../CodeDweller/configuration.hpp" | |||||
class snf_xci { // SNF XCI message interpreter. | class snf_xci { // SNF XCI message interpreter. | ||||
private: | private: |