Created
April 3, 2024 11:02
-
-
Save pejotes/5bcf64ff6cc4d45daf138e74a3dd71de to your computer and use it in GitHub Desktop.
zte_info.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from requests.exceptions import RequestException | |
import hashlib | |
import json | |
import urllib3 | |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
class ZTERouter: | |
def __init__(self, ip, username, password): | |
self.ip = ip | |
self.protocol = "http" | |
self.username = username | |
self.password = password | |
self.set_protocol() | |
self.referer = f"{self.protocol}://{self.ip}/" | |
def set_protocol(self): | |
protocols = ["http", "https"] | |
for protocol in protocols: | |
url = f"{protocol}://{self.ip}" | |
try: | |
response = requests.get(url, timeout=5, verify=False) | |
if response.ok: | |
self.protocol = protocol | |
return | |
except RequestException: | |
pass | |
def hash_password(self, password): | |
return hashlib.sha256(password.encode()).hexdigest() | |
def get_version(self): | |
header = {"Referer": self.referer} | |
payload = "isTest=false&cmd=wa_inner_version" | |
response = requests.get(self.referer + f"goform/goform_get_cmd_process?{payload}", headers=header, data=payload, verify=False) | |
return response.json()["wa_inner_version"] | |
def get_ld(self): | |
header = {"Referer": self.referer} | |
payload = "isTest=false&cmd=LD" | |
response = requests.get(self.referer + f"goform/goform_get_cmd_process?{payload}", headers=header, data=payload, verify=False) | |
return response.json()["LD"].upper() | |
def get_cookie(self, username, password, ld): | |
header = {"Referer": self.referer} | |
hashed_password = self.hash_password(password).upper() | |
zte_pass = self.hash_password(hashed_password + ld).upper() | |
old_login = self.get_version() | |
payload = { | |
'isTest': 'false', | |
'goformId': 'LOGIN', | |
'password': zte_pass | |
} | |
if username is not None and username != "": | |
payload['username'] = username | |
response = requests.post(self.referer + "goform/goform_set_cmd_process", headers=header, data=payload, verify=False) | |
return "stok=" + response.cookies["stok"].strip('\"') | |
def get_router_info(self): | |
cookie = self.get_cookie(username=self.username, password=self.password, ld=self.get_ld()) | |
cmd_url = f"{self.protocol}://{self.ip}/goform/goform_get_cmd_process?isTest=false&cmd=wa_inner_version%2Ccr_version%2Cnetwork_type%2Crssi%2Crscp%2Crmcc%2Crmnc%2Cenodeb_id%2Clte_rsrq%2Clte_rsrp%2CZ5g_snr%2CZ5g_rsrp%2CZCELLINFO_band%2CZ5g_dlEarfcn%2Clte_ca_pcell_arfcn%2Clte_ca_pcell_band%2Clte_ca_scell_band%2Clte_ca_pcell_bandwidth%2Clte_ca_scell_info%2Clte_ca_scell_bandwidth%2Cwan_lte_ca%2Clte_pci%2CZ5g_CELL_ID%2CZ5g_SINR%2Ccell_id%2Cwan_lte_ca%2Clte_ca_pcell_band%2Clte_ca_pcell_bandwidth%2Clte_ca_scell_band%2Clte_ca_scell_bandwidth%2Clte_ca_pcell_arfcn%2Clte_ca_scell_arfcn%2Clte_multi_ca_scell_info%2Cwan_active_band%2Cnr5g_pci%2Cnr5g_action_band%2Cnr5g_cell_id%2Clte_snr%2Cecio%2Cwan_active_channel%2Cnr5g_action_channel%2Cngbr_cell_info%2Cmonthly_tx_bytes%2Cmonthly_rx_bytes%2Clte_pci%2Clte_pci_lock%2Clte_earfcn_lock%2Cwan_ipaddr%2Cwan_apn%2Cpm_sensor_mdm%2Cpm_modem_5g%2Cnr5g_pci%2Cnr5g_action_channel%2Cnr5g_action_band%2CZ5g_SINR%2CZ5g_rsrp%2Cwan_active_band%2Cwan_active_channel%2Cwan_lte_ca%2Clte_multi_ca_scell_info%2Ccell_id%2Cdns_mode%2Cprefer_dns_manual%2Cstandby_dns_manual%2Cnetwork_type%2Crmcc%2Crmnc%2Clte_rsrq%2Clte_rssi%2Clte_rsrp%2Clte_snr%2Cwan_lte_ca%2Clte_ca_pcell_band%2Clte_ca_pcell_bandwidth%2Clte_ca_scell_band%2Clte_ca_scell_bandwidth%2Clte_ca_pcell_arfcn%2Clte_ca_scell_arfcn%2Cwan_ipaddr%2Cstatic_wan_ipaddr%2Copms_wan_mode%2Copms_wan_auto_mode%2Cppp_status%2Cloginfo%2Crealtime_time%2Csignalbar&multi_data=1" | |
headers = { | |
"Host": self.ip, | |
"Referer": f"{self.referer}index.html", | |
"Cookie": cookie | |
} | |
response = requests.get(cmd_url, headers=headers, verify=False) | |
print(response.text) | |
router = ZTERouter("192.168.254.1", "admin", "admin") | |
router.get_router_info() |
Author
pejotes
commented
Apr 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment