mirror of
https://github.com/hexahigh/nodejs-hash-antivirus.git
synced 2025-12-11 20:05:07 +01:00
added log file and migrated from require to import
This commit is contained in:
parent
b34c8fecd6
commit
d6a5ed4d31
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
db.txt
|
db.txt
|
||||||
h-db.txt
|
h-db.txt
|
||||||
customdb.txt
|
customdb.txt
|
||||||
|
log.txt
|
||||||
@ -1,5 +1,9 @@
|
|||||||
# nodejs-hash-antivirus
|
# nodejs-hash-antivirus
|
||||||
Simple antivirus written in node.js. Uses md5 hashes.
|
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
|
# Usage
|
||||||
<pre>
|
<pre>
|
||||||
Use "npm run" to run the main program.
|
Use "npm run" to run the main program.
|
||||||
|
|||||||
52
log.js
Normal file
52
log.js
Normal 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
52
main.js
@ -1,6 +1,14 @@
|
|||||||
var prompt = require("prompt-sync")({ sigint: true });
|
//var prompt = require("prompt-sync")({ sigint: true });
|
||||||
var fs = require('fs');
|
//var fs = require('fs');
|
||||||
var crypto = require('crypto');
|
//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
|
// Variables
|
||||||
var isdetected = false;
|
var isdetected = false;
|
||||||
@ -13,18 +21,20 @@ function delay(milliseconds) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
//Credits
|
//Credits
|
||||||
console.log('\x1b[32m%s\x1b[0m', "███╗ ███╗ █████╗ ██████╗ ███████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗ ███████╗██╗ ██╗")
|
AXlogColor('\x1b[32m%s\x1b[0m', "███╗ ███╗ █████╗ ██████╗ ███████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗ ███████╗██╗ ██╗")
|
||||||
console.log('\x1b[32m%s\x1b[0m', "████╗ ████║██╔══██╗██╔══██╗██╔════╝ ██╔══██╗╚██╗ ██╔╝ ██╔══██╗██╔═══██╗██╔═══██╗██╔════╝██╔══██╗██╔════╝██║ ██║")
|
AXlogColor('\x1b[32m%s\x1b[0m', "████╗ ████║██╔══██╗██╔══██╗██╔════╝ ██╔══██╗╚██╗ ██╔╝ ██╔══██╗██╔═══██╗██╔═══██╗██╔════╝██╔══██╗██╔════╝██║ ██║")
|
||||||
console.log('\x1b[32m%s\x1b[0m', "██╔████╔██║███████║██║ ██║█████╗ ██████╔╝ ╚████╔╝ ██████╔╝██║ ██║██║ ██║█████╗ ██║ ██║█████╗ ██║ ██║")
|
AXlogColor('\x1b[32m%s\x1b[0m', "██╔████╔██║███████║██║ ██║█████╗ ██████╔╝ ╚████╔╝ ██████╔╝██║ ██║██║ ██║█████╗ ██║ ██║█████╗ ██║ ██║")
|
||||||
console.log('\x1b[32m%s\x1b[0m', "██║╚██╔╝██║██╔══██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝ ██╔══██╗██║ ██║██║ ██║██╔══╝ ██║ ██║██╔══╝ ╚██╗ ██╔╝")
|
AXlogColor('\x1b[32m%s\x1b[0m', "██║╚██╔╝██║██╔══██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝ ██╔══██╗██║ ██║██║ ██║██╔══╝ ██║ ██║██╔══╝ ╚██╗ ██╔╝")
|
||||||
console.log('\x1b[32m%s\x1b[0m', "██║ ╚═╝ ██║██║ ██║██████╔╝███████╗ ██████╔╝ ██║ ██████╔╝╚██████╔╝╚██████╔╝██║ ██████╔╝███████╗ ╚████╔╝ ")
|
AXlogColor('\x1b[32m%s\x1b[0m', "██║ ╚═╝ ██║██║ ██║██████╔╝███████╗ ██████╔╝ ██║ ██████╔╝╚██████╔╝╚██████╔╝██║ ██████╔╝███████╗ ╚████╔╝ ")
|
||||||
console.log('\x1b[32m%s\x1b[0m', "╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═══╝ ")
|
AXlogColor('\x1b[32m%s\x1b[0m', "╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═══╝ ")
|
||||||
console.log('\x1b[36m%s\x1b[0m', "boofdev.eu.org" + " ©2023")
|
AXlogColor('\x1b[36m%s\x1b[0m', "boofdev.eu.org" + " ©2023")
|
||||||
console.log()
|
AXlog()
|
||||||
|
|
||||||
|
newSession();
|
||||||
|
|
||||||
//Ask user what database to use.
|
//Ask user what database to use.
|
||||||
console.log("What database should be used?")
|
AXlog("What database should be used?")
|
||||||
console.log("[1] Virus database")
|
AXlog("[1] Virus database")
|
||||||
const databasetouse = prompt("");
|
const databasetouse = prompt("");
|
||||||
if (databasetouse == 1) {
|
if (databasetouse == 1) {
|
||||||
databasetouse2 = "db.txt"
|
databasetouse2 = "db.txt"
|
||||||
@ -34,31 +44,31 @@ if (databasetouse == 69) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load database
|
// Load database
|
||||||
console.log("Loading database...")
|
AXlog("Loading database...")
|
||||||
var database0 = fs.readFileSync(databasetouse2).toString().split("\n");
|
var database0 = fs.readFileSync(databasetouse2).toString().split("\n");
|
||||||
var database = database0.toString().toUpperCase();
|
var database = database0.toString().toUpperCase();
|
||||||
console.log ("Database loaded!")
|
AXlog ("Database loaded!")
|
||||||
// Ask user what file they should scan
|
// Ask user what file they should scan
|
||||||
const filetoscan = prompt("Enter path of file to be scanned: ");
|
const filetoscan = prompt("Enter path of file to be scanned: ");
|
||||||
console.log("Obtaining hash...")
|
AXlog("Obtaining hash...")
|
||||||
const buff = fs.readFileSync(filetoscan);
|
const buff = fs.readFileSync(filetoscan);
|
||||||
var outputdata0 = crypto.createHash("md5").update(buff).digest("hex");
|
var outputdata0 = crypto.createHash("md5").update(buff).digest("hex");
|
||||||
var outputdata = outputdata0.toString().toUpperCase();
|
var outputdata = outputdata0.toString().toUpperCase();
|
||||||
console.log("Hash: " + outputdata)
|
AXlog("Hash: " + outputdata)
|
||||||
// Check if database contains output data
|
// 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)) {
|
if (database.includes(outputdata)) {
|
||||||
isdetected = true;
|
isdetected = true;
|
||||||
console.log("The file IS a virus.");
|
AXlog("The file IS a virus.");
|
||||||
} else {
|
} else {
|
||||||
isdetected = false;
|
isdetected = false;
|
||||||
console.log("The file is NOT a virus.");
|
AXlog("The file is NOT a virus.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*async function printout() {
|
/*async function printout() {
|
||||||
await delay(100);
|
await delay(100);
|
||||||
if (isdetected == true) {
|
if (isdetected == true) {
|
||||||
console.log("")
|
AXlog("")
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
@ -3,6 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "simple js virus scanner",
|
"description": "simple js virus scanner",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"update": "node update.js",
|
"update": "node update.js",
|
||||||
"custom": "node dbcreator.js",
|
"custom": "node dbcreator.js",
|
||||||
|
|||||||
15
update.js
15
update.js
@ -1,15 +1,16 @@
|
|||||||
var prompt = require("prompt-sync")({ sigint: true });
|
import promptSync from 'prompt-sync';
|
||||||
var fs = require('fs');
|
import * as fs from 'fs';
|
||||||
const http = require('http');
|
import * as http from 'http';
|
||||||
const https = require('https');
|
import * as https from 'https';
|
||||||
|
|
||||||
|
|
||||||
|
const prompt = promptSync({ sigint: true });
|
||||||
|
|
||||||
console.log("This will update the database.")
|
console.log("This will update the database.")
|
||||||
console.log("Do you wish to proceed? Y/N")
|
console.log("Do you wish to proceed? Y/N")
|
||||||
const useragree = prompt("");
|
const useragree = prompt("");
|
||||||
if (useragree == "Y") {
|
if (useragree == "Y") {
|
||||||
console.log("Deleting old files")
|
console.log("Deleting old files")
|
||||||
fs.unlinkSync("h-db.txt")
|
|
||||||
fs.unlinkSync("db.txt")
|
|
||||||
console.log("Downloading new files")
|
console.log("Downloading new files")
|
||||||
//download first database
|
//download first database
|
||||||
const db69 = fs.createWriteStream("h-db.txt");
|
const db69 = fs.createWriteStream("h-db.txt");
|
||||||
@ -31,5 +32,5 @@ if (useragree == "Y") {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
exit()
|
console.log("Exiting")
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user