Пример #1
0
        public void TestHasKeywordInLargeString()
        {
            var Directories = new List <string> {
                ""
            };
            var Regex = new SauronEye.RegexSearch(new List <string> {
                "pass"
            });
            var Keywords = new List <string> {
                "pass"
            };
            var ContentSearcher = new SauronEye.ContentsSearcher(Directories, Keywords, Regex, 1024);

            var testCases = new Dictionary <string, string>();

            testCases.Add("this is a long string containing a password", "...g containing a password... ");
            testCases.Add("password is this yet another", "...password is this ye... ");
            testCases.Add("password", "...password... ");
            testCases.Add("not a wachtwoord", "");
            testCases.Add("another password in this test makes it to password twice", "...another password in this te... ...st makes it to password twice... ");
            testCases.Add("password begin and at the end password", "...password begin and ... ...and at the end password... ");
            testCases.Add("long path before the password=wetiife", "...ath before the password=wetiife... ");
            testCases.Add("this is anther password testcase that is a normal one", "...this is anther password testcase t... ");

            foreach (KeyValuePair <string, string> kvp in testCases)
            {
                Assert.AreEqual(kvp.Value, ContentSearcher.HasKeywordInLargeString(kvp.Key));
            }
        }
Пример #2
0
        public void TestLongPaths()
        {
            var LongDirectories = new List <string> {
                Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + @"\testfiles\ininfafasf ienflaflieflanfeifnalnfae\ininfafasf ienflaflieflanfeifnalnfae\ininfafasf ienflaflieflanfeifnalnfae\ininfafasf ienflaflieflanfeifnalnfae\ienflaflieflanfeifnalnfae\dfiwnfwnfwnfownefinewnf.txt",
            };
            var Regex = new SauronEye.RegexSearch(new List <string> {
                "pass"
            });
            var Keywords = new List <string> {
                "pass"
            };
            var ContentSearcher = new SauronEye.ContentsSearcher(LongDirectories, Keywords, Regex, 1024);

            ContentSearcher.Search();

            var currentConsoleOut = Console.Out;

            var outputPath  = @"ininfafasf ienflaflieflanfeifnalnfae\ininfafasf ienflaflieflanfeifnalnfae\ininfafasf ienflaflieflanfeifnalnfae\ininfafasf ienflaflieflanfeifnalnfae\ienflaflieflanfeifnalnfae\dfiwnfwnfwnfownefinewnf.txt";
            var outputMatch = @"this is pass";

            using (var consoleOutput = new ConsoleOutput())
            {
                ContentSearcher.Search();
                Assert.IsTrue(consoleOutput.GetOuput().Contains(outputPath));
                Assert.IsTrue(consoleOutput.GetOuput().Contains(outputMatch));
            }

            Assert.AreEqual(currentConsoleOut, Console.Out);
        }
Пример #3
0
        public void Search()
        {
            if (Directory.Exists(SearchDirectory))
            {
                FilesFilteredOnExtension = EnumerateFiles(SearchDirectory, "*.*", SearchOption.AllDirectories);
                foreach (string filepath in FilesFilteredOnExtension)
                {
                    if (ContainsKeyword(Path.GetFileName(filepath)))
                    {
                        Results.Add(filepath);
                    }
                }
                foreach (string i in Results)
                {
                    Console.WriteLine("[+] {0}", i);
                }

                // Now search contents
                if (searchContents)
                {
                    Console.WriteLine("[*] Done searching file system, now searching contents");
                    var contentsSearcher = new ContentsSearcher(FilesFilteredOnExtension, Keywords, RegexSearcher);
                    contentsSearcher.Search();
                }
            }
        }
Пример #4
0
        public void Search()
        {
            if (Directory.Exists(SearchDirectory))
            {
                FilesFilteredOnExtension = EnumerateFiles(SearchDirectory, "*.*", SearchOption.AllDirectories);
                foreach (string filepath in FilesFilteredOnExtension)
                {
                    if (ContainsKeyword(Path.GetFileName(filepath)))
                    {
                        Results.Add(filepath);
                    }
                }
                if (CheckForMacro)
                {
                    OLXExplorer = new OLEExplorer();
                }
                foreach (string i in Results)
                {
                    bool containsVBA = false;
                    if (CheckForMacro && EndsWithOffice2003Extension(i))
                    {
                        containsVBA = OLXExplorer.CheckForVBAMacros(i);
                        if (!containsVBA)
                        {
                            continue;
                        }
                    }
                    if (BeforeDate != DateTime.MinValue || AfterDate != DateTime.MinValue)
                    {
                        if (MatchesLastWrite(i))
                        {
                            Console.WriteLine("[+] {0}", i);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        Console.WriteLine("[+] {0}", i);
                    }
                }

                // Now search contents
                if (searchContents)
                {
                    Console.WriteLine("[*] Done searching file system, now searching contents");
                    var contentsSearcher = new ContentsSearcher(FilesFilteredOnExtension, Keywords, RegexSearcher, this.maxFileSizeInKB);
                    contentsSearcher.Search();
                }
            }
        }
Пример #5
0
        public void Search()
        {
            if (Directory.Exists(SearchDirectory))
            {
                FilesFilteredOnExtension = EnumerateFiles(SearchDirectory, "*.*", SearchOption.AllDirectories);
                foreach (string filepath in FilesFilteredOnExtension)
                {
                    if (ContainsKeyword(Path.GetFileName(filepath)))
                    {
                        Results.Add(filepath);
                    }
                }
                if (CheckForMacro)
                {
                    OLXExplorer = new OLEExplorer();
                }
                foreach (string i in Results)
                {
                    bool containsVBA = false;
                    if (CheckForMacro && EndsWithOffice2003Extension(i))
                    {
                        containsVBA = OLXExplorer.CheckForVBAMacros(i);
                        if (!containsVBA)
                        {
                            continue;
                        }
                    }
                    if (BeforeDate != DateTime.MinValue || AfterDate != DateTime.MinValue)
                    {
                        if (MatchesLastWrite(i))
                        {
                            Console.WriteLine("[+] Find {0}", i);
                            if (ossflag)
                            {
                                Uploadfiles.Add(i);
                                Console.WriteLine("[+] Add {0} to Zip", i);
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        Console.WriteLine("[+] Find {0}", i);
                        if (ossflag)
                        {
                            Uploadfiles.Add(i);
                            Console.WriteLine("[+] Add {0} to Zip", i);
                        }
                    }
                }
                if (ossflag)
                {
                    Console.WriteLine("\n[*] Now Create Zipfile and Upload Zipfile to aliyunOSS");
                    Zipfile(Uploadfiles, this.bucketName, this.accessKeyId, this.accessKeySecret, this.endpoint);
                }

                // Now search contents
                if (searchContents)
                {
                    Console.WriteLine("[*] Done searching file system, now searching contents");
                    var contentsSearcher = new ContentsSearcher(FilesFilteredOnExtension, Keywords, RegexSearcher, this.maxFileSizeInKB, this.ossstring);
                    contentsSearcher.Search();
                }
            }
        }