예제 #1
0
        public IModel ImportStreams(string inputFileFullname)
        {
            var readLines = new FileHelper().ReadAllLines(inputFileFullname);
            string value = readLines.Aggregate(string.Empty, (current, line) => current + line);

            return JsonConvert.DeserializeObject<Model>(value);
        }
예제 #2
0
 public SecureDAO(String fileFullName)
 {
     this.fileFullName = fileFullName;
     fileHelper = new FileHelper(fileFullName);
     if (!File.Exists(fileFullName))
         fileHelper.CreateFile(fileFullName);
 }
예제 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     string filePath = CommonRequest.GetQueryString("FilePath");
     string fileName = CommonRequest.GetQueryString("FileName");
     if (File.Exists(filePath+fileName))
     {
         FileHelper fileHelper = new FileHelper(fileName, filePath, fileName);
         fileHelper.DownFile(Response);
     }
     else
     {
         Response.Write("文件不存在!");
     }
 }
예제 #4
0
 private void InitSetup()
 {
     try
     {
         string path = Conf.GetSetting<string>("mhSetupFile");
         Log.DebugFormat("Read MH-Setup-File: {0}", path);
         if (File.Exists(path))
         {
             FileHelper fReader = new FileHelper();
             setupPositions = fReader.ReadFromXml<MHSetupPosition>(path);
         }
         else
         {
             Log.DebugFormat("File does not exist: {0}", path);
         }
     }
     catch (Exception e)
     {
         Log.Fatal(e);
         throw e;
     }
 }
예제 #5
0
 public void SaveSetupPositions(List<MHSetupPosition> sps)
 {
     if (sps != null)
     {
         try
         {
             setupPositions = sps;
             FileHelper fWriter = new FileHelper();
             fWriter.WriteAsXml<MHSetupPosition>(sps, Conf.GetSetting<string>("mhSetupFile"));
         }
         catch (Exception e)
         {
             Log.Fatal(e);
         }
     }
 }
예제 #6
0
 public CommandHelper(DTE dte)
 {
     _dte = dte;
     _tortoiseProc = FileHelper.GetTortoiseSvnProc();
     _fileHelper = new FileHelper(dte);
 }
예제 #7
0
        /////////////////////////////////////////////////////
        //                                                 //
        // DoSignatureScan()                               //
        //                                                 //
        /////////////////////////////////////////////////////
        //Description:  Scans memory, disk and registry for
        //              given signatures.  Stores results in
        //              class global results object.
        //
        //Returns:      true if successful
        //////////////////////////////////////////////////////
        private unsafe bool DoSignatureScan()
        {
            AgentScanLog.AppendLine("");
            AgentScanLog.AppendLine("*********************************************");
            AgentScanLog.AppendLine("               SIGNATURE SCAN                ");
            AgentScanLog.AppendLine("*********************************************");
            AgentScanLog.AppendLine("");

            //
            //=============================================
            //          SCAN FOR REGISTRY SIGNATURES
            //=============================================
            //
            RegistryHelper RegistryScanner = new RegistryHelper();

            //mount NTUSER.DAT files (so every user's SID is mounted in HKEY_USERS)
            RegistryScanner.LoadNtUserDatFiles(false);

            if (AgentRegistrySignatures.Length > 0)
            {
                AgentScanLog.AppendLine("SCAN:  Scanning registry for infections...");

                //optionally scan HKCR for potentially malicious GUIDs
                //nb:  if any found, auto added to malware_info.GUIDs container
                if (AgentSettings.ContainsKey("Option_Scan_GUIDs"))
                    if (AgentSettings["Option_Scan_GUIDs"] == "True")
                        RegistryScanner.ScanForMaliciousGUIDs();

                //create a static GUID in our AgentRegistryGuidSignatures for every dynamic GUID
                RegistryScanner.LoadDynamicGUIDs(ref AgentRegistryGuidSignatures);

                //
                //perform actual scan
                //
                //initialization here is irrelevant; it will be allocated in the function
                RegistryScanner.ScanForRegistrySignatures(AgentRegistrySignatures, AgentRegistryGuidSignatures, ref AgentSignatureMatches.RegistrySignatureMatches);

                //append scan log
                AgentScanLog.AppendLine(RegistryScanner.RegistryHelperLog.ToString());
                AgentScanLog.AppendLine("SCAN:  Registry scan complete.");
            }

            //
            //=============================================
            //          SCAN FOR FILE SIGNATURES
            //=============================================
            //
            FileHelper FileScanner = new FileHelper();

            if (AgentFileSignatures.Length > 0)
            {
                AgentScanLog.AppendLine("SCAN:  Scanning all attached disks for file signatures...");

                //perform scan
                FileScanner.ScanForFileSignatures(AgentFileSignatures, ref AgentSignatureMatches.FileSignatureMatches);

                //append the file scan log
                AgentScanLog.AppendLine(FileScanner.FileHelperLog.ToString());
                AgentScanLog.AppendLine("SCAN:  Disk scans complete.");
            }

            //
            //=============================================
            //          SCAN FOR MEMORY SIGNATURES
            //=============================================
            //
            MemoryHelper MemoryScanner = new MemoryHelper();

            if (AgentMemorySignatures.Length > 0)
            {
                AgentScanLog.AppendLine("SCAN:  Scanning active processes for memory signatures...");

                //setup a few scan parameters based on agent settings
                //
                //search cmd line parameters?
                bool SearchCmdLine = false;
                if (AgentSettings.ContainsKey("MemorySignatures_SearchCmdLine"))
                    if (AgentSettings["MemorySignatures_SearchCmdLine"] == "True")
                        SearchCmdLine = true;
                //search heap space?
                bool SearchHeap = false;
                if (AgentSettings.ContainsKey("MemorySignatures_SearchHeapSpace"))
                    if (AgentSettings["MemorySignatures_SearchHeapSpace"] == "True")
                        SearchHeap = true;
                //search loaded module list (dlls)?
                bool SearchLoadedModuleList = false;
                if (AgentSettings.ContainsKey("MemorySignatures_SearchLoadedModules"))
                    if (AgentSettings["MemorySignatures_SearchLoadedModules"] == "True")
                        SearchLoadedModuleList = true;
                //search registry findings in process?
                bool SearchForRegistryFindings = false;
                if (AgentSettings.ContainsKey("MemorySignatures_UseRegistryFindings"))
                    if (AgentSettings["MemorySignatures_UseRegistryFindings"] == "True")
                        SearchForRegistryFindings = true;

                //perform scan
                MemoryScanner.ScanForMemorySignatures(AgentSignatureMatches.RegistrySignatureMatches, AgentMemorySignatures, ref AgentSignatureMatches.MemorySignatureMatches, SearchCmdLine, SearchHeap, SearchLoadedModuleList, SearchForRegistryFindings);

                //append the memory scanner log
                AgentScanLog.AppendLine(MemoryScanner.MemoryHelperLog.ToString());
                AgentScanLog.AppendLine("SCAN:  Process scan complete.");
            }

            //calculate total # of findings
            TotalFindingsCount = 0;

            if (AgentSignatureMatches.RegistrySignatureMatches != null)
                TotalFindingsCount += AgentSignatureMatches.RegistrySignatureMatches.Length;
            if (AgentSignatureMatches.FileSignatureMatches != null)
                TotalFindingsCount += AgentSignatureMatches.FileSignatureMatches.Length;
            if (AgentSignatureMatches.MemorySignatureMatches != null)
                TotalFindingsCount += AgentSignatureMatches.MemorySignatureMatches.Length;

            //unload NTUSER.DAT files
            RegistryScanner.LoadNtUserDatFiles(true);

            /*
            StreamWriter sw = new StreamWriter("AgentScanLog.txt");
            sw.WriteLine(AgentScanLog.ToString());
            sw.Close();*/

            return true;
        }
예제 #8
0
        /////////////////////////////////////////////////////
        //                                                 //
        // DoMitigate()                                    //
        //                                                 //
        /////////////////////////////////////////////////////
        //Description:  Performs various mitigation tasks, such
        //              as usb device disabling.
        //
        //              NOTE:  depends on DoSignatureScan()
        //
        //Returns:      true if successful
        //////////////////////////////////////////////////////
        private unsafe bool DoMitigate()
        {
            AgentScanLog.AppendLine("");
            AgentScanLog.AppendLine("*********************************************");
            AgentScanLog.AppendLine("            MITIGATE/CLEAN                   ");
            AgentScanLog.AppendLine("*********************************************");
            AgentScanLog.AppendLine("");

            //remove file references we found in registry from disk?
            bool removeReferences = false;
            if (AgentSettings.ContainsKey("Option_Delete_MalwareFoundInRegistry"))
                if (AgentSettings["Option_Delete_MalwareFoundInRegistry"] == "True")
                    removeReferences = true;

            //instantiate our helper classes
            RegistryHelper RegHelper = new RegistryHelper();
            FileHelper FileHelper = new FileHelper();
            MemoryHelper MemHelper = new MemoryHelper();

            if (AgentSignatureMatches.RegistrySignatureMatches != null)
                if (AgentSignatureMatches.RegistrySignatureMatches.Length > 0)
                    RegHelper.CleanRegistryFindings(ref AgentSignatureMatches.RegistrySignatureMatches, removeReferences);
            if (AgentSignatureMatches.FileSignatureMatches != null)
                if (AgentSignatureMatches.FileSignatureMatches.Length > 0)
                    FileHelper.CleanFileFindings(ref AgentSignatureMatches.FileSignatureMatches);
            if (AgentSignatureMatches.MemorySignatureMatches != null)
                if (AgentSignatureMatches.MemorySignatureMatches.Length > 0)
                    MemHelper.CleanMemoryFindings(ref AgentSignatureMatches.MemorySignatureMatches);

            //=============================================
            //          Disable/Disassociate autorun
            //=============================================
            if (AgentSettings["Option_Disable_Autorun"] == "True")
                Mitigate.DisableAndDisassociateAutorun();

            //=============================================
            //          Disable USB
            //=============================================
            if (AgentSettings["Option_Disable_USB"] == "True")
                Mitigate.DisableUseOfUSBDevices();

            AgentScanLog.AppendLine("MITIGATE:  Cleanup process complete.");
            AgentScanLog.AppendLine("MITIGATE:  Closing log file...");
            AgentScanLog.AppendLine("FINALIZE:  Codeword exiting on " + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));

            return true;
        }
예제 #9
0
        /////////////////////////////////////////////////////
        //                                                 //
        // DoCollect()                                     //
        //                                                 //
        /////////////////////////////////////////////////////
        //Description:  Collects all files identified in the scan
        //              as malicious and stuffs them into a
        //              password-protected, encrypted ZIP file.
        //
        //              NOTE:  depends on DoSignatureScan()
        //
        //
        //Returns:      true if successful
        //////////////////////////////////////////////////////
        private unsafe bool DoCollect()
        {
            AgentScanLog.AppendLine("");
            AgentScanLog.AppendLine("*********************************************");
            AgentScanLog.AppendLine("                  COLLECT                    ");
            AgentScanLog.AppendLine("*********************************************");
            AgentScanLog.AppendLine("");
            AgentScanLog.AppendLine("COLLECT:  Collecting evidence files...");

            //collect the following files to wrap up in archive file:
            //  1. all identified malware files
            //  2. infection log (Infection_Log.txt) which we create
            //  3. usb device list file (USB_Devices.txt) which we create
            //  4. .net installation log (if exists)
            //

            //---------------------------------
            //          BUILD ZIP NAME
            //---------------------------------
            ZipFileName = Collect.BuildZipName(TotalFindingsCount);
            ZipFile zip = new ZipFile(ZipFileName);

            if (AgentSettings.ContainsKey("Reporting_Archive_Password"))
            {
                IntPtr pptr = IntPtr.Zero;
                //do this secure string thing if password specified
                char[] str = AgentSettings["Reporting_Archive_Password"].ToCharArray();

                fixed (char* pChars = str)
                {
                    ZipPassword = new SecureString(pChars, str.Length);
                }

                //decrypt our password in memory
                pptr = Marshal.SecureStringToBSTR(ZipPassword);
                zip.Password = Marshal.PtrToStringBSTR(pptr);

                //zero the password memory
                Marshal.ZeroFreeBSTR(pptr);
            }

            zip.TempFileFolder = ".";
            ArrayList CollectList = new ArrayList();
            int count = 0;

            AgentScanLog.AppendLine("COLLECT:  Searching file signature matches for files...");

            //loop through file signatures
            foreach (CwXML.FileSignatureMatch fileMatch in AgentSignatureMatches.FileSignatureMatches)
                if (Collect.AddToZip(zip, fileMatch.FullPath))
                    count++;

            AgentScanLog.AppendLine("COLLECT:  Added " + count + " files.");
            count = 0;
            AgentScanLog.AppendLine("COLLECT:  Searching registry signature matches for files...");

            //loop through registry signatures
            foreach (CwXML.RegistrySignatureMatch registryMatch in AgentSignatureMatches.RegistrySignatureMatches)
                if (registryMatch.IsFileOnDisk)
                    if (Collect.AddToZip(zip, registryMatch.RegistryValueData))
                        count++;

            AgentScanLog.AppendLine("COLLECT:  Added " + count + " files.");
            AgentScanLog.AppendLine("COLLECT:  Generating infection summary report...");

            //---------------------------------
            //          ADD INFECTION LOG
            //---------------------------------
            //2.  infection log (Infection_Log.txt) which we create
            StreamWriter infectionlog = new StreamWriter("InfectionLog.txt");
            StringBuilder InfectionSummaryReport = new StringBuilder();

            //print infection summary for each signature type
            RegistryHelper RegHelper = new RegistryHelper();
            FileHelper FileHelper = new FileHelper();
            MemoryHelper MemHelper = new MemoryHelper();
            RegHelper.PrintRegistryFindings(AgentSignatureMatches.RegistrySignatureMatches, ref InfectionSummaryReport);
            FileHelper.PrintFileFindings(AgentSignatureMatches.FileSignatureMatches, ref InfectionSummaryReport);
            MemHelper.PrintMemoryFindings(AgentSignatureMatches.MemorySignatureMatches, ref InfectionSummaryReport);
            infectionlog.WriteLine(InfectionSummaryReport.ToString());
            infectionlog.Close();
            zip.AddFile("InfectionLog.txt");

            AgentScanLog.AppendLine("COLLECT:  Enumerating USB Devices...");

            //---------------------------------
            //          ADD USB DEVICES LOG
            //---------------------------------
            //3.  usb device list file (USB_Devices.txt) which we create
            StreamWriter usblogfile = new StreamWriter("USB_Devices.txt");
            StringBuilder UsbDevicesReport = new StringBuilder();
            Collect.EnumerateUSBDevices(ref UsbDevicesReport);
            usblogfile.WriteLine(UsbDevicesReport.ToString());
            usblogfile.Close();
            zip.AddFile("USB_Devices.txt");

            //---------------------------------
            //          ADD .NET LOG
            //---------------------------------
            //4.  .net installation log (if exists)
            try
            {
                FileInfo dotnetfxLogfile = new FileInfo("dotnetfx_install_log.txt");
                if (dotnetfxLogfile.Exists)
                    zip.AddFile("dotnetfx_install_log.txt");
            }
            catch { } //no biggie..

            AgentScanLog.AppendLine("COLLECT:  All evidence collected.");
            AgentScanLog.AppendLine("COLLECT:  Saving zip to disk...");
            zip.Save();
            zip.Dispose();  //at this point zip is closed and written to disk

            return true;
        }
예제 #10
0
        /// <summary>
        /// Manipulates the files.
        /// </summary>
        /// <returns>The path to the project file</returns>
        private string GetNewProjectFile()
        {
            string tempPath = string.Empty;
            // string k2DeployFolder = string.Empty;
            FileHelper fileHelper = new FileHelper();

            //Get the project folder
            string projectFolder = fileHelper.GetFolderFromPath(ProjectFilePath);
            LogHelper.LogMessage("      Project Folder: " + projectFolder);

            // Get the Project File Path
            string projectFile = fileHelper.GetFileNameFromPath(ProjectFilePath);
            LogHelper.LogMessage("      Project File: " + projectFile);

            LogHelper.LogMessage("   -- Getting path to a temporary folder for the K2 project files");
            tempPath = fileHelper.GetTempDirectory();

            TempDeployFolderPath = tempPath + @"\K2Deploy";

            LogHelper.LogMessage("      Temp Folder: " + TempDeployFolderPath);
            LogHelper.LogMessage("   -- Cleaning up files from any previous builds");
            fileHelper.DeleteDirectory(TempDeployFolderPath);

            LogHelper.LogMessage("   -- Copying files to the temp folder");
            fileHelper.CopyFolder(projectFolder, TempDeployFolderPath);
            LogHelper.LogMessage("      Files copied from '" + projectFolder + "' to '" + TempDeployFolderPath + "'");

            //Ensure we have access to all the files.
            LogHelper.LogMessage("   -- Setting ACL on folders and files in '" + TempDeployFolderPath + "'");
            bool success = fileHelper.SetAcl(TempDeployFolderPath, "F", true);
            if (!success) throw new Exception("Failed to set ACLs on folder " + TempDeployFolderPath);

            //Ensure the files are all writable
            LogHelper.LogMessage("   -- Setting writable permissions for folder: " + TempDeployFolderPath);
            fileHelper.SetWritable(TempDeployFolderPath);

            LogHelper.LogMessage("   -- Getting the Project File Path in Temp Folder");
            string newProjectFilePath = TempDeployFolderPath + @"\" + ProjectFilePath.Substring(1 + ProjectFilePath.LastIndexOf('\\'));
            LogHelper.LogMessage("      New Project File: " + newProjectFilePath);

            return newProjectFilePath;
        }
예제 #11
0
        private bool BuildCompileAndSaveProject(string projectFilePath,string outputPath,EnvironmentSettingsManager environmentManager, int stepNumber)
        {
            Project project;
            DeploymentPackage package;
            bool result = false;

            #region 4. Build

            LogHelper.LogMessage(String.Format("\n{0}.1 Beginning Build",stepNumber));
            LogHelper.LogMessage("   -- Loading project file: " + projectFilePath);
            project = new Project();
            project.Load(projectFilePath);

            LogHelper.LogMessage("   -- Building Project");
            result = K2Helper.CompileK2Project(project);

            if (!result)
                throw new Exception("The Project did not Compile successfully.\n");

            #endregion

            #region 5. Deployment Package Creation

            LogHelper.LogMessage(String.Format("\n{0}.2 Creating the Deployment Package",stepNumber));
            package = K2Helper.CreateDeploymentPackage(
                project, environmentManager, DeployLabel, DeployDescription, testOnly);

            #endregion

            #region 6. Save Deployment Package

            LogHelper.LogMessage(String.Format("\n{0}.3. Saving Deployment Package to '" + OutputPath + "'",stepNumber));
            FileHelper fileHelper = new FileHelper();
            fileHelper.DeleteDirectory(outputPath);

            package.Save(outputPath, "K2DeploymentPackage");
            LogHelper.LogMessage("   -- Package Saved");

            #endregion

            return result;
        }
예제 #12
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            EnvironmentSettingsManager environmentManager;

            string newProjectFilePath = string.Empty;
            bool result = false;

            int currentStep=0;

            // below if block added to check for and purge old cache file if it exists
            if (BinFileToDelete != string.Empty)
            {
                if (System.IO.File.Exists(BinFileToDelete))
                {
                    try
                    {
                        System.IO.File.Delete(BinFileToDelete);
                    }
                    catch (System.IO.IOException e)
                    {
                        LogHelper.LogMessage("\n\n*****Environment Cache Could Not Be Deleted*******\n");
                        LogHelper.LogMessage(e.Message.ToString());
                    }
                }
            }

            LogHelper.LogMessage("\n\n*****     BEGIN       *******\n");

            try
            {

                //check if file exists
                    //delete file

                #region 1. Validation
                LogHelper.LogStep(++currentStep, "Validating");
                ValidateK2Project();

                #endregion

                #region 2. Gather Environment Information
                LogHelper.LogStep(++currentStep, "Preparing Environment");
                LogHelper.LogMessage("   -- Getting K2 Environment Manager");

                environmentManager =
                    K2Helper.GetEnvironmentManager(ConnectionString, Environment, UseEnvironmentCache);

                #endregion

                #region 3. File Preparation
                LogHelper.LogStep(++currentStep,"Preparing Project files");

                //Edgar
                Dictionary<string, string> dictFiles = null;
                //check if the user want to compile the project as a whole or artifacts individually
                if (CompileProjectArtifactsIndividually)
                {
                    dictFiles = GetNewProjectFiles(ref newProjectFilePath);
                    LogHelper.LogMessage("\n3.1 Project files created in Temporary folder");

                    //we next need to create backup of the original file
                    FileHelper fileHelper = new FileHelper();

                    fileHelper.CopyFile(newProjectFilePath, newProjectFilePath + ".bak", true);
                    LogHelper.LogMessage("File has been backed up = "+ newProjectFilePath);

                    foreach (KeyValuePair<string, string> kvp in dictFiles)
                    {
                      //  currentStep += 1;
                        string artifactName = kvp.Key;
                        string newOutputPath = outputPath + @"\" + artifactName;

                        //we need to replace the original file w/ this one.
                       fileHelper.ReplaceFile(newProjectFilePath, kvp.Value);

                        //it will always compile the the project under the original name;
                        result = BuildCompileAndSaveProject(newProjectFilePath, newOutputPath, environmentManager,currentStep);
                        currentStep += 1;
                    }

                    fileHelper = null;
                }
                else {
                //default behavior as originally coded
                    newProjectFilePath = GetNewProjectFile();
                    LogHelper.LogMessage("\n3.1 Project files created in Temporary folder");

                    BuildCompileAndSaveProject(newProjectFilePath, outputPath, environmentManager, currentStep);
                    currentStep += 1;
                }
                //Edgar//
                #endregion
            /*
                #region 7. Execute Deployment Package

                // Execute the Deployment Package
                LogHelper.LogMessage("\nExecuting deployment package...");
                results = package.Execute();

                // Record success result
                result = results.Successful;
                LogHelper.LogMessage("\nSuccessful = " + result);

                #endregion
            */

                result = true;
            }
            catch(Exception ex)
            {
                LogHelper.LogMessage(ex.ToString());
                throw;
            }
            finally
            {
                LogHelper.LogMessage("\n*****       END       *******\n\n");
            }

            return result;
        }
예제 #13
0
        private void OnDumpRequested(MsgDump obj)
        {
            FileHelper fWriter = new FileHelper();

            if (obj.Key == "VM")
            {
                Log.DebugFormat("Try to write mapping to {0}", obj);
                List<ValueMapping> list = new List<ValueMapping>();

                foreach (KeyValuePair<int, ValueMapping> entry in VirtualToDMXMapping)
                {
                    list.Add(VirtualToDMXMapping[entry.Key]);
                }
                list.Add(VirtualToImgMapping);
                foreach (KeyValuePair<int, ValueMapping> entry in DMXToVirtualMapping)
                {
                    list.Add(DMXToVirtualMapping[entry.Key]);
                }
                list.Add(ImgToVirtualMapping);
                fWriter.WriteAsXml<ValueMapping>(list, obj.Filename);
            }

            if (obj.Key == "VMSETUP")
            {
                List<KeyValuePair<int, List<DMXImgSetupMappingValue>>> list = new List<KeyValuePair<int, List<DMXImgSetupMappingValue>>>();
                foreach (KeyValuePair<int, List<DMXImgSetupMappingValue>> item in DMXSetupValues)
                {
                    list.Add(item);
                }

                List<KeyValuePair<int, Position>> list2 = new List<KeyValuePair<int, Position>>();
                foreach (KeyValuePair<int, Position> pos in ImgSetupPositions)
                {
                    list2.Add(pos);
                }

                try
                {
                    fWriter.WriteAsXml<KeyValuePair<int, List<DMXImgSetupMappingValue>>>(list, obj.Filename);
                }
                catch (Exception e)
                {
                    Log.Fatal(e);
                }
                try
                {
                    fWriter.WriteAsXml<KeyValuePair<int, Position>>(list2, obj.Filename, true);
                }
                catch (Exception e)
                {
                    Log.Fatal(e);
                }
            }
        }
예제 #14
0
            /////////////////////////////////////////////////////
            //                                                 //
            // ToggleDotnetSecurity()                          //
            //                                                 //
            /////////////////////////////////////////////////////
            //Description:  Attempts to disable all .NET security
            //              settings with the caspol program.  To
            //              find this program, a full disk search
            //              is performed on any caspol for any .NET
            //              version, so all versions are rendered
            //              insecure.
            //Returns:      true if successful
            /////////////////////////////////////////////////////
            public static bool ToggleDotnetSecurity(string action, string mode)
            {
                ArrayList fileFolderCount = new ArrayList();
                fileFolderCount.Add(0);
                fileFolderCount.Add(0);
                FileHelper fh = new FileHelper();
                ArrayList caspols = fh.FileSearch("C:\\Windows\\Microsoft.NET\\Framework", "caspol.exe", "", "", "", "");

                //AgentScanLog.AppendLine(mode + ":  Found " + caspols.Count.ToString() + " caspol.exe programs.");

                if (caspols.Count == 0)
                {
                    AgentScanLog.AppendLine("WARNING:  Could not find caspol.exe.  .NET installation may be corrupt.  Continuing...");
                    return false;
                }
                else
                {
                    //call each caspol.exe for each version of .NET to disable them all
                    foreach (string caspol in caspols)
                    {
                        //AgentScanLog.AppendLine(mode + ":  Executing '" + caspol + "'...");

                        //kick off a new process for this caspol.exe execution - pass args to turn off security
                        System.Diagnostics.Process p = System.Diagnostics.Process.Start(caspol, "–polchgprompt off -security " + action + " -quiet");

                        //wait for the process to finish
                        while (!p.HasExited)
                        {
                        }

                        //AgentScanLog.AppendLine(mode + ":  Success.  File executed.");
                    }
                    AgentScanLog.AppendLine(mode + ":  Successfully turned " + action.ToUpper() + " .NET security.");
                    //AgentScanLog.AppendLine(mode + ":  Success.  All caspol's executed.");
                }

                return true;
            }
예제 #15
0
        public List<IHistoryItem> LoadHistory(string inputFileFullname)
        {
            if (!File.Exists(inputFileFullname))
            {
                return new List<IHistoryItem>();
            }

            var readLines = new FileHelper().ReadAllLines(inputFileFullname);
            string value = readLines.Aggregate(string.Empty, (current, line) => current + line);

            return new List<IHistoryItem>(JsonConvert.DeserializeObject<List<HistoryItem>>(value));
        }
예제 #16
0
        public void RegisterAndDownLoadReg()
        {
            try
            {
                string dbName = _request["dbName"];
                string appName = _request["appName"];
                string serverName = _request["serverName"];
                string userName = _request["userName"];
                string saPassword = _request["saPassword"];
                string serverProt = _request["serverProt"];
                string customerName = _request["customerName"];
                string subkey = @"software\mysoft\" + appName;
                string fullRegPath = @"[HKEY_LOCAL_MACHINE\SOFTWARE\mysoft\" + appName + "]";
                string regName = customerName + ".reg";

                saPassword = Cryptogram.EnCode(saPassword);

                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Windows Registry Editor Version 5.00");
                sb.AppendLine(fullRegPath);
                sb.AppendLine("\"DBName\"=\"" + dbName + "\"");
                sb.AppendLine("\"IsConnectSl\"=\"0\"");
                sb.AppendLine("\"IsRead\"=\"1\"");
                sb.AppendLine("\"SaPassword\"=\"" + saPassword + "\"");
                sb.AppendLine("\"ServerName\"=\"" + serverName.Replace(@"\", @"\\") + "\"");
                sb.AppendLine("\"ServerProt\"=\"" + serverProt + "\"");
                sb.AppendLine("\"UserName\"=\"" + userName + "\"");

                string filePath = System.Threading.Thread.GetDomain().BaseDirectory + "RegFile\\"; ;
                FileHelper fileHelper = new FileHelper(regName, filePath, regName);
                fileHelper.DeleteFile();
                fileHelper.WriteFile(sb.ToString());
                // fileHelper.DownFile(Response);

                _response.Write(filePath + "|" + regName);
            }
            catch (Exception ex)
            {
                ErrorHandler.ExceptionHandlerForWeb("SrcCodeManageAjax.RegisterAndDownLoadReg", ex.ToString());
                _response.Write(FlagEnum.Error);
            }
        }