小米路由器POST登录分析及实现过程

小米路由器POST登录分析及实现过程

前情提要:当前分析的样本为 小米路由器千兆版

分析POST提交数据

通过Google浏览器,使用F12(开发者工具)中的Network爬取post数据

图1.获取到的post数据

POST数据

分析可知

  • username为admin[明文]
  • password为**************[密文,当然这里也不可能写出来]
  • logtype为2[明文]
  • nonce为生成的文本,为0_MAC地址_不清楚__不清楚

分析源代码

路由器登录地址为 192.168.31.1 或者 miwifi.com

通过Google浏览器,使用Ctrl+U(查看源代码)

分析可知

  • 登录数据加密函数为**function loginHandle ( e ) **—位置为1269[每个人的可能不一样]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function loginHandle ( e ) {
e.preventDefault();
var formObj = document.rtloginform;
var pwd = $( '#password' ).val();
if ( pwd == '') {
return;
}
var nonce = Encrypt.init();
var oldPwd = Encrypt.oldPwd( pwd );
var param = {
username: 'admin',
password: oldPwd,
logtype: 2,
nonce: nonce
};
$.pub('loading:start');
var url = '/cgi-bin/luci/api/xqsystem/login';
$.post( url, param, function( rsp ) {
$.pub('loading:stop');
var rsp = $.parseJSON( rsp );
if ( rsp.code == 0 ) {
var redirect,
token = rsp.token;
if ( /action=wan/.test(location.href) ) {
redirect = buildUrl('wan', token);
} else if ( /action=lannetset/.test(location.href) ) {
redirect = buildUrl('lannetset', token);
} else {
redirect = rsp.url;
}
window.location.href = redirect;
} else if ( rsp.code == 403 ) {
window.location.reload();
} else {
pwdErrorCount ++;
var errMsg = '密码错误';
if (pwdErrorCount >= 4) {
errMsg = '多次密码错误,将禁止继续尝试';
}
Valid.fail( document.getElementById('password'), errMsg, false);
$( formObj )
.addClass( 'shake animated' )
.one( 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
$('#password').focus();
$( this ).removeClass('shake animated');
} );
}
});
}

分析函数

第一步,获取pwd值

1
var pwd = $( '#password' ).val(); '获取id为password的输入框内的内容

第二步,获取nonce值

1
var nonce = Encrypt.init(); ' 调用Encrypt函数中的init函数(?)

Encrypt函数中的init

1
2
3
4
5
6
init: function(){
var nonce = this.nonceCreat();
'调用nonceCreat
this.nonce = nonce;
return this.nonce; '返回 this.nonce
},

nonceCreat

1
2
3
4
5
6
7
8
9
10
11
12
13
nonceCreat: function(){
var type = 0;
'type为0
var deviceId = 'c6:8e:68:c1:1d:5e';
'deviceId为c6:8e:68:c1:1d:5e 电脑的MAC地址
var time = Math.floor(new Date().getTime() / 1000);
'time为 当前毫秒数/1000 的 浮点数
var random = Math.floor(Math.random() * 10000);
'random为 获取随机数的1万倍 的 浮点数
return [type, deviceId, time, random].join('_');
'返回 type deviceId time random
'返回 0_c6:8e:68:c1:1d:5e_当前时间_随机数
},

所以nonce等于0_c6:8e:68:c1:1d:5e_当前时间__随机数

1
var oldPwd = Encrypt.oldPwd( pwd ); '调用Encrypt函数中的oldPwd

Encrypt函数中的oldPwd

1
2
3
4
oldPwd : function(pwd){
return CryptoJS.SHA1(this.nonce + CryptoJS.SHA1(pwd + this.key).toString()).toString();
'返回 sha1加密(nonce + sha1加密(密码+key))
},

第三步,获取POST数据

1
2
3
4
5
6
var param = {
username: 'admin',
password: oldPwd,
logtype: 2,
nonce: nonce
};

与之前获取的POST数据进行对比

即可得到结果-Form Data

实现过程

下次再实现,这次就分析到这里

小米路由器POST登录分析及实现过程

https://acg-q.github.io/abbrlink/5b142f8.html

发布于

2020-03-25

更新于

2024-01-20

许可协议

评论