1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C# Web Request Bot's

Discussion in 'C, C++, C#' started by albaniax, Jan 11, 2012.

  1. albaniax

    albaniax Elite Member

    Joined:
    Aug 5, 2008
    Messages:
    1,586
    Likes Received:
    823
    Location:
    GER - ALB
    I'm looking for some C# .NET bots, where I can learn from. ( Visual Studio 2008 in school - 2010 at home )

    Basically, I have 5 days left for my programming class to finish my project. I choosed to make a few bots, registering Web 2.0 Blogs.

    So far, I know how to fill in the input boxes.. that's it.

    I would appreciate, if you can post some bot's you have done, where you use the http - WebRequest.

    I have to add, that I'm not that experienced at all in C#, so I only need basic stuff, otherwise it would be to obvious that someone else did it.

    Let me know,

    best regards
    Albaniax
     
    • Thanks Thanks x 1
  2. Jrim_Software

    Jrim_Software Power Member

    Joined:
    Aug 1, 2011
    Messages:
    772
    Likes Received:
    179
    Home Page:
    Why not use a WebBrowser for the automation instead of HttpWebRequest automation? You won't be able to 'fill boxes' without a WebBrowser object, and by then utilizing the MSHTML library to interact with the HTML DOM (document object model).
     
    • Thanks Thanks x 1
  3. Chris22

    Chris22 Regular Member

    Joined:
    Sep 29, 2010
    Messages:
    400
    Likes Received:
    1,059
    A web server doesn't know if the user 'filled boxes', it just knows HTTP requests. I'd say using HttpWebRequest over the WebBrowser object is a massive performance boost.
     
    • Thanks Thanks x 1
  4. Gary Becks

    Gary Becks Power Member

    Joined:
    Apr 11, 2010
    Messages:
    675
    Likes Received:
    282
    Location:
    Atl
    Home Page:
    Take this advise.

    Although if it's just for a simple school project using a web browser will be much easier and probably the quickest way to achieve your goal.
     
    • Thanks Thanks x 1
  5. osmose01

    osmose01 Registered Member

    Joined:
    Jun 21, 2009
    Messages:
    77
    Likes Received:
    5
    getting a tool like http fox for firefox to understand how the request is made will be a good start. at least to code your own dynamic request analyser but there is few thing to prevent people from botting atm .
     
  6. Chris22

    Chris22 Regular Member

    Joined:
    Sep 29, 2010
    Messages:
    400
    Likes Received:
    1,059
    There is nothing that will prevent people botting ever.

    Where there is a will, there is usually a way and this is definitely true of programming.
     
  7. weedsmoker

    weedsmoker Junior Member

    Joined:
    May 2, 2011
    Messages:
    190
    Likes Received:
    79
    I know i'm late with answer ;)

    1. Sometimes best way to learn how something works is to reverse engineer it. I download other peoples bots, decompile them and learn from their code. Often code is obfuscated, but even then you can learn how some stuff works.
    So, go to download section or to botnet forum, pick up bot you like, download dotpeek software for decompiling, it's free.

    2. Search google "site: pastebin.com c# vb.net facebook twitter bot" or something like that, you'll find lot of useful code.

    3. Get "HTTP Programming Recipes for C# Bots" book.

    If you work with webrequest or sockets, get wireshark or similar software for http analysing.
     
    • Thanks Thanks x 3
    Last edited: Jan 16, 2012
  8. albaniax

    albaniax Elite Member

    Joined:
    Aug 5, 2008
    Messages:
    1,586
    Likes Received:
    823
    Location:
    GER - ALB
    In case anyone else see's this, I have a problem here:

    http://pastebin.com/usg8sR4r

    Basically, I'm getting an null-reference error when I call the last method and it tries to fill in the Blogname, but not sure why.

    Normally it worked, but not after I had put it in another method.

    best regards,
    Albaniax
     
  9. albaniax

    albaniax Elite Member

    Joined:
    Aug 5, 2008
    Messages:
    1,586
    Likes Received:
    823
    Location:
    GER - ALB
    thanks to user "hatemachine" it's fixed now!

    CompletedEvent had to be added, my code was to fast in trying to fill the page, even before it was loaded.
     
  10. KabanaSoft

    KabanaSoft Newbie

    Joined:
    Jan 26, 2012
    Messages:
    3
    Likes Received:
    6
    I have alot of experience in writing C# web scraping applications...let me give you some advice.

    1) As osmose01 recommended, get HttpFox, and learn how to use it. Having a basic understanding for the fundamental interaction between how clients/servers interact via HTTP requests will help you greatly.

    2) I highly recommend not using the .NET web browser control...way too much overhead involved...learn how to use HttpWebRequest / HttpWebResponse classes, and how to add proper headers for the requests. The headers you see in HttpFox will help you build your GET requests using the HttpWebRequest object.

    3) Search for HtmlAgilityPack - its an open source library that makes parsing html for desired data a breeze. You will also need to learn how to use XPath queries, which are pretty easy.

    That should give you a good start. If you have any other questions feel free to ask me.
     
    • Thanks Thanks x 1
  11. SquallLTT

    SquallLTT Newbie

    Joined:
    Dec 24, 2011
    Messages:
    3
    Likes Received:
    0
    Just one question : is it worth time and effort of using socket instead of Httpwebrequest and httpwebresponse? I'm new so I need a right direction to go. Appreciate your answer :)
     
  12. erroronline14

    erroronline14 Regular Member

    Joined:
    Oct 16, 2009
    Messages:
    321
    Likes Received:
    922
    Here is a tip for you start.

    Learn how to use HttpWebRequest dont use webbrowser control, thats very very slow and hard to handle if you want to change proxies and other stuffs.

    Then use Firebug in Firefox to monitor the requests of the websites that you are trying to automate.
     
  13. albaniax

    albaniax Elite Member

    Joined:
    Aug 5, 2008
    Messages:
    1,586
    Likes Received:
    823
    Location:
    GER - ALB
    Thanks for the suggestions.

    I got as a grade a 3 which is C in the U.S. for my (short) project, which is more then enough for me, considering I only worked 4-5 hours on it.

    Firebug I already use, HttpFox is a nice tipp as I recently learned how get/set functions work. This would be the next step now.

    I choosed Python overall for my programming career, as I focus only to write web bots.

    regards
     
  14. crepito

    crepito Junior Member

    Joined:
    Oct 5, 2008
    Messages:
    145
    Likes Received:
    28
    Location:
    Portugal
    Just to add: I use TCPCatcher as my sniffer :)
     
  15. kizp10

    kizp10 Newbie

    Joined:
    May 16, 2010
    Messages:
    22
    Likes Received:
    3
    Home Page:
    Code:
                
    
    Dim request As WebRequest = WebRequest.Create(SomeWebsite)
                ' Set the Method property of the request to POST.
                request.Method = "POST"
                ' Create POST data and convert it to a byte array.
                Dim postData As String = "This is a test that posts this string to a Web server."
                Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
                ' Set the ContentType property of the WebRequest.
                request.ContentType = "application/x-www-form-urlencoded"
                ' Set the ContentLength property of the WebRequest.
                request.ContentLength = byteArray.Length
                ' Get the request stream.
                Dim dataStream As Stream = request.GetRequestStream()
                ' Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length)
                ' Close the Stream object.
                dataStream.Close()
                ' Get the response.
                Dim response As WebResponse = request.GetResponse()
                ' Display the status.
                Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
                ' Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream()
                ' Open the stream using a StreamReader for easy access.
                Dim reader As New StreamReader(dataStream)
                ' Read the content.
                Dim responseFromServer As String = reader.ReadToEnd()
                ' Display the content.
                Console.WriteLine(responseFromServer)
                ' Clean up the streams.
                reader.Close()
                dataStream.Close()
                response.Close()
    
    OR
    
    
    
                Dim request As WebRequest = WebRequest.Create(SomeWebsite)
                ' If required by the server, set the credentials.
                request.Credentials = CredentialCache.DefaultCredentials
                ' Get the response.
                Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
                ' Display the status.
                Console.WriteLine(response.StatusDescription)
                ' Get the stream containing content returned by the server.
                Dim dataStream As Stream = response.GetResponseStream()
                ' Open the stream using a StreamReader for easy access.
                Dim reader As New StreamReader(dataStream)
                ' Read the content.
                Dim responseFromServer As String = reader.ReadToEnd()
                ' Display the content.
                Console.WriteLine(responseFromServer)
                ' Cleanup the streams and the response.
                reader.Close()
                dataStream.Close()
                response.Close()
    
    

    c&p str8 from microsoft themselves, And thats just the send...

    Youll have to make that bot go to a page
    parse and load the forms to your program
    fill each form item correctly
    most likely go fetch captcha image
    copy to the local computer
    then have the user read and solve it, then add that text to your outgoing packet to send to the server.




    so yea its 100xs easier to make a bot with the web browser control.
     
  16. Stalli0n

    Stalli0n Junior Member

    Joined:
    Nov 17, 2010
    Messages:
    115
    Likes Received:
    83
    Location:
    Europe
    The webbrowser control is shit, the only valid use for it is when the page contains javascript, and even for that there are better solutions like Selenium.
     
    • Thanks Thanks x 1
  17. DutchTrafficService

    DutchTrafficService Regular Member

    Joined:
    Aug 12, 2010
    Messages:
    473
    Likes Received:
    234
    Get chilkat, you will thank me later ;)
     
  18. hiderightnow

    hiderightnow Junior Member

    Joined:
    Jul 19, 2010
    Messages:
    104
    Likes Received:
    22
    The Heaton research web spider is a great way to start. You can even download for free the examples in the book, of course it would be better to buy the ebook in the first place. The book is called "HTTP Programming Recipes for C# Bots", I believe it was mentioned earlier, it has all these recipes that start from the absolute beginner and build up to a complete web spider solution.