开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

友情提示:文字/图片广告均非论坛意见,请担保交易勿直接付款,由此产生的责任自负
查看: 1854|回复: 11
收起左侧

[求助] 哪位大神有华为路由器登录的例子!

[复制链接]
结帖率:93% (71/76)
发表于 2021-11-24 18:56:02 | 显示全部楼层 |阅读模式   河北省石家庄市
找到一个python的代码 可是小白的我也不认识  不会修改! 有大神帮忙修改下也可以!谢谢

[Python] 纯文本查看 复制代码
#!/usr/bin/python
# coding=utf-8
 
import sys
import requests
from lxml import etree
import json
 
import hashlib
import hmac
from Crypto import Random
 
gl_cookies = {}
gl_cookie = ''
gl_cookies_path = "cookies"
gl_csrf_param = ''
gl_csrf_token = ''
gl_count = 0
 
firstNonce = ''
finalNonce = ''
salt = ''
 
#由首页获取信息
def update_Information(html):
#   html = requests.get("http://192.168.3.1/html/index.html")
    global gl_cookies
    global gl_csrf_param
    global gl_csrf_token
    
    gl_cookies = html.cookies
    url_tree = etree.HTML(html.text)
    gl_csrf_param = url_tree.xpath("//meta[@name='csrf_param']/@content")[0]
    gl_csrf_token = url_tree.xpath("//meta[@name='csrf_token']/@content")[0]
 
def save_html(html):
    global gl_count
    gl_count += 1
    with open("H:%d.html" % gl_count, "wb") as f:
        f.write(bytes(html.text, encoding='utf-8'))
 
def salt_password(password, salt, iter_times):
    return hashlib.pbkdf2_hmac('sha256', password, salt, iter_times)
 
def Main_Login(sess, username, passwd):
    global gl_cookie
    global gl_cookies
    global gl_csrf_param
    global gl_csrf_token
 
    firstNonce = Random.get_random_bytes(32)
    result = sess.get("http://192.168.3.1/html/index.html")
    update_Information(result)
 
    request_header = {
    'Connection': 'keep-alive',
    'Cache-Control': 'max-age=0',
    'Origin': 'http://192.168.3.1',
    'Content-Type': 'application/json;charset=UTF-8',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'X-Requested-With': 'XMLHttpRequest',
    '_ResponseFormat': 'JSON',
    'Referer': 'http://192.168.3.1/html/index.html',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
    }
 
    firstNonce_str = Random.get_random_bytes(32).hex()
    firstNonce = bytes(firstNonce_str, encoding='utf-8')
    
    login_post_data = {
 
        'csrf': {'csrf_param': gl_csrf_param, 'csrf_token': gl_csrf_token},
        'data': {'username': 'admin', 'firstnonce': firstNonce_str},
    }
 
    url_routerlogin = 'http://192.168.3.1/api/system/user_login_nonce'  #/api/system/user_login_nonce
    deviceLogin = sess.post(url_routerlogin,
                                headers=request_header,  # headers http 头部信息
                                data=json.dumps(login_post_data, ensure_ascii=True),
                             #    params = {'_':int(time.time())}, #params 参数
                                cookies = gl_cookies,                                  #cookies cookie
                                # allow_redirects = False,                  #allow_redirects 禁用跳转
                              #  timeout=0.5
 
                                )
    login_respon = json.loads(deviceLogin.text)
    save_html(deviceLogin)
    # print(deviceLogin.url)
    if(login_respon['err'] == 0):
        print('first post success')
    else:
        print('first post failed')
 
    #  第二次post
    gl_csrf_param = login_respon['csrf_param']  #字符串 特别信息,包含所有字符,不是hex表示
    gl_csrf_token = login_respon['csrf_token']  #字符串 特别信息,包含所有字符,不是hex表示
    salt = bytes.fromhex(login_respon['salt'])    #只含0-9,a-f为hex表示,str转为bytes   #firstnonce也是
    finalNonce = login_respon['servernonce']
    authMsg = firstNonce_str + ',' + finalNonce + ',' + finalNonce
    iterations_rece = int(login_respon['iterations'])
 
    passwd = passwd.encode()  #str to bytes
 
    saltPassword = salt_password(passwd, salt, iterations_rece)  # 加盐算法不同语言命名有差异hashlib.pbkdf2_hmac
    mac = hmac.new(b'Client Key', saltPassword, hashlib.sha256)  #b'Client Key'作key,msg加密
    clientKey = mac.digest()
    storeKey = hashlib.sha256(clientKey).digest()
    mac = hmac.new(bytes(authMsg, encoding='utf-8'), storeKey, hashlib.sha256)
    clientSignature = mac.digest()
    clientKey = bytearray(clientKey)
    for i in range(len(clientKey)):
        clientKey = clientKey ^ clientSignature
    clientProof = bytes(clientKey)
 
    login_post_data = {   #要求为字符串
        'csrf': {'csrf_param': gl_csrf_param, 'csrf_token': gl_csrf_token},
        'data': {'finalnonce': finalNonce, 'clientproof': clientProof.hex()},    #传输时为hex码,不会出现异常码,出现不是ascii的情况
    }
 
    url_routerlogin = 'http://192.168.3.1/api/system/user_login_proof'  # /api/system/user_login_nonce
    deviceLogin = sess.post(url_routerlogin,
                            headers=request_header,  # headers http 头部信息
                            data=json.dumps(login_post_data),
                            #    params = {'_':int(time.time())}, #params 参数
                         #   cookies=gl_cookies,  # cookies cookie
                            # allow_redirects = False,                  #allow_redirects 禁用跳转
                            #  timeout=0.5
 
                            )
    login_respon = json.loads(deviceLogin.text)
    if(login_respon['err']==0):
        print('login success')
    else:
        print('login failed')
    return
 
 
if __name__ == "__main__":
    sess = requests.Session()
 
    username = 'admin'  # str(input('帐号:'))
    passwd = '123456'  # str(input('密码:'))
    Main_Login(sess, username, passwd)
 
    result = sess.get('http://192.168.3.1/api/system/HostInfo')
    false = False
    true = True
    result = eval(result.text)
 #   save_html(result)
    for device in result:
        if(device['Active']):
            print(device['HostName'])
  #  print(result.text)
    sys.exit(0)

结帖率:98% (46/47)
发表于 2021-11-24 19:01:48 | 显示全部楼层   重庆市重庆市
没有华为路由器,
回复 支持 反对

使用道具 举报

结帖率:93% (71/76)
 楼主| 发表于 2021-11-24 19:09:32 | 显示全部楼层   河北省石家庄市
Svlik 发表于 2021-11-24 19:01
没有华为路由器,

.........
回复 支持 反对

使用道具 举报

结帖率:93% (13/14)
发表于 2021-11-24 21:27:14 | 显示全部楼层   广东省东莞市
华为路由器在哪里领取
回复 支持 反对

使用道具 举报

发表于 2022-2-25 08:47:36 | 显示全部楼层   香港特别行政区*
你搞定了吗?
回复 支持 反对

使用道具 举报

结帖率:93% (71/76)
 楼主| 发表于 2022-2-27 19:26:54 | 显示全部楼层   河北省石家庄市

没有搞定!  不会JS  网上有PHP的开源 分析代码
回复 支持 反对

使用道具 举报

结帖率:87% (20/23)
发表于 2022-3-5 23:03:57 | 显示全部楼层   江苏省苏州市
同求  。。。。
回复 支持 反对

使用道具 举报

结帖率:50% (1/2)
发表于 2022-11-30 12:05:55 | 显示全部楼层   河北省廊坊市
楼主找到办法了吗?
回复 支持 反对

使用道具 举报

结帖率:93% (71/76)
 楼主| 发表于 2022-12-4 15:30:07 | 显示全部楼层   河北省石家庄市
万人倾心っ 发表于 2022-11-30 12:05
楼主找到办法了吗?

没有  看到有PHP的  但是我不会!
回复 支持 反对

使用道具 举报

结帖率:50% (1/2)
发表于 2022-12-6 10:14:30 | 显示全部楼层   河北省廊坊市
q6592081 发表于 2022-12-4 15:30
没有  看到有PHP的  但是我不会!

PHP那个我也看到了,同样不会= =!!
你可以试试填表的方式
回复 支持 反对

使用道具 举报

  高级模式
B Color Image Link Quote Code Smilies |上传

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
网站简介:精易论坛成立于2009年,是一个程序设计学习交流技术论坛,隶属于揭阳市揭东区精易科技有限公司所有。
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表