Example #1
0
        void ProcessClient(object state)
        {
            client = (TcpClient)state;
            var buffer             = new byte[1024];
            var clientData         = new StringBuilder();
            var isRequestCompleted = false;


            using (var stream = client.GetStream())
            {
                // Loop to receive all the data sent by the client.
                int bytesRead = 0;
                do
                {
                    // read the data
                    try
                    {
                        bytesRead = stream.Read(buffer, 0, buffer.Length);
                        if (bytesRead > 0)
                        {
                            // Translate data bytes to an ASCII string and append
                            clientData.Append(
                                Encoding.ASCII.GetString(buffer, 0, bytesRead));
                        }
                    }
                    catch (IOException ioe)
                    {
                        // read timed out, all data has been retrieved
                        Console.WriteLine("Read timed out: {0}", ioe.ToString());
                        bytesRead = 0;
                    }

                    isRequestCompleted = buffer.Contains((byte)10);
                }while (bytesRead == buffer.Length || !isRequestCompleted);

                frm_obj.Notify("Client says: " + clientData.ToString());
                string st = /*"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n" +*/ clientData.ToString();
                long   id = Extender.CurrentStamp();
                // Send back a response.

                //var request = Encoding.ASCII.GetBytes(st);
                //stream.Write(request, 0, request.Length);
                frm_obj.AddRequest(st, id);
                while (true)
                {
                    if (frm_obj.IsBusyNow())
                    {
                        Thread.Sleep(1000);
                    }


                    RequestStatue r = frm_obj.GetStatue(id);
                    if (r == RequestStatue.Pass || r == RequestStatue.InterceptResponse)
                    {
                        st = frm_obj.GetRequest();
                        __HTTTPAttack_ h = new __HTTTPAttack_();
                        h.SetFromHoleRequest(st.Split(new char[] { '\n' }), true);
                        frm_obj.SaveAttack(h);

                        string resp = h.DocumentText;
                        if (r == RequestStatue.Pass)
                        {
                            frm_obj.setCurrentInterceptedResponse(resp);
                            while (true)
                            {
                                if (frm_obj.proceed_Response_Interception())
                                {
                                    break;
                                }
                                resp = frm_obj.Return_Intercepted_response();
                                Thread.Sleep(2000);
                            }
                        }

                        var request = Encoding.ASCII.GetBytes(resp);
                        stream.Write(request, 0, request.Length);
                        frm_obj.Proceed();
                        return;
                    }
                    else if (r == RequestStatue.Wait)
                    {
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        string resp    = "<body><div id=\"container\"><div class=\"title\"><h2>Web_Gunners Professional</h2></div><h3>Error</h3><p>Request was dropped by user.</p><p>&nbsp;</p></div></body>";
                        var    request = Encoding.ASCII.GetBytes(resp);
                        stream.Write(request, 0, request.Length);
                        frm_obj.Proceed();

                        //   frm_obj.WriteLine("Rejected");
                        return;
                    }
                }
//                File.WriteAllText(Application.StartupPath + "\\prox", st);
            }
        }