Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidXanatos committed Sep 16, 2018
1 parent 034c9b3 commit 0f0edaf
Show file tree
Hide file tree
Showing 20 changed files with 2,229 additions and 812 deletions.
59 changes: 0 additions & 59 deletions wumgr/AppLog.cs

This file was deleted.

56 changes: 56 additions & 0 deletions wumgr/Common/AppLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class AppLog
{
private List<string> mLogList = new List<string>();

static public void Line(String line)
{
if (mInstance != null)
mInstance.logLine(line);
}

public void logLine(String line)
{
if (Logger != null)
{
mLogList.Add(line);
while (mLogList.Count > 100)
mLogList.RemoveAt(0);

LogEventArgs args = new LogEventArgs();
args.line = line;
Logger(this, args);
}
}

static public List<string> GetLog() { return mInstance.mLogList; }

public class LogEventArgs : EventArgs
{
public string line { get; set; }
}

static public event EventHandler<LogEventArgs> Logger;

static void LineLogger(object sender, LogEventArgs args)
{
Console.WriteLine("LOG: " + args.line);
}

static private AppLog mInstance = null;

public static AppLog GetInstance() { return mInstance; }

public AppLog()
{
mInstance = this;

Logger += LineLogger;
}
}
175 changes: 175 additions & 0 deletions wumgr/Common/FileOps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.AccessControl;
using System.Security.Principal;
using System.IO;


class FileOps
{
static public bool MoveFile(string from, string to, bool Overwrite = false)
{
try
{
if (File.Exists(to))
{
if (!Overwrite)
return false;
File.Delete(to);
}

File.Move(from, to);

if (File.Exists(from))
return false;
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
return false;
}
return true;
}

static public bool DeleteFile(string path)
{
try
{
File.Delete(path);
return true;
}
catch
{
return false;
}
}

static public int TestFileAdminSec(String filePath)
{
//get file info
FileInfo fi = new FileInfo(filePath);
if (!fi.Exists)
return 2;

//get security access
FileSecurity fs = fi.GetAccessControl();

//get any special user access
AuthorizationRuleCollection rules = fs.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier)); // get as SID not string


//remove any special access
foreach (FileSystemAccessRule rule in rules)
{
if (rule.AccessControlType != AccessControlType.Allow)
continue;
if (rule.IdentityReference.Value.Equals(SID_Admins) || rule.IdentityReference.Value.Equals(SID_System))
continue;
if ((rule.FileSystemRights & (FileSystemRights.Write | FileSystemRights.Delete)) != 0)
return 0;
}
return 1;
}

static public void SetFileAdminSec(String filePath)
{
//get file info
FileInfo fi = new FileInfo(filePath);
if(!fi.Exists){
FileStream f_out = fi.OpenWrite();
f_out.Close();
}

//get security access
FileSecurity fs = fi.GetAccessControl();

//remove any inherited access
fs.SetAccessRuleProtection(true, false);

//get any special user access
AuthorizationRuleCollection rules = fs.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)); // show as names

//remove any special access
foreach (FileSystemAccessRule rule in rules)
fs.RemoveAccessRule(rule);

fs.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(SID_Admins), FileSystemRights.FullControl, AccessControlType.Allow));
fs.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(SID_System), FileSystemRights.FullControl, AccessControlType.Allow));
fs.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(SID_Users), FileSystemRights.Read, AccessControlType.Allow));

//add current user with full control.
//fs.AddAccessRule(new FileSystemAccessRule(domainName + "\\" + userName, FileSystemRights.FullControl, AccessControlType.Allow));

//add all other users delete only permissions.
//SecurityIdentifier sid = new SecurityIdentifier("S-1-5-11"); // Authenticated Users
//fs.AddAccessRule(new FileSystemAccessRule(sid, FileSystemRights.Delete, AccessControlType.Allow));

//flush security access.
File.SetAccessControl(filePath, fs);
}

static string SID_null = "S-1-0-0"; // Null SID
static string SID_Worls = "S-1-1-0"; // World
static string SID_Local = "S-1-2-0"; // Local
static string SID_Console = "S-1-2-1"; // Console Logon
static string SID_OwnerID = "S-1-3-0"; // Creator Owner ID
static string SID_GroupeID = "S-1-3-1"; // Creator Group ID
static string SID_OwnerSvr = "S-1-3-2"; // Creator Owner Server
static string SID_CreatorSvr = "S-1-3-3"; // Creator Group Server
static string SID_OwnerRights = "S-1-3-4"; // Owner Rights
static string SID_NonUnique = "S-1-4"; // Non-unique Authority
static string SID_NTAuth = "S-1-5"; // NT Authority
static string SID_AllServices = "S-1-5-80-0"; // All Services
static string SID_DialUp = "S-1-5-1"; // Dialup
static string SID_LocalAcc = "S-1-5-113"; // Local account
static string SID_LocalAccAdmin = "S-1-5-114"; // Local account and member of Administrators group
static string SID_Net = "S-1-5-2"; // Network
static string SID_Natch = "S-1-5-3"; // Batch
static string SID_Interactive = "S-1-5-4"; // Interactive
//static string SID_ = "S-1-5-5- *X*- *Y* Logon Session
static string SID_Service = "S-1-5-6"; // Service
static string SID_AnonLogin = "S-1-5-7"; // Anonymous Logon

static string SID_Proxy = "S-1-5-8"; // Proxy
static string SID_EDC = "S-1-5-9"; // Enterprise Domain Controllers
static string SID_Self = "S-1-5-10"; // Self
static string SID_AuthenticetedUser = "S-1-5-11"; // Authenticated Users

static string SID_Restricted = "S-1-5-12"; // Restricted Code
static string SID_TermUser = "S-1-5-13"; // Terminal Server User
static string SID_RemoteLogin = "S-1-5-14"; // Remote Interactive Logon
static string SID_ThisORg = "S-1-5-15"; // This Organization
static string SID_IIS = "S-1-5-17"; // IIS_USRS
static string SID_System = "S-1-5-18"; // System(or LocalSystem)

static string SID_NTAuthL = "S-1-5-19"; // NT Authority(LocalService)
static string SID_NetServices = "S-1-5-20"; // Network Service

static string SID_Admins = "S-1-5-32-544"; // Administrators
static string SID_Users = "S-1-5-32-545"; // Users
static string SID_Guests = "S-1-5-32-546"; // Guests
static string SID_PowerUsers = "S-1-5-32-547"; // Power Users
static string SID_AccOps = "S-1-5-32-548"; // Account Operators
static string SID_ServerOps = "S-1-5-32-549"; // Server Operators
static string SID_PrintOps = "S-1-5-32-550"; // Print Operators
static string SID_BackupOps = "S-1-5-32-551"; // Backup Operators
static string SID_Replicators = "S-1-5-32-552"; // Replicators
static string SID_NTLM_Auth = "S-1-5-64-10"; // NTLM Authentication
static string SID_SCh_Auth = "S-1-5-64-14"; // SChannel Authentication
static string SID_DigestAuth = "S-1-5-64-21"; // Digest Authentication
static string SID_NT_Service = "S-1-5-80"; // NT Service
static string SID_All_Services = "S-1-5-80-0"; // All Services
static string SID_VM = "S-1-5-83-0"; // NT VIRTUAL MACHINE\Virtual Machines
static string SID_UntrustedLevel = "S-1-16-0"; // Untrusted Mandatory Level
static string SID_LowLevel = "S-1-16-4096"; // Low Mandatory Level
static string SID_MediumLevel = "S-1-16-8192"; // Medium Mandatory Level
static string SID_MediumPLevel = "S-1-16-8448"; // Medium Plus Mandatory Level
static string SID_HighLevel = "S-1-16-12288"; // High Mandatory Level
static string SID_SysLevel = "S-1-16-16384"; // System Mandatory Level
static string SID_PPLevel = "S-1-16-20480"; // Protected Process Mandatory Level
static string SID_SPLevel = "S-1-16-28672"; // Secure Process Mandatory Level

}
Loading

0 comments on commit 0f0edaf

Please sign in to comment.