Exemplo n.º 1
0
        public async Task SaveScanResourceTest()
        {
            int result = 0;
            await RestClient.Instance.SignIn();

            ScanResourceModel model;


            model         = new ScanResourceModel();
            model.Name    = "WebPageHtmlSource";
            model.Version = "1.0.0";
            model.ScanPrerequisiteName = "puppeteer";
            model.Resources            = await File.ReadAllBytesAsync(RootPath + "WebPageHtmlSourceWorker.zip" /*Utility.GetExecutionPath() + "\\WebPageHtmlSourceWorker.zip*/);

            result = await RestClient.Instance.PostAsync <int>("Scan/SaveScanResource", model);


            model         = new ScanResourceModel();
            model.Name    = "WebPageScreenshotWorker";
            model.Version = "1.0.0";
            model.ScanPrerequisiteName = "puppeteer";
            model.Resources            = await File.ReadAllBytesAsync(RootPath + "WebPageScreenshotWorker.zip");

            result = await RestClient.Instance.PostAsync <int>("Scan/SaveScanResource", model);


            model         = new ScanResourceModel();
            model.Name    = "WebPageSpider";
            model.Version = "1.0.0";
            model.ScanPrerequisiteName = "puppeteer";
            model.Resources            = await File.ReadAllBytesAsync(RootPath + "WebPageSpider.zip");

            result = await RestClient.Instance.PostAsync <int>("Scan/SaveScanResource", model);


            //model = new ScanResourceModel();
            //model.Name = "TerminalWorker";
            //model.Version = "1.0.0";
            //model.Resources = await File.ReadAllBytesAsync(Utility.GetExecutionPath() + "\\TerminalWorker.zip");
            //result = await RestClient.Instance.PostAsync<int>("Scan/SaveScanResource", model);

            //model = new ScanResourceModel();
            //model.Name = "Dollars";
            //model.Version = "1.0.0";
            //model.ScanPrerequisiteName = "puppeteer";
            //model.Resources = await File.ReadAllBytesAsync(Utility.GetExecutionPath() + "\\Dollars.zip");
            //result = await RestClient.Instance.PostAsync<int>("Scan/SaveScanResource", model);

            // model = new ScanResourceModel();
            // model.Name = "nmap_windows";
            // model.Version = "1.0.0";
            //// model.ScanPrerequisiteName = "nmap_windows";
            // model.Resources = await File.ReadAllBytesAsync(Utility.GetExecutionPath() + "\\NmapWorker.zip");
            // result = await RestClient.Instance.PostAsync<int>("Scan/SaveScanResource", model);

            Assert.AreEqual(result, 1);
        }
Exemplo n.º 2
0
        internal static async Task <DirectoryInfo> GetResourceDirectory(ScanModel model)
        {
            await _semaphoreSlim.WaitAsync();

            DirectoryInfo resourceFolder = null;

            try
            {
                DirectoryInfo preReqFolder       = null;
                string        resourceFolderPath = null;
                if (!String.IsNullOrEmpty(model.PrerequisiteName))
                {
                    if (!IsScanPrereqExist(model.PrerequisiteName))
                    {
                        ScanPrerequisiteModel prerequisiteModel = await KamajiClient.Instance.Scans.GetScanPrerequisiteBy(model.PrerequisiteName);

                        preReqFolder = await CreateScanPrereqFolder(prerequisiteModel.Name, prerequisiteModel.Resources);
                    }
                    else
                    {
                        preReqFolder = GetExistPrereq(model.PrerequisiteName);
                    }

                    resourceFolderPath = preReqFolder.FullName + "\\" + model.ResourceName;
                }
                else
                {
                    resourceFolderPath = ScanResourcesPath + model.ResourceName;//if it has no prereq, just copy to the root folder.
                }
                if (!Directory.Exists(resourceFolderPath))
                {
                    ScanResourceModel resourceModel = await KamajiClient.Instance.Scans.GetScanResourceBy(model.ResourceName);

                    if (null != resourceModel)
                    {
                        byte[] resources = resourceModel.Resources;
                        resourceFolder = Directory.CreateDirectory(resourceFolderPath);

                        await ExtractZip(resourceFolderPath, resources);
                    }
                }
                else
                {
                    resourceFolder = new DirectoryInfo(resourceFolderPath);
                }
            }
            finally
            {
                _semaphoreSlim.Release();
            }

            return(resourceFolder);
        }
Exemplo n.º 3
0
        [HttpGet]//Node bunu çağırıyor.
        public Task <IActionResult> GetScanResourceBy(string name)
        {
            return(this.ResultAsync(async() =>
            {
                ScanResourceModel ret = null;
                if (!String.IsNullOrEmpty(name))
                {
                    IScanResourceModel entity = await this.Db.ScanResources.GetBy(name);
                    if (null != entity)
                    {
                        ret = new ScanResourceModel();
                        ret.CopyPropertiesFrom(entity);

                        ret.ScanPrerequisiteName = await this.Db.ScanPrerequisites.GetNameBy(entity.ScanPrerequisiteId);
                    }
                }

                return ret;
            }));
        }
Exemplo n.º 4
0
        public Task <IActionResult> SaveScanResource(ScanResourceModel model)
        {
            return(this.ResultAsync(async() =>
            {
                int ret = 0;
                if (model.IsModelValid())
                {
                    IScanResourceModel entity = this.Db.ModelFactory.CreateScanResourceModel();
                    entity.CopyPropertiesFrom(model);
                    entity.CreatedDate = await this.Db.GetDbDateTime();
                    entity.LastModifiedDate = entity.CreatedDate;

                    if (!String.IsNullOrEmpty(model.ScanPrerequisiteName))
                    {
                        entity.ScanPrerequisiteId = await this.Db.ScanPrerequisites.GetScanPrerequisiteId(model.ScanPrerequisiteName);//a scan may not have an prerequest.
                    }
                    await this.Db.ScanResources.Save(entity);
                    ret = 1;
                }

                return ret;
            }));
        }