diff --git a/www/config.json b/www/config.json index 526b0c03..0b7e33ba 100644 --- a/www/config.json +++ b/www/config.json @@ -21,7 +21,9 @@ "host":"localhost", "port":"22", "password":"12345", - "username":"frank" + "username":"frank", + "command": "kubectl exec amf-45-ipds-0 -n ath-cmm-45 -- bash -c \"nft insert rule ip filter INPUT ip daddr IP_ATT drop\"" + }, "file_input": { "data_folder": [ diff --git a/www/reportReader/busReader.js b/www/reportReader/busReader.js index 5361545b..2438b8c4 100644 --- a/www/reportReader/busReader.js +++ b/www/reportReader/busReader.js @@ -48,8 +48,8 @@ async function queryIpMongo( attackId ) { const client = new MongoClient(url ,{ useNewUrlParser: true, useUnifiedTopology: true }); try { - // Connect to MongoDB - client.connect(). then( async () => { + // Connect to MongoDB + await client.connect(); const db = client.db(dbName); // Perform the aggregation query @@ -58,8 +58,8 @@ async function queryIpMongo( attackId ) { ipAttacker = result[0].ipSrcValue; } - } - ) + + } catch (err) { console.error('Error:', err); } finally { diff --git a/www/routes/sancus/remediation.js b/www/routes/sancus/remediation.js index 2e29fd22..06c31230 100644 --- a/www/routes/sancus/remediation.js +++ b/www/routes/sancus/remediation.js @@ -17,15 +17,17 @@ const connSettings = { router.post("",async function(req, res) { console.log("Received "+req.query.CID+" "+ req.query.IP ); - var scriptCode = `kubectl exec amf-45-ipds-0 -n ath-cmm-45 -- bash -c "nft insert rule ip filter INPUT ip daddr `+ req.query.IP +` drop"`; - + // var scriptCode = `kubectl exec amf-45-ipds-0 -n ath-cmm-45 -- bash -c "nft insert rule ip filter INPUT ip daddr `+ req.query.IP +` drop"`; + var scriptCode = config.master_node.command; + const command_ip = scriptCode.replace(/IP_ATT/g, req.query.IP); + console.log("Command "+command_ip ); //produceMessage(); //_publishMessage( "testTopic", "ciao" ) //var result=await produceMessage(req.query.CID); const ssh = new SSHClient(); try{ ssh.connect(connSettings).then( () =>{ - ssh.executeCommand ( scriptCode ) .then(() => { + ssh.executeCommand ( command_ip ) .then(() => { console.log('Command kubectl executed successfully'); res.status(204).end()//204: The server has successfully fulfilled the request and that there is no additional content to send in the response payload body. ssh.disconnect();