Пример #1
1
        public static int BuildPSAttack(Attack attack, GeneratedStrings generatedStrings)
        {
            //DateTime now = DateTime.Now;
            //string buildDate = String.Format("{0:MMMM dd yyyy} at {0:hh:mm:ss tt}", now);
            //using (StreamWriter buildDateFile = new StreamWriter(Path.Combine(attack.resources_dir, "attackDate.txt")))
            //{
            //    buildDateFile.Write(buildDate);
            //}
            string dotNetDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
            string msbuildPath = Path.Combine(dotNetDir, "msbuild.exe");
            if (File.Exists(msbuildPath))
            {
                Process msbuild = new Process();
                msbuild.StartInfo.FileName = msbuildPath;
                msbuild.StartInfo.Arguments = attack.build_args(Path.Combine(Strings.obfuscatedSourceDir, generatedStrings.Store["psaReplacement"] + ".sln"));
                msbuild.StartInfo.UseShellExecute = false;
                msbuild.StartInfo.RedirectStandardOutput = true;
                msbuild.StartInfo.RedirectStandardError = true;

                Console.WriteLine("Running build with this command: {0} {1}", msbuild.StartInfo.FileName, msbuild.StartInfo.Arguments);

                msbuild.Start();
                string output = msbuild.StandardOutput.ReadToEnd();
                Console.WriteLine(output);
                string err = msbuild.StandardError.ReadToEnd();
                Console.WriteLine(err);
                msbuild.WaitForExit();
                int exitCode = msbuild.ExitCode;
                msbuild.Close();
                return exitCode;
            }
            return 999;
        }
Пример #2
0
        public static void BuildConfigFile(Attack attack, GeneratedStrings generatedStrings)
        {
            attack.ClearConfigFile();
            PSAttackConfig psaConfig = new PSAttackConfig();
            psaConfig.Session = new Dictionary<string, object>();
            psaConfig.Session.Add("encryptionKey", generatedStrings.Store["encryptionKey"]);
            psaConfig.Session.Add("keyStoreFileName", generatedStrings.Store["keyStoreFileName"]);
            psaConfig.Initialize();

            var generatedCode = psaConfig.TransformText();
            File.WriteAllText(attack.config_file, generatedCode);
        }
Пример #3
0
        public static void BuildCsproj(List<Module> modules, Attack attack, GeneratedStrings generatedStrings)
        {
            attack.ClearCsproj();
            List<string> files = new List<string>();
            foreach (Module module in modules)
            {
                files.Add(CryptoUtils.EncryptString(attack, module.name, generatedStrings));
            }
            PSAttackCSProj csproj = new PSAttackCSProj();
            csproj.Session = new Dictionary<string, object>();
            csproj.Session.Add("files", files);
            csproj.Session.Add("keyStoreFileName", generatedStrings.Store["keyStoreFileName"]);
            csproj.Initialize();

            var generatedCode = csproj.TransformText();
            File.WriteAllText(attack.csproj_file, generatedCode);
        }
        public string ProcessSource(Display display, string sourcePath, GeneratedStrings generatedStrings, Attack attack)
        {
            string originalFileName = Path.GetFileName(sourcePath);
            string readScript = File.ReadAllText(sourcePath);
            string obfuscatedSourcePath = sourcePath.Replace(attack.unzipped_dir, Strings.obfuscatedSourceDir);
            string fileStub = obfuscatedSourcePath.Replace(Strings.obfuscatedSourceDir, "");
            obfuscatedSourcePath = Path.Combine(Strings.obfuscatedSourceDir, fileStub.Replace("PSAttack", generatedStrings.Store["psaReplacement"]));
            obfuscatedSourcePath = obfuscatedSourcePath.Replace("AttackState", generatedStrings.Store["attackStateReplacement"]);
            obfuscatedSourcePath = obfuscatedSourcePath.Replace("PSParam", generatedStrings.Store["psparamReplacement"]);

            // Process Rules
            foreach (Ruleset ruleset in this.Rulesets)
            {
                if (ruleset.Type == "SourceCode")
                {
                    if (originalFileName.ToLower().Contains(ruleset.FileName.ToLower()) || ruleset.FileName == "#ALL")
                    {
                        FileInfo file = new System.IO.FileInfo(obfuscatedSourcePath);
                        file.Directory.Create();
                        if (!(sourcePath.Contains(generatedStrings.Store["keyStoreFileName"]) || (sourcePath.Contains("Modules"))))
                        {
                            foreach (Rule rule in ruleset.Rules)
                            {
                                display.updateMessage("Running Replace Rule '" + rule.Name + "'");
                                readScript = RuleProcessor(display, rule, readScript);
                            }
                            File.WriteAllText(obfuscatedSourcePath, readScript);
                        }
                        else
                        {
                            File.Copy(sourcePath, obfuscatedSourcePath, true);
                        }
                    }
                }

            }
            return obfuscatedSourcePath;
        }