Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.IO;
- namespace TestScript
- {
- class Program
- {
- // Proxy IP and Proxy Port
- public static string pIP = "89.247.172.62";
- public static int pPort = 12600;
- //public static string pIP = "127.0.0.1";
- //public static int pPort = 3784;
- public static string userName = "anonymous";
- public static string userPass = "anonymous";
- // Destination IP and Destination Port
- public static string dIP = "92.61.32.19";
- public static int dPort = 6667;
- static void Main(string[] args)
- {
- // I have no clue what this it is.
- byte[] pRequest = new byte[257];
- byte[] pResponse = new byte[257];
- ushort nIndex;
- Console.WriteLine("Connnecting...");
- Socket myS = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- myS.Connect(pIP, pPort);
- Console.WriteLine("Connected...");
- nIndex = 0;
- pRequest[nIndex++] = 0x05; // Version 5.
- pRequest[nIndex++] = 0x02; // 2 Authentication methods are in packet...
- pRequest[nIndex++] = 0x00; // NO AUTHENTICATION REQUIRED
- pRequest[nIndex++] = 0x02; // USERNAME/PASSWORD
- // Send the authentication negotiation request...
- myS.Send(pRequest, nIndex, SocketFlags.None);
- // Receive 2 byte response...
- int nGot = myS.Receive(pResponse, 2, SocketFlags.None);
- if (nGot != 2)
- {
- Console.WriteLine("Bad response received from proxy server.");
- }
- Console.WriteLine("Response nGot: {0}", nGot);
- if (pResponse[1] == 0xFF)
- { // No authentication method was accepted close the socket.
- Console.WriteLine("None of the authentication method was accepted by proxy server.");
- myS.Close();
- }
- byte[] rawBytes;
- if (/*response[1]==0x02*/true)
- {//Username/Password Authentication protocol
- nIndex = 0;
- pRequest[nIndex++] = 0x05; // Version 5.
- // add user name
- pRequest[nIndex++] = (byte)userName.Length;
- rawBytes = System.Text.Encoding.Default.GetBytes(userName);
- rawBytes.CopyTo(pRequest, nIndex);
- nIndex += (ushort)rawBytes.Length;
- // add password
- pRequest[nIndex++] = (byte)userPass.Length;
- rawBytes = System.Text.Encoding.Default.GetBytes(userPass);
- rawBytes.CopyTo(pRequest, nIndex);
- nIndex += (ushort)rawBytes.Length;
- // Send the Username/Password request
- myS.Send(pRequest, nIndex, SocketFlags.None);
- // Receive 2 byte response...
- nGot = myS.Receive(pResponse, 2, SocketFlags.None);
- if (nGot != 2)
- {
- Console.WriteLine("Bad response received from proxy server.");
- }
- if (pResponse[1] != 0x00)
- {
- Console.WriteLine("Bad Usernaem/Password. {0}, {1}, {2}", pResponse[0], pResponse[1], pResponse[2]);
- }
- }
- // This version only supports connect command.
- // UDP and Bind are not supported.
- // Send connect request now...
- nIndex = 0;
- pRequest[nIndex++] = 0x05; // version 5.
- pRequest[nIndex++] = 0x01; // command = connect.
- pRequest[nIndex++] = 0x00; // Reserve = must be 0x00
- pRequest[nIndex++]=0x01;
- rawBytes = System.Text.Encoding.Default.GetBytes(dIP);
- rawBytes.CopyTo(pRequest,nIndex);
- nIndex += (ushort)rawBytes.Length;
- byte[] portBytes = BitConverter.GetBytes(dPort);
- for (int i = portBytes.Length - 1; i >= 0; i--)
- pRequest[nIndex++] = portBytes[i];
- // send connect request.
- myS.Send(pRequest, nIndex, SocketFlags.None);
- myS.Receive(pResponse); // Get variable length response...
- if (pResponse[1] != 0x00)
- Console.WriteLine(pResponse[1]);
- // Success Connected...
- //return myS;
- Console.WriteLine("Read line has started...");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement