diff --git a/README.md b/README.md index 2c591ae..8dbb704 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,8 @@ baseplate_proxy.add_child(LegoNettools) The nettools Lego could be triggered by various prefix. - [x] Whois -- [x] Resolver -- [ ] DNS -- [ ] Trace +- [x] Nslookup +- [x] DNS - [x] Ping - [x] QUALYS lab - [x] IP geo @@ -62,15 +61,17 @@ The nettools Lego could be triggered by various prefix. ` !ping {target}` -#### Resolver +#### Nslookup -` !resolver {--host | --nslookup} {target}` +` !nslookup {target}` #### Qualys ` !qualys {target}` -> Assessment could take time ! Be patient. +#### Dns + +` !dns {--A | --AAAA | --NS | --MX | --TXT } {target}` ## Contributing diff --git a/legos/nettools.py b/legos/nettools.py index bb16142..1349326 100644 --- a/legos/nettools.py +++ b/legos/nettools.py @@ -31,7 +31,8 @@ def listening_for(message): """ if Utilities.isNotEmpty(message['text']): - cmds = ['!whois', '!geoloc', '!ping', '!resolver', '!qualys'] + cmds = ['!whois', '!geoloc', '!ping', '!dns', + '!qualys', '!nslookup'] return message['text'].split()[0] in cmds def handle(self, message): @@ -107,7 +108,8 @@ def get_help(): str: Helper """ - help_text = '[!whois, !geoloc, !ping, !resolver, !qualys]'\ + help_text = '[!whois, !geoloc, !ping, !nslookup'\ + ', !dns, !qualys]'\ ' for further information' return help_text diff --git a/legos/tools/Dns.py b/legos/tools/Dns.py new file mode 100644 index 0000000..5b518da --- /dev/null +++ b/legos/tools/Dns.py @@ -0,0 +1,125 @@ +import dns.resolver + +from Legobot.Utilities import Utilities as utils +from legos.tools.Tool import ToolScheme + +__author__ = "zSec " +__copyright__ = "Copyright 2017, Legobot" + + +class Dns(ToolScheme): + """The DNS class allows a DNS lookup for various records. + """ + + def __init__(self, args): + if utils.isNotEmpty(args): + super().__init__(args) + + self.fncs = { + 'A': self._A, + 'AAAA': self._AAAA, + 'NS': self._NS, + 'MX': self._MX, + 'TXT': self._TXT + } + + def run(self): + if utils.isNotEmpty(self.target): + results = [] + + if len(self.cmds) > 0: + for cmd in self.cmds: + try: + results.append(self.fncs[cmd]()) + except KeyError: + results.append('Command unknown: ' + cmd) + else: + results.append(self._A()) + results.append(self._AAAA()) + results.append(self._NS()) + results.append(self._MX()) + results.append(self._TXT()) + + return '\n'.join(results) + else: + return self.getHelp() + + def _A(self): + """Get the A record + + Returns: + str: A Record + """ + try: + data = dns.resolver.query(self.target, 'A') + results = [] + for item in data: + results.append(str(item.address)) + return ' | '.join(results) + except: + return 'Domain name invalid' + + def _AAAA(self): + """Get the AAAA record + + Returns: + str: AAAA record + """ + try: + data = dns.resolver.query(self.target, 'AAAA') + results = [] + for item in data: + results.append(str(item.address)) + return ' | '.join(results) + except: + return 'Domain name invalid' + + def _NS(self): + """Get the NS record + + Returns: + str: NS record + """ + try: + data = dns.resolver.query(self.target, 'NS') + results = [] + for item in data: + results.append(str(item.target)) + return ' | '.join(results) + except: + return 'Domain name invalid' + + def _MX(self): + """Get the MX record + + Returns: + str: MX record + """ + try: + data = dns.resolver.query(self.target, 'MX') + results = [] + for item in data: + results.append(str(item.exchange)) + return ' | '.join(results) + except: + return 'Domain name invalid' + + def _TXT(self): + """Get the TXT record + + Returns: + str: TXT record + """ + try: + data = dns.resolver.query(self.target, 'TXT') + results = [] + for item in data: + results.append(str(item.strings)) + return ' | '.join(results) + except: + return 'Domain name invalid' + + def getHelp(self): + return "!dns {--A | --AAAA | " \ + "--NS | --MX | " \ + "--TXT} {target}" diff --git a/legos/tools/Resolver.py b/legos/tools/Nslookup.py similarity index 70% rename from legos/tools/Resolver.py rename to legos/tools/Nslookup.py index e1867b5..12e3f40 100644 --- a/legos/tools/Resolver.py +++ b/legos/tools/Nslookup.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +import re import socket from Legobot.Utilities import Utilities as utils @@ -9,7 +10,7 @@ __copyright__ = "Copyright 2017, Legobot" -class Resolver(ToolScheme): +class Nslookup(ToolScheme): """This class allows resolving the IP address from a domain name as well as the reverse process. """ @@ -18,23 +19,16 @@ def __init__(self, args): if utils.isNotEmpty(args): super().__init__(args) - self.fncs = { - 'host': self._host, - 'nslookup': self._nslookup - } - def run(self): if utils.isNotEmpty(self.target): - if len(self.cmds) > 0: - for cmd in self.cmds: - try: - return self.fncs[cmd]() - except KeyError: - return 'Command unknown: ' + cmd + if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", self.target): + return self._getIP() + else: + return self._getDomainName() else: return self.getHelp() - def _host(self): + def _getDomainName(self): """Retrieve the IP address corresponding to a domain name. Args: @@ -48,7 +42,7 @@ def _host(self): except: return 'Host cannot be resolved' - def _nslookup(self): + def _getIP(self): """Retrieve the domain name corresponding to an IP address. Args: @@ -63,4 +57,4 @@ def _nslookup(self): return 'IP address cannot be resolved' def getHelp(self): - return " !resolver {--host | --nslookup} {target}" + return " !nslookup {target}" diff --git a/requirements.txt b/requirements.txt index c4cb3fc..9e74169 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ urllib3 bandit==1.3.0 pytest==3.0.5 flake8==3.2.1 +dnspython diff --git a/setup.py b/setup.py index 3c9e6b3..3a91f55 100644 --- a/setup.py +++ b/setup.py @@ -18,9 +18,7 @@ install_requires=['legobot>=1.1.4,<=2.0.0', 'python-whois', 'urllib3', - 'bandit==1.3.0', - 'flake8==3.2.1', - 'pytest==3.0.5' + 'dnspython' ], classifiers=[ 'License :: OSI Approved :: MIT License',