Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ceramicskate0 authored Apr 6, 2020
1 parent 088aea8 commit ead6b98
Showing 1 changed file with 59 additions and 25 deletions.
84 changes: 59 additions & 25 deletions AutoUpdateSysmon/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -16,43 +17,49 @@ class Program

static void Main(string[] args)
{
try
if (IsUserAdministrator())
{
if (args.Length <= 0)
{
RunUpdate();
}
else
try
{
if (args[0] == "-h" || args[0] == "h" || args[0] == "help" || args[0] == "-help" || args[0] == "/h" || args[0] == "/help")
if (args.Length <= 0)
{
Console.WriteLine(@"Args must be in this fomat:
RunUpdate();
}
else
{
if (args[0] == "-h" || args[0] == "h" || args[0] == "help" || args[0] == "-help" || args[0] == "/h" || args[0] == "/help")
{
Console.WriteLine(@"Args must be in this fomat:
AutoUpdateSysmon.exe 'URL of Sysmon Config' 'Host Computer File Path of Sysmon xml file'
Example: ./AutoUpdateSysmon.exe 'https://raw.githubusercontent.com/ceramicskate0/sysmon-config/master/sysmonconfig-export.xml' 'C:\Windows\sysmonconfig-export.xml'");
}
else
{
RunUpdate(args[0], args[1]);
Console.WriteLine("[*] Update Status: Complete no issues.");
}
}
else
}
catch (Exception e)
{
Console.WriteLine("[!] App ERROR: Error: " + e.Message.ToString() + " " + e.InnerException.ToString());
try
{
RunUpdate();
}
catch (Exception r)
{
RunUpdate(args[0], args[1]);
Console.WriteLine("[*] Update Status: Complete no issues.");
Console.WriteLine("[!] Update Status: " + r.Message.ToString());
}
}
}
catch (Exception e)
else
{
Console.WriteLine("[!] App ERROR: Error: " + e.Message.ToString());
try
{
RunUpdate();
}
catch(Exception r)
{
Console.WriteLine("[!] Update Status: " + r.Message.ToString());
Environment.Exit(1);
}
Console.WriteLine("[!] App ERROR: Error: NOT RUNNING ELEVATED!");
}
Thread.Sleep(3000);
Thread.Sleep(5000);
}
private static void RunUpdate(string URL= @"https://raw.githubusercontent.com/ceramicskate0/sysmon-config/master/sysmonconfig-export.xml", string HostLocation= @"C:\Windows\sysmonconfig-export.xml")
{
Expand All @@ -70,14 +77,41 @@ private static void RunUpdate(string URL= @"https://raw.githubusercontent.com/ce
string output = process.StandardOutput.ReadToEnd();
Console.WriteLine("[*] Process Output:" + output);
}

internal static bool IsUserAdministrator()
{
bool isAdmin;
WindowsIdentity user = null;
try
{
user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch (UnauthorizedAccessException ex)
{
isAdmin = false;
}
catch (Exception ex)
{
isAdmin = false;
}
finally
{
if (user != null)
user.Dispose();
}
return isAdmin;
}

}
internal class CustomWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest w = base.GetWebRequest(uri);
w.UseDefaultCredentials = true;
w.Timeout = 1000;
w.Timeout = 5000;
return w;
}
}
Expand Down

0 comments on commit ead6b98

Please sign in to comment.