Skip to content

Commit

Permalink
Merge pull request #41 from MythicAgents/netstat-browserscript
Browse files Browse the repository at this point in the history
Netstat command browser script
  • Loading branch information
MEhrn00 authored Dec 19, 2024
2 parents e3aae0a + 102ce87 commit 2214c3f
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions Payload_Type/thanatos/thanatos/mythic/browser_scripts/netstat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
function(task, responses){
if (task.status.includes("error")) {
return {
"plaintext": responses.reduce((prev, cur) => prev + cur, ""),
};
}

if (responses.length <= 0) {
return {"plaintext": "No response yet from agent..."}
}

const title = "Network Connections";
const headers = [
{"plaintext": "protocol", "type": "string", "cellStyle": {}, "width": 125},
{"plaintext": "local address", "type": "string", "cellStyle": {}, "width": 300},
{"plaintext": "local port", "type": "number", "cellStyle": {}, "width": 200},
{"plaintext": "remote address", "type": "string", "cellStyle": {}, "width": 300},
{"plaintext": "remote port", "type": "number", "cellStyle": {}, "width": 200},
{"plaintext": "state", "type": "string", "cellStyle": {}, "width": 200},
{"plaintext": "pids", "type": "string", "cellStyle": {}, "width": 125},
];

let rows = [];

for (const response of responses) {
let data = {};
try {
data = JSON.parse(response);
} catch (error) {
console.log(error);
return {
"plaintext": responses.reduce((prev, cur) => prev + cur, ""),
}
}

rows.push.apply(rows, data.map((netstatEntry) => {
return {
"protocol": {
"plaintext": netstatEntry["proto"],
},
"local address": {
"plaintext": netstatEntry["local_addr"],
"copyIcon": netstatEntry["local_addr"] !== null && netstatEntry["local_addr"].trim().length !== 0,
},
"local port": {
"plaintext": netstatEntry["local_port"],
"copyIcon": true,
},
"remote address": {
"plaintext": netstatEntry["remote_addr"],
"copyIcon": netstatEntry["remote_addr"] !== null && netstatEntry["remote_addr"].trim().length !== 0,
},
"remote port": {
"plaintext": netstatEntry["remote_port"],
"copyIcon": netstatEntry["remote_port"] !== null && netstatEntry["remote_port"] !== 0,
},
"state": {
"plaintext": netstatEntry["state"],
},
"pids": {
"plaintext": netstatEntry["associated_pids"]?.join(),
"copyIcon": netstatEntry["associated_pids"] !== null && netstatEntry["associated_pids"].length !== 0,
},
}
}));
}

if (rows.length == 0) {
return {
"plaintext": responses.reduce((prev, cur) => prev + cur, ""),
}
} else {
return {
"table": [
{
"title": title,
"headers": headers,
"rows": rows,
}
]
};
}
}

0 comments on commit 2214c3f

Please sign in to comment.