added log file and migrated from require to import

This commit is contained in:
hexahigh 2023-04-15 14:50:26 +02:00
parent b34c8fecd6
commit d6a5ed4d31
6 changed files with 98 additions and 29 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
db.txt
h-db.txt
customdb.txt
customdb.txt
log.txt

View File

@ -1,5 +1,9 @@
# nodejs-hash-antivirus
Simple antivirus written in node.js. Uses md5 hashes.
<pre>
If you get any errors(Which you most likely will) please make a issue and send the log.txt file found in the same folder as the program
</pre>
# Usage
<pre>
Use "npm run" to run the main program.

52
log.js Normal file
View File

@ -0,0 +1,52 @@
import exp from 'constants';
import * as fs from 'fs';
var currentTime = "nAn";
export function newSession() {
getTime();
fs.appendFileSync('log.txt', '\r\n')
fs.appendFileSync('log.txt', "New session started at: " + currentTime + '\r\n')
fs.appendFileSync('log.txt', '\r\n')
}
export function AXlog(msg) {
getTime();
console.log(msg)
fs.appendFileSync('log.txt', "[" + currentTime + "] " + msg + '\r\n')
}
export function AXlogColor(param1, msg) {
getTime();
console.log(param1, msg)
fs.appendFileSync('log.txt', "[" + currentTime + "] " + msg + '\r\n')
}
function getTime() {
let date_time = new Date();
// get current date
// adjust 0 before single digit date
let date = ("0" + date_time.getDate()).slice(-2);
// get current month
let month = ("0" + (date_time.getMonth() + 1)).slice(-2);
// get current year
let year = date_time.getFullYear();
// get current hours
let hours = date_time.getHours();
// get current minutes
let minutes = date_time.getMinutes();
// get current seconds
let seconds = date_time.getSeconds();
// prints date in YYYY-MM-DD format
//console.log(year + "-" + month + "-" + date);
// prints date & time in YYYY-MM-DD HH:MM:SS format
currentTime = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
}

52
main.js
View File

@ -1,6 +1,14 @@
var prompt = require("prompt-sync")({ sigint: true });
var fs = require('fs');
var crypto = require('crypto');
//var prompt = require("prompt-sync")({ sigint: true });
//var fs = require('fs');
//var crypto = require('crypto');
import promptSync from 'prompt-sync';
import {AXlog, newSession, AXlogColor} from './log.js';
import * as fs from 'fs';
import * as crypto from 'crypto';
const prompt = promptSync({ sigint: true });
// Variables
var isdetected = false;
@ -13,18 +21,20 @@ function delay(milliseconds) {
});
}
//Credits
console.log('\x1b[32m%s\x1b[0m', "███╗ ███╗ █████╗ ██████╗ ███████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗ ███████╗██╗ ██╗")
console.log('\x1b[32m%s\x1b[0m', "████╗ ████║██╔══██╗██╔══██╗██╔════╝ ██╔══██╗╚██╗ ██╔╝ ██╔══██╗██╔═══██╗██╔═══██╗██╔════╝██╔══██╗██╔════╝██║ ██║")
console.log('\x1b[32m%s\x1b[0m', "██╔████╔██║███████║██║ ██║█████╗ ██████╔╝ ╚████╔╝ ██████╔╝██║ ██║██║ ██║█████╗ ██║ ██║█████╗ ██║ ██║")
console.log('\x1b[32m%s\x1b[0m', "██║╚██╔╝██║██╔══██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝ ██╔══██╗██║ ██║██║ ██║██╔══╝ ██║ ██║██╔══╝ ╚██╗ ██╔╝")
console.log('\x1b[32m%s\x1b[0m', "██║ ╚═╝ ██║██║ ██║██████╔╝███████╗ ██████╔╝ ██║ ██████╔╝╚██████╔╝╚██████╔╝██║ ██████╔╝███████╗ ╚████╔╝ ")
console.log('\x1b[32m%s\x1b[0m', "╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═══╝ ")
console.log('\x1b[36m%s\x1b[0m', "boofdev.eu.org" + " ©2023")
console.log()
AXlogColor('\x1b[32m%s\x1b[0m', "███╗ ███╗ █████╗ ██████╗ ███████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗ ███████╗██╗ ██╗")
AXlogColor('\x1b[32m%s\x1b[0m', "████╗ ████║██╔══██╗██╔══██╗██╔════╝ ██╔══██╗╚██╗ ██╔╝ ██╔══██╗██╔═══██╗██╔═══██╗██╔════╝██╔══██╗██╔════╝██║ ██║")
AXlogColor('\x1b[32m%s\x1b[0m', "██╔████╔██║███████║██║ ██║█████╗ ██████╔╝ ╚████╔╝ ██████╔╝██║ ██║██║ ██║█████╗ ██║ ██║█████╗ ██║ ██║")
AXlogColor('\x1b[32m%s\x1b[0m', "██║╚██╔╝██║██╔══██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝ ██╔══██╗██║ ██║██║ ██║██╔══╝ ██║ ██║██╔══╝ ╚██╗ ██╔╝")
AXlogColor('\x1b[32m%s\x1b[0m', "██║ ╚═╝ ██║██║ ██║██████╔╝███████╗ ██████╔╝ ██║ ██████╔╝╚██████╔╝╚██████╔╝██║ ██████╔╝███████╗ ╚████╔╝ ")
AXlogColor('\x1b[32m%s\x1b[0m', "╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═══╝ ")
AXlogColor('\x1b[36m%s\x1b[0m', "boofdev.eu.org" + " ©2023")
AXlog()
newSession();
//Ask user what database to use.
console.log("What database should be used?")
console.log("[1] Virus database")
AXlog("What database should be used?")
AXlog("[1] Virus database")
const databasetouse = prompt("");
if (databasetouse == 1) {
databasetouse2 = "db.txt"
@ -34,31 +44,31 @@ if (databasetouse == 69) {
}
// Load database
console.log("Loading database...")
AXlog("Loading database...")
var database0 = fs.readFileSync(databasetouse2).toString().split("\n");
var database = database0.toString().toUpperCase();
console.log ("Database loaded!")
AXlog ("Database loaded!")
// Ask user what file they should scan
const filetoscan = prompt("Enter path of file to be scanned: ");
console.log("Obtaining hash...")
AXlog("Obtaining hash...")
const buff = fs.readFileSync(filetoscan);
var outputdata0 = crypto.createHash("md5").update(buff).digest("hex");
var outputdata = outputdata0.toString().toUpperCase();
console.log("Hash: " + outputdata)
AXlog("Hash: " + outputdata)
// Check if database contains output data
console.log("Checking if the hash matches the database...")
AXlog("Checking if the hash matches the database...")
if (database.includes(outputdata)) {
isdetected = true;
console.log("The file IS a virus.");
AXlog("The file IS a virus.");
} else {
isdetected = false;
console.log("The file is NOT a virus.");
AXlog("The file is NOT a virus.");
}
/*async function printout() {
await delay(100);
if (isdetected == true) {
console.log("")
AXlog("")
}
}*/

View File

@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "simple js virus scanner",
"main": "main.js",
"type": "module",
"scripts": {
"update": "node update.js",
"custom": "node dbcreator.js",

View File

@ -1,15 +1,16 @@
var prompt = require("prompt-sync")({ sigint: true });
var fs = require('fs');
const http = require('http');
const https = require('https');
import promptSync from 'prompt-sync';
import * as fs from 'fs';
import * as http from 'http';
import * as https from 'https';
const prompt = promptSync({ sigint: true });
console.log("This will update the database.")
console.log("Do you wish to proceed? Y/N")
const useragree = prompt("");
if (useragree == "Y") {
console.log("Deleting old files")
fs.unlinkSync("h-db.txt")
fs.unlinkSync("db.txt")
console.log("Downloading new files")
//download first database
const db69 = fs.createWriteStream("h-db.txt");
@ -31,5 +32,5 @@ if (useragree == "Y") {
});
});
} else {
exit()
console.log("Exiting")
}