misc: add shodan internetdb command

This commit is contained in:
Cynthia Foxwell 2022-04-20 13:45:32 -06:00
parent 4c7e038866
commit 66c963190d

View file

@ -327,3 +327,62 @@ arsched.callback = async function (msg, line) {
};
};
hf.registerCommand(arsched);
const REGEX_IPV4 = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/;
const shodan = new Command("shodan");
shodan.category = CATEGORY;
shodan.helpText = "Look up an IP on Shodan InternetDB";
shodan.callback = async function (msg, line) {
if (!line || line == "") return "Arguments required.";
if (!REGEX_IPV4.test(line)) return "Invalid IP address.";
const data = await fetch("https://internetdb.shodan.io/" + line).then((res) =>
res.json()
);
return {
embed: {
title: `Results for \`${data.ip}\``,
fields: [
{
title: "Hostnames",
value:
data.hostnames.length > 0
? data.hostnames.map((str) => `\`${str}\``).join("\n")
: "None",
inline: true,
},
{
title: "Open ports",
value: data.ports.length > 0 ? data.ports.join(", ") : "None",
inline: true,
},
{
title: "Tags",
value:
data.tags.length > 0
? data.tags.map((str) => `\`${str}\``).join(", ")
: "None",
inline: true,
},
{
title: "CPEs",
value:
data.cpes.length > 0
? data.cpes.map((str) => `\`${str}\``).join("\n")
: "None",
inline: true,
},
{
title: "Vulnerabilities",
value:
data.vulns.length > 0
? data.vulns.map((str) => `\`${str}\``).join("\n")
: "None",
inline: true,
},
],
},
};
};
hf.registerCommand(shodan);