-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
86 lines (69 loc) · 2.68 KB
/
app.js
File metadata and controls
86 lines (69 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const express = require('express');
const fetch = require('node-fetch');
const fs = require('fs');
const { json } = require('express');
const apikey = '723a6f400cc6656c7e095e68165cd9b6bb42773a83faef359512a353785903b3';
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(json());
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.post('/checkHashes', async (req, res) => {
const { hashes } = req.body;
const analysisResults = [];
try {
const hashesArray = hashes.trim().split('\n');
// Skip sleep timer if there are less than 3 hashes as input
const shouldSkipSleep = hashesArray.length < 4;
for (const hash of hashesArray) {
const trimmedHash = hash.trim();
let hashType;
switch (trimmedHash.length) {
case 32:
hashType = 'MD5';
break;
case 40:
hashType = 'SHA-1';
break;
case 64:
hashType = 'SHA-256';
break;
default:
hashType = 'Unknown';
}
if (isIPAddress(trimmedHash)) {
console.log(`Skipped IP address: ${trimmedHash}`);
continue;
}
if (!shouldSkipSleep) {
// Introduce a 15-second delay before each API request
await sleep(15000); // 15 seconds in milliseconds
}
const response = await fetch(`https://www.virustotal.com/vtapi/v2/file/report?apikey=${apikey}&resource=${trimmedHash}`);
const result = await response.json();
if (result.positives !== 0) {
analysisResults.push(`${trimmedHash} (${hashType}) - ${result.positives} engines detected it as malicious`);
} else {
analysisResults.push(`${trimmedHash} (${hashType}) - Clean`);
}
}
res.json({ success: true, analysisResults });
} catch (error) {
console.error('Error occurred:', error);
res.status(500).json({ success: false, message: 'Error occurred while checking hashes' });
}
});
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Helper function to check if a string is an IP address
function isIPAddress(input) {
// Regular expression to match IPv4 and IPv6 addresses
const ipRegex = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$|^([a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/;
return ipRegex.test(input);
}
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});