Advertisement
njunwa1

c sharp replacer 2

Feb 9th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.20 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4. using System.IO;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.Threading;
  8. using System.Windows.Forms;
  9. class injek {
  10. const string server_ip = "202.93.240.212"; //dari a.buzzmechat.com
  11. const int server_port = 80;
  12. public static Socket GayClient = null; //dari TcpListener
  13. public static Socket GayServer = null; //
  14. static string _replace(string text) {
  15.   string[] pola = new string[] { "HTTP/1.1 402 Forbidden", "HTTP/1.1 403 Forbidden",
  16.    "HTTP/1.0 402 Bad Request", "HTTP/1.1 402 Bad Request", "HTTP/1.0 403 Bad request", "HTTP/1.1 400 Bad Request",
  17.    "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"
  18.   };
  19.   foreach (string cok in pola)
  20.   {
  21.    text = Regex.Replace(text, cok, "HTTP/1.1 200 OK");
  22.   }
  23.   return text;
  24. }
  25. public static void konekServer() {
  26.   Socket Gay = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  27.   try {
  28.    string request = "GET / HTTP/1.1\r\nHost: a.buzzmechat.com" +
  29.          "\r\nConnection: keep-alive\r\n\r\n"; //payload
  30.    Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
  31.    Byte[] bytesReceived = new Byte[1028*10];
  32.    Gay.Connect(new IPEndPoint(IPAddress.Parse(server_ip), server_port));
  33.    if(Gay.Connected) {
  34.         Console.WriteLine("Konek sukses");
  35.         Gay.Send(bytesSent, bytesSent.Length, SocketFlags.None);
  36.    }else {
  37.         Console.WriteLine("Gak Konek");
  38.         GayClient.Shutdown(SocketShutdown.Both);
  39.         GayClient.Close();
  40.    }
  41.    GayServer = Gay;
  42.   }
  43.   catch(Exception e) {
  44.    Console.WriteLine(e.ToString());
  45.   }
  46. }
  47. public static void cek(Socket sk) {
  48.   GayClient = sk;
  49.   Byte[] recv = new Byte[1028*10];
  50.   int len;
  51.   len = sk.Receive(recv);
  52.   string clientmsg = Encoding.ASCII.GetString(recv);
  53.   string cmd = clientmsg.Split(' ')[0].Trim();
  54.   Console.WriteLine("Data dari client : < "+len+" > "+clientmsg);
  55.   homo();
  56.   /*if(cmd == "CONNECT") {
  57.    Console.WriteLine("Konek server : < "+Length+" > "+ClientMsg);
  58.    homo();
  59.   }
  60.   else {
  61.    MessageBox.Show("Jembot");
  62.    Console.WriteLine("Mbuh : < "+Length+" > "+ClientMsg);
  63.    gay2();
  64.   }*/
  65. }
  66. public static void homo() {
  67.   konekServer();
  68.   while(true) {
  69.    try {
  70.         string page = null;
  71.         Byte[] recv = new Byte[1028*10];
  72.         Byte[] send = new Byte[1028*10];
  73.         int len = GayServer.Receive(recv, recv.Length, SocketFlags.None);
  74.         if(len == 0) {
  75.          //MessageBox.Show("break cok", "GayServer");
  76.          break;
  77.         }else {
  78.          page = Encoding.ASCII.GetString(recv);
  79.          page = _replace(page);
  80.          send = Encoding.ASCII.GetBytes(page);
  81.          Console.WriteLine("\r\nData dari server : <"+len+"> "+ page);
  82.          //MessageBox.Show(page, "From Server");
  83.          GayClient.Send(send, len, SocketFlags.None);
  84.         }
  85.         len = GayClient.Receive(recv, recv.Length, SocketFlags.None);
  86.         if(len == 0) {
  87.          //MessageBox.Show("break jancok", "GayClient");
  88.          break;
  89.         }else {
  90.          page = Encoding.ASCII.GetString(recv);
  91.          page = _replace(page);
  92.          Console.WriteLine("\r\nData dari client : <"+len+"> "+page);
  93.          //MessageBox.Show(page, "From Client");
  94.          send = Encoding.ASCII.GetBytes(page);
  95.          GayServer.Send(send, len, SocketFlags.None);
  96.         }
  97.    }
  98.    catch(Exception e) {
  99.         MessageBox.Show(e.ToString());
  100.    }
  101.   }
  102.   try
  103.   {
  104.    GayServer.Shutdown(SocketShutdown.Both);
  105.    GayClient.Shutdown(SocketShutdown.Both);
  106.    GayServer.Close();
  107.    GayClient.Close();
  108.   }
  109.   catch(Exception e) {
  110.    Console.WriteLine(e.ToString());
  111.   }
  112. }
  113. public static void Main() {
  114.   try {
  115.    TcpListener listen = new TcpListener(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 666));
  116.    listen.Start();
  117.    Socket sk;
  118.    while(true) {
  119.         try {
  120.          Console.WriteLine("Ngenteni cok..");
  121.          sk = listen.AcceptSocket();
  122.          new Thread(() => {
  123.           cek(sk);
  124.          }).Start();
  125.         }
  126.         catch(Exception e) {
  127.          Console.WriteLine(e.ToString());
  128.         }
  129.    }
  130.   }
  131.   catch(Exception e) {
  132.    Console.WriteLine(e.ToString());
  133.   }
  134.  
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement