Guest User

Untitled

a guest
Apr 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Security.Cryptography;
  7.  
  8. namespace ocC
  9. {
  10.     class Program
  11.     {
  12.         class cFound
  13.         {
  14.             public string szUser;
  15.             public string szPass;
  16.         }
  17.         static void PrintHelp()
  18.         {
  19.             System.Console.WriteLine(
  20.                 "OsCommerce Password Cracker\r\n" +
  21.                 "Usage: " + System.AppDomain.CurrentDomain.FriendlyName +
  22.                 " filetocrack -wl <wordlist>"
  23.                 );
  24.         }
  25.         static void Main(string[] args)
  26.         {
  27.             if (args.Length != 2)
  28.             {
  29.                 PrintHelp();
  30.                 return;
  31.             }
  32.  
  33.             if (File.Exists(args[0]) == false)
  34.             {
  35.                 System.Console.WriteLine("Input file not found.");
  36.                 return;
  37.             }
  38.             if (File.Exists(args[1]) == false)
  39.             {
  40.                 System.Console.WriteLine("Wordlist not found.");
  41.                 return;
  42.             }
  43.  
  44.             List<cFound> FoundPasswords = new List<cFound>();
  45.  
  46.             StreamReader srInput = new StreamReader(args[0]);
  47.             string szLine;
  48.             int iLineNum = 0;
  49.             while ((szLine = srInput.ReadLine()) != null)
  50.             {
  51.                 iLineNum++;
  52.  
  53.                 if ((szLine.Count(f => f == ':')) < 2)
  54.                 {
  55.                     System.Console.WriteLine("Invalid line in file (" + iLineNum + ")");
  56.                     continue;
  57.                 }
  58.  
  59.                 string szUser = szLine.Substring(0, szLine.IndexOf(":"));
  60.                 string szSalt = szLine.Substring(szLine.LastIndexOf(":") + 1);
  61.                 string szPass = szLine.Substring(szLine.IndexOf(":", szUser.Length) + 1, szLine.Length - szUser.Length - szSalt.Length - 2);
  62.  
  63.                 System.Console.WriteLine("Trying " + szUser + ":" + szPass);
  64.  
  65.                 StreamReader srWL = new StreamReader(args[1]);
  66.  
  67.                 string szWLLine;
  68.                 while ((szWLLine = srWL.ReadLine()) != null)
  69.                 {
  70.                     using (MD5 md5Hash = MD5.Create())
  71.                     {
  72.                         string szHash = szWLLine.Insert(0, szSalt);
  73.                         if (GetMd5Hash(md5Hash, szHash) != szPass)
  74.                             continue;
  75.                         else
  76.                         {
  77.                             cFound tmp = new cFound();
  78.                             tmp.szPass = szWLLine;
  79.                             tmp.szUser = szUser;
  80.                             FoundPasswords.Add(tmp);
  81.                            
  82.                             System.Console.WriteLine("Password for " + szUser + ":" + szPass + " = " + szWLLine);
  83.                             break;
  84.                         }
  85.                     }
  86.                 }
  87.                 srWL.Close();
  88.             }
  89.             srInput.Close();
  90.             foreach (cFound FoundPw in FoundPasswords)
  91.             {
  92.                 System.Console.WriteLine(FoundPw.szUser + ":" + FoundPw.szPass);
  93.             }
  94.         }
  95.         static string GetMd5Hash(MD5 md5Hash, string input)
  96.         {
  97.  
  98.             // Convert the input string to a byte array and compute the hash.
  99.             byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
  100.  
  101.             // Create a new Stringbuilder to collect the bytes
  102.             // and create a string.
  103.             StringBuilder sBuilder = new StringBuilder();
  104.  
  105.             // Loop through each byte of the hashed data
  106.             // and format each one as a hexadecimal string.
  107.             for (int i = 0; i < data.Length; i++)
  108.             {
  109.                 sBuilder.Append(data[i].ToString("x2"));
  110.             }
  111.  
  112.             // Return the hexadecimal string.
  113.             return sBuilder.ToString();
  114.         }
  115.     }
  116. }
Add Comment
Please, Sign In to add comment