This repository has been archived by the owner on Jan 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
95 lines (72 loc) · 2.49 KB
/
index.js
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
87
88
89
90
91
92
93
94
95
const express = require('express');
const axios = require('axios');
const FormData = require('form-data');
const multer = require('multer');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json());
// MobSF API configurations
const MOBSF_BASE_URL = process.env.MOBSF_BASE_URL;
const MOBSF_API_KEY = process.env.MOBSF_API_KEY;
const upload = multer({ storage: multer.memoryStorage() });
app.get('/', (req, res) => {
res.send('Hello World!')
})
// New endpoint to receive file and call /api/v1/upload
app.post('/upload', upload.single('file'), async (req, res) => {
if (!req.file) {
return res.status(400).json({ error: 'No file provided' });
}
const formData = new FormData();
formData.append('file', req.file.buffer, req.file.originalname);
try {
const response = await axios.post(MOBSF_BASE_URL+'/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': MOBSF_API_KEY,
},
});
res.json(response.data);
} catch (error) {
console.error('Error forwarding file upload:', error);
res.status(500).json({ error: 'Error forwarding file upload' });
}
});
// New endpoint to forward scan request
app.post('/scan', async (req, res) => {
const { hash, re_scan } = req.body;
if (!hash) {
return res.status(400).json({ error: 'Missing required parameter: hash' });
}
try {
const formData = new FormData();
formData.append('hash', hash);
formData.append('re_scan', 0);
const response = await axios.post(MOBSF_BASE_URL + '/scan', formData, {
headers: {
'Authorization': MOBSF_API_KEY,
},
});
res.json(response.data);
} catch (error) {
console.error('Error forwarding scan request:', error);
res.status(500).json({ error: 'Error forwarding scan request'});
}
});
// New endpoint to forward scan request
app.get('/recent-scans', async (req, res) => {
try {
const response = await axios.get(MOBSF_BASE_URL+'/scans', {
headers: {
'Authorization': MOBSF_API_KEY,
},
});
res.json(response.data);
} catch (error) {
console.error('Error forwarding scan request:', error);
res.status(500).json({ error: 'Error forwarding scan request' });
}
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});