Guest User

Untitled

a guest
Sep 1st, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Net.Security;
  5. using System.Security.Cryptography.X509Certificates;
  6.  
  7. namespace NTLMProxyTester
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. if (args.Length == 0)
  14. {
  15. Console.WriteLine("usage: <program.exe> http(s)://example.com proxyHost proxyPort proxyUsername proxyPassword proxyDomain...");
  16. return;
  17. }
  18. try
  19. {
  20. // setup where the request is going to
  21. HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(args[0]));
  22. Console.WriteLine(string.Format("Making request to: {0}", request.RequestUri.ToString()));
  23.  
  24. ServicePointManager.ServerCertificateValidationCallback += delegate(
  25. object sender,
  26. X509Certificate certificate,
  27. X509Chain chain,
  28. SslPolicyErrors sslPolicyErrors)
  29. {
  30. bool validationResult = true;
  31. return validationResult;
  32. };
  33.  
  34. // setup the request credentials
  35. NetworkCredential proxyCredentials = new NetworkCredential()
  36. {
  37. UserName = args[3],
  38. Password = args[4],
  39. Domain = args[5]
  40. };
  41.  
  42. Console.WriteLine(string.Format("Proxy credentials:"));
  43. Console.WriteLine(string.Format(" - username: {0}", proxyCredentials.UserName));
  44. Console.WriteLine(string.Format(" - password: {0}", proxyCredentials.Password));
  45. Console.WriteLine(string.Format(" - domain: {0}", proxyCredentials.Domain));
  46.  
  47. // setup the proxy details
  48. WebProxy proxy = new WebProxy(string.Format("{0}:{1}", args[1], args[2]), false);
  49. IWebProxy proxySettings = proxy;
  50. // associate the proxy settings with the NetworkCredentials directly
  51. proxySettings.Credentials = proxyCredentials;
  52. request.Proxy = proxySettings;
  53.  
  54. Console.WriteLine(string.Format("Proxy address: {0}", proxySettings.GetProxy(request.RequestUri)));
  55.  
  56. // make the request and deal with the response
  57. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  58. {
  59. Console.WriteLine("Response incoming...");
  60.  
  61. using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
  62. {
  63. Console.WriteLine(responseReader.ReadToEnd());
  64. }
  65. }
  66. }
  67. catch (Exception ex)
  68. {
  69. Console.WriteLine(ex);
  70. }
  71. }
  72. }
  73. }
Add Comment
Please, Sign In to add comment