Adjust namespaces

This commit is contained in:
MaxXor 2018-10-04 21:49:24 +02:00
parent 0df0242fc9
commit 1ca2ca6dd4
147 changed files with 700 additions and 1496 deletions

View File

@ -1,49 +0,0 @@
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Quasar.Client.Core.Cryptography;
using Quasar.Client.Core.Helper;
namespace Quasar.Client.Tests.Core.Encryption
{
[TestClass]
public class AESTests
{
[TestMethod, TestCategory("Encryption")]
public void EncryptAndDecryptStringTest()
{
var input = FileHelper.GetRandomFilename(100);
var password = FileHelper.GetRandomFilename(50);
AES.SetDefaultKey(password);
var encrypted = AES.Encrypt(input);
Assert.IsNotNull(encrypted);
Assert.AreNotEqual(encrypted, input);
var decrypted = AES.Decrypt(encrypted);
Assert.AreEqual(input, decrypted);
}
[TestMethod, TestCategory("Encryption")]
public void EncryptAndDecryptByteArrayTest()
{
var input = FileHelper.GetRandomFilename(100);
var inputByte = Encoding.UTF8.GetBytes(input);
var password = FileHelper.GetRandomFilename(50);
AES.SetDefaultKey(password);
var encryptedByte = AES.Encrypt(inputByte);
Assert.IsNotNull(encryptedByte);
CollectionAssert.AllItemsAreNotNull(encryptedByte);
CollectionAssert.AreNotEqual(encryptedByte, inputByte);
var decryptedByte = AES.Decrypt(encryptedByte);
CollectionAssert.AreEqual(inputByte, decryptedByte);
}
}
}

View File

@ -1,7 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Quasar.Client.Core.Helper;
using Quasar.Client.Helper;
namespace Quasar.Client.Tests.Core.Helper
namespace Quasar.Client.Tests.Helper
{
[TestClass]
public class FileHelperTests

View File

@ -7,7 +7,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Quasar.Client.Tests</RootNamespace>
<AssemblyName>Client.Tests</AssemblyName>
<AssemblyName>Quasar.Client.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@ -53,21 +53,13 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Core\Helper\FileHelper.Tests.cs" />
<Compile Include="Core\Compression\JpgCompression.Tests.cs" />
<Compile Include="Core\Compression\SafeQuickLZ.Tests.cs" />
<Compile Include="Core\Encryption\AES.Tests.cs" />
<Compile Include="Core\Encryption\SHA256.Tests.cs" />
<Compile Include="Helper\FileHelper.Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Quasar.Client\Quasar.Client.csproj">
<Project>{9f5cf56a-ddb2-4f40-ab99-2a1dc47588e1}</Project>
<Name>Client</Name>
</ProjectReference>
<ProjectReference Include="..\Quasar.Common\Quasar.Common.csproj">
<Project>{C7C363BA-E5B6-4E18-9224-39BC8DA73172}</Project>
<Name>Quasar.Common</Name>
<Name>Quasar.Client</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />

View File

@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Threading;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Utilities;
using Quasar.Common.Video.Codecs;
namespace Quasar.Client.Core.Commands
namespace Quasar.Client.Commands
{
/* THIS PARTIAL CLASS SHOULD CONTAIN VARIABLES NECESSARY FOR VARIOUS COMMANDS (if needed). */
public static partial class CommandHandler

View File

@ -1,13 +1,13 @@
using System;
using System.Net;
using System.Threading;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Installation;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Helper;
using Quasar.Client.Installation;
using Quasar.Client.Utilities;
using Quasar.Common.IO;
using Quasar.Common.Messages;
namespace Quasar.Client.Core.Commands
namespace Quasar.Client.Commands
{
/* THIS PARTIAL CLASS SHOULD CONTAIN METHODS THAT HANDLE CONNECTION COMMANDS. */
public static partial class CommandHandler

View File

@ -2,14 +2,14 @@
using System.IO;
using System.Security;
using System.Threading;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Helper;
using Quasar.Client.Utilities;
using Quasar.Common.Enums;
using Quasar.Common.IO;
using Quasar.Common.Messages;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Commands
namespace Quasar.Client.Commands
{
/* THIS PARTIAL CLASS SHOULD CONTAIN METHODS THAT MANIPULATE DIRECTORIES AND FILES (excluding the program). */
public static partial class CommandHandler

View File

@ -4,12 +4,12 @@
using System.Net;
using System.Threading;
using System.Windows.Forms;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Helper;
using Quasar.Client.Utilities;
using Quasar.Common.IO;
using Quasar.Common.Messages;
namespace Quasar.Client.Core.Commands
namespace Quasar.Client.Commands
{
/* THIS PARTIAL CLASS SHOULD CONTAIN MISCELLANEOUS METHODS. */
public static partial class CommandHandler

View File

@ -1,11 +1,11 @@
using System;
using Quasar.Client.Core.Extensions;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Registry;
using Quasar.Client.Extensions;
using Quasar.Client.Helper;
using Quasar.Client.Registry;
using Quasar.Common.Messages;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Commands
namespace Quasar.Client.Commands
{
/* THIS PARTIAL CLASS SHOULD CONTAIN METHODS THAT MANIPULATE THE REGISTRY. */
public static partial class CommandHandler

View File

@ -5,10 +5,10 @@
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Recovery.Browsers;
using Quasar.Client.Core.Recovery.FtpClients;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Helper;
using Quasar.Client.Recovery.Browsers;
using Quasar.Client.Recovery.FtpClients;
using Quasar.Client.Utilities;
using Quasar.Common.Enums;
using Quasar.Common.IO;
using Quasar.Common.Messages;
@ -16,7 +16,7 @@
using Quasar.Common.Video;
using Quasar.Common.Video.Codecs;
namespace Quasar.Client.Core.Commands
namespace Quasar.Client.Commands
{
/* THIS PARTIAL CLASS SHOULD CONTAIN METHODS THAT HANDLE SURVEILLANCE COMMANDS. */
public static partial class CommandHandler

View File

@ -7,16 +7,16 @@
using System.Windows.Forms;
using Microsoft.Win32;
using Quasar.Client.Config;
using Quasar.Client.Core.Data;
using Quasar.Client.Core.Extensions;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Data;
using Quasar.Client.Extensions;
using Quasar.Client.Helper;
using Quasar.Client.Utilities;
using Quasar.Common.Enums;
using Quasar.Common.Messages;
using Models = Quasar.Common.Models;
using Process = System.Diagnostics.Process;
namespace Quasar.Client.Core.Commands
namespace Quasar.Client.Commands
{
/* THIS PARTIAL CLASS SHOULD CONTAIN METHODS THAT MANIPULATE THE SYSTEM (drives, directories, files, etc.). */
public static partial class CommandHandler

View File

@ -6,7 +6,7 @@
using Models = Quasar.Common.Models;
using Process = System.Diagnostics.Process;
namespace Quasar.Client.Core.Commands
namespace Quasar.Client.Commands
{
/* THIS PARTIAL CLASS SHOULD CONTAIN METHODS THAT HANDLE TCP Connections COMMANDS. */

View File

@ -1,8 +1,7 @@
using System;
using Quasar.Client.Core.Helper;
using Quasar.Client.Helper;
#if !DEBUG
using Quasar.Client.Core.Cryptography;
using Quasar.Common.Cryptography;
#endif
namespace Quasar.Client.Config
@ -60,15 +59,15 @@ public static bool Initialize()
public static bool Initialize()
{
if (string.IsNullOrEmpty(VERSION)) return false;
AES.SetDefaultKey(ENCRYPTIONKEY);
TAG = AES.Decrypt(TAG);
VERSION = AES.Decrypt(VERSION);
HOSTS = AES.Decrypt(HOSTS);
SUBDIRECTORY = AES.Decrypt(SUBDIRECTORY);
INSTALLNAME = AES.Decrypt(INSTALLNAME);
MUTEX = AES.Decrypt(MUTEX);
STARTUPKEY = AES.Decrypt(STARTUPKEY);
LOGDIRECTORYNAME = AES.Decrypt(LOGDIRECTORYNAME);
Aes128.SetDefaultKey(ENCRYPTIONKEY);
TAG = Aes128.Decrypt(TAG);
VERSION = Aes128.Decrypt(VERSION);
HOSTS = Aes128.Decrypt(HOSTS);
SUBDIRECTORY = Aes128.Decrypt(SUBDIRECTORY);
INSTALLNAME = Aes128.Decrypt(INSTALLNAME);
MUTEX = Aes128.Decrypt(MUTEX);
STARTUPKEY = Aes128.Decrypt(STARTUPKEY);
LOGDIRECTORYNAME = Aes128.Decrypt(LOGDIRECTORYNAME);
FixDirectory();
return true;
}

View File

@ -1,29 +0,0 @@
using System.Runtime.CompilerServices;
namespace Quasar.Client.Core.Helper
{
public static class CryptographyHelper
{
/// <summary>
/// Compares two byte arrays for equality.
/// </summary>
/// <param name="a1">Byte array to compare</param>
/// <param name="a2">Byte array to compare</param>
/// <returns>True if equal, else false</returns>
/// <remarks>
/// Assumes that the byte arrays have the same length.
/// This method is safe against timing attacks.
/// </remarks>
[MethodImpl(MethodImplOptions.NoOptimization)]
public static bool AreEqual(byte[] a1, byte[] a2)
{
bool result = true;
for (int i = 0; i < a1.Length; ++i)
{
if (a1[i] != a2[i])
result = false;
}
return result;
}
}
}

View File

@ -1,6 +1,6 @@
using System.Windows.Forms;
namespace Quasar.Client.Core.Data
namespace Quasar.Client.Data
{
public static class ClientData
{

View File

@ -1,6 +1,6 @@
using System.Runtime.Serialization;
namespace Quasar.Client.Core.Data
namespace Quasar.Client.Data
{
[DataContract]
public class GeoInformation

View File

@ -1,6 +1,6 @@
using System.Net;
namespace Quasar.Client.Core.Data
namespace Quasar.Client.Data
{
public class Host
{

View File

@ -4,7 +4,7 @@
using Microsoft.Win32;
using Quasar.Common.Utilities;
namespace Quasar.Client.Core.Extensions
namespace Quasar.Client.Extensions
{
public static class RegistryKeyExtensions
{

View File

@ -2,7 +2,7 @@
using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace Quasar.Client.Core.Extensions
namespace Quasar.Client.Extensions
{
/// <summary>
/// Socket Extension for KeepAlive

View File

@ -3,9 +3,9 @@
using System.Management;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using Quasar.Client.Core.Cryptography;
using Quasar.Common.Cryptography;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class DevicesHelper
{
@ -13,7 +13,7 @@ public static class DevicesHelper
static DevicesHelper()
{
HardwareId = SHA256.ComputeHash(GetCpuName() + GetMainboardIdentifier() + GetBiosIdentifier());
HardwareId = Sha256.ComputeHash(GetCpuName() + GetMainboardIdentifier() + GetBiosIdentifier());
}
public static string GetBiosIdentifier()

View File

@ -1,17 +1,17 @@
using System;
using System.IO;
using System.Text;
using Quasar.Client.Core.Cryptography;
using Quasar.Client.Core.Data;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Data;
using Quasar.Client.Utilities;
using Quasar.Common.Cryptography;
using Quasar.Common.Enums;
using Quasar.Common.Helpers;
using Quasar.Common.Utilities;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class FileHelper
{
private const string CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static readonly SafeRandom Random = new SafeRandom();
public static ContentType GetContentType(string fileExtension)
@ -73,11 +73,7 @@ public static ContentType GetContentType(string fileExtension)
public static string GetRandomFilename(int length, string extension = "")
{
StringBuilder randomName = new StringBuilder(length);
for (int i = 0; i < length; i++)
randomName.Append(CHARS[Random.Next(CHARS.Length)]);
return string.Concat(randomName.ToString(), extension);
return string.Concat(StringHelper.GetRandomString(length), extension);
}
/// <summary>
@ -190,7 +186,7 @@ public static void WriteLogFile(string filename, string appendText)
using (FileStream fStream = File.Open(filename, FileMode.Create, FileAccess.Write))
{
byte[] data = AES.Encrypt(Encoding.UTF8.GetBytes(appendText));
byte[] data = Aes128.Encrypt(Encoding.UTF8.GetBytes(appendText));
fStream.Seek(0, SeekOrigin.Begin);
fStream.Write(data, 0, data.Length);
}
@ -202,7 +198,7 @@ public static void WriteLogFile(string filename, string appendText)
/// <param name="filename">The filename of the log.</param>
public static string ReadLogFile(string filename)
{
return File.Exists(filename) ? Encoding.UTF8.GetString(AES.Decrypt(File.ReadAllBytes(filename))) : string.Empty;
return File.Exists(filename) ? Encoding.UTF8.GetString(Aes128.Decrypt(File.ReadAllBytes(filename))) : string.Empty;
}
}
}

View File

@ -1,7 +1,7 @@
using System.IO;
using System.Text.RegularExpressions;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class FormatHelper
{

View File

@ -4,9 +4,9 @@
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml;
using Quasar.Client.Core.Data;
using Quasar.Client.Data;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class GeoLocationHelper
{

View File

@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quasar.Client.Core.Data;
using Quasar.Client.Data;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class HostHelper
{

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Windows.Forms;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class KeyloggerHelper
{

View File

@ -1,6 +1,6 @@
using System.Threading;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class MutexHelper
{

View File

@ -2,9 +2,9 @@
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Utilities;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class NativeMethodsHelper
{

View File

@ -2,7 +2,7 @@
using System.Management;
using System.Text.RegularExpressions;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class PlatformHelper
{

View File

@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Win32;
using Quasar.Client.Core.Extensions;
using Quasar.Client.Extensions;
using Quasar.Common.Models;
using Quasar.Common.Utilities;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class RegistryKeyHelper
{

View File

@ -2,9 +2,9 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Utilities;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class ScreenHelper
{

View File

@ -1,7 +1,7 @@
using System;
using System.Management;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class SystemHelper
{

View File

@ -2,11 +2,11 @@
using System.Diagnostics;
using System.Security.Principal;
using System.Threading;
using Quasar.Client.Core.Networking;
using Quasar.Client.Networking;
using Quasar.Common.Enums;
using Quasar.Common.Messages;
namespace Quasar.Client.Core.Helper
namespace Quasar.Client.Helper
{
public static class WindowsAccountHelper
{

View File

@ -3,10 +3,10 @@
using System.IO;
using System.Threading;
using Quasar.Client.Config;
using Quasar.Client.Core.Data;
using Quasar.Client.Core.Helper;
using Quasar.Client.Data;
using Quasar.Client.Helper;
namespace Quasar.Client.Core.Installation
namespace Quasar.Client.Installation
{
public static class ClientInstaller
{

View File

@ -1,10 +1,10 @@
using System;
using System.Diagnostics;
using Quasar.Client.Config;
using Quasar.Client.Core.Helper;
using Quasar.Client.Helper;
using Quasar.Common.Messages;
namespace Quasar.Client.Core.Installation
namespace Quasar.Client.Installation
{
public static class ClientUninstaller
{

View File

@ -2,11 +2,11 @@
using System.Diagnostics;
using System.IO;
using Quasar.Client.Config;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Helper;
using Quasar.Client.Utilities;
using Quasar.Common.Messages;
namespace Quasar.Client.Core.Installation
namespace Quasar.Client.Installation
{
public static class ClientUpdater
{

View File

@ -2,10 +2,10 @@
using System.Diagnostics;
using Microsoft.Win32;
using Quasar.Client.Config;
using Quasar.Client.Core.Data;
using Quasar.Client.Core.Helper;
using Quasar.Client.Data;
using Quasar.Client.Helper;
namespace Quasar.Client.Core.Installation
namespace Quasar.Client.Installation
{
public static class Startup
{

View File

@ -7,14 +7,14 @@
using System.Threading;
using ProtoBuf;
using ProtoBuf.Meta;
using Quasar.Client.Core.Compression;
using Quasar.Client.Core.Cryptography;
using Quasar.Client.Core.Extensions;
using Quasar.Client.Core.ReverseProxy;
using Quasar.Client.Extensions;
using Quasar.Client.ReverseProxy;
using Quasar.Common.Cryptography;
using Quasar.Common.IO.Compression;
using Quasar.Common.Messages;
using Quasar.Common.Networking;
namespace Quasar.Client.Core.Networking
namespace Quasar.Client.Networking
{
public class Client : ISender
{
@ -484,7 +484,7 @@ private void AsyncReceive(object state)
if (!isError)
{
if (encryptionEnabled)
_payloadBuffer = AES.Decrypt(_payloadBuffer);
_payloadBuffer = Aes128.Decrypt(_payloadBuffer);
isError = _payloadBuffer.Length == 0; // check if payload decryption failed
}
@ -651,7 +651,7 @@ private byte[] BuildMessage(byte[] payload)
payload = SafeQuickLZ.Compress(payload);
if (encryptionEnabled)
payload = AES.Encrypt(payload);
payload = Aes128.Encrypt(payload);
byte[] message = new byte[payload.Length + HEADER_SIZE];
Array.Copy(BitConverter.GetBytes(payload.Length), message, HEADER_SIZE);

View File

@ -1,8 +1,8 @@
using Quasar.Client.Core.Commands;
using Quasar.Client.Core.ReverseProxy;
using Quasar.Client.Commands;
using Quasar.Client.ReverseProxy;
using Quasar.Common.Messages;
namespace Quasar.Client.Core.Networking
namespace Quasar.Client.Networking
{
public static class PacketHandler
{

View File

@ -2,15 +2,15 @@
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using Quasar.Client.Commands;
using Quasar.Client.Config;
using Quasar.Client.Core.Commands;
using Quasar.Client.Core.Data;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Data;
using Quasar.Client.Helper;
using Quasar.Client.Utilities;
using Quasar.Common.Messages;
using Quasar.Common.Utilities;
namespace Quasar.Client.Core.Networking
namespace Quasar.Client.Networking
{
public class QuasarClient : Client
{

View File

@ -3,14 +3,14 @@
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Quasar.Client.Commands;
using Quasar.Client.Config;
using Quasar.Client.Core.Commands;
using Quasar.Client.Core.Cryptography;
using Quasar.Client.Core.Data;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Installation;
using Quasar.Client.Core.Networking;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Data;
using Quasar.Client.Helper;
using Quasar.Client.Installation;
using Quasar.Client.Networking;
using Quasar.Client.Utilities;
using Quasar.Common.Cryptography;
namespace Quasar.Client
{
@ -90,7 +90,7 @@ private static bool Initialize()
if (!MutexHelper.CreateMutex(Settings.MUTEX) || hosts.IsEmpty || string.IsNullOrEmpty(Settings.VERSION)) // no hosts to connect
return false;
AES.SetDefaultKey(Settings.KEY, Settings.AUTHKEY);
Aes128.SetDefaultKey(Settings.KEY, Settings.AUTHKEY);
ClientData.InstallPath = Path.Combine(Settings.DIRECTORY, ((!string.IsNullOrEmpty(Settings.SUBDIRECTORY)) ? Settings.SUBDIRECTORY + @"\" : "") + Settings.INSTALLNAME);
GeoLocationHelper.Initialize();

View File

@ -61,61 +61,57 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Core\Commands\RegistryHandler.cs" />
<Compile Include="Core\Commands\TcpConnectionsHandler.cs" />
<Compile Include="Core\Data\ClientData.cs" />
<Compile Include="Core\Data\GeoInformation.cs" />
<Compile Include="Core\Helper\CryptographyHelper.cs" />
<Compile Include="Core\Helper\MutexHelper.cs" />
<Compile Include="Core\Helper\WindowsAccountHelper.cs" />
<Compile Include="Core\Helper\FileHelper.cs" />
<Compile Include="Core\Helper\FormatHelper.cs" />
<Compile Include="Core\Helper\HostHelper.cs" />
<Compile Include="Core\Helper\NativeMethodsHelper.cs" />
<Compile Include="Core\Helper\PlatformHelper.cs" />
<Compile Include="Core\Helper\RegistryKeyHelper.cs" />
<Compile Include="Core\Helper\ScreenHelper.cs" />
<Compile Include="Core\Helper\DevicesHelper.cs" />
<Compile Include="Core\Helper\SystemHelper.cs" />
<Compile Include="Core\Installation\ClientInstaller.cs" />
<Compile Include="Core\Installation\ClientUninstaller.cs" />
<Compile Include="Core\Installation\ClientUpdater.cs" />
<Compile Include="Core\Installation\Startup.cs" />
<Compile Include="Core\Networking\Client.cs" />
<Compile Include="Core\Commands\CommandHandler.cs" />
<Compile Include="Core\Commands\ConnectionHandler.cs" />
<Compile Include="Core\Commands\FileHandler.cs" />
<Compile Include="Core\Commands\MiscHandler.cs" />
<Compile Include="Core\Commands\SurveillanceHandler.cs" />
<Compile Include="Core\Commands\SystemHandler.cs" />
<Compile Include="Core\Compression\SafeQuickLZ.cs" />
<Compile Include="Core\Cryptography\AES.cs" />
<Compile Include="Core\Cryptography\SHA256.cs" />
<Compile Include="Core\Extensions\RegistryKeyExtensions.cs" />
<Compile Include="Core\Networking\PacketHandler.cs" />
<Compile Include="Core\Networking\QuasarClient.cs" />
<Compile Include="Core\Recovery\FtpClients\FileZilla.cs" />
<Compile Include="Core\Recovery\FtpClients\WinSCP.cs" />
<Compile Include="Core\Registry\RegistryEditor.cs" />
<Compile Include="Core\Registry\RegistrySeeker.cs" />
<Compile Include="Core\Data\Host.cs" />
<Compile Include="Core\Utilities\HostsManager.cs" />
<Compile Include="Core\Utilities\NativeMethods.cs" />
<Compile Include="Core\Extensions\SocketExtensions.cs" />
<Compile Include="Core\Helper\KeyloggerHelper.cs" />
<Compile Include="Core\Utilities\Shell.cs" />
<Compile Include="Core\Recovery\Browsers\Chrome.cs" />
<Compile Include="Core\Recovery\Browsers\Firefox.cs" />
<Compile Include="Core\Recovery\Utilities\Chromium.cs" />
<Compile Include="Core\Recovery\Utilities\JsonUtil.cs" />
<Compile Include="Core\Recovery\Utilities\SQLiteHandler.cs" />
<Compile Include="Core\Recovery\Browsers\InternetExplorer.cs" />
<Compile Include="Core\Recovery\Browsers\Opera.cs" />
<Compile Include="Core\Recovery\Browsers\Yandex.cs" />
<Compile Include="Core\ReverseProxy\ReverseProxyClient.cs" />
<Compile Include="Core\ReverseProxy\ReverseProxyCommandHandler.cs" />
<Compile Include="Core\Helper\GeoLocationHelper.cs" />
<Compile Include="Core\Utilities\Keylogger.cs" />
<Compile Include="Commands\RegistryHandler.cs" />
<Compile Include="Commands\TcpConnectionsHandler.cs" />
<Compile Include="Data\ClientData.cs" />
<Compile Include="Data\GeoInformation.cs" />
<Compile Include="Helper\MutexHelper.cs" />
<Compile Include="Helper\WindowsAccountHelper.cs" />
<Compile Include="Helper\FileHelper.cs" />
<Compile Include="Helper\FormatHelper.cs" />
<Compile Include="Helper\HostHelper.cs" />
<Compile Include="Helper\NativeMethodsHelper.cs" />
<Compile Include="Helper\PlatformHelper.cs" />
<Compile Include="Helper\RegistryKeyHelper.cs" />
<Compile Include="Helper\ScreenHelper.cs" />
<Compile Include="Helper\DevicesHelper.cs" />
<Compile Include="Helper\SystemHelper.cs" />
<Compile Include="Installation\ClientInstaller.cs" />
<Compile Include="Installation\ClientUninstaller.cs" />
<Compile Include="Installation\ClientUpdater.cs" />
<Compile Include="Installation\Startup.cs" />
<Compile Include="Networking\Client.cs" />
<Compile Include="Commands\CommandHandler.cs" />
<Compile Include="Commands\ConnectionHandler.cs" />
<Compile Include="Commands\FileHandler.cs" />
<Compile Include="Commands\MiscHandler.cs" />
<Compile Include="Commands\SurveillanceHandler.cs" />
<Compile Include="Commands\SystemHandler.cs" />
<Compile Include="Extensions\RegistryKeyExtensions.cs" />
<Compile Include="Networking\PacketHandler.cs" />
<Compile Include="Networking\QuasarClient.cs" />
<Compile Include="Recovery\FtpClients\FileZilla.cs" />
<Compile Include="Recovery\FtpClients\WinSCP.cs" />
<Compile Include="Registry\RegistryEditor.cs" />
<Compile Include="Registry\RegistrySeeker.cs" />
<Compile Include="Data\Host.cs" />
<Compile Include="Utilities\HostsManager.cs" />
<Compile Include="Utilities\NativeMethods.cs" />
<Compile Include="Extensions\SocketExtensions.cs" />
<Compile Include="Helper\KeyloggerHelper.cs" />
<Compile Include="Utilities\Shell.cs" />
<Compile Include="Recovery\Browsers\Chrome.cs" />
<Compile Include="Recovery\Browsers\Firefox.cs" />
<Compile Include="Recovery\Utilities\Chromium.cs" />
<Compile Include="Recovery\Utilities\JsonUtil.cs" />
<Compile Include="Recovery\Utilities\SQLiteHandler.cs" />
<Compile Include="Recovery\Browsers\InternetExplorer.cs" />
<Compile Include="Recovery\Browsers\Opera.cs" />
<Compile Include="Recovery\Browsers\Yandex.cs" />
<Compile Include="ReverseProxy\ReverseProxyClient.cs" />
<Compile Include="ReverseProxy\ReverseProxyCommandHandler.cs" />
<Compile Include="Helper\GeoLocationHelper.cs" />
<Compile Include="Utilities\Keylogger.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Config\Settings.cs" />

View File

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using Quasar.Client.Core.Recovery.Utilities;
using Quasar.Client.Recovery.Utilities;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Recovery.Browsers
namespace Quasar.Client.Recovery.Browsers
{
public class Chrome
{

View File

@ -6,13 +6,13 @@
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32;
using Quasar.Client.Core.Extensions;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Recovery.Utilities;
using Quasar.Client.Core.Utilities;
using Quasar.Client.Extensions;
using Quasar.Client.Helper;
using Quasar.Client.Recovery.Utilities;
using Quasar.Client.Utilities;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Recovery.Browsers
namespace Quasar.Client.Recovery.Browsers
{
/// <summary>
/// A small class to recover Firefox Data

View File

@ -8,10 +8,10 @@
using System.Security.Cryptography;
using System.Text;
using Microsoft.Win32;
using Quasar.Client.Core.Helper;
using Quasar.Client.Helper;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Recovery.Browsers
namespace Quasar.Client.Recovery.Browsers
{
public static class InternetExplorer
{

View File

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using Quasar.Client.Core.Recovery.Utilities;
using Quasar.Client.Recovery.Utilities;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Recovery.Browsers
namespace Quasar.Client.Recovery.Browsers
{
public class Opera
{

View File

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using Quasar.Client.Core.Recovery.Utilities;
using Quasar.Client.Recovery.Utilities;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Recovery.Browsers
namespace Quasar.Client.Recovery.Browsers
{
public class Yandex
{

View File

@ -5,7 +5,7 @@
using System.Xml;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Recovery.FtpClients
namespace Quasar.Client.Recovery.FtpClients
{
public class FileZilla
{

View File

@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Win32;
using Quasar.Client.Core.Extensions;
using Quasar.Client.Core.Helper;
using Quasar.Client.Extensions;
using Quasar.Client.Helper;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Recovery.FtpClients
namespace Quasar.Client.Recovery.FtpClients
{
public class WinSCP
{

View File

@ -5,7 +5,7 @@
using System.Text;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Recovery.Utilities
namespace Quasar.Client.Recovery.Utilities
{
public class ChromiumBase
{

View File

@ -2,7 +2,7 @@
using System.Runtime.Serialization.Json;
using System.Text;
namespace Quasar.Client.Core.Recovery.Utilities
namespace Quasar.Client.Recovery.Utilities
{
public static class JsonUtil
{

View File

@ -5,7 +5,7 @@
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
namespace Quasar.Client.Core.Recovery.Utilities
namespace Quasar.Client.Recovery.Utilities
{
public class SQLiteHandler
{

View File

@ -1,10 +1,10 @@
using System;
using Microsoft.Win32;
using Quasar.Client.Core.Extensions;
using Quasar.Client.Core.Helper;
using Quasar.Client.Extensions;
using Quasar.Client.Helper;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Registry
namespace Quasar.Client.Registry
{
public class RegistryEditor
{

View File

@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using Microsoft.Win32;
using Quasar.Client.Core.Extensions;
using Quasar.Client.Core.Helper;
using Quasar.Client.Extensions;
using Quasar.Client.Helper;
using Quasar.Common.Models;
namespace Quasar.Client.Core.Registry
namespace Quasar.Client.Registry
{
public class RegistrySeeker
{

View File

@ -3,7 +3,7 @@
using System.Net.Sockets;
using Quasar.Common.Messages;
namespace Quasar.Client.Core.ReverseProxy
namespace Quasar.Client.ReverseProxy
{
public class ReverseProxyClient
{

View File

@ -1,6 +1,6 @@
using Quasar.Common.Messages;
namespace Quasar.Client.Core.ReverseProxy
namespace Quasar.Client.ReverseProxy
{
public class ReverseProxyCommandHandler
{

View File

@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using Quasar.Client.Core.Data;
using Quasar.Client.Data;
namespace Quasar.Client.Core.Utilities
namespace Quasar.Client.Utilities
{
public class HostsManager
{

View File

@ -6,11 +6,11 @@
using System.Windows.Forms;
using Gma.System.MouseKeyHook;
using Quasar.Client.Config;
using Quasar.Client.Core.Helper;
using Quasar.Client.Core.Networking;
using Quasar.Client.Helper;
using Quasar.Client.Networking;
using Timer = System.Timers.Timer;
namespace Quasar.Client.Core.Utilities
namespace Quasar.Client.Utilities
{
/// <summary>
/// This class provides keylogging functionality and modifies/highlights the output for

View File

@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
using System.Text;
namespace Quasar.Client.Core.Utilities
namespace Quasar.Client.Utilities
{
/// <summary>
/// Provides access to Win32 API and Microsoft C Runtime Library (msvcrt.dll).

View File

@ -6,7 +6,7 @@
using System.Threading;
using Quasar.Common.Messages;
namespace Quasar.Client.Core.Utilities
namespace Quasar.Client.Utilities
{
/// <summary>
/// This class manages a remote shell session.

View File

@ -1,9 +1,9 @@
using System;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Quasar.Common.Video.Compression;
using System;
using System.Drawing;
namespace Quasar.Client.Tests.Core.Compression
namespace Quasar.Common.Tests.Compression
{
[TestClass]
public class JpgCompressionTests

View File

@ -1,8 +1,8 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Quasar.Client.Core.Compression;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Quasar.Common.IO.Compression;
using System;
namespace Quasar.Client.Tests.Core.Compression
namespace Quasar.Common.Tests.Compression
{
[TestClass]
public class SafeQuickLZTests

View File

@ -0,0 +1,49 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Quasar.Common.Cryptography;
using Quasar.Common.Helpers;
using System.Text;
namespace Quasar.Common.Tests.Cryptography
{
[TestClass]
public class Aes128Tests
{
[TestMethod, TestCategory("Encryption")]
public void EncryptAndDecryptStringTest()
{
var input = StringHelper.GetRandomString(100);
var password = StringHelper.GetRandomString(50);
Aes128.SetDefaultKey(password);
var encrypted = Aes128.Encrypt(input);
Assert.IsNotNull(encrypted);
Assert.AreNotEqual(encrypted, input);
var decrypted = Aes128.Decrypt(encrypted);
Assert.AreEqual(input, decrypted);
}
[TestMethod, TestCategory("Encryption")]
public void EncryptAndDecryptByteArrayTest()
{
var input = StringHelper.GetRandomString(100);
var inputByte = Encoding.UTF8.GetBytes(input);
var password = StringHelper.GetRandomString(50);
Aes128.SetDefaultKey(password);
var encryptedByte = Aes128.Encrypt(inputByte);
Assert.IsNotNull(encryptedByte);
CollectionAssert.AllItemsAreNotNull(encryptedByte);
CollectionAssert.AreNotEqual(encryptedByte, inputByte);
var decryptedByte = Aes128.Decrypt(encryptedByte);
CollectionAssert.AreEqual(inputByte, decryptedByte);
}
}
}

View File

@ -1,17 +1,17 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Quasar.Client.Core.Cryptography;
using Quasar.Client.Core.Helper;
using Quasar.Common.Cryptography;
using Quasar.Common.Helpers;
namespace Quasar.Client.Tests.Core.Encryption
namespace Quasar.Common.Tests.Cryptography
{
[TestClass]
public class SHA256Tests
public class Sha256Tests
{
[TestMethod, TestCategory("Encryption")]
public void ComputeHashTest()
{
var input = FileHelper.GetRandomFilename(100);
var result = SHA256.ComputeHash(input);
var input = StringHelper.GetRandomString(100);
var result = Sha256.ComputeHash(input);
Assert.IsNotNull(result);
Assert.AreNotEqual(result, input);

View File

@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Quasar Common Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Quasar")]
[assembly: AssemblyCopyright("Copyright © MaxXor 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("cfda6d2e-8ab3-4349-b89a-33e1f0dab32b")]
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CFDA6D2E-8AB3-4349-B89A-33E1F0DAB32B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Quasar.Common.Tests</RootNamespace>
<AssemblyName>Quasar.Common.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
<Private>False</Private>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Compression\JpgCompression.Tests.cs" />
<Compile Include="Compression\SafeQuickLZ.Tests.cs" />
<Compile Include="Cryptography\Aes128.Tests.cs" />
<Compile Include="Cryptography\Sha256.Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Quasar.Common\Quasar.Common.csproj">
<Project>{c7c363ba-e5b6-4e18-9224-39bc8da73172}</Project>
<Name>Quasar.Common</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,13 +1,15 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using Quasar.Client.Core.Helper;
namespace Quasar.Client.Core.Cryptography
namespace Quasar.Common.Cryptography
{
public static class AES
public static class Aes128
{
private const int KeyLength = 16;
private const int AuthKeyLength = 64;
private const int IvLength = 16;
private const int HmacSha256Length = 32;
private static byte[] _defaultKey;
@ -19,19 +21,29 @@ public static class AES
0x44, 0xD2, 0x1E, 0x62, 0xB9, 0xD4, 0xF1, 0x80, 0xE7, 0xE6, 0xC3, 0x39, 0x41
};
public static void SetDefaultKey(string key)
public static void SetDefaultKey(string password)
{
using (Rfc2898DeriveBytes derive = new Rfc2898DeriveBytes(key, Salt, 50000))
{
_defaultKey = derive.GetBytes(16);
_defaultAuthKey = derive.GetBytes(64);
}
var keys = DeriveKeys(password);
_defaultKey = keys.Item1;
if (_defaultKey == null || _defaultKey.Length != KeyLength) throw new ArgumentException($"Key must be {KeyLength} bytes.");
_defaultAuthKey = keys.Item2;
if (_defaultAuthKey == null || _defaultAuthKey.Length != AuthKeyLength) throw new ArgumentException($"Auth key must be {AuthKeyLength} bytes.");
}
public static void SetDefaultKey(string key, string authKey)
{
_defaultKey = Convert.FromBase64String(key);
if (_defaultKey == null || _defaultKey.Length != KeyLength) throw new ArgumentException($"Key must be {KeyLength} bytes.");
_defaultAuthKey = Convert.FromBase64String(authKey);
if (_defaultAuthKey == null || _defaultAuthKey.Length != AuthKeyLength) throw new ArgumentException($"Auth key must be {AuthKeyLength} bytes.");
}
public static Tuple<byte[], byte[]> DeriveKeys(string password)
{
using (Rfc2898DeriveBytes derive = new Rfc2898DeriveBytes(password, Salt, 50000))
{
return new Tuple<byte[], byte[]>(derive.GetBytes(KeyLength), derive.GetBytes(AuthKeyLength));
}
}
public static string Encrypt(string input, string key)
@ -52,7 +64,7 @@ public static string Encrypt(string input)
*/
public static byte[] Encrypt(byte[] input)
{
if (_defaultKey == null || _defaultKey.Length == 0) throw new Exception("Key can not be empty.");
if (_defaultKey == null || _defaultKey.Length == 0) throw new ArgumentException("Key can not be empty.");
if (input == null || input.Length == 0) throw new ArgumentException("Input can not be empty.");
byte[] data = input, encdata = new byte[0];
@ -102,8 +114,8 @@ public static byte[] Encrypt(byte[] input, byte[] key)
byte[] authKey;
using (Rfc2898DeriveBytes derive = new Rfc2898DeriveBytes(key, Salt, 50000))
{
key = derive.GetBytes(16);
authKey = derive.GetBytes(64);
key = derive.GetBytes(KeyLength);
authKey = derive.GetBytes(AuthKeyLength);
}
byte[] data = input, encdata = new byte[0];
@ -153,7 +165,7 @@ public static string Decrypt(string input)
public static byte[] Decrypt(byte[] input)
{
if (_defaultKey == null || _defaultKey.Length == 0) throw new Exception("Key can not be empty.");
if (_defaultKey == null || _defaultKey.Length == 0) throw new ArgumentException("Key can not be empty.");
if (input == null || input.Length == 0) throw new ArgumentException("Input can not be empty.");
byte[] data = new byte[0];
@ -177,7 +189,7 @@ public static byte[] Decrypt(byte[] input)
byte[] receivedHash = new byte[HmacSha256Length];
ms.Read(receivedHash, 0, receivedHash.Length);
if (!CryptographyHelper.AreEqual(hash, receivedHash))
if (!AreEqual(hash, receivedHash))
return data;
}
@ -199,5 +211,27 @@ public static byte[] Decrypt(byte[] input)
}
return data;
}
/// <summary>
/// Compares two byte arrays for equality.
/// </summary>
/// <param name="a1">Byte array to compare</param>
/// <param name="a2">Byte array to compare</param>
/// <returns>True if equal, else false</returns>
/// <remarks>
/// Assumes that the byte arrays have the same length.
/// This method is safe against timing attacks.
/// </remarks>
[MethodImpl(MethodImplOptions.NoOptimization)]
private static bool AreEqual(byte[] a1, byte[] a2)
{
bool result = true;
for (int i = 0; i < a1.Length; ++i)
{
if (a1[i] != a2[i])
result = false;
}
return result;
}
}
}

View File

@ -1,9 +1,9 @@
using System.Security.Cryptography;
using System.Text;
namespace Quasar.Client.Core.Cryptography
namespace Quasar.Common.Cryptography
{
public static class SHA256
public static class Sha256
{
public static string ComputeHash(string input)
{
@ -22,4 +22,4 @@ public static string ComputeHash(string input)
return hash.ToString().ToUpper();
}
}
}
}

View File

@ -0,0 +1,20 @@
using Quasar.Common.Utilities;
using System.Text;
namespace Quasar.Common.Helpers
{
public static class StringHelper
{
private const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static readonly SafeRandom Random = new SafeRandom();
public static string GetRandomString(int length)
{
StringBuilder randomName = new StringBuilder(length);
for (int i = 0; i < length; i++)
randomName.Append(Alphabet[Random.Next(Alphabet.Length)]);
return randomName.ToString();
}
}
}

View File

@ -2,7 +2,7 @@
#pragma warning disable 0675
namespace Quasar.Client.Core.Compression
namespace Quasar.Common.IO.Compression
{
// QuickLZ data compression library
// Copyright (C) 2006-2011 Lasse Mikkel Reinhold

View File

@ -13,6 +13,7 @@
[assembly: AssemblyCopyright("Copyright © MaxXor 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("Quasar.Common.Tests")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from

View File

@ -47,6 +47,10 @@
<Reference Include="System.ServiceModel" />
</ItemGroup>
<ItemGroup>
<Compile Include="Cryptography\Aes128.cs" />
<Compile Include="Cryptography\Sha256.cs" />
<Compile Include="Helpers\StringHelper.cs" />
<Compile Include="IO\Compression\SafeQuickLZ.cs" />
<Compile Include="Enums\ConnectionState.cs" />
<Compile Include="Enums\ContentType.cs" />
<Compile Include="Enums\StartupType.cs" />

View File

@ -1,118 +0,0 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Quasar.Server.Core.Compression;
namespace Quasar.Server.Tests.Core.Compression
{
[TestClass]
public class SafeQuickLZTests
{
/*
* Purpose: To validate a small amount of data after compression/decompression
* using SafeQuickLZ with level 1 compression.
*/
[TestMethod, TestCategory("Compression")]
public void SmallDataCompressionTestLevel1()
{
byte[] smallData = new byte[100];
// Fill the small data array with random data.
new Random().NextBytes(smallData);
// Store the compressed data.
byte[] smallDataCompressed = SafeQuickLZ.Compress(smallData, 1);
// The original should not equal the compressed data.
Assert.AreNotEqual(smallData, smallDataCompressed, "Original data is equal to the compressed data!");
// Store the decompressed data.
byte[] smallDataDecompressed = SafeQuickLZ.Decompress(smallDataCompressed);
// The compressed data should not equal the decompressed data.
Assert.AreNotEqual(smallDataCompressed, smallDataDecompressed, "Compressed data is equal to the decompressed data!");
// The original data must equal the decompressed data; must be able to make a round-trip.
CollectionAssert.AreEqual(smallData, smallDataDecompressed, "Original data does not match the decompressed data!");
}
/*
* Purpose: To validate a small amount of data after compression/decompression
* using SafeQuickLZ with level 3 compression.
*/
[TestMethod, TestCategory("Compression")]
public void SmallDataCompressionTestLevel3()
{
byte[] smallData = new byte[100];
// Fill the small data array with random data.
new Random().NextBytes(smallData);
// Store the compressed data.
byte[] smallDataCompressed = SafeQuickLZ.Compress(smallData, 3);
// The original should not equal the compressed data.
Assert.AreNotEqual(smallData, smallDataCompressed, "Original data is equal to the compressed data!");
// Store the decompressed data.
byte[] smallDataDecompressed = SafeQuickLZ.Decompress(smallDataCompressed);
// The compressed data should not equal the decompressed data.
Assert.AreNotEqual(smallDataCompressed, smallDataDecompressed, "Compressed data is equal to the decompressed data!");
// The original data must equal the decompressed data; must be able to make a round-trip.
CollectionAssert.AreEqual(smallData, smallDataDecompressed, "Original data does not match the decompressed data!");
}
/*
* Purpose: To validate a large amount of data after compression/decompression
* using SafeQuickLZ with level 1 compression.
*/
[TestMethod, TestCategory("Compression")]
public void BigDataCompressionTestLevel1()
{
byte[] bigData = new byte[100000];
// Fill the big data array with random data.
new Random().NextBytes(bigData);
// Store the compressed data.
byte[] bigDataCompressed = SafeQuickLZ.Compress(bigData, 1);
// The original should not equal the compressed data.
Assert.AreNotEqual(bigData, bigDataCompressed, "Original data is equal to the compressed data!");
// Store the decompressed data.
byte[] bigDataDecompressed = SafeQuickLZ.Decompress(bigDataCompressed);
// The compressed data should not equal the decompressed data.
Assert.AreNotEqual(bigDataCompressed, bigDataDecompressed, "Compressed data is equal to the decompressed data!");
// The original data must equal the decompressed data; must be able to make a round-trip.
CollectionAssert.AreEqual(bigData, bigDataDecompressed, "Original data does not match the decompressed data!");
}
/*
* Purpose: To validate a large amount of data after compression/decompression
* using SafeQuickLZ with level 3 compression.
*/
[TestMethod, TestCategory("Compression")]
public void BigDataCompressionTestLevel3()
{
byte[] bigData = new byte[100000];
// Fill the big data array with random data.
new Random().NextBytes(bigData);
// Store the compressed data.
byte[] bigDataCompressed = SafeQuickLZ.Compress(bigData, 3);
// The original should not equal the compressed data.
Assert.AreNotEqual(bigData, bigDataCompressed, "Original data is equal to the compressed data!");
// Store the decompressed data.
byte[] bigDataDecompressed = SafeQuickLZ.Decompress(bigDataCompressed);
// The compressed data should not equal the decompressed data.
Assert.AreNotEqual(bigDataCompressed, bigDataDecompressed, "Compressed data is equal to the decompressed data!");
// The original data must equal the decompressed data; must be able to make a round-trip.
CollectionAssert.AreEqual(bigData, bigDataDecompressed, "Original data does not match the decompressed data!");
}
}
}

View File

@ -1,49 +0,0 @@
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Quasar.Server.Core.Cryptography;
using Quasar.Server.Core.Helper;
namespace Quasar.Server.Tests.Core.Encryption
{
[TestClass]
public class AESTests
{
[TestMethod, TestCategory("Encryption")]
public void EncryptAndDecryptStringTest()
{
var input = FileHelper.GetRandomFilename(100);
var password = FileHelper.GetRandomFilename(50);
AES.SetDefaultKey(password);
var encrypted = AES.Encrypt(input);
Assert.IsNotNull(encrypted);
Assert.AreNotEqual(encrypted, input);
var decrypted = AES.Decrypt(encrypted);
Assert.AreEqual(input, decrypted);
}
[TestMethod, TestCategory("Encryption")]
public void EncryptAndDecryptByteArrayTest()
{
var input = FileHelper.GetRandomFilename(100);
var inputByte = Encoding.UTF8.GetBytes(input);
var password = FileHelper.GetRandomFilename(50);
AES.SetDefaultKey(password);
var encryptedByte = AES.Encrypt(inputByte);
Assert.IsNotNull(encryptedByte);
CollectionAssert.AllItemsAreNotNull(encryptedByte);
CollectionAssert.AreNotEqual(encryptedByte, inputByte);
var decryptedByte = AES.Decrypt(encryptedByte);
CollectionAssert.AreEqual(inputByte, decryptedByte);
}
}
}

View File

@ -7,7 +7,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Quasar.Server.Tests</RootNamespace>
<AssemblyName>Server.Tests</AssemblyName>
<AssemblyName>Quasar.Server.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@ -55,18 +55,12 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Core\Compression\SafeQuickLZ.Tests.cs" />
<Compile Include="Core\Encryption\AES.Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Quasar.Common\Quasar.Common.csproj">
<Project>{c7c363ba-e5b6-4e18-9224-39bc8da73172}</Project>
<Name>Quasar.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Quasar.Server\Quasar.Server.csproj">
<Project>{14ca405b-8bac-48ab-9fba-8fb5df88fd0d}</Project>
<Name>Server</Name>
<Name>Quasar.Server</Name>
</ProjectReference>
</ItemGroup>
<Choose>

View File

@ -1,12 +1,12 @@
using System;
using Mono.Cecil;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Quasar.Server.Core.Cryptography;
using Quasar.Server.Core.Data;
using Quasar.Server.Core.Helper;
using Quasar.Server.Data;
using Quasar.Server.Helper;
using System;
using Quasar.Common.Cryptography;
using Vestris.ResourceLib;
namespace Quasar.Server.Core.Build
namespace Quasar.Server.Build
{
/// <summary>
/// Provides methods used to create a custom client executable.
@ -22,8 +22,10 @@ public static class ClientBuilder
public static void Build(BuildOptions options)
{
// PHASE 1 - Settings
string encKey = FileHelper.GetRandomFilename(20), key, authKey;
CryptographyHelper.DeriveKeys(options.Password, out key, out authKey);
var keys = Aes128.DeriveKeys(options.Password);
var key = Convert.ToBase64String(keys.Item1);
var authKey = Convert.ToBase64String(keys.Item2);
AssemblyDefinition asmDef = AssemblyDefinition.ReadAssembly("client.bin");
foreach (var typeDef in asmDef.Modules[0].Types)
@ -34,6 +36,8 @@ public static void Build(BuildOptions options)
{
if (methodDef.Name == ".cctor")
{
string encKey = FileHelper.GetRandomFilename(20);
int strings = 1, bools = 1;
for (int i = 0; i < methodDef.Body.Instructions.Count; i++)
@ -43,10 +47,10 @@ public static void Build(BuildOptions options)
switch (strings)
{
case 1: //version
methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Version, encKey);
methodDef.Body.Instructions[i].Operand = Aes128.Encrypt(options.Version, encKey);
break;
case 2: //ip/hostname
methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.RawHosts, encKey);
methodDef.Body.Instructions[i].Operand = Aes128.Encrypt(options.RawHosts, encKey);
break;
case 3: //key
methodDef.Body.Instructions[i].Operand = key;
@ -55,25 +59,25 @@ public static void Build(BuildOptions options)
methodDef.Body.Instructions[i].Operand = authKey;
break;
case 5: //installsub
methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.InstallSub, encKey);
methodDef.Body.Instructions[i].Operand = Aes128.Encrypt(options.InstallSub, encKey);
break;
case 6: //installname
methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.InstallName, encKey);
methodDef.Body.Instructions[i].Operand = Aes128.Encrypt(options.InstallName, encKey);
break;
case 7: //mutex
methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Mutex, encKey);
methodDef.Body.Instructions[i].Operand = Aes128.Encrypt(options.Mutex, encKey);
break;
case 8: //startupkey
methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.StartupName, encKey);
methodDef.Body.Instructions[i].Operand = Aes128.Encrypt(options.StartupName, encKey);
break;
case 9: //encryption key
methodDef.Body.Instructions[i].Operand = encKey;
break;
case 10: //tag
methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.Tag, encKey);
methodDef.Body.Instructions[i].Operand = Aes128.Encrypt(options.Tag, encKey);
break;
case 11: //LogDirectoryName
methodDef.Body.Instructions[i].Operand = AES.Encrypt(options.LogDirectoryName, encKey);
methodDef.Body.Instructions[i].Operand = Aes128.Encrypt(options.LogDirectoryName, encKey);
break;
}
strings++;

View File

@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
using System.Security;
namespace Quasar.Server.Core.Build
namespace Quasar.Server.Build
{
public static class IconInjector
{

View File

@ -5,7 +5,7 @@
using Mono.Cecil;
using Quasar.Common.Utilities;
namespace Quasar.Server.Core.Build
namespace Quasar.Server.Build
{
public class Renamer
{

View File

@ -1,7 +1,7 @@
using System;
using System.Windows.Forms;
using Quasar.Server.Core.Helper;
using Quasar.Server.Core.Utilities;
using Quasar.Server.Helper;
using Quasar.Server.Utilities;
namespace Quasar.Server.Controls
{

View File

@ -2,7 +2,7 @@
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using Quasar.Server.Core.Utilities;
using Quasar.Server.Utilities;
namespace Quasar.Server.Controls
{

View File

@ -1,7 +1,7 @@
using System.Windows.Forms;
using Quasar.Common.Models;
using Quasar.Server.Core.Extensions;
using Quasar.Server.Core.Registry;
using Quasar.Server.Extensions;
using Quasar.Server.Registry;
namespace Quasar.Server.Controls
{

View File

@ -1,513 +0,0 @@
using System;
#pragma warning disable 0675
namespace Quasar.Server.Core.Compression
{
// QuickLZ data compression library
// Copyright (C) 2006-2011 Lasse Mikkel Reinhold
// lar@quicklz.com
//
// QuickLZ can be used for free under the GPL 1, 2 or 3 license (where anything
// released into public must be open source) or under a commercial license if such
// has been acquired (see http://www.quicklz.com/order.html). The commercial license
// does not cover derived or ported versions created by third parties under GPL.
//
// Only a subset of the C library has been ported, namely level 1 and 3 not in
// streaming mode.
//
// Version: 1.5.0 final
public static class SafeQuickLZ
{
public const int QLZ_VERSION_MAJOR = 1;
public const int QLZ_VERSION_MINOR = 5;
public const int QLZ_VERSION_REVISION = 0;
// Streaming mode not supported
public const int QLZ_STREAMING_BUFFER = 0;
// Bounds checking not supported Use try...catch instead
public const int QLZ_MEMORY_SAFE = 0;
// Decrease QLZ_POINTERS_3 to increase level 3 compression speed. Do not edit any other values!
private const int HASH_VALUES = 4096;
private const int MINOFFSET = 2;
private const int UNCONDITIONAL_MATCHLEN = 6;
private const int UNCOMPRESSED_END = 4;
private const int CWORD_LEN = 4;
private const int DEFAULT_HEADERLEN = 9;
private const int QLZ_POINTERS_1 = 1;
private const int QLZ_POINTERS_3 = 16;
private static int HeaderLength(byte[] source)
{
return ((source[0] & 2) == 2) ? 9 : 3;
}
public static int SizeDecompressed(byte[] source)
{
if (HeaderLength(source) == 9)
return source[5] | (source[6] << 8) | (source[7] << 16) | (source[8] << 24);
else
return source[2];
}
public static int SizeCompressed(byte[] source)
{
if (HeaderLength(source) == 9)
return source[1] | (source[2] << 8) | (source[3] << 16) | (source[4] << 24);
else
return source[1];
}
private static void WriteHeader(byte[] dst, int level, bool compressible, int sizeCompressed,
int sizeDecompressed)
{
dst[0] = (byte)(2 | (compressible ? 1 : 0));
dst[0] |= (byte)(level << 2);
dst[0] |= (1 << 6);
dst[0] |= (0 << 4);
FastWrite(dst, 1, sizeDecompressed, 4);
FastWrite(dst, 5, sizeCompressed, 4);
}
public static byte[] Compress(byte[] source, int level = 3)
{
if (source.Length == 0)
return new byte[0];
int[,] hashtable;
switch (level)
{
case 1:
hashtable = new int[HASH_VALUES, QLZ_POINTERS_1];
break;
case 3:
hashtable = new int[HASH_VALUES, QLZ_POINTERS_3];
break;
default:
throw new ArgumentException("C# version only supports level 1 and 3");
}
int src = 0;
int dst = DEFAULT_HEADERLEN + CWORD_LEN;
uint cword_val = 0x80000000;
int cword_ptr = DEFAULT_HEADERLEN;
byte[] destination = new byte[source.Length + 400];
int[] cachetable = new int[HASH_VALUES];
byte[] hash_counter = new byte[HASH_VALUES];
byte[] d2;
int fetch = 0;
int last_matchstart = (source.Length - UNCONDITIONAL_MATCHLEN - UNCOMPRESSED_END - 1);
int lits = 0;
if (src <= last_matchstart)
fetch = source[src] | (source[src + 1] << 8) | (source[src + 2] << 16);
while (src <= last_matchstart)
{
if ((cword_val & 1) == 1)
{
if (src > source.Length >> 1 && dst > src - (src >> 5))
{
d2 = new byte[source.Length + DEFAULT_HEADERLEN];
WriteHeader(d2, level, false, source.Length, source.Length + DEFAULT_HEADERLEN);
Array.Copy(source, 0, d2, DEFAULT_HEADERLEN, source.Length);
return d2;
}
FastWrite(destination, cword_ptr, (int)((cword_val >> 1) | 0x80000000), 4);
cword_ptr = dst;
dst += CWORD_LEN;
cword_val = 0x80000000;
}
if (level == 1)
{
int hash = ((fetch >> 12) ^ fetch) & (HASH_VALUES - 1);
int o = hashtable[hash, 0];
int cache = cachetable[hash] ^ fetch;
cachetable[hash] = fetch;
hashtable[hash, 0] = src;
if (cache == 0 && hash_counter[hash] != 0 &&
(src - o > MINOFFSET ||
(src == o + 1 && lits >= 3 && src > 3 && source[src] == source[src - 3] &&
source[src] == source[src - 2] && source[src] == source[src - 1] &&
source[src] == source[src + 1] && source[src] == source[src + 2])))
{
cword_val = ((cword_val >> 1) | 0x80000000);
if (source[o + 3] != source[src + 3])
{
int f = 3 - 2 | (hash << 4);
destination[dst + 0] = (byte)(f >> 0 * 8);
destination[dst + 1] = (byte)(f >> 1 * 8);
src += 3;
dst += 2;
}
else
{
int old_src = src;
int remaining = ((source.Length - UNCOMPRESSED_END - src + 1 - 1) > 255
? 255
: (source.Length - UNCOMPRESSED_END - src + 1 - 1));
src += 4;
if (source[o + src - old_src] == source[src])
{
src++;
if (source[o + src - old_src] == source[src])
{
src++;
while (source[o + (src - old_src)] == source[src] && (src - old_src) < remaining)
src++;
}
}
int matchlen = src - old_src;
hash <<= 4;
if (matchlen < 18)
{
int f = (hash | (matchlen - 2));
destination[dst + 0] = (byte)(f >> 0 * 8);
destination[dst + 1] = (byte)(f >> 1 * 8);
dst += 2;
}
else
{
FastWrite(destination, dst, hash | (matchlen << 16), 3);
dst += 3;
}
}
fetch = source[src] | (source[src + 1] << 8) | (source[src + 2] << 16);
lits = 0;
}
else
{
lits++;
hash_counter[hash] = 1;
destination[dst] = source[src];
cword_val = (cword_val >> 1);
src++;
dst++;
fetch = ((fetch >> 8) & 0xffff) | (source[src + 2] << 16);
}
}
else
{
fetch = source[src] | (source[src + 1] << 8) | (source[src + 2] << 16);
int o, offset2;
int matchlen, k, m, best_k = 0;
byte c;
int remaining = ((source.Length - UNCOMPRESSED_END - src + 1 - 1) > 255
? 255
: (source.Length - UNCOMPRESSED_END - src + 1 - 1));
int hash = ((fetch >> 12) ^ fetch) & (HASH_VALUES - 1);
c = hash_counter[hash];
matchlen = 0;
offset2 = 0;
for (k = 0; k < QLZ_POINTERS_3 && c > k; k++)
{
o = hashtable[hash, k];
if ((byte)fetch == source[o] && (byte)(fetch >> 8) == source[o + 1] &&
(byte)(fetch >> 16) == source[o + 2] && o < src - MINOFFSET)
{
m = 3;
while (source[o + m] == source[src + m] && m < remaining)
m++;
if ((m > matchlen) || (m == matchlen && o > offset2))
{
offset2 = o;
matchlen = m;
best_k = k;
}
}
}
o = offset2;
hashtable[hash, c & (QLZ_POINTERS_3 - 1)] = src;
c++;
hash_counter[hash] = c;
if (matchlen >= 3 && src - o < 131071)
{
int offset = src - o;
for (int u = 1; u < matchlen; u++)
{
fetch = source[src + u] | (source[src + u + 1] << 8) | (source[src + u + 2] << 16);
hash = ((fetch >> 12) ^ fetch) & (HASH_VALUES - 1);
c = hash_counter[hash]++;
hashtable[hash, c & (QLZ_POINTERS_3 - 1)] = src + u;
}
src += matchlen;
cword_val = ((cword_val >> 1) | 0x80000000);
if (matchlen == 3 && offset <= 63)
{
FastWrite(destination, dst, offset << 2, 1);
dst++;
}
else if (matchlen == 3 && offset <= 16383)
{
FastWrite(destination, dst, (offset << 2) | 1, 2);
dst += 2;
}
else if (matchlen <= 18 && offset <= 1023)
{
FastWrite(destination, dst, ((matchlen - 3) << 2) | (offset << 6) | 2, 2);
dst += 2;
}
else if (matchlen <= 33)
{
FastWrite(destination, dst, ((matchlen - 2) << 2) | (offset << 7) | 3, 3);
dst += 3;
}
else
{
FastWrite(destination, dst, ((matchlen - 3) << 7) | (offset << 15) | 3, 4);
dst += 4;
}
lits = 0;
}
else
{
destination[dst] = source[src];
cword_val = (cword_val >> 1);
src++;
dst++;
}
}
}
while (src <= source.Length - 1)
{
if ((cword_val & 1) == 1)
{
FastWrite(destination, cword_ptr, (int)((cword_val >> 1) | 0x80000000), 4);
cword_ptr = dst;
dst += CWORD_LEN;
cword_val = 0x80000000;
}
destination[dst] = source[src];
src++;
dst++;
cword_val = (cword_val >> 1);
}
while ((cword_val & 1) != 1)
{
cword_val = (cword_val >> 1);
}
FastWrite(destination, cword_ptr, (int)((cword_val >> 1) | 0x80000000), CWORD_LEN);
WriteHeader(destination, level, true, source.Length, dst);
d2 = new byte[dst];
Array.Copy(destination, d2, dst);
return d2;
}
private static void FastWrite(byte[] a, int i, int value, int numbytes)
{
for (int j = 0; j < numbytes; j++)
a[i + j] = (byte)(value >> (j * 8));
}
public static byte[] Decompress(byte[] source)
{
if (source.Length == 0)
return new byte[0];
int level = (source[0] >> 2) & 0x3;
if (level != 1 && level != 3)
throw new ArgumentException("C# version only supports level 1 and 3");
int size = SizeDecompressed(source);
int src = HeaderLength(source);
int dst = 0;
uint cword_val = 1;
byte[] destination = new byte[size];
int[] hashtable = new int[4096];
byte[] hash_counter = new byte[4096];
int last_matchstart = size - UNCONDITIONAL_MATCHLEN - UNCOMPRESSED_END - 1;
int last_hashed = -1;
int hash;
uint fetch = 0;
if ((source[0] & 1) != 1)
{
byte[] d2 = new byte[size];
Array.Copy(source, HeaderLength(source), d2, 0, size);
return d2;
}
for (; ; )
{
if (cword_val == 1)
{
cword_val =
(uint)
(source[src] | (source[src + 1] << 8) | (source[src + 2] << 16) | (source[src + 3] << 24));
src += 4;
if (dst <= last_matchstart)
{
if (level == 1)
fetch = (uint)(source[src] | (source[src + 1] << 8) | (source[src + 2] << 16));
else
fetch =
(uint)
(source[src] | (source[src + 1] << 8) | (source[src + 2] << 16) |
(source[src + 3] << 24));
}
}
if ((cword_val & 1) == 1)
{
uint matchlen;
uint offset2;
cword_val = cword_val >> 1;
if (level == 1)
{
hash = ((int)fetch >> 4) & 0xfff;
offset2 = (uint)hashtable[hash];
if ((fetch & 0xf) != 0)
{
matchlen = (fetch & 0xf) + 2;
src += 2;
}
else
{
matchlen = source[src + 2];
src += 3;
}
}
else
{
uint offset;
if ((fetch & 3) == 0)
{
offset = (fetch & 0xff) >> 2;
matchlen = 3;
src++;
}
else if ((fetch & 2) == 0)
{
offset = (fetch & 0xffff) >> 2;
matchlen = 3;
src += 2;
}
else if ((fetch & 1) == 0)
{
offset = (fetch & 0xffff) >> 6;
matchlen = ((fetch >> 2) & 15) + 3;
src += 2;
}
else if ((fetch & 127) != 3)
{
offset = (fetch >> 7) & 0x1ffff;
matchlen = ((fetch >> 2) & 0x1f) + 2;
src += 3;
}
else
{
offset = (fetch >> 15);
matchlen = ((fetch >> 7) & 255) + 3;
src += 4;
}
offset2 = (uint)(dst - offset);
}
destination[dst + 0] = destination[offset2 + 0];
destination[dst + 1] = destination[offset2 + 1];
destination[dst + 2] = destination[offset2 + 2];
for (int i = 3; i < matchlen; i += 1)
{
destination[dst + i] = destination[offset2 + i];
}
dst += (int)matchlen;
if (level == 1)
{
fetch =
(uint)
(destination[last_hashed + 1] | (destination[last_hashed + 2] << 8) |
(destination[last_hashed + 3] << 16));
while (last_hashed < dst - matchlen)
{
last_hashed++;
hash = (int)(((fetch >> 12) ^ fetch) & (HASH_VALUES - 1));
hashtable[hash] = last_hashed;
hash_counter[hash] = 1;
fetch = (uint)(fetch >> 8 & 0xffff | destination[last_hashed + 3] << 16);
}
fetch = (uint)(source[src] | (source[src + 1] << 8) | (source[src + 2] << 16));
}
else
{
fetch =
(uint)
(source[src] | (source[src + 1] << 8) | (source[src + 2] << 16) |
(source[src + 3] << 24));
}
last_hashed = dst - 1;
}
else
{
if (dst <= last_matchstart)
{
destination[dst] = source[src];
dst += 1;
src += 1;
cword_val = cword_val >> 1;
if (level == 1)
{
while (last_hashed < dst - 3)
{
last_hashed++;
int fetch2 = destination[last_hashed] | (destination[last_hashed + 1] << 8) |
(destination[last_hashed + 2] << 16);
hash = ((fetch2 >> 12) ^ fetch2) & (HASH_VALUES - 1);
hashtable[hash] = last_hashed;
hash_counter[hash] = 1;
}
fetch = (uint)(fetch >> 8 & 0xffff | source[src + 2] << 16);
}
else
{
fetch = (uint)(fetch >> 8 & 0xffff | source[src + 2] << 16 | source[src + 3] << 24);
}
}
else
{
while (dst <= size - 1)
{
if (cword_val == 1)
{
src += CWORD_LEN;
cword_val = 0x80000000;
}
destination[dst] = source[src];
dst++;
src++;
cword_val = cword_val >> 1;
}
return destination;
}
}
}
}
}
}

View File

@ -1,197 +0,0 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Quasar.Server.Core.Helper;
namespace Quasar.Server.Core.Cryptography
{
public static class AES
{
private const int IvLength = 16;
private const int HmacSha256Length = 32;
private static byte[] _defaultKey;
private static byte[] _defaultAuthKey;
public static readonly byte[] Salt =
{
0xBF, 0xEB, 0x1E, 0x56, 0xFB, 0xCD, 0x97, 0x3B, 0xB2, 0x19, 0x2, 0x24, 0x30, 0xA5, 0x78, 0x43, 0x0, 0x3D, 0x56,
0x44, 0xD2, 0x1E, 0x62, 0xB9, 0xD4, 0xF1, 0x80, 0xE7, 0xE6, 0xC3, 0x39, 0x41
};
public static void SetDefaultKey(string key)
{
using (Rfc2898DeriveBytes derive = new Rfc2898DeriveBytes(key, Salt, 50000))
{
_defaultKey = derive.GetBytes(16);
_defaultAuthKey = derive.GetBytes(64);
}
}
public static string Encrypt(string input, string key)
{
return Convert.ToBase64String(Encrypt(Encoding.UTF8.GetBytes(input), Encoding.UTF8.GetBytes(key)));
}
public static string Encrypt(string input)
{
return Convert.ToBase64String(Encrypt(Encoding.UTF8.GetBytes(input)));
}
/* FORMAT
* ----------------------------------------
* | HMAC | IV | CIPHERTEXT |
* ----------------------------------------
* 32 bytes 16 bytes
*/
public static byte[] Encrypt(byte[] input)
{
if (_defaultKey == null || _defaultKey.Length == 0) throw new Exception("Key can not be empty.");
if (input == null || input.Length == 0) throw new ArgumentException("Input can not be empty.");
byte[] data = input, encdata = new byte[0];
try
{
using (var ms = new MemoryStream())
{
ms.Position = HmacSha256Length; // reserve first 32 bytes for HMAC
using (var aesProvider = new AesCryptoServiceProvider())
{
aesProvider.KeySize = 128;
aesProvider.BlockSize = 128;
aesProvider.Mode = CipherMode.CBC;
aesProvider.Padding = PaddingMode.PKCS7;
aesProvider.Key = _defaultKey;
aesProvider.GenerateIV();
using (var cs = new CryptoStream(ms, aesProvider.CreateEncryptor(), CryptoStreamMode.Write))
{
ms.Write(aesProvider.IV, 0, aesProvider.IV.Length); // write next 16 bytes the IV, followed by ciphertext
cs.Write(data, 0, data.Length);
cs.FlushFinalBlock();
using (var hmac = new HMACSHA256(_defaultAuthKey))
{
byte[] hash = hmac.ComputeHash(ms.ToArray(), HmacSha256Length, ms.ToArray().Length - HmacSha256Length); // compute the HMAC of IV and ciphertext
ms.Position = 0; // write hash at beginning
ms.Write(hash, 0, hash.Length);
}
}
}
encdata = ms.ToArray();
}
}
catch
{
}
return encdata;
}
public static byte[] Encrypt(byte[] input, byte[] key)
{
if (key == null || key.Length == 0) throw new Exception("Key can not be empty.");
byte[] authKey;
using (Rfc2898DeriveBytes derive = new Rfc2898DeriveBytes(key, Salt, 50000))
{
key = derive.GetBytes(16);
authKey = derive.GetBytes(64);
}
byte[] data = input, encdata = new byte[0];
try
{
using (var ms = new MemoryStream())
{
ms.Position = HmacSha256Length; // reserve first 32 bytes for HMAC
using (var aesProvider = new AesCryptoServiceProvider())
{
aesProvider.KeySize = 128;
aesProvider.BlockSize = 128;
aesProvider.Mode = CipherMode.CBC;
aesProvider.Padding = PaddingMode.PKCS7;
aesProvider.Key = key;
aesProvider.GenerateIV();
using (var cs = new CryptoStream(ms, aesProvider.CreateEncryptor(), CryptoStreamMode.Write))
{
ms.Write(aesProvider.IV, 0, aesProvider.IV.Length); // write next 16 bytes the IV, followed by ciphertext
cs.Write(data, 0, data.Length);
cs.FlushFinalBlock();
using (var hmac = new HMACSHA256(authKey))
{
byte[] hash = hmac.ComputeHash(ms.ToArray(), HmacSha256Length, ms.ToArray().Length - HmacSha256Length); // compute the HMAC of IV and ciphertext
ms.Position = 0; // write hash at beginning
ms.Write(hash, 0, hash.Length);
}
}
}
encdata = ms.ToArray();
}
}
catch
{
}
return encdata;
}
public static string Decrypt(string input)
{
return Encoding.UTF8.GetString(Decrypt(Convert.FromBase64String(input)));
}
public static byte[] Decrypt(byte[] input)
{
if (_defaultKey == null || _defaultKey.Length == 0) throw new Exception("Key can not be empty.");
if (input == null || input.Length == 0) throw new ArgumentException("Input can not be empty.");
byte[] data = new byte[0];
try
{
using (var ms = new MemoryStream(input))
{
using (var aesProvider = new AesCryptoServiceProvider())
{
aesProvider.KeySize = 128;
aesProvider.BlockSize = 128;
aesProvider.Mode = CipherMode.CBC;
aesProvider.Padding = PaddingMode.PKCS7;
aesProvider.Key = _defaultKey;
// read first 32 bytes for HMAC
using (var hmac = new HMACSHA256(_defaultAuthKey))
{
var hash = hmac.ComputeHash(ms.ToArray(), HmacSha256Length, ms.ToArray().Length - HmacSha256Length);
byte[] receivedHash = new byte[HmacSha256Length];
ms.Read(receivedHash, 0, receivedHash.Length);
if (!CryptographyHelper.AreEqual(hash, receivedHash))
return data;
}
byte[] iv = new byte[IvLength];
ms.Read(iv, 0, IvLength); // read next 16 bytes for IV, followed by ciphertext
aesProvider.IV = iv;
using (var cs = new CryptoStream(ms, aesProvider.CreateDecryptor(), CryptoStreamMode.Read))
{
byte[] temp = new byte[ms.Length - IvLength + 1];
data = new byte[cs.Read(temp, 0, temp.Length)];
Buffer.BlockCopy(temp, 0, data, 0, data.Length);
}
}
}
}
catch
{
}
return data;
}
}
}

View File

@ -1,41 +0,0 @@
using System;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using Quasar.Server.Core.Cryptography;
namespace Quasar.Server.Core.Helper
{
public static class CryptographyHelper
{
/// <summary>
/// Compares two byte arrays for equality.
/// </summary>
/// <param name="a1">Byte array to compare</param>
/// <param name="a2">Byte array to compare</param>
/// <returns>True if equal, else false</returns>
/// <remarks>
/// Assumes that the byte arrays have the same length.
/// This method is safe against timing attacks.
/// </remarks>
[MethodImpl(MethodImplOptions.NoOptimization)]
public static bool AreEqual(byte[] a1, byte[] a2)
{
bool result = true;
for (int i = 0; i < a1.Length; ++i)
{
if (a1[i] != a2[i])
result = false;
}
return result;
}
public static void DeriveKeys(string password, out string key, out string authKey)
{
using (Rfc2898DeriveBytes derive = new Rfc2898DeriveBytes(password, AES.Salt, 50000))
{
key = Convert.ToBase64String(derive.GetBytes(16));
authKey = Convert.ToBase64String(derive.GetBytes(64));
}
}
}
}

View File

@ -1,4 +1,4 @@
namespace Quasar.Server.Core.Data
namespace Quasar.Server.Data
{
public class BuildOptions
{

View File

@ -3,9 +3,9 @@
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using Quasar.Server.Core.Helper;
using Quasar.Server.Helper;
namespace Quasar.Server.Core.Data
namespace Quasar.Server.Data
{
public class BuilderProfile
{

View File

@ -1,4 +1,4 @@
namespace Quasar.Server.Core.Data
namespace Quasar.Server.Data
{
public class Host
{

View File

@ -3,7 +3,7 @@
using System.Xml;
using System.Xml.XPath;
namespace Quasar.Server.Core.Data
namespace Quasar.Server.Data
{
public static class Settings
{

View File

@ -1,8 +1,8 @@
using System.Windows.Forms;
using Quasar.Server.Core.Helper;
using Quasar.Server.Core.Utilities;
using Quasar.Server.Helper;
using Quasar.Server.Utilities;
namespace Quasar.Server.Core.Extensions
namespace Quasar.Server.Extensions
{
public static class ListViewExtensions
{

View File

@ -1,7 +1,7 @@
using System;
using Microsoft.Win32;
namespace Quasar.Server.Core.Extensions
namespace Quasar.Server.Extensions
{
public static class RegistryKeyExtensions
{

View File

@ -2,7 +2,7 @@
using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace Quasar.Server.Core.Extensions
namespace Quasar.Server.Extensions
{
/// <summary>
/// Socket Extension for KeepAlive

View File

@ -1,7 +1,7 @@
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Quasar.Server.Core.Data;
using Quasar.Server.Data;
namespace Quasar.Server.Forms
{

View File

@ -6,9 +6,9 @@
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using Quasar.Server.Core.Build;
using Quasar.Server.Core.Data;
using Quasar.Server.Core.Helper;
using Quasar.Server.Build;
using Quasar.Server.Data;
using Quasar.Server.Helper;
namespace Quasar.Server.Forms
{

View File

@ -3,9 +3,9 @@
using System.Windows.Forms;
using Quasar.Common.Messages;
using Quasar.Common.Models;
using Quasar.Server.Core.Helper;
using Quasar.Server.Core.Messages;
using Quasar.Server.Core.Networking;
using Quasar.Server.Helper;
using Quasar.Server.Messages;
using Quasar.Server.Networking;
namespace Quasar.Server.Forms
{

View File

@ -1,6 +1,6 @@
using System;
using System.Windows.Forms;
using Quasar.Server.Core.Helper;
using Quasar.Server.Helper;
namespace Quasar.Server.Forms
{

View File

@ -6,10 +6,10 @@
using Quasar.Common.Messages;
using Quasar.Common.Models;
using Quasar.Server.Controls;
using Quasar.Server.Core.Helper;
using Quasar.Server.Core.Messages;
using Quasar.Server.Core.Networking;
using Quasar.Server.Helper;
using Quasar.Server.Messages;
using Quasar.Server.Models;
using Quasar.Server.Networking;
using Process = System.Diagnostics.Process;
namespace Quasar.Server.Forms

View File

@ -3,9 +3,9 @@
using System.IO;
using System.Windows.Forms;
using Quasar.Common.Messages;
using Quasar.Server.Core.Helper;
using Quasar.Server.Core.Messages;
using Quasar.Server.Core.Networking;
using Quasar.Server.Helper;
using Quasar.Server.Messages;
using Quasar.Server.Networking;
namespace Quasar.Server.Forms
{

View File

@ -4,17 +4,17 @@
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using Quasar.Common.Cryptography;
using Quasar.Common.Enums;
using Quasar.Common.IO;
using Quasar.Common.Messages;
using Quasar.Server.Core.Cryptography;
using Quasar.Server.Core.Data;
using Quasar.Server.Core.Extensions;
using Quasar.Server.Core.Helper;
using Quasar.Server.Core.Messages;
using Quasar.Server.Core.Networking;
using Quasar.Server.Core.Networking.Utilities;
using Quasar.Server.Core.Utilities;
using Quasar.Server.Data;
using Quasar.Server.Extensions;
using Quasar.Server.Helper;
using Quasar.Server.Messages;
using Quasar.Server.Networking;
using Quasar.Server.Networking.Utilities;
using Quasar.Server.Utilities;
namespace Quasar.Server.Forms
{
@ -34,7 +34,7 @@ public partial class FrmMain : Form
public FrmMain()
{
AES.SetDefaultKey(Settings.Password);
Aes128.SetDefaultKey(Settings.Password);
_clientStatusHandler = new ClientStatusHandler();
RegisterMessageHandler();
@ -135,7 +135,7 @@ private void lstClients_SelectedIndexChanged(object sender, EventArgs e)
UpdateWindowTitle();
}
private void ServerState(Core.Networking.Server server, bool listening, ushort port)
private void ServerState(Networking.Server server, bool listening, ushort port)
{
try
{

View File

@ -6,10 +6,10 @@
using System.Windows.Forms;
using Quasar.Common.Messages;
using Quasar.Common.Models;
using Quasar.Server.Core.Data;
using Quasar.Server.Core.Helper;
using Quasar.Server.Core.Messages;
using Quasar.Server.Core.Networking;
using Quasar.Server.Data;
using Quasar.Server.Helper;
using Quasar.Server.Messages;
using Quasar.Server.Networking;
namespace Quasar.Server.Forms
{

View File

@ -1,7 +1,7 @@
using System;
using System.Windows.Forms;
using Quasar.Common.Models;
using Quasar.Server.Core.Registry;
using Quasar.Server.Registry;
namespace Quasar.Server.Forms
{

View File

@ -2,7 +2,7 @@
using System.Windows.Forms;
using Quasar.Common.Models;
using Quasar.Common.Utilities;
using Quasar.Server.Core.Registry;
using Quasar.Server.Registry;
namespace Quasar.Server.Forms
{

View File

@ -8,11 +8,11 @@
using Quasar.Common.Models;
using Quasar.Common.Utilities;
using Quasar.Server.Controls;
using Quasar.Server.Core.Extensions;
using Quasar.Server.Core.Helper;
using Quasar.Server.Core.Messages;
using Quasar.Server.Core.Networking;
using Quasar.Server.Core.Registry;
using Quasar.Server.Extensions;
using Quasar.Server.Helper;
using Quasar.Server.Messages;
using Quasar.Server.Networking;
using Quasar.Server.Registry;
namespace Quasar.Server.Forms
{

Some files were not shown because too many files have changed in this diff Show More