sasfvs

Untitled

Jul 4th, 2017
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9.  
  10. namespace NliWebSec
  11. {
  12.     class sourcecodeleak
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             List<string> mytargets = new List<string>();
  17.  
  18.             string html = null;
  19.             Console.WriteLine("Please enter the root url of your target: ");
  20.             string url = Console.ReadLine();
  21.             /*Console.WriteLine("Please enter the level: ");
  22.             int lvl = Convert.ToInt32(Console.ReadLine());
  23.             for (int i = 0; i < lvl; i++)
  24.             {
  25.             }*/
  26.             // reading the html response from the target
  27.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  28.             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  29.             if (response.StatusCode == HttpStatusCode.OK)
  30.             {
  31.                 Stream receiveStream = response.GetResponseStream();
  32.                 StreamReader readStream = null;
  33.  
  34.                 if (response.CharacterSet == null)
  35.                 {
  36.                     readStream = new StreamReader(receiveStream);
  37.                 }
  38.                 else
  39.                 {
  40.                     readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
  41.                 }
  42.  
  43.                 html = readStream.ReadToEnd();
  44.  
  45.                 response.Close();
  46.                 readStream.Close();
  47.             }
  48.             //searching for urls / paths in the html response of the target
  49.             foreach (Match item in Regex.Matches(html, @"(http|ftp|https):\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?"))
  50.             {
  51.                 string draft = item.Value;
  52.                 //the role of this if is to filter false positives and 3rd parties resources from crawl
  53.                 if (draft.StartsWith(url)) {
  54.                     mytargets.Add(item.Value);
  55.                 }
  56.             }
  57.             mytargets.ToArray();
  58.             for (int i = 0; i < mytargets.Count(); i++)
  59.             {
  60.                 Console.WriteLine(mytargets[i]);
  61.             }
  62.             Console.WriteLine();
  63.             Console.ReadLine();
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment