Example #1
0
        public static void VerifySignature(params string[] files)
        {
#if !DEBUG // && false
            try
            {
                var key = new PublicKey(new Oid("1.2.840.113549.1.1.1"), new AsnEncodedData(new byte[] { 05, 00 }), new AsnEncodedData(Properties.Resources.sakura_sign));
                using (var rsa = (RSACryptoServiceProvider)key.Key)
                {
                    var failure = files.Where(f => !File.Exists(f + ".sig") || !rsa.VerifyData(File.ReadAllBytes(f), "SHA256", File.ReadAllBytes(f + ".sig"))).ToList();
                    if (failure.Count == 0)
                    {
                        return;
                    }
                    NTAPI.MessageBox(0, "@@@@@@@@@@@@@@@@@@\n" +
                                     "         !!!  警告: 文件签名验证失败  !!!\n" +
                                     "@@@@@@@@@@@@@@@@@@\n\n" +
                                     "下列文件未通过数字签名校验:\n" + string.Join("\n", failure) + "\n\n" +
                                     "这些文件可能已损坏或被纂改, 这意味着您的电脑可能已经被病毒感染, 请立即进行杀毒并重新下载启动器\n\n" +
                                     "如果您准备自己编译启动器或使用其他版本的 frpc, 请自行修改 SakuraLibrary\\Utils.cs 或使用 Debug 构建来禁用签名验证", "Error", 0x10);
                }
            }
            catch (Exception e)
            {
                NTAPI.MessageBox(0, "@@@@@@@@@@@@@@@@@@\n" +
                                 "         !!!  警告: 文件签名验证失败  !!!\n" +
                                 "@@@@@@@@@@@@@@@@@@\n" +
                                 "出现内部错误, 请截图此报错并联系管理员\n\n" + e, "Error", 0x10);
            }
            Environment.Exit(0);
#endif
        }
Example #2
0
 public static Process[] SearchProcess(string name, string testPath = null) => Process.GetProcessesByName(name).Where(p =>
 {
     try
     {
         uint size = 256;
         var sb    = new StringBuilder((int)size - 1);
         if (NTAPI.QueryFullProcessImageName(p.Handle, 0, sb, ref size))
         {
             return(testPath == null || Path.GetFullPath(sb.ToString()) == testPath);
         }
     }
     catch { }
     return(false);
 }).ToArray();
Example #3
0
        public static void VerifySignature(params string[] files)
        {
#if !DEBUG // && false
            var failure = files.Where(f => !WinTrust.VerifyFile(f)).ToArray();
            if (failure.Length == 0)
            {
                return;
            }
            NTAPI.MessageBox(0, "@@@@@@@@@@@@@@@@@@\n" +
                             "         !!!  警告: 文件签名验证失败  !!!\n" +
                             "@@@@@@@@@@@@@@@@@@\n\n" +
                             "下列文件未通过数字签名校验:\n" + string.Join("\n", failure) + "\n\n" +
                             "这些文件可能已损坏或被纂改, 这意味着您的电脑可能已经被病毒感染, 请立即进行杀毒并重新下载启动器\n\n" +
                             "如果您准备自己编译启动器或使用其他版本的 frpc, 请自行修改 SakuraLibrary\\Utils.cs 或使用 Debug 构建来禁用签名验证", "Error", 0x10);
            Environment.Exit(0);
#endif
        }
Example #4
0
        public static void VerifySignature(params string[] files)
        {
            // 如果您准备自己编译启动器或使用其他版本的 frpc
            // 请自行修改此部分代码或使用 Debug 构建来禁用签名验证

#if !DEBUG // && false
            try
            {
                var failure = files.Where(f => !File.Exists(f)).ToList();
                if (failure.Count != 0)
                {
                    NTAPI.MessageBox(0, "@@@@@@@@@@@@@@@@@@\n" +
                                     "         !!!  错误: 启动器文件损坏  !!!\n" +
                                     "@@@@@@@@@@@@@@@@@@\n\n" +
                                     "下列文件不存在:\n" + string.Join("\n", failure) + "\n\n" +
                                     "请重新安装启动器\n如果重装后还看到此提示,请检查杀毒软件是否删除了启动器文件", "错误", 0x10);
                    Environment.Exit(1);
                }

                var key = new PublicKey(new Oid("1.2.840.113549.1.1.1"), new AsnEncodedData(new byte[] { 05, 00 }), new AsnEncodedData(Properties.Resources.sakura_sign));
                using (var rsa = (RSACryptoServiceProvider)key.Key)
                {
                    failure = files.Where(f => !File.Exists(f + ".sig") || !rsa.VerifyData(File.ReadAllBytes(f), "SHA256", File.ReadAllBytes(f + ".sig"))).ToList();
                    if (failure.Count == 0)
                    {
                        return;
                    }
                    NTAPI.MessageBox(0, "@@@@@@@@@@@@@@@@@@\n" +
                                     "         !!!  警告: 文件签名验证失败  !!!\n" +
                                     "@@@@@@@@@@@@@@@@@@\n\n" +
                                     "下列文件未通过数字签名校验:\n" + string.Join("\n", failure) + "\n\n" +
                                     "这些文件可能已损坏或被纂改, 这意味着您的电脑可能已经被病毒感染\n\n" +
                                     "请立即进行全盘杀毒并重新安装启动器", "错误", 0x10);
                }
            }
            catch (Exception e)
            {
                NTAPI.MessageBox(0, "@@@@@@@@@@@@@@@@@@\n" +
                                 "         !!!  警告: 文件签名验证失败  !!!\n" +
                                 "@@@@@@@@@@@@@@@@@@\n" +
                                 "出现内部错误, 请截图此报错并联系管理员\n\n" + e, "错误", 0x10);
            }
            Environment.Exit(1);
#endif
        }
Example #5
0
        public static string SetServicePermission()
        {
            var sc = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == Consts.ServiceName);

            if (sc == null)
            {
                return("Service not found");
            }

            var buffer = new byte[0];

            if (!NTAPI.QueryServiceObjectSecurity(sc.ServiceHandle, SecurityInfos.DiscretionaryAcl, buffer, 0, out uint size))
            {
                int err = Marshal.GetLastWin32Error();
                if (err != 122 && err != 0) // ERROR_INSUFFICIENT_BUFFER
                {
                    return("QueryServiceObjectSecurity[1] error: " + err);
                }
                buffer = new byte[size];
                if (!NTAPI.QueryServiceObjectSecurity(sc.ServiceHandle, SecurityInfos.DiscretionaryAcl, buffer, size, out size))
                {
                    return("QueryServiceObjectSecurity[2] error: " + Marshal.GetLastWin32Error());
                }
            }

            var rsd = new RawSecurityDescriptor(buffer, 0);

            var dacl = new DiscretionaryAcl(false, false, rsd.DiscretionaryAcl);

            dacl.SetAccess(AccessControlType.Allow, new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), (int)(ServiceAccessRights.SERVICE_QUERY_STATUS | ServiceAccessRights.SERVICE_START | ServiceAccessRights.SERVICE_STOP | ServiceAccessRights.SERVICE_INTERROGATE), InheritanceFlags.None, PropagationFlags.None);

            buffer = new byte[dacl.BinaryLength];
            dacl.GetBinaryForm(buffer, 0);

            rsd.DiscretionaryAcl = new RawAcl(buffer, 0);

            buffer = new byte[rsd.BinaryLength];
            rsd.GetBinaryForm(buffer, 0);

            if (!NTAPI.SetServiceObjectSecurity(sc.ServiceHandle, SecurityInfos.DiscretionaryAcl, buffer))
            {
                return("SetServiceObjectSecurity error: " + Marshal.GetLastWin32Error());
            }
            return(null);
        }