-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from MythicAgents/netstat-browserscript
Netstat command browser script
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
Payload_Type/thanatos/thanatos/mythic/browser_scripts/netstat.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
] | ||
}; | ||
} | ||
} |