C# 编写,是为了跟 Cobalt Strike 配套使用,方便。

public class Program
{

    public static void ThreadList(string ip, string port)
    {
        Console.WriteLine("");
        try
        {
            ip = ip.Trim(new char[] { '.' });
            string cip = "";
            if (regexAll(ip))
            {
                cip = ip.Substring(0, ip.LastIndexOf('.'));
            }
            else if (regexAll_1(ip))
            {
                cip = ip;
            }
            for (int i = 1; i < 255; i++)
            {
                arrayList.Add(new threadStart(cip + "." + i.ToString(), port));
            }
            Thread[] array = new Thread[arrayList.Count];
            for (int j = 0; j < arrayList.Count; j++)
            {
                array[j] = new Thread(new ThreadStart(((threadStart)arrayList[j]).method_0));
                array[j].Start();
            }
            for (int j = 0; j < array.Length; j++)
            {
                array[j].Join();
            }
            GC.Collect();
            arrayList.Clear();
        }
        catch (Exception ex)
        {
            Debug.Print(ex.Message);
        }
    }

    public static void GetAll(string ip, string ports)
    {
        string[] port = ports.Split(new char[] { ',' });
        for (int i = 0; i < port.Length; i++)
        {
            string url = String.Format("http://{0}:{1}", ip, port[i]);
            String regex = @"<title>.+</title>";
            try
            {
                var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
                req.Method = "GET";
                req.Timeout = 1000;
                var res = (HttpWebResponse)req.GetResponse();
                if (res.StatusCode == HttpStatusCode.OK || res.StatusCode == HttpStatusCode.Forbidden || res.StatusCode == HttpStatusCode.Redirect || res.StatusCode == HttpStatusCode.MovedPermanently)
                {
                    int_0++;
                    try
                    {
                        WebClient web = new WebClient();
                        byte[] buffer = web.DownloadData(url);
                        string html = Encoding.UTF8.GetString(buffer);
                        String title = Regex.Match(html, regex).ToString();

                        title = Regex.Replace(title, @"<title>", "");
                        title = Regex.Replace(title, @"</title>", "");
                        Console.WriteLine("{0,-25} {1,-15} {2,-25} {3,-25}", url, Convert.ToInt32(res.StatusCode), res.Server, title);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            catch (WebException ex)
            {
            }
        }
    }

    public static int int_0 = 0;
    public static ArrayList arrayList = new ArrayList();
    public static bool regexAll(string string_0)
    {
        Regex regex = new Regex("^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$");
        return regex.IsMatch(string_0);
    }
    public static bool regexAll_1(string string_0)
    {
        Regex regex = new Regex("^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$");
        return regex.IsMatch(string_0);
    }
    public static bool regexAll_2(string string_0)
    {
        Regex regex = new Regex("^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$");
        return regex.IsMatch(string_0);
    }

    static void Main(string[] args)
    {
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        Console.WriteLine();
        Console.WriteLine("Scaning Web Title....");
        Console.WriteLine("{0,-25} {1,-15} {2,-25} {3,-25}", "URL", "StatusCode", "res.Server", "Title");

        if (args.Contains("-CIP"))
        {
            ThreadList(args[1], args[2]);
        }
        else if (args.Contains("-BIP"))
        {
            ScanBIP.ThreadBool(args[1], args[2]);
            int maxWorkerThreads, workerThreads, portThreads;
            while (true)
            {

                ThreadPool.GetMaxThreads(out maxWorkerThreads, out portThreads);
                ThreadPool.GetAvailableThreads(out workerThreads, out portThreads);
                if (maxWorkerThreads - workerThreads == 0)
                {
                    Console.WriteLine("Thread Finished!");
                    break;
                }
            }
        }
        else if (args.Contains("-IP"))
        {
            GetAll(args[1], args[2]);

        }
        stopwatch.Stop();
        Console.WriteLine("Count: {0}  Time taken: {1}", int_0, stopwatch.ElapsedMilliseconds);
        //Console.WriteLine("Finish!");
    }
}
public class threadStart
{
    private string ipss = "";
    private string port = "";

    public threadStart(string ip, string port)
    {
        this.ipss = ip;
        this.port = port;
    }

    public void method_0()
    {
        Program.GetAll(this.ipss, this.port);
    }
}

效果如下:
222.png

标签: none

添加新评论