Exemple #1
0
        static void Main(string[] args)
        {
            PrintBanner();

            SFOptions options = new SFOptions();

            foreach (string a in args)
            {
                if (a.StartsWith("--path="))
                {
                    string[] components = a.Split('=');
                    options.set_path(components[1]);
                }
                else if (a.StartsWith("--input-file="))
                {
                    string[] components = a.Split('=');
                    options.set_input_file(components[1]);
                }
                else if (a.StartsWith("--keywords="))
                {
                    string[] components = a.Split('=');
                    string[] values     = components[1].Split(',');
                    options.set_keywords(values);
                }
                else if (a.StartsWith("--extensions="))
                {
                    string[] components = a.Split('=');
                    string[] values     = components[1].Split(',');
                    options.set_extensions(values);
                }
                else if (a.Equals("--exclude-hidden"))
                {
                    options.exclude_hidden = true;
                }
                else if (a.Equals("--acl-filter-mode-and"))
                {
                    options.acl_filter_mode_and = true;
                }
                else if (a.Equals("--readable"))
                {
                    options.acl_filter_readable = true;
                }
                else if (a.Equals("--writeable"))
                {
                    options.acl_filter_writeable = true;
                }
                else if (a.Equals("--grepable"))
                {
                    options.grepable = true;
                }
                else
                {
                    Console.WriteLine("Invalid flag: " + a);
                    return;
                }
            }

            if (options.read_paths_from_file)
            {
                foreach (string path in ReadPathsFromFile(options.input_file))
                {
                    SearchFileShare(path, options);
                }
            }
            else
            {
                SearchFileShare(options.path, options);
            }
        }
Exemple #2
0
        public static void SearchFileShare(string path, SFOptions options)
        {
            Console.WriteLine("[*] Searching for files in " + path);
            foreach (string file in DirWalk(path))
            {
                bool   keyword_match    = false;
                bool   extension_match  = false;
                bool   readable         = false;
                bool   writeable        = false;
                bool   acl_filter_match = false;
                string keyword          = "";
                string extension        = "";

                if (options.keywords == null)
                {
                    keyword_match = true;
                }
                else
                {
                    for (int i = 0; i < options.keywords.Length; i++)
                    {
                        if (file.ToLower().Contains(options.keywords[i].ToLower()))
                        {
                            keyword_match = true;
                            keyword       = options.keywords[i];
                            break;
                        }
                    }
                }

                if (options.extensions == null)
                {
                    extension_match = true;
                }
                else
                {
                    for (int i = 0; i < options.extensions.Length; i++)
                    {
                        if (file.ToLower().EndsWith("." + options.extensions[i].ToLower()))
                        {
                            extension_match = true;
                            extension       = options.extensions[i];
                            break;
                        }
                    }
                }

                if (!(keyword_match && extension_match))
                {
                    continue;
                }
                if (FileHasPermission(file, FileSystemRights.Read))
                {
                    readable = true;
                }
                if (FileHasPermission(file, FileSystemRights.Write))
                {
                    writeable = true;
                }
                if (options.acl_filter_readable && options.acl_filter_writeable)
                {
                    if (options.acl_filter_mode_and && readable && writeable)
                    {
                        acl_filter_match = true;
                    }
                    else if (readable || writeable)
                    {
                        acl_filter_match = true;
                    }
                }
                else if (!(options.acl_filter_readable || options.acl_filter_writeable))
                {
                    acl_filter_match = true;
                }
                else if (options.acl_filter_readable && readable)
                {
                    acl_filter_match = true;
                }
                else if (options.acl_filter_writeable && writeable)
                {
                    acl_filter_match = true;
                }
                if (!acl_filter_match)
                {
                    continue;
                }
                if (options.exclude_hidden && System.IO.File.GetAttributes(file).HasFlag(System.IO.FileAttributes.Hidden))
                {
                    continue;
                }

                if (options.grepable)
                {
                    Console.WriteLine("SharpFinder," + keyword + "," + extension + "," + file + "," + readable + "," + writeable);
                }
                else
                {
                    Console.WriteLine(file);
                    Console.WriteLine("\tKeyword: " + keyword);
                    Console.WriteLine("\tExtension: " + extension);
                    Console.WriteLine("\tWriteable: " + writeable);
                    Console.WriteLine("\tReadable: " + readable);
                }
            }
        }