Page 2 of 2

Re: Referer spoofing in webrequests with C#

PostPosted: Mon Jul 19, 2010 2:19 pm
by 0xBEEF1337
Delete.

Re: Referer spoofing in webrequests with C#

PostPosted: Mon Jul 19, 2010 3:24 pm
by dgsc1
tremor77 wrote:
I'm making a selective browser that makes a request to a site of my choosing, shows me the source code
, allows me to alter it, then parses that code...


how far along are you with the application? Do you have the gui in place? If you can give me an idea to what you have working at this point maybe I can help fill in the gaps. Personally I'm too lazy to gin up this type of software on my own but it's something I might be able to contribute a few lines of code to.

oh and sorry about my secret code.. I was utterly bored to hell.


sure, I'll post the source code I have so far... though i haven't commented it much yet and theres still lots of refining to do... the GUI is mostly done, but theres still much to be desired on my part

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;

namespace Get_Sourcecode_Application
{
    public class GUIClass : System.Windows.Forms.Form
    {
        private TextBox URLBar;
        private TextBox HTML;
        private Button Button1;
        private Button Button2;
        private WebBrowser browser;
        [STAThread]
        static void Main()
        {
        GUIClass myclass=new GUIClass();
        Application.EnableVisualStyles();
        Application.Run(myclass);
        }
        public GUIClass()
        {
        this.Paint+=new PaintEventHandler(DrawGraphics);
        InitializeComponent();
        }
        ~GUIClass()
        {
        this.browser.Dispose();
        }
        private void InitializeComponent()
        {
        /*                     This Window                         */
        this.Size = new Size(1400, 700);
        this.Text = "My Selective Browser";
        this.StartPosition = FormStartPosition.CenterScreen;
       
        /*                    End This Window                      */
        /*                       URL Bar                           */
        this.URLBar = new TextBox();
        this.URLBar.Size=new Size(this.Size.Width-100, 20);
        this.URLBar.Location=new Point(43, 10);
        this.Controls.Add(this.URLBar);
        this.URLBar.Focus();
        /*                     End URL Bar                         */
        /*                         HTML                            */
        this.HTML=new TextBox();
        this.HTML.Size=new Size(594,563);
        this.HTML.Location = new Point(43, 60);
        this.HTML.Multiline = true;
        this.HTML.ScrollBars = ScrollBars.Vertical;
        this.Controls.Add(this.HTML);
        /*                       End HTML                          */
        /*                       Go Button                         */
        this.Button1 = new Button();
        this.Button1.Text = "Go";
        this.Button1.Location = new Point(this.Size.Width-52, 10);
        this.Button1.Size = new Size(30, 20);
        this.Button1.Click+=new EventHandler(this.GoButtonClicked);
        this.Controls.Add(this.Button1);
        this.AcceptButton = Button1;
        /*                     End Go Button                       */
        /*                     Parse Button                        */
        this.Button2 = new Button();
        this.Button2.Text = "Parse";
        this.Button2.Location = new Point(310, 635);
        this.Button2.Size = new Size(50, 20);
        this.Button2.Click+=new EventHandler(this.Parse);
        this.Controls.Add(this.Button2);
        /*                   End Parse Button                      */
        /*                        Parser                           */
        this.browser = new WebBrowser();
        this.browser.Size=new Size(this.HTML.Size.Width-27, this.HTML.Size.Height);
        this.browser.Location = new Point(this.HTML.Size.Width + 60, this.HTML.Location.Y);
        this.Controls.Add(this.browser);
        }
        private void DrawGraphics(object bla1, PaintEventArgs bla2)
        {
        Graphics words;
        Font font1;
        SolidBrush font1brush;
        words = this.CreateGraphics();
        font1 = new Font("Times New Roman", 12);
        font1brush = new SolidBrush(Color.Black);
        words.DrawString("URL:", font1, font1brush, 1, 10);
        words.DrawString("HTML Source Code.", font1, font1brush, 254, 40);
        font1.Dispose();
        font1brush.Dispose();
        words.Dispose();
        }
        private void GoButtonClicked(Object sender, EventArgs e)
        {
        string URL=this.URLBar.Text;
        URL = URLobtainer();
        this.URLBar.Text = URL;
        HTMLobtainer(URL);
        }
        private void Parse(Object sender, EventArgs e)
        {
        this.browser.DocumentText = this.HTML.Text;
        }
        public string URLobtainer()
        {
        string URL=this.URLBar.Text;
        if (!URL.StartsWith("http://www."))
            {
            if (URL.StartsWith("www"))
                {
                URL = "http://" + URL;
                }
            else
                {
                URL = "http://www." + URL;
                }
            }
        return URL;
        }
        public string HTMLobtainer(string URL)
        {
            string HTML_code = String.Empty;
            WebResponse MyWRspns = null;
            StreamReader my_stream_reader = null;
            Stream my_stream = null;
            string exception;
            try
            {
                WebRequest MyWRqst = WebRequest.Create(URL);
                MyWRspns = MyWRqst.GetResponse();
                my_stream = MyWRspns.GetResponseStream();
                Encoding encoding = Encoding.GetEncoding("utf-8");
                my_stream_reader = new StreamReader(my_stream, encoding);
                HTML_code = my_stream_reader.ReadToEnd();
                this.HTML.Text= HTML_code;
                return "success";
            }
            catch (Exception ex)
            {
                exception=ex.ToString();
                exception = exception + " exception shown...";
                MessageBox.Show(exception);
                return "failure";
            }
            finally
            {
                if (my_stream_reader != null)
                {
                    my_stream_reader.Close();
                }
                if (MyWRspns != null)
                {
                    MyWRspns.Close();
                }
                if (my_stream != null)
                {
                    my_stream.Close();
                }
            }
        }
    }
}



-- Mon Jul 19, 2010 3:26 pm --

hahaha... now I feel self-concious about my code... I'm sorry for any inadequacies... It's the best I could manage at the time being :)

-- Tue Jul 20, 2010 12:25 pm --

hey guys... what excatly gets sent during a webrequest? I mean... what are the requirements?... do all the headers have to be sent?

Re: Referer spoofing in webrequests with C#

PostPosted: Wed Jul 21, 2010 8:34 am
by 0xBEEF1337
Delete.