private void SendResult(StreamWriter sw, CrackResults cr) { string serializedobj = JsonConvert.SerializeObject(cr); sw.WriteLine(serializedobj); sw.WriteLine("EndOfFile"); }
public void HandleConnection() { Stream ns = connectionSocket.GetStream(); try { StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns); sw.AutoFlush = true; string message = sr.ReadLine(); while (!string.IsNullOrEmpty(message)) { if (message.StartsWith("getpw")) { string passWordS = JsonConvert.SerializeObject(MyMaster.Workload); sw.WriteLine(passWordS); sw.WriteLine("EndOfFile"); } if (message.StartsWith("getdc")) { string listString = JsonConvert.SerializeObject(MyMaster.GiveWorkLoad()); sw.WriteLine(listString); sw.WriteLine("EndOfFile"); Workload = true; } if (Workload) { string receivedstring = ""; while (true) { string incomingString = sr.ReadLine(); if (incomingString == "EndOfFile") { break; } receivedstring += incomingString; } CrackResults results = JsonConvert.DeserializeObject <CrackResults>(receivedstring); Workload = false; MyMaster.ResultsList.AddRange(results.Results); Console.WriteLine("this client finito: " + connectionSocket.GetHashCode()); Console.WriteLine(results.TotalsString); Console.WriteLine(results.TimeString); } message = sr.ReadLine(); Console.WriteLine("Client: " + message); } } catch (Exception) { Console.WriteLine("Client DC: " + this.GetHashCode()); } ns.Close(); connectionSocket.Close(); }
public void BeginWork() { // TODO Connect this to master // TODO MAKE this accept tcp work from master try { TcpClient tcpClient = new TcpClient(Ip, 5678); Stream stream = tcpClient.GetStream(); Results = new List <FullUser>(); StreamWriter sw = new StreamWriter(stream); StreamReader sr = new StreamReader(stream); sw.AutoFlush = true; UserInfosList = GetPasswords(sr, sw); while (true) { DictionaryList = GetWorkStarted(sr, sw); if (DictionaryList != null || DictionaryList.Count != 0) { Stopwatch stopwatch = Stopwatch.StartNew(); foreach (var dictionaryEntry in DictionaryList) { Results.AddRange(CheckWordWithVariations(dictionaryEntry, UserInfosList)); } stopwatch.Stop(); //Console.WriteLine(string.Join(", ", Results)); string total = $"Out of {UserInfosList.Count} password {Results.Count} was found "; Console.WriteLine(total); Console.WriteLine(); string time = $"Time elapsed: {stopwatch.Elapsed}"; Console.WriteLine(time); var resultObject = new CrackResults(Results, stopwatch.Elapsed, total, time); SendResult(sw, resultObject); } } } catch (Exception e) { Console.WriteLine(e); } }
public void ResultsCallback(CrackResults results) { lock (ResultsLocker) { Hashestried += results.Hashes; ClientsWorkTimeSpan = ClientsWorkTimeSpan.Add(results.TimeElapsed); if (results.Results.Count < 1) { return; } foreach (var user in results.Results) { if (!ResultsList.ContainsKey(user.Username)) { ResultsList.Add(user.Username, user); } if (Workload.ContainsKey(user.Username)) { Workload.Remove(user.Username); } } } }
public void HandleConnection() { Stream ns = connectionSocket.GetStream(); try { StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns); sw.AutoFlush = true; string message = sr.ReadLine(); while (!string.IsNullOrEmpty(message)) { if (message.StartsWith("getpw")) { string passWordS = JsonConvert.SerializeObject(MyMaster.Workload.Select(kvp => kvp.Value).ToList()); sw.WriteLine(passWordS); sw.WriteLine("EndOfFile"); } if (message.StartsWith("getdc")) { string listString = JsonConvert.SerializeObject(MyMaster.GetWorkLoadCallback()); sw.WriteLine(listString); sw.WriteLine("EndOfFile"); _workload = true; } if (_workload) { string receivedstring = ""; while (true) { string incomingString = sr.ReadLine(); if (incomingString == "EndOfDictionary") { throw new ApplicationExitException("End of dicitonary reached"); } if (incomingString == "EndOfFile") { break; } receivedstring += incomingString; } CrackResults results = JsonConvert.DeserializeObject <CrackResults>(receivedstring); _workload = false; Task.Run(() => MyMaster.ResultsCallback(results)); Console.WriteLine("Client has finished its current work: " + connectionSocket.GetHashCode()); Console.WriteLine(results.TotalsString); Console.WriteLine(results.TimeString); } message = sr.ReadLine(); } } catch (Exception e) { Console.WriteLine("Client DC: " + connectionSocket.GetHashCode()); if (e is ApplicationExitException) { MyMaster.ShutdownCallback(this); } } ns.Close(); connectionSocket.Close(); }
public void BeginWork() { try { TcpClient = new TcpClient(MastersIp, MastersPort); Stream stream = TcpClient.GetStream(); StreamWriter sw = new StreamWriter(stream); StreamReader sr = new StreamReader(stream); sw.AutoFlush = true; UserInfosList = GetPasswords(sr, sw); Console.WriteLine("Getting passwords"); while (true) { Console.WriteLine("Getting work to do"); DictionaryList = GetWorkStarted(sr, sw); if (DictionaryList == null || DictionaryList.Count < 1) { sw.WriteLine("EndOfDictionary"); sw.Flush(); Thread.Sleep(100); throw new ApplicationExitException("Server reached end of dictionary"); } if (DictionaryList != null && DictionaryList.Count > 0) { Console.WriteLine("Working!"); Stopwatch stopwatch = Stopwatch.StartNew(); int[] hashes = { 0 }; var numOfThreads = Environment.ProcessorCount; if (numOfThreads > 1) { var split = DictionaryList.Count / numOfThreads; var lists = SplitList(DictionaryList, split); var listCount = lists.Count; var tasks = new List <Task>(); if (listCount > numOfThreads) { var diff = listCount - numOfThreads; if (diff > 0) { numOfThreads += diff; } } for (int i = 0; i < numOfThreads; i++) { var i1 = i; tasks.Add(Task.Run(() => { CrackMethod(hashes, lists[i1]); })); } Task.WaitAll(tasks.ToArray()); } else { CrackMethod(hashes, DictionaryList); } stopwatch.Stop(); string total = $"Theres {UserInfosList.Count} passwords left\n{Results.Count} passwords was found\n{DictionaryList.Count} words was tested"; Console.WriteLine(total); Console.WriteLine(); TimeElapsed = TimeElapsed.Add(stopwatch.Elapsed); string time = $"Time elapsed: {stopwatch.Elapsed}"; Console.WriteLine(time); var resultObject = new CrackResults(Results, stopwatch.Elapsed, total, time, hashes[0]); SendResult(sw, resultObject); } } } catch (Exception e) { if (e is ApplicationExitException) { Console.WriteLine("Shutdown recieved"); Console.WriteLine("Total time slave was working on passwords: " + TimeElapsed); TcpClient.Close(); } else { Console.WriteLine(e); } } }