Skip to content

Commit

Permalink
🛫 Release 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
valnoxy committed Jan 19, 2022
1 parent 57f09c9 commit 0d11325
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 3 deletions.
18 changes: 16 additions & 2 deletions PowerChutePatch/PowerChutePatch/PowerChutePatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<Company>valnoxy</Company>
<Company>Exploitox</Company>
<Authors>valnoxy</Authors>
<Copyright>Copyright (c) 2018 - 2022 valnoxy.</Copyright>
<Copyright>Copyright (c) 2018 - 2022 valnoxy. All rightes reserved.</Copyright>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>bucker_icon.ico</ApplicationIcon>
<DebugType>none</DebugType>
<PackageProjectUrl>https://github.com/valnoxy/PowerChute-Log4j-Patch</PackageProjectUrl>
<Product>bucker</Product>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>

<ItemGroup>
<Content Include="bucker_icon.ico" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.ServiceProcess.ServiceController" Version="6.0.0" />
</ItemGroup>

</Project>
124 changes: 123 additions & 1 deletion PowerChutePatch/PowerChutePatch/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,134 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.ServiceProcess;

namespace PowerChutePatch
{
internal class Program
{
public static string path = "C:\\Program Files (x86)\\APC\\PowerChute Business Edition\\agent\\lib";

static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.WriteLine("[i] Log4j Patcher for PowerChute [Version: 1.0]");
Console.WriteLine("[i] by valnoxy (https://valnoxy.dev)");
Console.WriteLine("\n[i] This tool is open source! See: https://github.com/valnoxy/PowerChute-Log4j-Patch");

CheckSys();
RunService(false);

string log4j = String.Empty;
if (File.Exists(Path.Combine(path, "log4j-core-2.14.1.jar")))
log4j = "log4j-core-2.14.1.jar";
if (File.Exists(Path.Combine(path, "log4j-core-2.11.1.jar")))
log4j = "log4j-core-2.11.1.jar";
if (File.Exists(Path.Combine(path, "log4j-core-2.2.jar")))
log4j = "log4j-core-2.2.jar";

Console.WriteLine("[i] Removing vulnerable classes from jar file ...");
RemoveClass(Path.Combine(path, log4j));
RunService(true);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[i] PowerChute was successfully patched! Closing ...");
Console.ForegroundColor = ConsoleColor.White;
System.Threading.Thread.Sleep(5000);
}

static void CheckSys()
{
Console.WriteLine("[i] Searching for APC PowerChute Business Edition ...");
if (!Directory.Exists(path))
{
Console.WriteLine("[!] Error: Cannot find PowerChute Business Edition.");
Console.WriteLine("[!] Provided path: " + path);
System.Threading.Thread.Sleep(5000);
Environment.Exit(-1);
}
else
{
Console.WriteLine("[i] PowerChute Business Edition found!");
}
}

private static void RunService(bool v)
{
// Check whether the apcpbeagent service is started.
ServiceController sc = new ServiceController();
sc.ServiceName = "apcpbeagent";
Console.WriteLine("[i] The apcpbeagent service status is currently set to {0}",
sc.Status.ToString());

if (v == true)
{
if (sc.Status != ServiceControllerStatus.Running)
{
// Start the service if the current status is stopped.
Console.WriteLine("[i] Starting the apcpbeagent service ...");
try
{
// Start the service, and wait until its status is "Running".
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running);

// Display the current service status.
Console.WriteLine("[i] The apcpbeagent service status is now set to {0}.",
sc.Status.ToString());
}
catch (InvalidOperationException)
{
Console.WriteLine("[!] Could not start the apcpbeagent service.");
System.Threading.Thread.Sleep(5000);
Environment.Exit(-1);
}
}
}

if (v == false)
{
if (sc.Status != ServiceControllerStatus.Stopped)
{
// Stop the service if the current status is started.
Console.WriteLine("[i] Stopping the apcpbeagent service ...");
try
{
// Stop the service, and wait until its status is "Stopped".
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped);

// Display the current service status.
Console.WriteLine("[i] The apcpbeagent service status is now set to {0}.",
sc.Status.ToString());
}
catch (InvalidOperationException)
{
Console.WriteLine("[!] Could not stop the apcpbeagent service.");
System.Threading.Thread.Sleep(5000);
Environment.Exit(-1);
}
}
}
}

static void RemoveClass(string file)
{
using (ZipArchive zip = ZipFile.Open(@file, ZipArchiveMode.Update))
{
zip.Entries.Where(x => x.FullName.Contains("JndiManager.class")).ToList()
.ForEach(y =>
{
zip.GetEntry(y.FullName).Delete();
Console.WriteLine("[i] Removing: JndiManager.class");
});
zip.Entries.Where(x => x.FullName.Contains("JndiLookup.class")).ToList()
.ForEach(y =>
{
zip.GetEntry(y.FullName).Delete();
Console.WriteLine("[i] Removing: JndiLookup.class");
});
}
Console.WriteLine($"[i] File {file} successfully updated.");
}
}
}
79 changes: 79 additions & 0 deletions PowerChutePatch/PowerChutePatch/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC-Manifestoptionen
Wenn Sie die Ebene der Benutzerkontensteuerung für Windows ändern möchten, ersetzen Sie den
Knoten "requestedExecutionLevel" wie folgt.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Durch Angabe des Elements "requestedExecutionLevel" wird die Datei- und Registrierungsvirtualisierung deaktiviert.
Entfernen Sie dieses Element, wenn diese Virtualisierung aus Gründen der Abwärtskompatibilität
für die Anwendung erforderlich ist.
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Eine Liste der Windows-Versionen, unter denen diese Anwendung getestet
und für die sie entwickelt wurde. Wenn Sie die Auskommentierung der entsprechenden Elemente aufheben,
wird von Windows automatisch die kompatibelste Umgebung ausgewählt. -->

<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->

</application>
</compatibility>

<!-- Gibt an, dass die Anwendung mit DPI-Werten kompatibel ist und von Windows nicht automatisch auf höhere
DPI-Werte skaliert wird. WPF-Anwendungen (Windows Presentation Foundation) sind automatisch mit DPI-Werten kompatibel, eine Aktivierung
ist nicht erforderlich. Für Windows Forms-Anwendungen für .NET Framework 4.6, die diese Einstellung aktivieren, muss
auch die Einstellung "'EnableWindowsFormsHighDpiAutoResizing" in der Datei "app.config" auf TRUE festgelegt werden.
Hierdurch können für die Anwendung lange Pfade verwendet werden. Weitere Informationen finden Sie unter https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation.-->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->

<!-- Designs für allgemeine Windows-Steuerelemente und -Dialogfelder (Windows XP und höher) aktivieren -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->

</assembly>
Binary file added PowerChutePatch/PowerChutePatch/bucker_icon.ico
Binary file not shown.

0 comments on commit 0d11325

Please sign in to comment.