ValueError: invalid literal for int() with base 10: '1d' or similar
mrkwagga opened this issue · comments
Hi Guys - Thanks for creating this tool! I'm trying to scan our routers, and everyone gives an error similar to below:
Mikrotik ip address: 192.168.0.1
Traceback (most recent call last):
File "C:\Users\werne\Downloads\routeros-scanner-main\main.py", line 62, in <module>
main(args)
File "C:\Users\werne\Downloads\routeros-scanner-main\main.py", line 31, in main
res = command.run_ssh(ssh_client)
File "C:\Users\werne\Downloads\routeros-scanner-main\commands\dns.py", line 16, in run_ssh
sus_dns, recommendation = self.check_results_ssh(res, enabled)
File "C:\Users\werne\Downloads\routeros-scanner-main\commands\dns.py", line 27, in check_results_ssh
if int(item['ttl'].partition('s')[0]) > 200000:
ValueError: invalid literal for int() with base 10: '1d'
Confirmed:
RouterOS 6.48.6
Python 3.9.10
There is problem while parsing dns cache ttl values. I created a quick and dirty replacement for dns.py which just skips when parsing fails.
Just modify dns.py like below
from commands.basecommand import BaseCommand
import re
class DNS(BaseCommand):
def __init__(self):
self.__name__ = 'DNS Cache'
def run_ssh(self, sshc):
data = self._ssh_data(sshc, '/ip dns print')
enabled = 'allow-remote-requests: yes' in data.lower()
res = self._ssh_data_with_header(sshc, '/ip dns cache print detail')
sus_dns, recommendation = self.check_results_ssh(res, enabled)
return {'raw_data': res,
'suspicious': sus_dns,
'recommendation': recommendation}
def check_results_ssh(self, res, enabled):
sus_dns = []
recommendation = []
for item in res:
try:
i = int(hms(item['ttl'].partition('s')[0]))
except IndexError:
continue
if i > 200000:
sus_dns.append(f'Domain name: {item["name"]} with ip {item["address"]}: might be DNS poisoning- '
f'severity: high')
if enabled:
recommendation.append('In case DNS cache is not required on your router - disable it')
return sus_dns, recommendation
def hms(s):
l = list(map(int, re.split('[wdhms]', s)[:-1]))
if len(l) == 5:
return l[0]*604800 + l[1]*86400 + l[2]*3600 + l[3]*60 + l[4]
elif len(l) == 4:
return l[0]*86400 + l[1]*3600 + l[2]*60 + l[3]
elif len(l) == 3:
return l[0]*3600 + l[1]*60 + l[2]
elif len(l) == 2:
return l[0]*60 + l[1]
else:
return l[0]
I was working on debugging this when I saw there was a new comment. Thanks! Patch confirmed working:
RouterOS 6.47.8 Python 3.9.6
There is problem while parsing dns cache ttl values. I created a quick and dirty replacement for dns.py which just skips when parsing fails. Just modify dns.py like below
from commands.basecommand import BaseCommand import re class DNS(BaseCommand): def __init__(self): self.__name__ = 'DNS Cache' def run_ssh(self, sshc): data = self._ssh_data(sshc, '/ip dns print') enabled = 'allow-remote-requests: yes' in data.lower() res = self._ssh_data_with_header(sshc, '/ip dns cache print detail') sus_dns, recommendation = self.check_results_ssh(res, enabled) return {'raw_data': res, 'suspicious': sus_dns, 'recommendation': recommendation} def check_results_ssh(self, res, enabled): sus_dns = [] recommendation = [] for item in res: try: i = int(hms(item['ttl'].partition('s')[0])) except IndexError: continue if i > 200000: sus_dns.append(f'Domain name: {item["name"]} with ip {item["address"]}: might be DNS poisoning- ' f'severity: high') if enabled: recommendation.append('In case DNS cache is not required on your router - disable it') return sus_dns, recommendation def hms(s): l = list(map(int, re.split('[wdhms]', s)[:-1])) if len(l) == 5: return l[0]*604800 + l[1]*86400 + l[2]*3600 + l[3]*60 + l[4] elif len(l) == 4: return l[0]*86400 + l[1]*3600 + l[2]*60 + l[3] elif len(l) == 3: return l[0]*3600 + l[1]*60 + l[2] elif len(l) == 2: return l[0]*60 + l[1] else: return l[0]
`Traceback (most recent call last):
File "/root/routeros-scanner/main.py", line 62, in
main(args)
File "/root/routeros-scanner/main.py", line 28, in main
ssh_client.connect(hostname=args.ip, port=args.port, username=args.userName, password=args.password)
File "/usr/local/lib/python3.9/dist-packages/paramiko/client.py", line 435, in connect
self._auth(
File "/usr/local/lib/python3.9/dist-packages/paramiko/client.py", line 766, in _auth
raise saved_exception File "/usr/local/lib/python3.9/dist-packages/paramiko/client.py", line 753, in _auth
File "/usr/local/lib/python3.9/dist-packages/paramiko/auth_handler.py", line 244, in wait_for_response
raise e
paramiko.ssh_exception.AuthenticationException: Authentication failed.`
@KILLERMANTV , irrelevant to this issue.
@KILLERMANTV , irrelevant to this issue.
yea functionality irrelevant