[转]WebQQ登录过程分析

近来遇到vista和QQ的兼容性问题,丫的,无奈用起来WebQQ,面对这垃圾网络,又一看是http不禁对其安全性产生了质疑,近来抄起了.net 于是用fiddler2来capture,得到密钥分析其加密过程,一百度,发现有人早有分析,且看相关分析:
http://htsoft.net.cn/html/ytag/qq%E5%AF%86%E7%A0%81%E5%8A%A0%E5%AF%86%E6%96%B9%E5%BC%8F
关于在网页登陆QQ时密码的加密方式
类归于: C#相关 — HtSoft @ 2009-10-18 13:25:56 还没有评论

在网页上登录QQ时,密码是通过加密后POST给服务器的,如何加密的可以找到JS文件加以分析,JS文件中貌似整的比较复杂,全是位运算,本想把JS转成C#,一个函数一个函数转换,尝试了一下放弃了,太麻烦。

最后非常简单的解决了这个问题,其实看JS文件被误导了,加密方式很简单,如下:

MD5(MD5_3(QQ密码)+验证码大写),顺便贴上C#代码:

public static class qqPwdEncrypt
{
/// <summary>
/// 计算网页上QQ登录时密码加密后的结果
/// </summary>
/// <param name="pwd" />QQ密码</param>
/// <param name="verifyCode" />验证码</param>
/// <returns></returns>
public static String Encrypt(string pwd, string verifyCode)
{
return (md5(md5_3(pwd).ToUpper() + verifyCode.ToUpper())).ToUpper();
}
/// <summary>
/// 计算字符串的三次MD5
/// </summary>
/// <param name="s" /></param>
/// <returns></returns>
private static String md5_3(String s)
{
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);

bytes = md5.ComputeHash(bytes);
bytes = md5.ComputeHash(bytes);
bytes = md5.ComputeHash(bytes);

md5.Clear();

string ret = "";
for (int i = 0; i < bytes.Length; i++)
{
ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');
}

return ret.PadLeft(32, '0');
}
/// <summary>
/// 计算字符串的一次MD5
/// </summary>
/// <param name="s" /></param>
/// <returns></returns>
private static String md5(String s)
{
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);

bytes = md5.ComputeHash(bytes);

md5.Clear();

string ret = "";
for (int i = 0; i < bytes.Length; i++)
{
ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');
}

return ret.PadLeft(32, '0');
}
}


=====================================================================

先介绍一下有关加密的信息:

1、打开http://xiaoyou.qq.com/

2、开启fiddler监听HTTP包

3、登录QQ,我这里就随手写了个QQ:123456密码123456验证码efta

U代表QQ号

P代表加密后的密码

verifycode代表验证码

其余都是固定的,不叙述了

要登录农场,必须要模拟发送以上数据来登录校友,而密码必须加密成如上才能通过验证。

现在讲解一下如何把明文的1234加密成09967317CCFC266ADA83C9B1BEA30825(这么恶心的密码)

这个是腾讯加密的JavaScript脚本 密码加密JavaScript

初步看了一下觉得相当之恶心,所以在网上搜索了半天找到的一点线索就是 3次MD5加密后转换大些 + 验证码转换大写,再次MD5加密

可是我按照这方法试了得到的结果却不是正确的。百思不得其解,求助了园子里认识的朋友,他给我发了段C#的代码,确实可以得到正确的。代码如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Collections;

namespace QQ校友助手
{
class QQPassword
{
public static string binl2hex(byte[] buffer)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < buffer.Length; i++)
{
builder.Append(buffer[i].ToString("x2"));
}
return builder.ToString();
}
public static string md5_3(string input)
{
MD5 md = MD5.Create();
byte[] buffer = md.ComputeHash(Encoding.Default.GetBytes(input));
buffer = md.ComputeHash(buffer);
buffer = md.ComputeHash(buffer);
return binl2hex(buffer);
}

public static string md5(string input)
{
byte[] buffer = MD5.Create().ComputeHash(Encoding.Default.GetBytes(input));
return binl2hex(buffer);
}

public static string getPassword(string password, string verifycode)
{
return md5(md5_3(password).ToUpper() + verifycode.ToUpper()).ToUpper();
}


}
}


Encoding.Default.GetBytes(input)获取的是字符串的ASCII码

用VS跟踪调试了好久,发现问题出在 C#的computehash是初级hash,得到的并不是16进制的MD5字符串,需要经过binl2hex才能转换成MD5字符串。也就是说初级hash了3次,才合并大写验证码进行最后一次MD5加密。


知道了原理后,我改成Delphi源码:

procedure TForm1.btn4Click(Sender: TObject);
var
hash: T4x4LongWordRecord;
hashstr: string;
i: integer;
temp3: string;
begin
SetLength(hashstr, 16);
with TIdHashMessageDigest5.Create do begin
hash := HashValue('123456');    //此处的hash也是初级的
Move(hash, hashstr[1], 16);
for i := 1 to Length(hashstr) do
temp3 := temp3 + Char(hashstr[i]);
hash := HashValue(temp3);
Move(hash, hashstr[1], 16);
temp3 := '';
for i := 1 to Length(hashstr) do
temp3 := temp3 + Char(hashstr[i]);
temp3 := AsHex(HashValue(temp3));  //此处的AsHex就是转换最终的MD5字符串(32位)
temp3 := temp3 + 'EFTA';
temp3 := AsHex(HashValue(temp3));
ShowMessage(temp3);
Free;
end;
end;


以上代码可以得到09967317CCFC266ADA83C9B1BEA30825这加密后的字符串

我现在写的QQ农夫只是用浏览器直接登录,没有采用模拟post数据的方式登录。所以之前没有对这个加密算法做研究。

希望对QQ密码加密的分析对大家有启发!


文章来自学IT网:http://www.xueit.com/js/show-4765-2.aspx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值