Здравствуйте подскажите пожалуйста как организовать перебор паролей и портов в telnetlib

WiriNCROSS

Новичок
Пользователь
Мар 18, 2021
2
0
1
Python 3.9:
OS - Windows 10
Задача подключатся и сетевое оборудование с помощью скрипта, есть 2 варианта портов и 4 варианта паролей имя пользователя всегда admin

Python:
import telnetlib
import time
import random
import string
import datetime
from colorama import init, Back, Style, Fore
start_time = time.time()
start_time = time.time()
adress = input('Введите адрес обьекта ---- ')
iprouter = input('Введите IP роутера ------- ')
user = 'admin'
print('--- Пользователь admin ---')
password = input('Введите пароль ----------- ')
loginOffice = input('Введите логин от Office -- ')
PassOffice = input('Введите пароль от Office - ')
VPNip = input('Введите VPNip Office ----- ')
Subnet = input('Введите Подсеть аптеки --- ')
IPserv ='.'.join(Subnet.split('.')[:-1]) +'.'+ str(int(Subnet.split('.')[-1]) + 1)
IPreg = '.'.join(Subnet.split('.')[:-1]) +'.'+ str(int(Subnet.split('.')[-1]) + 27)
now = datetime.datetime.now()
nowt = (now.strftime('%d-%m-%Y %H:%M'))
init()
#Автологин
tn = telnetlib.Telnet(iprouter, 23,)
tn.read_until(b'Login: ', timeout=2)
tn.write(user.encode('ascii') + b'\n')
tn.read_until(b'Password: ', timeout=2)
tn.write(password.encode('ascii') + b'\n')
tn.read_until(b'(config)> ', timeout=1)
print('* * * * * * *Подключение к ротеру ——————'+Fore.GREEN+' Успех!!!'+Fore.RESET+'* * * * * * * * * * * * * * *')
tn.read_until(b'(config)> ', timeout=2)
tn.write('show version'.encode('ascii') + b'\n')
time.sleep(5)
#Собираем инфу из роутера
tn.read_until(b"(config)> ", timeout=2)
tn.write('show version'.encode('ascii') + b"\n")
time.sleep(5)
# Парсим вывод комманды 
out = tn.read_very_eager().decode('ascii')
out = out.split(' ')
if 'description:' in out:
    i1 = out.index('description:')
    model = (out[i1 + 1])+' '+(out[i1 + 2])+' '+(out[i1 + 3]).strip('\r\n\r\n(config)>')
elif 'device:' in out:
    i3 = out.index('device:')
    model = (out[i3 + 1])+' '+(out[i3 + 2]).strip('\r\n')
else:
    model = "неизвестная модель"
i2 = out.index('release:')
release = (out[i2 + 1]).strip('\r\n')
print("* * * * * * *Данные о модели и прошивке получены ---"+Fore.GREEN+" Успех!!!"+Fore.RESET+"* * * * * * * * * * * * * * *")
tn.read_until(b"(config)> ", timeout=2)
tn.write('show interface PPTP0'.encode('ascii') + b"\n")
time.sleep(2)
# Парсим вывод комманды 
out1 = tn.read_very_eager().decode('ascii')
out1 = out1.split(' ') 
if 'description:' in out1:
    i4 = out1.index('description:')
    des = (out1[i4 + 1]).strip('\r\n')
else:
    des = 'Подключение VPN не настроенно'
print("* * * * * * *Сбор данных о VPN  --------------------"+Fore.GREEN+" Успех!!!"+Fore.RESET+"* * * * * * * * * * * * * * *")
# Сбор Серийного номера
tn.read_until(b"(config)> ", timeout=2)
tn.write('show defaults'.encode('ascii') + b"\n")
time.sleep(15)
out2 = tn.read_very_eager().decode('ascii')
out2 = out2.split(' ')
if 'serial:' in out2:
    i5 = out2.index('serial:')
    sn = (out2[i5 + 1]).strip('\r\n')
else:
    sn = 'В FW нет serial'
#Сбор MAC Адреса
tn.read_until(b"(config)> ", timeout=1)
tn.write('show interface ISP'.encode('utf-8') + b"\n")
time.sleep(5)
out3 = tn.read_very_eager().decode('utf-8')
out3 = out3.split(' ')
if 'mac:' in out3:
    i6 = out3.index('mac:')
    mac = (out3[i6 + 1]).strip('\r\n')
else:
    mac = 'Не удалось получить mac'
print("* * * * * * *Данные о Serial и MAC получены  -------"+Fore.GREEN+" Успех!!!"+Fore.RESET+"* * * * * * * * * * * * * * *")
outlog = (nowt+";"+iprouter+";"+loginOffice+";"+PassOffice+";"+VPNip+";"+Subnet+";"+IPreg+";"+pas+";"+model+";"+release+";"+sn+";"+mac+";"+des+";"+adress+"\n")
#Запись данных в файл 
handle = open("output_log.csv", "a")
handle.write (outlog)
handle.close()

handle.close()

Можно ли сделать так чтобы скрипт перебирал сначала 2 порта для подключения 23 и 48888 и после удачного подключения начинал перебирать пароли 4шт
Заранее благодарен
 
Последнее редактирование:

WiriNCROSS

Новичок
Пользователь
Мар 18, 2021
2
0
1
Привел код в читаемый вид
 

Форум IT Специалистов