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 22, 2022
1 parent a448cf6 commit 6041882
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<strong>Version: </strong>1.0.0
<br />
<br />
<!--<a href="https://github.com/valnoxy/UniFi-Log4j-Patch/releases"><strong>Download now »</strong></a>-->
<strong>No downloads available yet!</strong>
<a href="https://github.com/valnoxy/UniFi-Log4j-Patch/releases"><strong>Download now »</strong></a>
<br />
<br />
<a href="https://github.com/valnoxy/UniFi-Log4j-Patch/issues">Report Bug</a>
Expand Down
40 changes: 24 additions & 16 deletions UniFi-Controller-Patch/UniFi-Controller-Patch/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.ServiceProcess;

namespace UniFiControllerPatch
{
internal class Program
{
public static string unifi = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) , "Ubiquiti UniFi\\lib\\");
public static string unifi = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Ubiquiti UniFi\\lib\\");
public static string unifi_jar = Path.Combine(unifi, "ace.jar");
static void Main(string[] args)
{
Console.WriteLine("[i] Log4j Patcher for UniFi Network Controller [Version: 1.0.0]");
Console.WriteLine("[i] by valnoxy (https://valnoxy.dev)");
Console.WriteLine("\n[i] This tool is open source! See: https://github.com/valnoxy/UniFi-Controller-Patch");
Console.WriteLine("\n[i] This tool is open source! See: https://github.com/valnoxy/UniFi-Log4j-Patch");

string service = CheckSys();

RunService(service, false);
RunService(service, false, false);

string log4jver = String.Empty;
if (service == "svc")
Expand Down Expand Up @@ -67,7 +64,7 @@ static void Main(string[] args)
Console.WriteLine("[!] This Version of UniFi Network Controller is too old. Please update it before using this patch.");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("[!] Restart service ...");
RunService(service, true);
RunService(service, true, true);

Console.WriteLine("[!] Terminating in 10 sec ...");
System.Threading.Thread.Sleep(10000);
Expand All @@ -78,7 +75,7 @@ static void Main(string[] args)
UpdateClass(unifi, "https://dl.exploitox.de/other/vuln/log4j/v2.17.1/log4j-api-2.17.1.jar", log4jver, "api");
UpdateClass(unifi, "https://dl.exploitox.de/other/vuln/log4j/v2.17.1/log4j-core-2.17.1.jar", log4jver, "core");
UpdateClass(unifi, "https://dl.exploitox.de/other/vuln/log4j/v2.17.1/log4j-slf4j-impl-2.17.1.jar", log4jver, "slf4j-impl");
RunService(service, true);
RunService(service, true, true);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[i] PowerChute was successfully patched! Closing ...");
Console.ForegroundColor = ConsoleColor.White;
Expand All @@ -102,36 +99,47 @@ static string CheckSys()
}
}

private static void RunService(string servicename, bool v)
private static void RunService(string servicename, bool v, bool ui)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";

if (v == true)
{
p.StartInfo.Arguments = $"/c java -jar {unifi_jar} startsvc";
p.StartInfo.Arguments = $"/c java -jar \"{unifi_jar}\" startsvc";
}

if (v == false)
{
p.StartInfo.Arguments = $"/c java -jar {unifi_jar} stopsvc";
p.StartInfo.Arguments = $"/c java -jar \"{unifi_jar}\" stopsvc";

Console.WriteLine("[i] Please close UniFi Network application if opened.");
Console.Write("[i] Press ENTER to continue.");
Console.ReadLine();
}

p.Start();
p.WaitForExit();

if (ui == true)
{
Console.WriteLine("[i] Starting UniFi Network application ...");
p.StartInfo.Arguments = $"/c java -jar \"{unifi_jar}\" ui";
p.Start();
}
}

private static void UpdateClass(string path, string url, string log4jver, string log4jmodule)
{
using (var client = new WebClient())
using (var client = new WebClient()) // TODO: Switch to HttpClient
{
// =================================
// = Downloading Class =
// =================================
Console.Write($"[i] Downloading log4j-{log4jmodule}-2.17.1.jar ... ");
try
{
client.DownloadFile(url, path);
Console.Write($"[i] Downloading log4j-{log4jmodule}-2.17.1.jar ... ");
client.DownloadFile(url, Path.Combine(path, $"log4j-{log4jmodule}-2.17.1.jar"));
}
catch (Exception ex)
{
Expand All @@ -146,7 +154,7 @@ private static void UpdateClass(string path, string url, string log4jver, string
// =================================
try
{
Console.WriteLine($"[i] Removing log4j-{log4jmodule}-{log4jver}.jar ... ");
Console.Write($"[i] Removing log4j-{log4jmodule}-{log4jver}.jar ... ");
File.Delete(Path.Combine(path, $"log4j-{log4jmodule}-{log4jver}.jar"));
}
catch (Exception ex)
Expand All @@ -162,7 +170,7 @@ private static void UpdateClass(string path, string url, string log4jver, string
// =================================
try
{
Console.WriteLine($"[i] Linking to log4j-{log4jmodule}-2.17.1.jar ... ");
Console.Write($"[i] Linking to log4j-{log4jmodule}-2.17.1.jar ... ");
SymbolLink.SymbolicLink.CreateSymbolicLink(Path.Combine(path, $"log4j-{log4jmodule}-2.17.1.jar"), Path.Combine(path, $"log4j-{log4jmodule}-{log4jver}.jar"), true);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Copyright>Copyright (c) 2018 - 2022 valnoxy. All rightes reserved.</Copyright>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>bucker_icon.ico</ApplicationIcon>
<DebugType>none</DebugType>
<DebugType>full</DebugType>
<PackageProjectUrl>https://github.com/valnoxy/UniFi-Controller-Patch</PackageProjectUrl>
<Product>bucker</Product>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
Expand Down

0 comments on commit 6041882

Please sign in to comment.