Skip to content
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 4 additions & 2 deletions legos/nettools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
125 changes: 125 additions & 0 deletions legos/tools/Dns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import dns.resolver

from Legobot.Utilities import Utilities as utils
from legos.tools.Tool import ToolScheme

__author__ = "zSec <[email protected]>"
__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}"
24 changes: 9 additions & 15 deletions legos/tools/Resolver.py → legos/tools/Nslookup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import re
import socket

from Legobot.Utilities import Utilities as utils
Expand All @@ -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.
"""
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -63,4 +57,4 @@ def _nslookup(self):
return 'IP address cannot be resolved'

def getHelp(self):
return " !resolver {--host | --nslookup} {target}"
return " !nslookup {target}"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ urllib3
bandit==1.3.0
pytest==3.0.5
flake8==3.2.1
dnspython
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down