Ejemplo n.º 1
0
        public static string PermInt2Str(int current_perm, PermissionType permissionType = PermissionType.DEFAULT)
        {
            Dictionary <string, int> interesting_perms = new Dictionary <string, int>();

            if (permissionType == PermissionType.DEFAULT)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    // This isn't an exhaustive list of possible permissions. Just the interesting ones.
                    { "AllAccess", 0xf01ff },
                    { "GenericAll", 0x10000000 },
                    { "FullControl", (int)FileSystemRights.FullControl },
                    { "TakeOwnership", (int)FileSystemRights.TakeOwnership },

                    { "GenericWrite", 0x40000000 },
                    { "WriteData/CreateFiles", (int)FileSystemRights.WriteData },
                    { "Modify", (int)FileSystemRights.Modify },
                    { "Write", (int)FileSystemRights.Write },

                    { "ChangePermissions", (int)FileSystemRights.ChangePermissions },

                    { "Delete", (int)FileSystemRights.Delete },
                    { "DeleteSubdirectoriesAndFiles", (int)FileSystemRights.DeleteSubdirectoriesAndFiles },
                    { "AppendData/CreateDirectories", (int)FileSystemRights.AppendData },
                    { "WriteAttributes", (int)FileSystemRights.WriteAttributes },
                    { "WriteExtendedAttributes", (int)FileSystemRights.WriteExtendedAttributes },
                };
            }

            else if (permissionType == PermissionType.READABLE_OR_WRITABLE)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    // This isn't an exhaustive list of possible permissions. Just the interesting ones.
                    { "AllAccess", 0xf01ff },
                    { "GenericAll", 0x10000000 },
                    { "FullControl", (int)FileSystemRights.FullControl },
                    { "TakeOwnership", (int)FileSystemRights.TakeOwnership },

                    { "GenericWrite", 0x40000000 },
                    { "WriteData/CreateFiles", (int)FileSystemRights.WriteData },
                    { "Modify", (int)FileSystemRights.Modify },
                    { "Write", (int)FileSystemRights.Write },

                    { "Read", (int)FileSystemRights.Read },
                    { "ReadData", (int)FileSystemRights.ReadData },

                    { "ChangePermissions", (int)FileSystemRights.ChangePermissions },

                    { "Delete", (int)FileSystemRights.Delete },
                    { "DeleteSubdirectoriesAndFiles", (int)FileSystemRights.DeleteSubdirectoriesAndFiles },
                    { "AppendData/CreateDirectories", (int)FileSystemRights.AppendData },
                    { "WriteAttributes", (int)FileSystemRights.WriteAttributes },
                    { "WriteExtendedAttributes", (int)FileSystemRights.WriteExtendedAttributes },
                };
            }

            else if (permissionType == PermissionType.WRITEABLE_OR_EQUIVALENT)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    { "AllAccess", 0xf01ff },
                    { "GenericAll", 0x10000000 },
                    { "FullControl", (int)FileSystemRights.FullControl },                 //0x1f01ff - 2032127
                    { "TakeOwnership", (int)FileSystemRights.TakeOwnership },             //0x80000 - 524288
                    { "GenericWrite", 0x40000000 },
                    { "WriteData/CreateFiles", (int)FileSystemRights.WriteData },         //0x2
                    { "Modify", (int)FileSystemRights.Modify },                           //0x301bf - 197055
                    { "Write", (int)FileSystemRights.Write },                             //0x116 - 278
                    { "ChangePermissions", (int)FileSystemRights.ChangePermissions },     //0x40000 - 262144
                    { "AppendData/CreateDirectories", (int)FileSystemRights.AppendData }, //4
                };
            }

            else if (permissionType == PermissionType.WRITEABLE_OR_EQUIVALENT_REG)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    { "AllAccess", 0xf01ff },
                    { "GenericAll", 0x10000000 },
                    { "FullControl", (int)RegistryRights.FullControl },             //983103
                    { "TakeOwnership", (int)RegistryRights.TakeOwnership },         //524288
                    { "GenericWrite", 0x40000000 },
                    { "WriteKey", (int)RegistryRights.WriteKey },                   //131078
                    { "SetValue", (int)RegistryRights.SetValue },                   //2
                    { "ChangePermissions", (int)RegistryRights.ChangePermissions }, //262144
                    { "CreateSubKey", (int)RegistryRights.CreateSubKey },           //4
                };
            }

            else if (permissionType == PermissionType.WRITEABLE_OR_EQUIVALENT_SVC)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    { "AllAccess", 0xf01ff },
                    //{"QueryConfig" , 1},  //Grants permission to query the service's configuration.
                    //{"ChangeConfig" , 2}, //Grants permission to change the service's permission.
                    //{"QueryStatus" , 4},  //Grants permission to query the service's status.
                    //{"EnumerateDependents" , 8}, //Grants permissionto enumerate the service's dependent services.
                    //{"PauseContinue" , 64}, //Grants permission to pause/continue the service.
                    //{"Interrogate" , 128},  //Grants permission to interrogate the service (i.e. ask it to report its status immediately).
                    //{"UserDefinedControl" , 256}, //Grants permission to run the service's user-defined control.
                    //{"Delete" , 65536},  //Grants permission to delete the service.
                    //{"ReadControl" , 131072}, //Grants permission to query the service's security descriptor.
                    { "WriteDac", 262144 },               //Grants permission to set the service's discretionary access list.
                    { "WriteOwner", 524288 },             //Grants permission to modify the group and owner of a service.
                    //{"Synchronize" , 1048576},
                    { "AccessSystemSecurity", 16777216 }, //The right to get or set the SACL in the object security descriptor.
                    { "GenericAll", 268435456 },
                    { "GenericWrite", 1073741824 },
                    { "GenericExecute", 536870912 },
                    { "Start", 16 }, //Grants permission to start the service.
                    { "Stop", 32 },  //Grants permission to stop the service.
                    //{"GenericRead" , 2147483648}
                };
            }


            try
            {
                foreach (KeyValuePair <string, int> entry in interesting_perms)
                {
                    if ((entry.Value & current_perm) == entry.Value)
                    {
                        return(entry.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                Beaprint.GrayPrint("Error in PermInt2Str: " + ex);
            }
            return("");
        }
Ejemplo n.º 2
0
        public static string PermInt2Str(int current_perm, PermissionType permissionType = PermissionType.DEFAULT)
        {
            Dictionary <string, int> interesting_perms = new Dictionary <string, int>();

            if (permissionType == PermissionType.DEFAULT)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    // This isn't an exhaustive list of possible permissions. Just the interesting ones.
                    { "AllAccess", 0xf01ff },
                    { "GenericAll", 0x10000000 },
                    { "FullControl", (int)FileSystemRights.FullControl },
                    { "TakeOwnership", (int)FileSystemRights.TakeOwnership },

                    { "GenericWrite", 0x40000000 },
                    { "WriteData/CreateFiles", (int)FileSystemRights.WriteData },
                    { "Modify", (int)FileSystemRights.Modify },
                    { "Write", (int)FileSystemRights.Write },

                    { "ChangePermissions", (int)FileSystemRights.ChangePermissions },

                    { "Delete", (int)FileSystemRights.Delete },
                    { "DeleteSubdirectoriesAndFiles", (int)FileSystemRights.DeleteSubdirectoriesAndFiles },
                    { "AppendData/CreateDirectories", (int)FileSystemRights.AppendData },
                    { "WriteAttributes", (int)FileSystemRights.WriteAttributes },
                    { "WriteExtendedAttributes", (int)FileSystemRights.WriteExtendedAttributes },
                };
            }

            else if (permissionType == PermissionType.READABLE_OR_WRITABLE)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    // This isn't an exhaustive list of possible permissions. Just the interesting ones.
                    { "AllAccess", 0xf01ff },
                    { "GenericAll", 0x10000000 },
                    { "FullControl", (int)FileSystemRights.FullControl },
                    { "TakeOwnership", (int)FileSystemRights.TakeOwnership },

                    { "GenericWrite", 0x40000000 },
                    { "WriteData/CreateFiles", (int)FileSystemRights.WriteData },
                    { "Modify", (int)FileSystemRights.Modify },
                    { "Write", (int)FileSystemRights.Write },

                    { "Read", (int)FileSystemRights.Read },
                    { "ReadData", (int)FileSystemRights.ReadData },

                    { "ChangePermissions", (int)FileSystemRights.ChangePermissions },

                    { "Delete", (int)FileSystemRights.Delete },
                    { "DeleteSubdirectoriesAndFiles", (int)FileSystemRights.DeleteSubdirectoriesAndFiles },
                    { "AppendData/CreateDirectories", (int)FileSystemRights.AppendData },
                    { "WriteAttributes", (int)FileSystemRights.WriteAttributes },
                    { "WriteExtendedAttributes", (int)FileSystemRights.WriteExtendedAttributes },
                };
            }

            else if (permissionType == PermissionType.WRITEABLE_OR_EQUIVALENT)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    { "AllAccess", 0xf01ff },
                    { "GenericAll", 0x10000000 },
                    { "FullControl", (int)FileSystemRights.FullControl },                 //0x1f01ff - 2032127
                    { "TakeOwnership", (int)FileSystemRights.TakeOwnership },             //0x80000 - 524288
                    { "GenericWrite", 0x40000000 },
                    { "WriteData/CreateFiles", (int)FileSystemRights.WriteData },         //0x2
                    { "Modify", (int)FileSystemRights.Modify },                           //0x301bf - 197055
                    { "Write", (int)FileSystemRights.Write },                             //0x116 - 278
                    { "ChangePermissions", (int)FileSystemRights.ChangePermissions },     //0x40000 - 262144
                    { "AppendData/CreateDirectories", (int)FileSystemRights.AppendData }, //4
                };
            }

            else if (permissionType == PermissionType.WRITEABLE_OR_EQUIVALENT_SVC)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    { "AllAccess", 0xf01ff },
                    { "GenericAll", 0x10000000 },
                    { "FullControl", (int)RegistryRights.FullControl },             //983103
                    { "TakeOwnership", (int)RegistryRights.TakeOwnership },         //524288
                    { "GenericWrite", 0x40000000 },
                    { "WriteKey", (int)RegistryRights.WriteKey },                   //131078
                    { "SetValue", (int)RegistryRights.SetValue },                   //2
                    { "ChangePermissions", (int)RegistryRights.ChangePermissions }, //262144
                    { "CreateSubKey", (int)RegistryRights.CreateSubKey },           //4
                    { "Start", 0x00000010 },
                    { "Stop", 0x00000020 },
                };
            }

            try
            {
                foreach (KeyValuePair <string, int> entry in interesting_perms)
                {
                    if ((entry.Value & current_perm) == entry.Value)
                    {
                        return(entry.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                Beaprint.GrayPrint("Error in PermInt2Str: " + ex);
            }
            return("");
        }