Example #1
0
        /// <summary>
        /// Runs the password cracking algorithm
        /// </summary>
        public void RunCracking()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            List <UserInfo> userInfos =
                PasswordFileHandler.ReadPasswordFile("passwords.txt");

            Console.WriteLine("passwd opeend");

            List <UserInfoClearText> result = new List <UserInfoClearText>();

            using (FileStream fs = new FileStream("webster-dictionary.txt", FileMode.Open, FileAccess.Read))

                using (StreamReader dictionary = new StreamReader(fs))
                {
                    while (!dictionary.EndOfStream)
                    {
                        String dictionaryEntry = dictionary.ReadLine();
                        IEnumerable <UserInfoClearText> partialResult = CheckWordWithVariations(dictionaryEntry, userInfos);
                        result.AddRange(partialResult);
                    }
                }
            stopwatch.Stop();
            Console.WriteLine(string.Join(", ", result));
            Console.WriteLine("Out of {0} password {1} was found ", userInfos.Count, result.Count);
            Console.WriteLine();
            Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
        }
        /// <summary>
        /// Runs the password cracking algorithm
        /// </summary>
        public string RunCracking(string [] dictionary)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            List <UserInfo> userInfos =
                PasswordFileHandler.ReadPasswordFile("passwords.txt");
            //Console.WriteLine("passwd opeend");

            List <UserInfoClearText> results = new List <UserInfoClearText>();

            for (int i = 0; i < dictionary.Length; i++)
            {
                String dictionaryEntry = dictionary[i];
                IEnumerable <UserInfoClearText> partialResult = CheckWordWithVariations(dictionaryEntry, userInfos);
                results.AddRange(partialResult);
            }

            stopwatch.Stop();
            //Console.WriteLine(string.Join(", ", results));
            //Console.WriteLine("Out of {0} password {1} was found ", userInfos.Count, results.Count);
            //Console.WriteLine();
            //Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);

            string output = "";

            for (int i = 0; i < results.Count; i++)
            {
                output += $"{results[i].UserName}:{results[i].Password}|";
            }

            return(output);
        }
Example #3
0
        /// <summary>
        /// Runs the password cracking algorithm
        /// </summary>
        public List <UserInfoClearText> RunCracking()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            Console.WriteLine("Cracking started");
            List <UserInfo> userInfos =
                PasswordFileHandler.ReadPasswordFile("passwords.txt");
            List <UserInfoClearText> result = new List <UserInfoClearText>();

            using (FileStream fs = new FileStream("webster-dictionary.txt", FileMode.Open, FileAccess.Read))
                using (StreamReader dictionary = new StreamReader(fs))
                {
                    try
                    {
                        while (!dictionary.EndOfStream)
                        {
                            String dictionaryEntry = dictionary.ReadLine();
                            IEnumerable <UserInfoClearText> partialResult = CheckWordWithVariations(dictionaryEntry, userInfos);
                            result.AddRange(partialResult);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("skipping first line" + ex);
                    }
                }
            stopwatch.Stop();
            Console.WriteLine(string.Join(", ", result));
            Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            return(result);
        }
Example #4
0
        /// <summary>
        /// Runs the password cracking algorithm
        /// </summary>
        public void RunCracking()
        {
            //Added word count
            dictionaryWordCount = 0;

            Stopwatch stopwatch = Stopwatch.StartNew();

            List <UserInfo> userInfos =
                PasswordFileHandler.ReadPasswordFile("passwords.txt");
            List <UserInfoClearText> result = new List <UserInfoClearText>();

            using (FileStream fs = new FileStream(NameOfDictionaryFile, FileMode.Open, FileAccess.Read))
                using (StreamReader dictionary = new StreamReader(fs))
                {
                    while (!dictionary.EndOfStream)
                    {
                        String dictionaryEntry = dictionary.ReadLine();
                        IEnumerable <UserInfoClearText> partialResult = CheckWordWithVariations(dictionaryEntry, userInfos);
                        result.AddRange(partialResult);

                        //Added counting
                        dictionaryWordCount++;
                    }
                }
            stopwatch.Stop();
            Console.WriteLine(string.Join(", ", result));
            Console.WriteLine("Out of {0} password {1} was found ", userInfos.Count, result.Count);
            Console.WriteLine();
            Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);

            //Added speed:
            Console.WriteLine("Average speed (words/second): {0}", dictionaryWordCount / (ulong)(stopwatch.Elapsed.Seconds));
        }
        public void Start()
        {
            List <UserInfo> userInfos =
                PasswordFileHandler.ReadPasswordFile("passwords.txt");

            TcpListener tcpListener = new TcpListener(Ip, 9999);

            tcpListener.Start();

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            while (Finished == false)
            {
                Task.Run(() =>
                {
                    TcpClient cl         = tcpListener.AcceptTcpClient();
                    var resultFromClinet = ClientWork(cl);
                    results.AddRange(resultFromClinet);
                    //Thread.Sleep(10000);
                });
            }
            stopWatch.Stop();
            Console.WriteLine("Time elapsed since server start: " + stopWatch.Elapsed.ToString());
            Console.WriteLine("{0} passwords found out of {1}", results.Count, userInfos.Count);
            foreach (var user in results)
            {
                Console.WriteLine(user.UserName + " : " + user.Password);
            }
        }
        private Dictionary <string, UserInfo> PreparePasswords(string path)
        {
            var pwList = PasswordFileHandler.ReadPasswordFile(path);

            if (pwList == null || pwList.Count < 1)
            {
                return(null);
            }
            return(pwList.ToDictionary(userInfo => userInfo.Username));
        }
        public void Listener(int port)
        {
            //Read the passwords into a list
            List <UserInfo> userInfos =
                PasswordFileHandler.ReadPasswordFile("passwords.txt");

            ////Read the Desctionary
            List <List <string> > chunks = new List <List <string> >();

            using (FileStream fs = new FileStream("webster-dictionary.txt", FileMode.Open, FileAccess.Read))
                using (StreamReader dictionary = new StreamReader(fs))
                {
                    List <string> tempList = new List <string>();
                    while (!dictionary.EndOfStream)
                    {
                        //if you want to send chunks to the client then create chunks
                        //You must use a logic where it puts 10000 dictinary words in tempList and then
                        //Adds tempList to chucks
                        tempList.Add(dictionary.ReadLine());
                        //after the modulus % condition is satisfied i.e. when there is 10000 words in tempList
                        //then
                        if (tempList.Count == 10000)
                        {
                            chunks.Add(tempList);
                            tempList = new List <string>();
                        }
                        // IEnumerable<UserInfoClearText> partialResult = CheckWordWithVariations(dictionaryEntry, userInfos);
                        // result.AddRange(partialResult);
                    }
                    chunks.Add(tempList);
                }
            //now you can send the first chuck to the Slave i.e. the client

            //TcpListener serverSocket = new TcpListener(port);
            TcpListener server = new TcpListener(IPAddress.Loopback, port);

            server.Start();
            Console.WriteLine("Server listning on port: " + port);

            TcpClient connectionSocket = server.AcceptTcpClient();

            Console.WriteLine("Server activated");

            Stream       ns = connectionSocket.GetStream();
            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true; // enable automatic flushing

            string request = sr.ReadLine();

            Console.WriteLine(request);
        }
        public void EnvokeCracking()
        {
            Stream       ns = connectionSocket.GetStream();
            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true; // enable automatic flushing

            string message = sr.ReadLine();

            while (message != null && message != "")
            {
                if (message == "start" || message == "Start" || message == "s" || message == "S")
                {
                    //Console.WriteLine("Cracking is started");
                    //Cracking cracker = new Cracking();

                    //Task.Factory.StartNew(() => { cracker.RunCracking(); });


                    Stopwatch stopwatch = Stopwatch.StartNew();

                    List <UserInfo> userInfos =
                        PasswordFileHandler.ReadPasswordFile("passwords.txt");
                    Console.WriteLine("passwd opeend");

                    List <UserInfoClearText> result = new List <UserInfoClearText>();

                    using (FileStream fs = new FileStream("webster-dictionary.txt", FileMode.Open, FileAccess.Read))

                        using (StreamReader dictionary = new StreamReader(fs))
                        {
                            while (!dictionary.EndOfStream)
                            {
                                String dictionaryEntry = dictionary.ReadLine();
                                IEnumerable <UserInfoClearText> partialResult = CheckWordWithVariations(dictionaryEntry, userInfos);
                                result.AddRange(partialResult);
                            }
                            var sendResult = JsonConvert.SerializeObject(result);
                            sw.WriteLine(sendResult);
                        }
                }
                else
                {
                    throw new ArgumentException();
                }
            }
        }
        public List <UserInfoClearText> RunCracker()
        {
            List <UserInfo> userInfos =
                PasswordFileHandler.ReadPasswordFile("passwords.txt");

            Console.WriteLine("Cracker thread started");

            List <UserInfoClearText> result = new List <UserInfoClearText>();

            foreach (var entry in dictionary)
            {
                IEnumerable <UserInfoClearText> partialResult = CheckWordWithVariations(entry, userInfos);
                result.AddRange(partialResult);
            }
            return(result);
        }
Example #10
0
        //public BlockingCollection<string> Spliting()
        //{
        //    var numberOfClients = Program.connectedClients.Count;
        //    var numberOfWords = collectionOfWords.Count;
        //    var divisionNumber = numberOfWords / numberOfClients;

        //    if (numberOfWords % numberOfClients == 0)
        //    {
        //        for (int i = 0; i < divisionNumber; i++)
        //        {
        //            List<string> dividedWordsList = new List<string>();

        //        }
        //    }

        //}

        /// <summary>
        /// Runs the password cracking algorithm
        /// </summary>
        public void RunCracking()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            List <UserInfo> userInfos =
                PasswordFileHandler.ReadPasswordFile("passwords.txt");

            Console.WriteLine("passwd opeend");

            List <UserInfoClearText> result = new List <UserInfoClearText>();

            using (FileStream fs = new FileStream("webster-dictionary.txt", FileMode.Open, FileAccess.Read)) // deals with byte[] data

                using (StreamReader dictionary = new StreamReader(fs))                                       // encodes text to byte[]
                {
                    while (!dictionary.EndOfStream)
                    {
                        String dictionaryEntry = dictionary.ReadLine();
                        collectionOfWords.Add(dictionaryEntry);
                        Console.WriteLine(dictionaryEntry);

                        foreach (var word in collectionOfWords)
                        {
                            Console.WriteLine(word);
                        }


                        // for int loop until, for instance, 1/3 of the collection, if there are 3 clients connected
                        // Get number of clients and divide collectionOfWords by the number of clients
                        // Send divided parts to the seperate clients

                        Console.ReadKey();
                        // partial result should be send as a request to be proccessed by the slave client

                        //IEnumerable<UserInfoClearText> partialResult = CheckWordWithVariations(dictionaryEntry, userInfos);
                        //result.AddRange(partialResult);
                    }
                }
            stopwatch.Stop();
            Console.WriteLine(string.Join(", ", result));
            Console.WriteLine("Out of {0} password {1} was found ", userInfos.Count, result.Count);
            Console.WriteLine();
            Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
        }
        public static List <List <UserInfo> > SplitToChunks()
        {
            int             ctr       = 0;
            List <UserInfo> userInfos = PasswordFileHandler.ReadPasswordFile("passwords.txt");

            List <UserInfo> temp = new List <UserInfo>();

            foreach (var user in userInfos)
            {
                temp.Add(user);

                ctr++;
                if (ctr == 5)
                {
                    chunks.Add(temp);
                    ctr = 0;
                }
            }

            return(chunks);
        }
Example #12
0
        static void Main(string[] args)
        {
            Console.Write("Reading passwords file... ");
            List <UserInfo> userInfos = PasswordFileHandler.ReadPasswordFile("passwords.txt");

            string users = "";

            foreach (UserInfo u in userInfos)
            {
                users += u + "|";
            }
            if (users != "")
            {
                Console.Write("OK\n");
            }
            else
            {
                Console.Write("FAILED\n");
            }

            Console.Write("Reading dictionary file... ");
            var dictionary = File.ReadAllText("dictionary.txt");

            dictionary = dictionary.Replace('\n', '|');
            if (dictionary != "")
            {
                Console.Write("OK\n");
            }
            else
            {
                Console.Write("FAILED\n");
            }

            Console.Write("Splitting dictionary... ");
            var splitDictionary = SplitDictionary(dictionary);

            if (splitDictionary.Length != 0)
            {
                Console.Write("OK\n");
            }
            else
            {
                Console.Write("FAILED\n");
            }

            List <string> allChunks = new List <string>();

            for (int i = 0; i < splitDictionary.GetLength(0); i++)
            {
                StringBuilder chunk = new StringBuilder();
                for (int j = 0; j < splitDictionary.GetLength(1); j++)
                {
                    chunk.Append(splitDictionary[i, j]);
                    chunk.Append('|');
                }
                allChunks.Add(chunk.ToString());
            }

            Console.Write("Starting server... ");
            TcpListener serverSocket = new TcpListener(IPAddress.Any, 7777);

            serverSocket.Start();
            Console.Write("OK\n");

            List <Task <string> > tasks = new List <Task <string> >();

            for (int i = 0; i < NumberOfClients; i++)
            {
                var chunk = allChunks[i];
                tasks.Add(Task.Run(() => RunClientAsync(serverSocket, users, chunk)));
            }
            Console.Write("Waiting for clients' response... ");
            string[] result = Task.WhenAll(tasks).Result;
            Console.Write("OK\n\n");

            string output = "";

            foreach (string s in result)
            {
                output += s;
            }

            output = output.Replace(':', ' ').Replace('|', '\n');
            Console.Write(output);

            serverSocket.Stop();

            Console.Write("\nPress any key to exit...");
            Console.ReadKey();
        }
Example #13
0
 private List <UserInfo> PrepareWorkload(string path)
 {
     return(PasswordFileHandler.ReadPasswordFile(path));
 }
Example #14
0
        public void RunCrackingModified(int encryptorCount)
        {
            dictionaryWordCount = 0;

            Stopwatch stopwatch = Stopwatch.StartNew();

            List <UserInfo>          userInfos = PasswordFileHandler.ReadPasswordFile("passwords.txt");
            List <UserInfoClearText> result    = new List <UserInfoClearText>();

            BlockingCollection <string> wordDictionary = new BlockingCollection <string>();

            BlockingCollection <string> transformedWordsDictionary = new BlockingCollection <string>(10000);

            //Tuple is used for joining passwords with their encrypted version, so that we will not need to search for them in other threads,
            //e.g.: password (string): "pswd", encrypted password (byte[]): "????????"
            BlockingCollection <Tuple <string, byte[]> > encryptedWordsDictionary = new BlockingCollection <Tuple <string, byte[]> >();

            //Only one cracker is veeeeeeeeeeeeery slow
            //            Parallel.Invoke(() => ReadDictionary(dictionary),
            //                () => TransformDictionary(dictionary, transformedDictionary),
            //                () => EncryptDictionary(transformedDictionary, encryptedDictionary),
            //                () => ComparePasswords(userInfos, encryptedDictionary),
            //                () => PrintCounts(dictionary, transformedDictionary, encryptedDictionary)
            //                );

            //This is a much faster solution - to make much more hash calculators

            //Making many crackers, so that we could start them in separate threads. We can't use one Cracker object,
            //because one method can only be used by one thread at the same time.
            //You can change the number of "crackers" by changing the value of howManyCrackers. It should be at least 1.
            Cracking[] crackingObjects;
            int        howManyCrackers = encryptorCount;

            crackingObjects = new Cracking[howManyCrackers];
            for (int i = 0; i < howManyCrackers; i++)
            {
                crackingObjects[i] = new Cracking();
            }

            //Starting all the tasks except EncryptDictionary
            Task.Run(() => ReadDictionary(wordDictionary));
            Task.Run(() => TransformDictionary(wordDictionary, transformedWordsDictionary));
            //ComparePasswords is going to return a list of found passwords, so we are making it as a Task with return:
            Task <List <UserInfoClearText> > taskOfComparing = Task <List <UserInfoClearText> > .Factory.StartNew(
                () => ComparePasswords(userInfos, encryptedWordsDictionary)
                );

            //Run a thread for seeing how many things there are in BlockingCollections every second, while debugging:
            //Task.Run(() => PrintCounts(wordDictionary, transformedWordsDictionary, encryptedWordsDictionary));

            //The bottleneck is here (most of the calculations are made in method EncryptDictionary), so
            //we are making few processes who encrypt passwords separately.
            //So now we are running all the EncryptDictionary threads in parallel!
            Parallel.For(0, howManyCrackers,
                         (i) => crackingObjects[i].EncryptDictionary(transformedWordsDictionary, encryptedWordsDictionary));
            //Can also use Tasks instead of parallel, and if you want more Encryptors and/or Comparators:
            //            for (int i = 0; i < howManyCrackers/2; i++)
            //            {
            //                int j = i;
            //                Task.Run(() => (new Cracking()).ComparePasswords(userInfos, encryptedDictionary));
            //            }
            //
            //            for (int i = 0; i < howManyCrackers / 2; i++)
            //            {
            //                int j = i;
            //                Task.Run(() => crackingMachinesHaha[j].EncryptDictionary(transformedDictionary, encryptedDictionary));
            //            }

            //Saving results (this will wait here until the ComparePasswords task in object taskOfComparing will finish it's work):
            result = taskOfComparing.Result;

            //Printing results and stopping stopwatch
            stopwatch.Stop();
            Console.WriteLine(string.Join(", ", result));
            Console.WriteLine("Out of {0} password {1} was found ", userInfos.Count, result.Count);
            Console.WriteLine();
            Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);

            Console.WriteLine("Average speed (words/second): {0}", dictionaryWordCount / (ulong)(stopwatch.Elapsed.Seconds));
        }
Example #15
0
        public void Start()
        {
            stopwatch = new Stopwatch();
            _lock     = new object();
            userInfos =
                PasswordFileHandler.ReadPasswordFile("passwords.txt");
            //Console.WriteLine("passwd opeend");

            result = new List <UserInfoClearText>();

            Chunks = CreateChunks("webster-dictionary.txt", 10000);

            //IP configuration
            //IPAddress ipa = IPAddress.Parse("127.0.0.1");
            IPAddress ipa = IPAddress.Parse("192.168.104.137");

            TcpListener tcp = new TcpListener(ipa, 7000);

            //Starting Server and sending the accepted client to a "DoClient"
            tcp.Start();
            Console.WriteLine("Server Started");

            while (true)
            {
                if (tcp.Pending())
                {
                    Task.Run(() =>
                    {
                        TcpClient tempSocket = tcp.AcceptTcpClient();
                        _clientsConnected++;
                        EndPoint clientIP = tempSocket.Client.RemoteEndPoint;
                        Console.WriteLine(clientIP + ": CONNECTED, total clients: " + _clientsConnected);

                        DoClient(tempSocket);

                        _clientsConnected--;
                        Console.WriteLine(clientIP + ": DISCONNECTED, total clients: " + _clientsConnected);
                        tempSocket.Close();
                    });
                }

                if (_inCompletedChunks.Count == 0)
                {
                    stopwatch.Stop();
                    break;
                }

                //Console.WriteLine("test");
            }


            #region old while loop
            //while (true)
            //{
            //    Task.Run(() =>
            //    {
            //        //Thread thread = Thread.CurrentThread;
            //        TcpClient tempSocket = tcp.AcceptTcpClient();
            //        EndPoint clientIP = tempSocket.Client.RemoteEndPoint;
            //        Console.WriteLine(clientIP + ": CONNECTED");
            //        _clientsConnected++;

            //        DoClient(tempSocket);

            //        if (!tempSocket.Connected)
            //        {
            //            Console.WriteLine(clientIP + ": DISCONNECTED");
            //            _clientsConnected--;
            //        }
            //        tempSocket.Close();
            //        //if (thread != null) thread.Abort();
            //        //thread.Abort();
            //    });

            //    if (_inCompletedChunks.Count <= 0)
            //    {
            //        stopwatch.Stop();
            //        break;
            //    }
            //    //Console.WriteLine(Process.GetCurrentProcess().Threads.Count);
            //    //Thread.Sleep(100);
            //    //Console.WriteLine("test");
            //}
            #endregion

            //Console.WriteLine("\n\n-----PASSWORDS FOUND-----");
            //foreach (UserInfoClearText r in result)
            //{
            //    Console.WriteLine(r);
            //}

            Console.WriteLine("\n-------------------------");
            Console.WriteLine("Done");
            Console.WriteLine($"Took: {stopwatch.Elapsed}");
            Console.WriteLine("-------------------------\n");

            tcp.Stop();
        }
Example #16
0
        /// <summary>
        /// Based on a specific ip and port will the method create a socket connection using TcpClient.
        /// </summary>
        /// <param name="ip"></param> the specific ip eg. 100.200.19.7
        /// <param name="port"></param> the specific ip eg. 6789
        public async void StartConnection(String ip, int port)
        {
            //We reads all the password and username Pairs and saves them to a list<UserInfo>
            List <UserInfo> list       = PasswordFileHandler.ReadPasswordFile("passwords.txt");
            int             chucnkSize = 10000; //adjust after need

            Console.WriteLine("starting connectiong");
            //Creating a TcpClient
            TcpClient clientSocket = new TcpClient(ip, port);

            Console.WriteLine("Connection to slave");

            //able the class to read & write over over the socket connecting, using a stream.
            Stream       ns = clientSocket.GetStream();
            StreamReader sr = new StreamReader(ns);
            StreamWriter sw = new StreamWriter(ns);

            sw.AutoFlush = true;

            //Protocol logic
            for (int i = 0; i < 1; i++)
            {
                //Sends a hole list
                var SendList = JsonConvert.SerializeObject(list);  //Converts the list to JSON, so it can be send.
                sw.WriteLine(SendList);
                Console.WriteLine("Brugerlist er sendt");

                //Confirm message from slaves
                string message = sr.ReadLine();
                Console.WriteLine(message);

                ////sends chunck size to slaves.
                sw.WriteLine(chucnkSize);
                string confirmChunckSize = sr.ReadLine();
                Console.WriteLine(confirmChunckSize);

                Console.WriteLine("communication established");

                //Calls the method belows
                await StartCracking();
            }

            //method to envoke the slave to start cracking.
            async Task StartCracking()
            {
                //Start Cracking
                Console.WriteLine("-----------------------");
                Console.WriteLine("Type 'Start' to crack");
                string commandStartCrack = Console.ReadLine();;

                sw.WriteLine(commandStartCrack);

                Console.WriteLine("--- Cracking is running, please wait ---");
                string result = sr.ReadLine();

                Console.WriteLine(result);

                IList <UserInfo> resivedResult = JsonConvert.DeserializeObject <List <UserInfo> >(result);

                foreach (var item in resivedResult)
                {
                    item.ToString();
                }

                Console.WriteLine("Done");
                Console.WriteLine("No more from server. Press Enter");
                Console.ReadLine();

                ns.Close();
            }
        }