Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("usage : dotnet run -\"Path\"\nPath should be Folder or file");
                Console.WriteLine("Example : dotnet run -\"D:\\Examples\"");
                return;
            }
            string path    = args[0].TrimStart('-');
            string argPath = path;

            path = path.TrimEnd('\\');
            if (!Directory.Exists(path) && !File.Exists(path))
            {
                Console.WriteLine($"{argPath} is invalid");
                return;
            }
            IEnumerable <VulnerabilityDetail> vulnerabilities;
            SASTApp sASTApp = new SASTApp();

            if (Directory.Exists(path))
            {
                sASTApp.LoadFolder(path);
            }
            else if (File.Exists(path))
            {
                sASTApp.LoadFiles(new string[] { path });
            }
            vulnerabilities = sASTApp.ScanAll();
            //File.Create(@"F:\Proto Geek\Task 1\Examples\output.txt");
            if (vulnerabilities != null)
            {
                foreach (var vul in vulnerabilities)
                {
                    File.AppendAllText(@"F:\Proto Geek\Task 1\Examples\output.txt", vul.ToString() + "\n");
                    //Console.WriteLine("\n" + vul);
                }
            }
            Console.WriteLine("Press any key to Exit");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public async Task <string> ScanPost([FromForm] IFormFile File)
        {
            if (File == null)
            {
                Response.StatusCode = 400;
                return("Please provide File parameter");
            }
            FileInfo fileInfo = new FileInfo(File.FileName);

            if (string.IsNullOrEmpty(fileInfo.Extension) || fileInfo.Extension.ToLower() != ".zip")
            {
                return("Please upload zip file only");
            }
            else
            {
                string result = string.Empty;
                //Create directory to extract
                try
                {
                    var extractDirectory = Path.Combine(_fileConfiguration.DirectoryPath, Path.GetFileNameWithoutExtension(File.FileName));
                    var filePath         = Path.Combine(_fileConfiguration.DirectoryPath, File.FileName);

                    if (!Directory.Exists(_fileConfiguration.DirectoryPath))
                    {
                        Directory.CreateDirectory(_fileConfiguration.DirectoryPath);
                    }

                    if (Directory.Exists(extractDirectory))
                    {
                        Directory.Delete(extractDirectory, true);
                    }

                    //Store zip file to Directory
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        File.CopyTo(stream);
                    }

                    //Etraction of Files to Folder
                    ZipFile.ExtractToDirectory(filePath, extractDirectory);

                    //Scanning of Files
                    SASTApp sASTApp = new SASTApp();
                    if (Directory.Exists(extractDirectory) && sASTApp.LoadFolder(extractDirectory))
                    {
                        Response.StatusCode = 200;
                        IEnumerable <VulnerabilityDetail> vulnerabilities = sASTApp.ScanAll();
                        result = Newtonsoft.Json.JsonConvert.SerializeObject(vulnerabilities);
                    }
                }
                catch (PathTooLongException _)
                {
                    Response.StatusCode = 400;
                    result = "File Name was too long, Please upload with short name";
                }
                catch (InvalidDataException _)
                {
                    Response.StatusCode = 400;
                    result = "Unable to extract files from corrupted zip File.";
                }
                catch (Exception otherException)
                {
                    Response.StatusCode = 400;
                    result = otherException.ToString();
                }
                return(result);
            }
        }