daily pastebin goal
73%
SHARE
TWEET

Untitled

a guest Jun 18th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Net;
  3. using System.Net.Sockets;
  4. using System.IO;
  5.  
  6. namespace TestScript
  7. {
  8.  
  9.     class Program
  10.     {
  11.         // Proxy IP and Proxy Port
  12.         public static string pIP = "89.247.172.62";
  13.         public static int pPort = 12600;
  14.         //public static string pIP = "127.0.0.1";
  15.         //public static int pPort = 3784;
  16.  
  17.         public static string userName = "anonymous";
  18.         public static string userPass = "anonymous";
  19.  
  20.         // Destination IP and Destination Port
  21.         public static string dIP = "92.61.32.19";
  22.         public static int dPort = 6667;
  23.        
  24.  
  25.         static void Main(string[] args)
  26.         {
  27.          // I have no clue what this it is.
  28.         byte[] pRequest = new byte[257];
  29.         byte[] pResponse = new byte[257];
  30.         ushort nIndex;
  31.  
  32.         Console.WriteLine("Connnecting...");
  33.             Socket myS = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  34.             myS.Connect(pIP, pPort);
  35.         Console.WriteLine("Connected...");
  36.  
  37.  
  38.             nIndex = 0;
  39.             pRequest[nIndex++] = 0x05; // Version 5.
  40.             pRequest[nIndex++] = 0x02; // 2 Authentication methods are in packet...
  41.             pRequest[nIndex++] = 0x00; // NO AUTHENTICATION REQUIRED
  42.             pRequest[nIndex++] = 0x02; // USERNAME/PASSWORD
  43.  
  44.             // Send the authentication negotiation request...
  45.             myS.Send(pRequest, nIndex, SocketFlags.None);
  46.  
  47.             // Receive 2 byte response...
  48.             int nGot = myS.Receive(pResponse, 2, SocketFlags.None);
  49.  
  50.             if (nGot != 2)
  51.             {
  52.                 Console.WriteLine("Bad response received from proxy server.");
  53.             }
  54.  
  55.             Console.WriteLine("Response nGot: {0}", nGot);
  56.  
  57.             if (pResponse[1] == 0xFF)
  58.             {    // No authentication method was accepted close the socket.
  59.                 Console.WriteLine("None of the authentication method was accepted by proxy server.");
  60.                 myS.Close();
  61.             }
  62.  
  63.             byte[] rawBytes;
  64.  
  65.             if (/*response[1]==0x02*/true)
  66.             {//Username/Password Authentication protocol
  67.                 nIndex = 0;
  68.                 pRequest[nIndex++] = 0x05; // Version 5.
  69.  
  70.                 // add user name
  71.                 pRequest[nIndex++] = (byte)userName.Length;
  72.                 rawBytes = System.Text.Encoding.Default.GetBytes(userName);
  73.                 rawBytes.CopyTo(pRequest, nIndex);
  74.                 nIndex += (ushort)rawBytes.Length;
  75.  
  76.                 // add password
  77.                 pRequest[nIndex++] = (byte)userPass.Length;
  78.                 rawBytes = System.Text.Encoding.Default.GetBytes(userPass);
  79.                 rawBytes.CopyTo(pRequest, nIndex);
  80.                 nIndex += (ushort)rawBytes.Length;
  81.  
  82.                 // Send the Username/Password request
  83.                 myS.Send(pRequest, nIndex, SocketFlags.None);
  84.  
  85.                 // Receive 2 byte response...
  86.                 nGot = myS.Receive(pResponse, 2, SocketFlags.None);
  87.                 if (nGot != 2)
  88.                 {
  89.                     Console.WriteLine("Bad response received from proxy server.");
  90.                 }
  91.                 if (pResponse[1] != 0x00)
  92.                 {
  93.                     Console.WriteLine("Bad Usernaem/Password. {0}, {1}, {2}", pResponse[0], pResponse[1], pResponse[2]);
  94.                 }
  95.             }
  96.  
  97.             // This version only supports connect command.
  98.             // UDP and Bind are not supported.
  99.  
  100.             // Send connect request now...
  101.             nIndex = 0;
  102.             pRequest[nIndex++] = 0x05;    // version 5.
  103.             pRequest[nIndex++] = 0x01;    // command = connect.
  104.             pRequest[nIndex++] = 0x00;    // Reserve = must be 0x00
  105.  
  106.                 pRequest[nIndex++]=0x01;
  107.                 rawBytes = System.Text.Encoding.Default.GetBytes(dIP);
  108.                 rawBytes.CopyTo(pRequest,nIndex);
  109.                 nIndex += (ushort)rawBytes.Length;
  110.  
  111.                 byte[] portBytes = BitConverter.GetBytes(dPort);
  112.                 for (int i = portBytes.Length - 1; i >= 0; i--)
  113.                     pRequest[nIndex++] = portBytes[i];
  114.  
  115.                 // send connect request.
  116.                 myS.Send(pRequest, nIndex, SocketFlags.None);
  117.                 myS.Receive(pResponse);    // Get variable length response...
  118.                 if (pResponse[1] != 0x00)
  119.                     Console.WriteLine(pResponse[1]);
  120.  
  121.                 // Success Connected...
  122.                 //return myS;
  123.  
  124.             Console.WriteLine("Read line has started...");
  125.             Console.ReadLine();
  126.  
  127.  
  128.         }
  129.     }
  130. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top