updating datavase compiler
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
// Function to sort words into files based on the first two characters
|
// Function to sort words into files based on the first two characters
|
||||||
function sort_hashes($inputFile) {
|
function sort_hashes($inputFile, $excluded) {
|
||||||
// Open the input file for reading
|
// Open the input file for reading
|
||||||
$handle = fopen($inputFile, "r");
|
$handle = fopen($inputFile, "r");
|
||||||
if ($handle === false) {
|
if ($handle === false) {
|
||||||
@@ -10,50 +10,93 @@ function sort_hashes($inputFile) {
|
|||||||
// Read each line from the input file
|
// Read each line from the input file
|
||||||
while (($line = fgets($handle)) !== false) {
|
while (($line = fgets($handle)) !== false) {
|
||||||
// Remove leading/trailing whitespace and split the line into words
|
// Remove leading/trailing whitespace and split the line into words
|
||||||
|
$line = trim($line);
|
||||||
|
$hash = substr($line, 0, 32); // Assuming the hash is the first 32 characters
|
||||||
|
|
||||||
// Get the first two characters of the word
|
// Check if the hash is in the excluded array
|
||||||
$prefix = substr($line, 0, 2);
|
if (in_array($hash, $excluded)) {
|
||||||
|
continue; // Skip this hash
|
||||||
|
}
|
||||||
|
|
||||||
// Create the filename for the corresponding file
|
// Get the first two characters of the word
|
||||||
$filename = "/var/www/html/database_srv/".$prefix . ".jdbf";
|
$prefix = substr($hash, 0, 2);
|
||||||
|
|
||||||
// Open or create the file for writing
|
// Create the filename for the corresponding file
|
||||||
$fileHandle = fopen($filename, "a");
|
$filename = "/var/www/html/database_srv/".$prefix . ".jdbf";
|
||||||
if ($fileHandle === false) {
|
|
||||||
die("Unable to open/create file: $filename");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the word to the file
|
// Open or create the file for writing
|
||||||
fwrite($fileHandle, $line);
|
$fileHandle = fopen($filename, "a");
|
||||||
|
if ($fileHandle === false) {
|
||||||
|
die("Unable to open/create file: $filename");
|
||||||
|
}
|
||||||
|
|
||||||
// Close the file handle
|
// Write the word to the file
|
||||||
fclose($fileHandle);
|
fwrite($fileHandle, $line . PHP_EOL);
|
||||||
|
|
||||||
}
|
// Close the file handle
|
||||||
|
fclose($fileHandle);
|
||||||
|
}
|
||||||
|
|
||||||
// Close the input file handle
|
// Close the input file handle
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
}
|
}
|
||||||
function download_files(){
|
|
||||||
//download from virusshare
|
function download_files($excluded){
|
||||||
$file_count=485;
|
//download from virusshare
|
||||||
for($i=0;$i<$file_count;$i++){
|
$file_count=485;
|
||||||
$fileNumber = sprintf('%05d', $i);
|
for($i=0;$i<$file_count;$i++){
|
||||||
$url="https://virusshare.com/hashfiles/VirusShare_$fileNumber.md5";
|
$fileNumber = sprintf('%05d', $i);
|
||||||
$ch = curl_init($url);
|
$url="https://virusshare.com/hashfiles/VirusShare_$fileNumber.md5";
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
$ch = curl_init($url);
|
||||||
$fileContents = curl_exec($ch);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
file_put_contents("/var/www/html/database_srv/$fileNumber.md5", $fileContents);
|
$fileContents = curl_exec($ch);
|
||||||
sort_hashes("/var/www/html/database_srv/$fileNumber.md5");
|
file_put_contents("/var/www/html/database_srv/$fileNumber.md5", $fileContents);
|
||||||
}
|
sort_hashes("/var/www/html/database_srv/$fileNumber.md5", $excluded);
|
||||||
//download from https://bazaar.abuse.ch/export/txt/md5/recent/
|
}
|
||||||
$url="https://bazaar.abuse.ch/export/txt/md5/recent/";
|
//download from https://bazaar.abuse.ch/export/txt/md5/recent/
|
||||||
$ch = curl_init($url);
|
$url="https://bazaar.abuse.ch/export/txt/md5/recent/";
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
$ch = curl_init($url);
|
||||||
$fileContents = curl_exec($ch);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
file_put_contents("/var/www/html/database_srv/buf.md5", $fileContents);
|
$fileContents = curl_exec($ch);
|
||||||
sort_hashes("/var/www/html/database_srv/buf.md5");
|
file_put_contents("/var/www/html/database_srv/buf.md5", $fileContents);
|
||||||
|
sort_hashes("/var/www/html/database_srv/buf.md5", $excluded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
include "../../../config.php";
|
||||||
|
$conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD,$DB_DATABASE);
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
$success=0;
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
// Load excluded hashes from sig_ex table
|
||||||
|
$excluded = array();
|
||||||
|
$sql = "SELECT signature FROM sig_ex";
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
if ($result->num_rows > 0) {
|
||||||
|
while($row = $result->fetch_assoc()) {
|
||||||
|
$excluded[] = $row["hash"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load included hashes from sig_in table
|
||||||
|
$included = array();
|
||||||
|
$sql = "SELECT signature FROM sig_in";
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
if ($result->num_rows > 0) {
|
||||||
|
while($row = $result->fetch_assoc()) {
|
||||||
|
$included[] = $row["hash"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the database connection
|
||||||
|
$conn->close();
|
||||||
|
|
||||||
|
// Add included array to output files this will then be processed like any other normal input file
|
||||||
|
file_put_contents("/var/www/html/database_srv/included_hashes.txt", implode(PHP_EOL, $included));
|
||||||
|
|
||||||
|
// This code updates and compiles our databases
|
||||||
$directory = '/var/www/html/database_srv'; // Path to the directory
|
$directory = '/var/www/html/database_srv'; // Path to the directory
|
||||||
|
|
||||||
// Get a list of all files in the directory
|
// Get a list of all files in the directory
|
||||||
@@ -67,7 +110,5 @@ foreach ($files as $file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
download_files();
|
download_files($excluded);
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ async function add_item(db,element_id1,field1,element_id2,field2){ //we have two
|
|||||||
<a class="nav-link" href="database_settings.php?show=excluded" id="excluded_tab">Excluded signatures</a>
|
<a class="nav-link" href="database_settings.php?show=excluded" id="excluded_tab">Excluded signatures</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="database_settings.php?show=excluded" id="included_tab">Included Signatures</a>
|
<a class="nav-link" href="database_settings.php?show=included" id="included_tab">Included Signatures</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user