Skip to content

Commit

Permalink
Fix ip bug retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
Frankccv committed Sep 27, 2023
1 parent c4a2816 commit 00fb33a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion www/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 4 additions & 4 deletions www/reportReader/busReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,8 +58,8 @@ async function queryIpMongo( attackId ) {
ipAttacker = result[0].ipSrcValue;

}
}
)


} catch (err) {
console.error('Error:', err);
} finally {
Expand Down
8 changes: 5 additions & 3 deletions www/routes/sancus/remediation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 00fb33a

Please sign in to comment.