Changeset 035c51f in nscp


Ignore:
Timestamp:
02/03/08 11:10:38 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
777180d
Parents:
52215d7
Message:

+ Added encryption subsystem to NSCA module (still no mcrypt support, but atleast you have "xor" and passwords)

Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • NSC.dist

    r3f69109 r035c51f  
    181181; real.ini 
    182182 
     183 
    183184[NSCA Agent] 
    184185;# CHECK INTERVALL (in seconds) 
    185186;   How often we should run the checks and submit the results. 
    186 interval=5 
     187;interval=5 
    187188; 
    188189;# ENCRYPTION METHOD 
     
    196197; Values: 
    197198; 0 = None  (Do NOT use this option) 
    198 ; -- only 0 is supported as of now, but will change in the future -- 
    199 ;encryption_method=0 
     199; 1 = Simple XOR  (No security, just obfuscation, but very fast) 
     200; (no MCRYPT yet, but soon...) 
     201;encryption_method=1 
     202; 
     203;# ENCRYPTION PASSWORD 
     204;  This is the password/passphrase that should be used to encrypt the sent packets.  
     205;password= 
    200206; 
    201207;# BIND TO ADDRESS 
    202208;  Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. 
    203209;  Leaving this blank will bind to "one" local interface. 
    204 ; -- not supported as of now -- 
    205210;bind_to_address= 
    206211; 
     
    212217;  The port to the nagios server to submit results to. 
    213218;nsca_port=5667 
    214  
    215 ; The checks to run everytime we submit results back to nagios 
     219; 
     220 
     221;# CHECK COMMAND LIST 
     222;  The checks to run everytime we submit results back to nagios 
    216223; 
    217224[NSCA Commands] 
    218225my_cpu_check=checkCPU warn=80 crit=90 time=20m time=10s time=4 
    219226my_mem_check=checkMem MaxWarn=80% MaxCrit=90% ShowAll type=page 
    220 my_svc_check=checkServiceState CheckAll 
     227my_svc_check=checkServiceState CheckAll exclude=wampmysqld exclude=MpfService 
  • changelog

    r52215d7 r035c51f  
    55 * Add module for relaying events 
    66 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 
     7 
     82008-02-03 MickeM 
     9 + Added encryption subsystem to NSCA module (still no mcrypt support, but atleast you have "xor") 
    710 
    8112008-02-02 MickeM 
  • include/Socket.cpp

    r47b843a r035c51f  
    4242  char *tmpBuffer = new char[tmpBufferLength+1]; 
    4343  int n=recv(socket_,tmpBuffer,tmpBufferLength,0); 
    44   std::wcout << _T("read: ") << n << std::endl; 
     44  //std::wcout << _T("read: ") << n << std::endl; 
    4545  while ((n!=SOCKET_ERROR )&&(n!=0)) { 
    4646    if (n == tmpBufferLength) { 
  • include/Socket.h

    r47b843a r035c51f  
    137137      length_ = length; 
    138138      buffer_[length_] = 0; 
     139    } 
     140    std::wstring toString() { 
     141      std::wstringstream ss; 
     142      for (unsigned int i =0;i<length_;i++) { 
     143        if (i%64==0) { 
     144          ss << std::endl; 
     145        } 
     146        if (buffer_[i] < 30 || buffer_[i] > 'z') 
     147          ss << _T(" "); 
     148        else 
     149          ss << buffer_[i]; 
     150      } 
     151      return ss.str(); 
    139152    } 
    140153  }; 
  • include/config.h

    r47b843a r035c51f  
    142142#define NSCA_PORT _T("nsca_port") 
    143143#define NSCA_PORT_DEFAULT 5667 
     144#define NSCA_ENCRYPTION _T("encryption_method") 
     145#define NSCA_ENCRYPTION_DEFAULT 1 
     146#define NSCA_PASSWORD _T("password") 
     147#define NSCA_PASSWORD_DEFAULT _T("") 
    144148 
    145149#define C_SYSTEM_SVC_ALL_0 _T("check_all_services[SERVICE_BOOT_START]") 
  • modules/NSCAAgent/NSCAAgent-2005.vcproj

    r3f69109 r035c51f  
    7070        Name="VCLinkerTool" 
    7171        AdditionalDependencies="ws2_32.lib" 
    72         OutputFile="$(OutDir)\$(ProjectName).dll" 
     72        OutputFile="../../Debug/modules/$(ProjectName).dll" 
    7373        LinkIncremental="2" 
    7474        ModuleDefinitionFile="NSCAAgent.def" 
     
    19011901      <File 
    19021902        RelativePath="..\..\include\error.hpp" 
     1903        > 
     1904      </File> 
     1905      <File 
     1906        RelativePath=".\nsca_enrypt.hpp" 
    19031907        > 
    19041908      </File> 
  • modules/NSCAAgent/NSCAThread.cpp

    r5ca3931 r035c51f  
    2727  host_ = NSCModuleHelper::getSettingsString(NSCA_AGENT_SECTION_TITLE, NSCA_HOSTNAME, NSCA_HOSTNAME_DEFAULT); 
    2828  port_ = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_PORT, NSCA_PORT_DEFAULT); 
     29  encryption_method_ = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_ENCRYPTION, NSCA_ENCRYPTION_DEFAULT); 
     30  password_ = strEx::wstring_to_string(NSCModuleHelper::getSettingsString(NSCA_AGENT_SECTION_TITLE, NSCA_PASSWORD, NSCA_PASSWORD_DEFAULT)); 
    2931  std::list<std::wstring> items = NSCModuleHelper::getSettingsSection(NSCA_CMD_SECTION_TITLE); 
    3032  for (std::list<std::wstring>::const_iterator cit = items.begin(); cit != items.end(); ++cit) { 
     
    100102        results.push_back((*cit).execute(host_)); 
    101103      } 
    102  
    103104      send(results); 
    104  
    105105      _time64( &stop ); 
    106106      __int64 elapsed = stop-start; 
     
    129129} 
    130130void NSCAThread::send(const std::list<Command::Result> &results) { 
    131   NSC_LOG_MESSAGE_STD(_T(">>> Attempting to send results...")); 
    132   simpleSocket::Socket socket(true); 
    133   simpleSocket::DataBuffer inc; 
    134   if (socket.connect(host_, port_) == SOCKET_ERROR) { 
    135     NSC_LOG_MESSAGE_STD(_T("<<< Could not connect to: ") + host_ + strEx::itos(port_)); 
     131  try { 
     132    nsca_encrypt crypt_inst; 
     133    simpleSocket::Socket socket(true); 
     134    simpleSocket::DataBuffer inc; 
     135    if (socket.connect(host_, port_) == SOCKET_ERROR) { 
     136      NSC_LOG_ERROR_STD(_T("<<< Could not connect to: ") + host_ + strEx::itos(port_)); 
     137      return; 
     138    } 
     139    if (!socket.readAll(inc, sizeof(NSCAPacket::init_packet_struct), sizeof(NSCAPacket::init_packet_struct))) { 
     140      NSC_LOG_ERROR_STD(_T("<<< Failed to read header: ") + host_ + strEx::itos(port_)); 
     141      return; 
     142    } 
     143    NSCAPacket::init_packet_struct *packet_in = (NSCAPacket::init_packet_struct*) inc.getBuffer(); 
     144    try { 
     145      crypt_inst.encrypt_init(password_.c_str(),encryption_method_,packet_in->iv); 
     146    } catch (nsca_encrypt::exception &e) { 
     147      NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header: ") + e.getMessage()); 
     148      return; 
     149    } catch (...) { 
     150      NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header!")); 
     151      return; 
     152    } 
     153 
     154    try { 
     155      for (std::list<Command::Result>::const_iterator cit = results.begin(); cit != results.end(); ++cit) { 
     156        //NSC_DEBUG_MSG_STD(_T("Sending : ") + (*cit).toString()); 
     157        socket.send((*cit).getBuffer(crypt_inst)); 
     158      } 
     159    } catch (nsca_encrypt::exception &e) { 
     160      NSC_LOG_ERROR_STD(_T("<<< Failed to encrypt packet: ") + e.getMessage()); 
     161      return; 
     162    } catch (...) { 
     163      NSC_LOG_ERROR_STD(_T("<<< Failed to encrypt packet!")); 
     164      return; 
     165    } 
     166    socket.close(); 
     167  } catch (...) { 
     168    NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header!")); 
    136169    return; 
    137170  } 
    138   NSC_DEBUG_MSG_STD(_T("... Connected, attempting to read: ") + strEx::itos(sizeof(NSCAPacket::init_packet_struct))); 
    139   if (!socket.readAll(inc, sizeof(NSCAPacket::init_packet_struct), sizeof(NSCAPacket::init_packet_struct))) { 
    140     NSC_LOG_MESSAGE_STD(_T("<<< Failed to read header: ") + host_ + strEx::itos(port_)); 
    141     return; 
    142   } 
    143   NSC_DEBUG_MSG_STD(_T("... Read...")); 
    144   NSCAPacket::init_packet_struct *packet_in = (NSCAPacket::init_packet_struct*) inc.getBuffer(); 
    145   NSC_LOG_MESSAGE_STD(_T("Read: ") + strEx::format_date(packet_in->timestamp)); 
    146   for (std::list<Command::Result>::const_iterator cit = results.begin(); cit != results.end(); ++cit) { 
    147     NSC_LOG_MESSAGE_STD(_T("Sending : ") + (*cit).toString()); 
    148     socket.send((*cit).getBuffer()); 
    149   } 
    150   NSC_DEBUG_MSG_STD(_T("... Done...")); 
    151   socket.close(); 
    152   NSC_LOG_MESSAGE_STD(_T("<<< Attempting to send results...")); 
    153171} 
    154172 
  • modules/NSCAAgent/NSCAThread.h

    r5ca3931 r035c51f  
    2525#include <arrayBuffer.h> 
    2626#include <Socket.h> 
     27#include "nsca_enrypt.hpp" 
    2728 
    2829/** 
     
    139140    Result(std::wstring _host) : host(_host){ 
    140141      _time32(&time); 
    141       time+=60*60 + 2*60; 
     142      //time+=60*60 + 2*60; 
    142143    } 
    143144    std::wstring service; 
     
    153154    } 
    154155 
    155     simpleSocket::DataBuffer getBuffer() const { 
     156    simpleSocket::DataBuffer getBuffer(nsca_encrypt &crypt_inst) const { 
    156157      std::string s = strEx::wstring_to_string(service); 
    157158      std::string r = strEx::wstring_to_string(result); 
     
    170171      unsigned int calculated_crc32=calculate_crc32(reinterpret_cast<char*>(&data),sizeof(data)); 
    171172      data.crc32_value=static_cast<NSCAPacket::u_int32_t>(htonl(calculated_crc32)); 
    172  
    173       return simpleSocket::DataBuffer(reinterpret_cast<char*>(&data),sizeof(data)); 
     173      char * buffer = reinterpret_cast<char*>(&data); 
     174      crypt_inst.encrypt_buffer(buffer, sizeof(data)); 
     175      return simpleSocket::DataBuffer(buffer,sizeof(data)); 
    174176    } 
    175177 
     
    207209  std::wstring host_; 
    208210  unsigned int port_; 
     211  std::string password_; 
     212  int encryption_method_; 
    209213 
    210214public: 
Note: See TracChangeset for help on using the changeset viewer.