前几天闲来没事,做了个网易邮箱批量注册机,应该说没有解决验证码自动识别,所以也不能说是批量注册机。

但是可以谈谈实现思路

首先说明一下,网易的验证码的取得的算法应该是经常变的,还有其他请求应该也是经常变的。所以如果有朋友想要了解这方面的知识,我个人觉得思想才是最重要,以不变应万变

正所谓道高一尺魔高一丈!!!

1、先给看个界面吧(做的很粗糙)                                                         

image

2、实现的重点就是取验证码和提交数据,其他都很简单

3、网易在取验证码做了js的加密,只要你用心破解还是很简单的,为什么呢?js无论怎么加密,其实都是能看到源文件的。应该是在  /unireg/js/register/common/verifyutils-min.js 中,就是一堆算法,换句话说如果这个算法稍微变一下,我们取验证码的方法就要跟着变

这里给出取验证码的代码

   1: private void getYzm()
   2: {
   3:     Proxying proxy = new Proxying();
   4:     // 验证码
   5:     List<string> strEnvList = getEnv();
   6:     string yzmParam1 = strEnvList[0];
   7:     string yzmParam2 = strEnvList[1];
   8:     string yzmUri = "http://reg.email.163.com/mailregAll/regvf1/verifyCodeImgF.jsp?env=" + yzmParam1 + "&type=zh&t=" + yzmParam2;
   9:  
  10:     HttpWebRequest yzmRequest = (HttpWebRequest)WebRequest.Create(yzmUri);
  11:     proxy.ProxySetting(yzmRequest, "172.122.1.8", "xumingsheng", "000000");//加在获取响应前
  12:     yzmRequest.Method = "GET";
  13:     yzmRequest.ContentType = getContenType();
  14:     yzmRequest.Timeout = 60000;
  15:     yzmRequest.Headers["Cache-Control"] = webHeaderCollection["Cache-Control"];
  16:     yzmRequest.Headers["x-requested-with"] = "XMLHttpRequest";
  17:     yzmRequest.Headers["Accept-Language"] = "ja";
  18:     yzmRequest.Headers["Accept-Encoding"] = "gzip, deflate";
  19:     yzmRequest.Headers["Pragma"] = "no-cache";
  20:     yzmRequest.Headers["Cookie"] = webHeaderCollection["Set-Cookie"];
  21:     yzmRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
  22:     yzmRequest.Referer = "http://reg.email.163.com/mailregAll/reg0.jsp";
  23:  
  24:  
  25:  
  26:     HttpWebResponse yzmResponse = (HttpWebResponse)yzmRequest.GetResponse();
  27:     //webHeaderCollection = yzmResponse.Headers;
  28:  
  29:     pictureYzm.Image = Image.FromStream(yzmResponse.GetResponseStream());
  30:  
  31: }

   1: /// <summary>
   2: /// 网易验证码js计算方式翻译版
   3: /// </summary>
   4: /// <returns></returns>
   5: private List<string> getEnv() 
   6: {
   7:     long W = 1346334231661;
   8:     string WW = W.ToString();
   9:  
  10:     long U = (W % 100 - W % 10) / 10;
  11:     string UU = U.ToString();
  12:     long V = W % 10;
  13:     string VV = V.ToString();
  14:     long I = long.Parse(WW.ToCharArray()[10].ToString());
  15:     string II = I.ToString();
  16:  
  17:     // N 是T的反数
  18:     // long T = Number( W%10 + W%100 + W.charAt(10) )*Number(_$);
  19:     long T = long.Parse(VV + UU + II) * MW163;
  20:     string TT = T.ToString();
  21:     string NN = string.Empty;
  22:     for (int i = TT.Length - 1; i >= 0; i--)
  23:     {
  24:         char[] TTT = TT.ToCharArray();
  25:         NN = NN + TTT[i];
  26:     }
  27:  
  28:     string strEnv = II + NN + UU + VV;
  29:  
  30:     List<string> strEnvList = new List<string>();
  31:     strEnvList.Add(strEnv);
  32:     strEnvList.Add(WW);
  33:  
  34:     return strEnvList;
  35: }
  36:  
  37:  
  38: /*
  39:  现在要用c#做出这种js 的gettimer的效果,首先要转换成统一的单位,我们以转成百纳秒为单位
  40: 
  41:     然后做到的就是统一的时间取得点,以 1970 年 1 月 1 日 为起点,这时就要算出来,从0001 年 1 月 1 日到1970 年 1 月 1 日经过了多少纳秒
  42:     可以通过以下代码得知一个常量private long lLeft = 621355968000000000;
  43:     Console.WriteLine (DateTime.Parse("1970-1-1").Ticks);
  44: 
  45:     比如我现在要得到"2009-7-15 08:33:19"的毫秒数
  46:     首先转成UTC时间
  47:     DateTime dt1 = Convert.ToDateTime("2009-7-15 08:33:19").ToUniversalTime ();
  48: 
  49:     然后得到从 1970 年 1 月 1 日到刚才那个时间的百纳秒数
  50:     long Sticks = (dt1.Ticks - DateTime.Parse("1970-1-1").Ticks)
  51: 
  52:     最后因为要转成js的效果,所以把百纳秒转成毫秒,Sticks/10000000; 最后得到的结果是1247617999
  53: 
  54:     同理把这个毫秒数转成本地时间就返过来推,北京与utc是相差8个小时的,所以最后用ToLocalTime 转成本地时间就可以解决时差问题了。
  55:  
  56:  
  57:  */
  58: private long lLeft = 621355968000000000;
  59:  
  60: //将数字变成时间
  61: public string GetTimeFromInt(long ltime)
  62: {
  63:  
  64:     long Eticks = (long)(ltime * 10000000) + lLeft;
  65:     DateTime dt = new DateTime(Eticks).ToLocalTime();
  66:     return dt.ToString();
  67:  
  68: }
  69:  
  70: //将时间变成数字
  71: public long GetIntFromTime(DateTime dt)
  72: {
  73:     DateTime dt1 = dt.ToUniversalTime();
  74:     long Sticks = (dt1.Ticks - lLeft) / 10000;
  75:     return Sticks;
  76:  
  77: } 
  78:  
  79:     }

4、提交。这个就比较简单了啊,就是一个普通的post提交,由于我这里有代理,就写了个代理,大家可以忽略

   1: /// <summary>
   2: /// 邮箱注册
   3: /// </summary>
   4: /// <param name="sender"></param>
   5: /// <param name="e"></param>
   6: private void btnBatchReg_Click(object sender, EventArgs e)
   7: {
   8:     try
   9:     {
  10:         string postdata = "uname=" + txtMailAddr.Text
  11:             + "&password=" + txtMailPassword.Text
  12:             + "&optshi=" + "28203"
  13:             + "&passwordconf=" + txtMailPassword.Text
  14:             + "&mobile=" + ""
  15:             + "&" + encodeFormItemPair("verifycode", txtMailYzm.Text)
  16:             + "&domain=163.com&version=regvf1";
  17:         string postUrl = "http://reg.email.163.com/mailregAll/createmail2.do";
  18:         //HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create(postUrl);
  19:         HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create(postUrl);
  20:         Proxying proxy = new Proxying();
  21:         proxy.ProxySetting(wreq, "代理IP地址", "代理用户名", "代理密码");//加在获取响应前
  22:  
  23:         wreq.Method = "POST";
  24:         wreq.ContentType = getContenType();
  25:         wreq.Timeout = 60000;
  26:         wreq.Headers["Cache-Control"] = webHeaderCollection["Cache-Control"];
  27:         wreq.Headers["x-requested-with"] = "XMLHttpRequest";
  28:         wreq.Headers["Accept-Language"] = "ja";
  29:         wreq.Headers["Accept-Encoding"] = "gzip, deflate";
  30:         wreq.Headers["Pragma"] = "no-cache";
  31:         wreq.Headers["Cookie"] = webHeaderCollection["Set-Cookie"];
  32:         wreq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
  33:  
  34:  
  35:         wreq.Referer = "http://reg.email.163.com/mailregAll/reg0.jsp?from=163mail_right";
  36:         Stream reqStream = wreq.GetRequestStream();
  37:         StreamWriter sw = new StreamWriter(reqStream, encode);
  38:         sw.Write(postdata);
  39:         sw.Close();
  40:  
  41:         WebResponse wres = wreq.GetResponse();
  42:  
  43:         Stream resStream = wres.GetResponseStream();
  44:         StreamReader sr = new StreamReader(resStream, encode);
  45:  
  46:         string s = sr.ReadToEnd();
  47:         sr.Close();
  48:         //return s;
  49:     }
  50:     catch (WebException ex)
  51:     {
  52:        // return ex.ToString();
  53:     }
  54: }