Пример #1
0
        /// From winpeas
        public static string PermInt2Str(int current_perm, bool only_write_or_equivalent = false, bool is_service = false)
        {
            Dictionary <string, int> 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 },
            };

            if (only_write_or_equivalent)
            {
                interesting_perms = new Dictionary <string, int>()
                {
                    { "AllAccess", 0xf01ff },
                    { "GenericAll", 0x10000000 },
                    { "FullControl", (int)FileSystemRights.FullControl },             //0x1f01ff
                    { "TakeOwnership", (int)FileSystemRights.TakeOwnership },         //0x80000
                    { "GenericWrite", 0x40000000 },
                    { "WriteData/CreateFiles", (int)FileSystemRights.WriteData },     //0x2
                    { "Modify", (int)FileSystemRights.Modify },                       //0x301bf
                    { "Write", (int)FileSystemRights.Write },                         //0x116
                    { "ChangePermissions", (int)FileSystemRights.ChangePermissions }, //0x40000
                };
            }

            if (is_service)
            {
                interesting_perms["Start"] = 0x00000010;
                interesting_perms["Stop"]  = 0x00000020;
            }

            try
            {
                foreach (KeyValuePair <string, int> entry in interesting_perms)
                {
                    if ((entry.Value & current_perm) == entry.Value)
                    {
                        return(entry.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                PrintUtils.TestError("Error in PermInt2Str: " + ex);
            }
            return("");
        }
Пример #2
0
        public static string GetFirewallProfiles()
        {
            string result = "";

            try
            {
                Type          tNetFwPolicy2 = Type.GetTypeFromProgID("HNetCfg.FwPolicy2");
                INetFwPolicy2 fwPolicy2     = (INetFwPolicy2)Activator.CreateInstance(tNetFwPolicy2);
                var           types         = fwPolicy2.CurrentProfileTypes.ToString();
                result = String.Format("{0}", (FirewallProfiles)Int32.Parse(types.ToString()));
            }
            catch (Exception ex)
            {
                PrintUtils.TestError(ex.Message);
            }
            return(result);
        }