Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Net.Sockets;
- using System.Net;
- using System.IO;
- using System.Threading;
- using System.Windows.Forms;
- using System.Diagnostics;
- namespace Injekan
- {
- public class HttpProxyRequestProcesster
- {
- private Socket ClientSocket;
- private Encoding ASCII = Encoding.ASCII;
- private static ArrayList _Threads=new ArrayList();
- private static string _proxy = "";
- private static int _port = 0;
- public static ArrayList Threads
- {
- get { return HttpProxyRequestProcesster._Threads; }
- }
- public HttpProxyRequestProcesster(Socket TcpClientSocket)
- {
- ClientSocket = TcpClientSocket;
- }
- public void Process()
- {
- Init();
- Byte[] ReadBuff = new byte[1024 * 10];
- int Length = 0;
- try
- {
- Length = ClientSocket.Receive(ReadBuff);
- if (0 == Length)
- {
- End();
- return;
- }
- }
- catch(Exception e)
- {
- End();
- }
- string ClientMsg = ASCII.GetString(ReadBuff);
- string Line="";
- try
- {
- Line = ClientMsg.Substring(0, ClientMsg.IndexOf("\r\n"));
- }
- catch
- {
- End();
- return;
- }
- string[] CmdArray = Line.Split(' ');
- string Cmd = CmdArray[0];
- string RawUrl = CmdArray[1];
- if (Cmd == "CONNECT")
- {
- DoConnect(RawUrl);
- }
- else
- {
- DoOther(RawUrl, ClientMsg);
- }
- End();
- }
- private void DoConnect(string RawUrl)
- {
- string[] Args = RawUrl.Split(':');
- _proxy = "162.243.47.159"; //ganti proxinya boss
- _port = 8080 ; //ganti port proxyna
- // string _replace(string text) {
- // string[] pola = new string[] { "HTTP/1.1 402 Forbidden", "HTTP/1.1 403 Forbidden",
- // "HTTP/1.0 402 Bad Request", "HTTP/1.1 402 Bad Request", "HTTP/1.0 403 Bad request", "HTTP/1.1 400 Bad Request",
- // "HTTP/1.0 502 Gateway Timeout", "HTTP/1.1 502 Internal Server Error", "HTTP/1.1 402 not authenticated", "HTTP/1.1 100 Connection established"
- //};
- // foreach (string cok in pola)
- // {
- // text = Regex.Replace(text, cok, "HTTP/1.1 200 OK");
- // }
- // return text;
- // }
- string Host = Args[0];
- int Port = int.Parse(Args[1]);
- RawUrl = Host + ":" + Port;
- Socket ServerSocket = null;
- try
- {
- ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- ServerSocket.Connect(_proxy, _port);
- }
- catch (Exception e)
- {
- ProcessException.Process(e);
- }
- if (ServerSocket.Connected)
- {
- //string payload="masukin disini method injeknya + rawurl (coba breakpoint, liat isi rawurl pasti ngerti)"; // ganti sama injeknannya boss
- //CR =% 0D = \ r
- //LF =% 0a = \ n
- /*string request = "GET / HTTP/1.1\r\nHost: a.buzzmechat.com" +
- "\r\nConnection: keep-alive\r\n\r\n";*/
- /*string payload = "GET / HTTP/1.1" + "\r\n" + "Host: mobi.kampret.com" + "\r\n\r\n\r\n\r\n";
- string req = "CONNECT " + RawUrl + " HTTP/1.0\r\n";
- Debug.Print(payload + req); // kl error di bagian ini tambahin "using System.Diagnostics;"
- ServerSocket.Send(ASCII.GetBytes(payload + req));
- ServerSocket.Send(ASCII.GetBytes("\r\n"), 2, SocketFlags.None);*/
- string payload = "GET http://halotel.co.tz HTTP/1.1\nHost: halotel.co.tz:80\n\nCONNECT " + RawUrl + " HTTP/1.0\n"; //set break point di rawurl connect esteh
- //liat value rawurl,
- string netdata = "CONNECT " + RawUrl + " HTTP/1.0\r\n";
- Debug.Print(payload + netdata);
- ServerSocket.Send(ASCII.GetBytes(payload+netdata)); // tinggal gabungin sama metode injek
- //ServerSocket.Send(ASCII.GetBytes(payload));
- ServerSocket.Send(ASCII.GetBytes("\r\n"), 2, SocketFlags.None); //"\r\n" coba di modifikasi tergantung operator bisa
- // \r\r\r bisa \n\n bisa yang lainnya tergantung operator
- // kalo ga sesuai ga akan konek estehnya
- }
- else
- {
- ClientSocket.Shutdown(SocketShutdown.Both);
- ClientSocket.Close();
- }
- ForwardTcpData(ClientSocket, ServerSocket);
- }
- public void Init()
- {
- lock (_Threads)
- {
- _Threads.Add(Thread.CurrentThread);
- }
- }
- public void End()
- {
- lock (_Threads)
- {
- _Threads.Remove(Thread.CurrentThread);
- }
- try
- {
- ClientSocket.Shutdown(SocketShutdown.Both);
- ClientSocket.Close();
- }
- catch { ;}
- }
- /// <summary>
- /// </summary>
- /// <param name="RawUrl"></param>
- /// <param name="ClientMsg"></param>
- public void DoOther(string RawUrl, string ClientMsg)
- {
- RawUrl = RawUrl.Substring(0 + "http://".Length);
- int Port;
- string Host;
- string Url;
- int index1 = RawUrl.IndexOf(':');
- if (index1 == -1)
- {
- Port = 80;
- int index2 = RawUrl.IndexOf('/');
- if (index2 == -1)
- {
- Host = RawUrl;
- Url = "/";
- }
- else
- {
- Host = RawUrl.Substring(0, index2);
- Url = RawUrl.Substring(index2);
- }
- }
- else
- {
- int index2 = RawUrl.IndexOf('/');
- if (index2 == -1)
- {
- Host = RawUrl.Substring(0, index1);
- Port = Int32.Parse(RawUrl.Substring(index1 + 1));
- Url = "/";
- }
- else
- {
- if (index2 < index1)
- {
- Host = RawUrl.Substring(0, index2);
- Port = 80;
- }
- else
- {
- Host = RawUrl.Substring(0, index1);
- Port = Int32.Parse(RawUrl.Substring(index1 + 1, index2 - index1 - 1));
- }
- Url = RawUrl.Substring(index2);
- }
- }
- IPAddress[] address = null;
- try
- {
- IPHostEntry IPHost = Dns.GetHostEntry(Host);
- address = IPHost.AddressList;
- }
- catch (Exception e)
- {
- ProcessException.Process(e.ToString());
- return;
- }
- Socket IPsocket = null;
- try
- {
- IPEndPoint ipEndpoint = new IPEndPoint(address[0], Port);
- IPsocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- IPsocket.Connect(ipEndpoint);
- string ReqData = ClientMsg;
- ReqData = ReqData.Replace("http://" + RawUrl, Url);
- string[] body = ReqData.Split(new string[1] { "\r\n\r\n" }, StringSplitOptions.None);
- string head = null;
- string post = null;
- head = body[0];
- if (body.Length == 2)
- {
- post = body[1];
- }
- string[] ReqArray = head.Split(new string[1] { "\r\n" }, StringSplitOptions.None);
- ReqData = "";
- for (int index = 0; index < ReqArray.Length; index++)
- {
- if (ReqArray[index].StartsWith("Proxy-Connection:"))
- {
- ReqArray[index] = ReqArray[index].Replace("Proxy-Connection:", "Connection:");
- //ReqArray[index] = "Connection: close";
- }
- if (ReqArray[index] != "")
- {
- ReqData = ReqData + ReqArray[index] + "\r\n";
- }
- }
- ReqData = ReqData + "\r\n";
- if (post != null)
- {
- ReqData = ReqData + post;
- }
- ReqData = ReqData.Trim();
- byte[] SendBuff = ASCII.GetBytes(ReqData);
- IPsocket.Send(SendBuff);
- }
- catch (Exception e)
- {
- ProcessException.Process(e);
- }
- while (true)
- {
- Byte[] RecvBuff = new byte[1024 * 20];
- try
- {
- if (!IPsocket.Poll(15 * 1000 * 1000, SelectMode.SelectRead))
- {
- break;
- }
- }
- catch (Exception e)
- {
- ProcessException.Process("Poll: " + e.Message);
- break;
- }
- int Length = 0;
- try
- {
- Length = IPsocket.Receive(RecvBuff);
- if (0 == Length)
- {
- break;
- }
- }
- catch (Exception e)
- {
- ProcessException.Process("Recv: " + e.Message);
- break;
- }
- try
- {
- Length = ClientSocket.Send(RecvBuff, Length, 0);
- }
- catch (Exception e)
- {
- ProcessException.Process("Send: " + e.Message);
- }
- }
- try
- {
- ClientSocket.Shutdown(SocketShutdown.Both);
- ClientSocket.Close();
- IPsocket.Shutdown(SocketShutdown.Both);
- IPsocket.Close();
- }
- catch { ; }
- }
- private void ForwardTcpData(Socket client, Socket server)
- {
- ArrayList ReadList = new ArrayList(2);
- while (true)
- {
- ReadList.Clear();
- ReadList.Add(client);
- ReadList.Add(server);
- try
- {
- Socket.Select(ReadList, null, null, 1 * 1000 * 1000);
- }
- catch (SocketException e)
- {
- ProcessException.Process("Select error: " + e.Message);
- break;
- }
- if (ReadList.Count == 0)
- {
- continue;
- }
- if (ReadList.Contains(client))
- {
- byte[] Recv = new byte[1024 * 10];
- int Length = 0;
- try
- {
- Length = client.Receive(Recv, Recv.Length, 0);
- if (Length == 0)
- {
- break;
- }
- }
- catch (Exception e)
- {
- break;
- }
- try
- {
- Length = server.Send(Recv, Length, 0);
- }
- catch (Exception e)
- {
- ProcessException.Process("Write data to server error: " + e.Message);
- break;
- }
- }
- if (ReadList.Contains(server))
- {
- byte[] Recv = new byte[1024 * 10];
- int Length = 0;
- try
- {
- Length = server.Receive(Recv, Recv.Length, 0);
- if (Length == 0)
- {
- Console.WriteLine("Server is disconnected");
- break;
- }
- }
- catch (Exception e)
- {
- ProcessException.Process("Read from server error: " + e.Message);
- break;
- }
- try
- {
- Length = client.Send(Recv, Length, 0);
- }
- catch (Exception e)
- {
- ProcessException.Process("Write data to client error: " + e.Message);
- break;
- }
- }
- }
- try
- {
- client.Shutdown(SocketShutdown.Both);
- server.Shutdown(SocketShutdown.Both);
- client.Close();
- server.Close();
- }
- catch
- {
- //ProcessException.Process(e.Message);
- }
- finally
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement