Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="templateFile"></param>
        private void LoadAttackTemplate(string templateFile)
        {
            this.templateFile = templateFile;

            // Verify if input file is  correct.
            if (string.IsNullOrEmpty(templateFile))
            {
                throw new Exception("Something is wrong with the template file");
            }

            if (!File.Exists(templateFile))
            {
                throw new Exception("The template file does not exist");
            }

            if (Path.GetExtension(templateFile).ToLower() != $".{Minary.Config.MinaryFileExtension}")
            {
                throw new Exception("The defined file is no Minary template file");
            }

            // Load tepmlate data into object
            this.TemplateData = this.infrastructure.LoadAttackTemplate(templateFile);
            this.callObj      = new Calls(this.minaryMain, this.TemplateData);

            // Activate relevant plugins. Deactivate non-relevant plugins
            this.HideAllTabPages();
            this.LoadPlugins();
            this.ExecuteArpScan();
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="serializableObject"></param>
        /// <param name="outputFile"></param>
        public void SaveTemplate(MinaryTemplateData serializableObject, string outputFile)
        {
            BinaryFormatter myBinaryFormat   = new BinaryFormatter();
            FileStream      outputFileStream = new FileStream(outputFile, FileMode.Create);

            myBinaryFormat.Serialize(outputFileStream, serializableObject);
            outputFileStream.Close();
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="templateData"></param>
 private void TrimTemplateData(MinaryTemplateData templateData)
 {
     if (templateData.AttackConfig.IsAdvancedScan == 0)
     {
         templateData.AttackConfig.NumberSelectedTargetSystems = 0;
         templateData.AttackConfig.ScanNetwork = 0;
         templateData.AttackConfig.StartAttack = 0;
     }
 }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="templateObj"></param>
        /// <param name="outputFilePath"></param>
        public void SaveAttackTemplate(MinaryTemplateData templateObj, string outputFilePath)
        {
            // Verify if objects were instantiated
            if (templateObj == null)
            {
                throw new Exception("Something is wrong with the template");
            }

            if (templateObj.TemplateConfig == null)
            {
                throw new Exception("Something is wrong with the template configuration");
            }

            if (templateObj == null ||
                templateObj.Plugins == null)
            {
                throw new Exception("Something is wrong with the plugin data");
            }

            // Verify passed values
            if (templateObj.Plugins.Count == 0)
            {
                throw new Exception("You must activate at least one plugin to create a valid template");
            }

            if (string.IsNullOrEmpty(templateObj.TemplateConfig.Name))
            {
                throw new Exception("Something is wrong with the template name");
            }

            if (string.IsNullOrEmpty(templateObj.TemplateConfig.Description))
            {
                throw new Exception("Something is wrong with the template description");
            }

            if (string.IsNullOrEmpty(templateObj.TemplateConfig.Reference))
            {
                throw new Exception("Something is wrong with the template reference URL");
            }

            if (string.IsNullOrEmpty(templateObj.TemplateConfig.Author))
            {
                throw new Exception("Something is wrong with the author name");
            }

            if (string.IsNullOrEmpty(templateObj.TemplateConfig.Timestamp))
            {
                throw new Exception("Something is wrong with the time stamp");
            }

            if (string.IsNullOrEmpty(outputFilePath))
            {
                throw new Exception("Something is wrong with the output file");
            }

            this.infrastructure.SaveTemplate(templateObj, outputFilePath);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="newTemplateData"></param>
        /// <returns></returns>
        private bool TemplateParametersAreValid(MinaryTemplateData newTemplateData)
        {
            if (newTemplateData == null)
            {
                throw new Exception("Template object is invalid");
            }

            if (newTemplateData.TemplateConfig == null)
            {
                throw new Exception("Config section is invalid");
            }

            if (string.IsNullOrEmpty(newTemplateData.TemplateConfig.Name))
            {
                throw new Exception("The template name is invalid");
            }

            if (string.IsNullOrEmpty(newTemplateData.TemplateConfig.Description))
            {
                throw new Exception("The template description is invalid");
            }

            if (string.IsNullOrEmpty(newTemplateData.TemplateConfig.Version))
            {
                throw new Exception("The tmeplate version is invalid");
            }

            if (string.IsNullOrEmpty(newTemplateData.TemplateConfig.Reference))
            {
                throw new Exception("The template reference URL is invalid");
            }

            Uri uriResult;

            if (!Uri.TryCreate(newTemplateData.TemplateConfig.Reference, UriKind.Absolute, out uriResult) ||
                !(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps))
            {
                throw new Exception("The template reference URL is invalid");
            }

            if (string.IsNullOrEmpty(newTemplateData.TemplateConfig.Author))
            {
                throw new Exception("The template author is invalid");
            }

            if (newTemplateData.AttackConfig.NumberSelectedTargetSystems <= 0)
            {
                throw new Exception("The \"Maximum number target systems\" is invalid");
            }

            return(true);
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="templateFile"></param>
        private void LoadAttackTemplate(string templateFile)
        {
            this.templateFile = templateFile;

            // Verify if input file is  correct.
            if (string.IsNullOrEmpty(templateFile))
            {
                throw new Exception("Something is wrong with the template file");
            }

            if (!File.Exists(templateFile))
            {
                throw new Exception("The template file does not exist");
            }

            if (Path.GetExtension(templateFile).ToLower() != $".{Minary.Config.MinaryFileExtension}")
            {
                throw new Exception("The defined file is no Minary template file");
            }

            // Load tepmlate data into object
            this.TemplateData = this.infrastructure.LoadAttackTemplate(templateFile);
            this.callObj      = new Calls(this.minaryMain, this.TemplateData);

            // Set debugging status
            bool isDebuggingOn = this.TemplateData.AttackConfig.IsDebuggingOn == 1 ? true : false;

            this.minaryMain.SetDebuggingStatus(isDebuggingOn);

            // Open simple attack GUI
            if (this.TemplateData.AttackConfig.IsAdvancedScan == 0)
            {
                this.LoadPlugins();
                this.OpenSimpleGui();
                this.AddMessage("Simple GUI opened", "Simple GUI");
                this.AddMessage("Loading template done.", "Template");
                this.AddMessage("Closing this view in 5 seconds ...", "Template");
                this.CloseFormInXSeconds(5);
                return;
            }


            // Open advanced GUI
            // 1. Hide all tabs
            // 2. Load Plugins
            // 3. ARP scan
            // 4. Attack

            this.HideAllTabPages();
            this.LoadPlugins();
            this.ExecuteArpScan();
        }
Beispiel #7
0
        public bool IsFileATemplate(string filePath)
        {
            bool retVal = false;

            try
            {
                MinaryTemplateData deserializedObjectData = this.LoadAttackTemplate(filePath);
                if (deserializedObjectData != null)
                {
                    retVal = true;
                }
            }
            catch
            {
            }

            return(retVal);
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="newTemplateData"></param>
        private void SaveTemplateToFile(MinaryTemplateData newTemplateData)
        {
            // Add .mry extension if missing
            var minaryFileExtension = $".{Minary.Config.MinaryFileExtension}";

            if (!this.sfd_TemplateFile.FileName.ToLower().EndsWith(minaryFileExtension))
            {
                this.sfd_TemplateFile.FileName += minaryFileExtension;
            }

            // Serialize and save template
            this.taskLayerCreateTemplate.SaveAttackTemplate(newTemplateData, this.sfd_TemplateFile.FileName);
            var message = $"Template \"{newTemplateData.TemplateConfig.Name}\" was saved successfully.";

            MessageDialog.Inst.ShowInformation(string.Empty, message, this);

            base.Dispose(true);
        }
Beispiel #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bt_Save_Click(object sender, EventArgs e)
        {
            // Create and populate temlate object
            var newTemplateData = new MinaryTemplateData();

            newTemplateData.TemplateConfig.Name        = this.tb_TemplateName.Text;
            newTemplateData.TemplateConfig.Description = this.tb_TemplateDescription.Text;
            newTemplateData.TemplateConfig.Reference   = this.tb_TemplateReferenceLink.Text;
            newTemplateData.TemplateConfig.Author      = this.tb_AuthorName.Text;
            newTemplateData.TemplateConfig.Version     = this.tb_Version.Text;

            // Configure attack settings
            int tmpNumberSelectedTargetSystems = -1;

            int.TryParse(this.tb_MaxNoTargetSystems.Text, out tmpNumberSelectedTargetSystems);
            newTemplateData.AttackConfig.NumberSelectedTargetSystems = tmpNumberSelectedTargetSystems;
            newTemplateData.AttackConfig.ScanNetwork    = this.cb_ArpScan.Checked ? 1 : 0;
            newTemplateData.AttackConfig.StartAttack    = this.cb_StartAttackingTargets.Checked ? 1 : 0;
            newTemplateData.AttackConfig.IsAdvancedScan = this.rb_GuiAdvanced.Checked ? 1 : 0;
            newTemplateData.AttackConfig.IsDebuggingOn  = this.rb_DebuggingOn.Checked ? 1 : 0;

            try
            {
                this.TemplateParametersAreValid(newTemplateData);
            }
            catch (Exception ex)
            {
                MessageDialog.Inst.ShowError(string.Empty, ex.Message, this);
                return;
            }

            // Plugin data
            foreach (TabPage tmpTabPage in this.minaryMain.MinaryTabPageHandler.VisibleTabPages)
            {
                Minary.DataTypes.MinaryExtension tmpExtension = this.minaryMain.PluginHandler.TabPagesCatalog[tmpTabPage.Text];
                TemplatePluginData tmpPluginData = tmpExtension.PluginObject.OnGetTemplateData();
                newTemplateData.Plugins.Add(new Plugin(tmpTabPage.Text, tmpPluginData));
            }

            // Show save file dialog
            this.sfd_TemplateFile.InitialDirectory = Path.Combine(Directory.GetCurrentDirectory(), Minary.Config.CustomTemplatesDir);
            this.sfd_TemplateFile.Filter           = $"Minary template files|*.{Minary.Config.MinaryFileExtension}";
            this.sfd_TemplateFile.Title            = $"Export current configuration to a .{Minary.Config.MinaryFileExtension} file";
            this.sfd_TemplateFile.AddExtension     = true;
            DialogResult dialogResult = this.sfd_TemplateFile.ShowDialog();

            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }
            else if (string.IsNullOrEmpty(this.sfd_TemplateFile.FileName))
            {
                var message = "You didn't define an output file";
                MessageDialog.Inst.ShowWarning(string.Empty, message, this);
                return;
            }

            // Save template to file system
            try
            {
                this.SaveTemplateToFile(newTemplateData);
                this.minaryMain.TemplateName.Text = newTemplateData.TemplateConfig.Name;
            }
            catch (Exception ex)
            {
                LogCons.Inst.Write(LogLevel.Error, $"Error occurred while saving template : {ex.Message}");
                string message = $"Error occurred while saving template : {ex.Message}";
                MessageDialog.Inst.ShowWarning(string.Empty, message, this);
            }
        }
Beispiel #10
0
 public Calls(MinaryMain minaryMain, MinaryTemplateData minaryTemplate)
 {
     this.minaryMain     = minaryMain;
     this.minaryTemplate = minaryTemplate;
     this.arpScanHandler = minaryMain.ArpScanHandler;
 }