diff --git a/README.md b/README.md index 5526afb..7e07ca7 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ We are excited to share with the world a chat bot that we affectionately call Cy !whois \ - WHOIS Query (ex: cylance[.]com) !nslookup \ - DNS forward/reverse Query (ex: www[.]cylance[.]com) !geoip \ - Perform GeoIP lookup of host (ex: www[.]cylance[.]com) + !censys \ - Return Censys information on host (ex: 1.2.3.4) !unshorten \ - Unshortens URLs (ex: goo[.]gl/IGL1lE) !screenshot - Takes a screenshot of a website and returns the .png - Accepts defanged [()] URLs !linkextractor \ - Extracts links from a site and safely displays them (ex: hxxps://www[.]google[.]com) diff --git a/plugins/censys/censys.plug b/plugins/censys/censys.plug new file mode 100644 index 0000000..9d17951 --- /dev/null +++ b/plugins/censys/censys.plug @@ -0,0 +1,9 @@ +[Core] +Name = censys +Module = censts + +[Documentation] +Description = This plugin queries Censys.io for information about an IP address. + +[Python] +Version = 2+ diff --git a/plugins/censys/censys.py b/plugins/censys/censys.py new file mode 100644 index 0000000..c3c089b --- /dev/null +++ b/plugins/censys/censys.py @@ -0,0 +1,41 @@ +# !censys is used for Querying the censys.io API + +import os, requests, json, re +from errbot import BotPlugin, botcmd, arg_botcmd + +base_url = "https://www.censys.io/api/v1" +api_id = "changeme" +api_secret = "changeme" + + +class censys(BotPlugin): + @arg_botcmd("query", type=str) # flags a command + def censys(self, msg, query=None): + query = re.sub("[\[()\]]", "", query) + uri = "view/ipv4/{}".format(query) + api_creds = (api_id, api_secret) + response = requests.get(base_url + uri, auth=api_creds) + json_resp = response.json() + + if json_resp.get("error", False): + answer = 'Error: ' + json_resp["error"] + "\r\n" + else: + answer = "IP: {0}\r\n".format(ip) + answer += "Tags: {0}\r\n".format(", ".join(json_resp["tags"])) + answer += "Protocols: {0}\r\n".format(", ".join(json_resp["protocols"])) + if (80) in json_resp["ports"]: + try: + answer += "Web page title (80/http): {0}\r\n".format( + json_resp["80"]["http"]["get"]["title"] + ) + except KeyError: + pass + if (443) in json_resp["ports"]: + try: + answer += "Web page title (443/https): {0}\r\n".format( + json_resp["443"]["https"]["get"]["title"] + ) + except KeyError: + pass + answer += "Updated at: {0}\r\n".format(json_resp["updated_at"]) + return answer