Benutzer-Werkzeuge

Webseiten-Werkzeuge


know-how:threat_intel

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
know-how:threat_intel [2024/02/26 10:32] ccknow-how:threat_intel [2024/03/26 08:24] (aktuell) – [Schnittstelle f. Datebank / Input der Daten] cc
Zeile 25: Zeile 25:
 </code> </code>
   * Storage Engine **default-storage-engine = Aria** - als Nachfolger von **myisam** - ich benötige Crash resistenten Table   * Storage Engine **default-storage-engine = Aria** - als Nachfolger von **myisam** - ich benötige Crash resistenten Table
-===== Schnittstelle f. Datebank / Input der Daten =====+===== Schnittstelle f. Datenbank / Input der Daten =====
   * syslog-ng loggt direkt auf eine pipe / für das Skript macht es keinen Unterschied ob ein Logfile gelesen wird oder die Pipe geöffnet   * syslog-ng loggt direkt auf eine pipe / für das Skript macht es keinen Unterschied ob ein Logfile gelesen wird oder die Pipe geöffnet
  
 <code> <code>
 +
 <?php <?php
 // Shouldn't be used anymore // Shouldn't be used anymore
Zeile 93: Zeile 94:
  $matches=$matches[0];  $matches=$matches[0];
  
- for($i=0; $i<count($matches); $i++)+ $wrongCommit=false; 
 + 
 + for($i=0; $i<count($matches) && $wrongCommit==false ; $i++)
  {  {
  $cut_array=explode("=",$matches[$i]);  $cut_array=explode("=",$matches[$i]);
  if(count($cut_array)== 2)  if(count($cut_array)== 2)
  {  {
- $inputMaster[$cut_array[0]]=$cut_array[1];+ if(!isset($inputMaster[$cut_array[0]])) 
 +
 + $inputMaster[$cut_array[0]]=$cut_array[1]; 
 +  
 + if(isset($inputMaster["SRC"]) && filter_var($inputMaster["SRC"], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)===false) 
 +
 + $wrongCommit=true; 
 +
 +  
 +  
 +
 + else 
 +
 + #2024-02-16 cc: no multiple SRC definitions ! 
 + if(isset($inputMaster["SRC"]) && $cut_array[0]=="SRC"
 +
 + $wrongCommit=true; 
 +
 + }
  }  }
  
Zeile 104: Zeile 125:
  
  
- //Jan 26 01:46:54 + if($wrongCommit===false)
- if(preg_match('/^[A-Z,a-z]{3}[ ]{1}[0-9]{1,2}[ ]{1}([0-9]{1,2}:){2}[0-9]{1,2}/i',$line,$matches_time)===0)+
  {  {
- $inputMaster["timestamp"]=time(); 
- $inputMaster["datetime"]= date("Y-m-d H:i:s",$inputMaster["timestamp"]); 
- $inputMaster["original_time"]=false; 
- } 
- else 
- { 
- $inputMaster["timestamp"]=strtotime($matches_time[0]); 
- $inputMaster["datetime"]= date("Y-m-d H:i:s",$inputMaster["timestamp"]); 
- $inputMaster["original_time"]=$matches_time[0]; 
  
- }+ //Jan 26 01:46:54 
 + if(preg_match('/^[A-Z,a-z]{3}[ ]{1}[0-9]{1,2}[ ]{1}([0-9]{1,2}:){2}[0-9]{1,2}/i',$line,$matches_time)===0) 
 +
 + $inputMaster["timestamp"]=time(); 
 + $inputMaster["datetime"]= date("Y-m-d H:i:s",$inputMaster["timestamp"]); 
 + $inputMaster["original_time"]=false; 
 +
 + else 
 +
 + $inputMaster["timestamp"]=strtotime($matches_time[0]); 
 + $inputMaster["datetime"]= date("Y-m-d H:i:s",$inputMaster["timestamp"]); 
 + $inputMaster["original_time"]=$matches_time[0];
  
 + }
  
- $inputMaster["original_line"]=$line; 
- $inputMaster["hash"]=hash('sha256',$line); 
- if(isset($inputMaster["SRC"])) 
- { 
-                       $inputMaster["country"]=getCountry($inputMaster["SRC"]); 
  
-        + $inputMaster["original_line"]=$line; 
-+ $inputMaster["hash"]=hash('sha256',$line); 
- else + if(isset($inputMaster["SRC"])) 
- { +
- $inputMaster["SRC"]="00"; +                        $inputMaster["country"]=getCountry($inputMaster["SRC"]);
- $inputMaster["country"]="00"; +
- }+
  
 + //$reader = new Reader('/usr/local/etc/dbip-country.mmdb');
 + //$inputMaster["country"]=($reader->country($inputMaster["SRC"]))->country->isoCode;
 +
 + }
 + else
 + {
 + $inputMaster["SRC"]="00";
 + $inputMaster["country"]="00";
 + }
  
- if(isset($inputMaster["DST"])) 
- { 
- $inputMaster["DST"]=hash('sha1',$inputMaster["DST"]); 
  
- } + if(isset($inputMaster["DST"])) 
- else +
- + $inputMaster["DST"]=hash('sha1',$inputMaster["DST"]);
- $inputMaster["DST"]=hash('sha1',"00"); +
- }+
  
 + }
 + else
 + {
 + $inputMaster["DST"]=hash('sha1',"00");
 + }
  
- if(!isset($inputMaster["DPT"]) || strlen($inputMaster["DPT"])===0 ) 
- { 
- $inputMaster["DPT"]=0; 
- } 
  
- if(!isset($inputMaster["SPT"]) || strlen($inputMaster["SPT"])===0 ) + if(!isset($inputMaster["DPT"]) || strlen($inputMaster["DPT"])===0 ) 
- +
- $inputMaster["SPT"]=0; + $inputMaster["DPT"]=0; 
- }+ }
  
 + if(!isset($inputMaster["SPT"]) || strlen($inputMaster["SPT"])===0 )
 + {
 + $inputMaster["SPT"]=0;
 + }
  
- $entriesOk++; 
  
- $insert_statement->bind_param("ssssiisss",$inputMaster["hash"],$inputMaster["original_line"],$inputMaster["SRC"],$inputMaster["DST"],$inputMaster["DPT"],$inputMaster["SPT"],$inputMaster["PROTO"],$inputMaster["country"],$inputMaster["datetime"]);+ $entriesOk++; 
 + 
 + $insert_statement->bind_param("ssssiisss",$inputMaster["hash"],$inputMaster["original_line"],$inputMaster["SRC"],$inputMaster["DST"],$inputMaster["DPT"],$inputMaster["SPT"],$inputMaster["PROTO"],$inputMaster["country"],$inputMaster["datetime"]);
  
  //print_r($inputMaster);  //print_r($inputMaster);
   
- if($insert_statement->execute()) + if($insert_statement->execute()) 
- +
- $entriesOk++;+ $entriesOk++; 
 +
 + else 
 +
 + $entriesFail++; 
 + echo "MYSQL Failure: ".$insert_statement->error."\n"; 
 + print_r($inputMaster); 
 + }
  }  }
  else  else
  {  {
 + echo "\nInvalid Commit: $line \n";
 +
 + //print_r($inputMaster);
 + //print_r($matches);
 +
  $entriesFail++;  $entriesFail++;
- echo "MYSQL Failure: ".$insert_statement->error."\n"; 
- print_r($inputMaster); 
  }  }
  
Zeile 226: Zeile 262:
  
 ?> ?>
 +
  
 </code> </code>
know-how/threat_intel.1708939954.txt.gz · Zuletzt geändert: 2024/02/26 10:32 von cc