Skip to content

Commit e0e41c4

Browse files
authored
Merge pull request #1 from Chnoky/developments---1.0.0
Allow separators in sudoers for powershell arguments or options
2 parents ce3401c + 73c155c commit e0e41c4

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ In command console or powershell console :<br>
5656
Run "sudoWs_client.exe <Path to script | Powershell command>"
5757
<br><br>
5858
If the args is not in sudoers, execution is denied.<br>
59-
If the args is in sudoers but not with NOPASSWD option, UAC for Adminisrator password is prompting.<br>
59+
If the args is in sudoers with PASSWD (or none) option, UAC for Adminisrator password is prompting.<br>
6060
If the args is in sudoers with NOPASSWD option, the command or script is run with elevated account (SYSTEM) and the standard output is return.<br>

sudoWs_server/sudoWs_server/getAutorization.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Configuration;
4+
using System.Text.RegularExpressions;
45

56
public class GetAuthorization
67
{
78
private static List<String[]> ReadPriviledges()
89
{
910
string file = System.IO.File.ReadAllText(ConfigurationManager.AppSettings.Get("sudoers"));
1011
string[] readPriviledges = file.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
12+
string sudoersPattern = @"^(u|g);(.*?);(.*);($|NOPASSWD$|PASSWD$)";
1113

1214
List<String[]> privilegesList = new List<String[]>();
1315
for (int i = 0; i < readPriviledges.Length; i++)
1416
{
15-
if (readPriviledges[i].Split(";").Length >= 3 && readPriviledges[i].Split(";").Length <= 4)
17+
if(Regex.IsMatch(readPriviledges[i], sudoersPattern))
1618
{
17-
privilegesList.Add(readPriviledges[i].Split(";"));
19+
Match matchSyntax = Regex.Match(readPriviledges[i], sudoersPattern);
20+
privilegesList.Add(new[] { matchSyntax.Groups[1].Value, matchSyntax.Groups[2].Value, matchSyntax.Groups[3].Value, matchSyntax.Groups[4].Value });
1821
}
1922
}
2023

@@ -29,21 +32,25 @@ public static int IsUserGranted(String username, String commandLine)
2932
foreach(String[] priviledge in privileges)
3033
{
3134
if(priviledge[0] == "u" && priviledge[1] == username)
32-
{
35+
{
3336
if (priviledge[2] == commandLine)
34-
{
37+
{
3538
if(priviledge[3] == "NOPASSWD")
36-
{
39+
{
3740
return 0;
3841
}
39-
else
40-
{
42+
else if(priviledge[3] == "PASSWD" || priviledge[3] == "")
43+
{
4144
return 1;
4245
}
43-
}
44-
}
45-
else if(priviledge[0] == "g")
46-
{
46+
else
47+
{
48+
return 2;
49+
}
50+
}
51+
}
52+
else if(priviledge[0] == "g")
53+
{
4754
bool isAMember = GetUserInfo.IsUserGroupMember(username, priviledge[1]);
4855

4956
if (priviledge[2] == commandLine && isAMember)

sudoers/sudoers.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
### !!!Please ensure this file is only readable by Windows administrators!!!T
2-
###This file is the whitelist commands or scripts for sudoWs
1+
### !!!Please ensure this file is only readable by Windows administrators!!!
2+
### This file is the whitelist commands or scripts for sudoWs
33
###
44
### Format is the following :
5-
### [u|g];[username|groupname];[powershell command|path to powershell script];[NOPASSWD]
5+
### [u|g];[username|groupname];[powershell command|path to powershell script];[|PASSWD|NOPASSWD]
6+
###
7+
### HINT : format must match regex ^(u|g);(.*?);(.*);($|NOPASSWD$|PASSWD$)
68
###
79
### 1) u for user, g for group
810
### 2) username if u in 1), group name otherwise
911
### 3) Command or script that will be literally executed in a powershell call
10-
### 3) NOPASSWD : do not prompt administrator password. Other value will ask for adminisrator password
12+
### 3) NOPASSWD : do not prompt administrator password. PASSWD or no option will ask for adminisrator password
1113
###
1214
### Format is case sensitive
1315
###

0 commit comments

Comments
 (0)