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

[VB.NET] HELP - Webbrowser Open File dialog control

Discussion in 'BlackHat Lounge' started by healzer, Aug 6, 2011.

  1. healzer

    healzer Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jun 26, 2011
    Messages:
    2,363
    Likes Received:
    1,966
    Gender:
    Male
    Occupation:
    Marketing automation tools
    Location:
    Somewhere in Europe
    Home Page:
    Hi, I was searching all over the internet to find a specific code/way to do the following: (in Visual Basic)

    I want to create a bot which fills in Forms (SUCCESS)
    and
    Each site has a "Browse" button to select a certain file from my computer to upload.

    So the File dialog box is run from the browser and not created in my application actually.

    When the File Dialog opens with this code: (below), how can I make the bot/application select the file I want to upload (eg.: C:\my Files\test.jpg)

    Code:
    WebBrowser1.Document.GetElementById("file").InvokeMember("click")
     
    Last edited: Aug 6, 2011
  2. wowhaxor

    wowhaxor Executive VIP Premium Member

    Joined:
    Apr 28, 2007
    Messages:
    2,021
    Likes Received:
    3,353
    Location:
    ?¿?
    Home Page:
    You want to hardcode it to open a specific file or prompt you to select a file?
     
    • Thanks Thanks x 1
  3. healzer

    healzer Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jun 26, 2011
    Messages:
    2,363
    Likes Received:
    1,966
    Gender:
    Male
    Occupation:
    Marketing automation tools
    Location:
    Somewhere in Europe
    Home Page:
    Yes, I want to make it open a File automatically.
    (I've read that it's not possible, but I'm not giving up hope, I know it can be done)
     
  4. wowhaxor

    wowhaxor Executive VIP Premium Member

    Joined:
    Apr 28, 2007
    Messages:
    2,021
    Likes Received:
    3,353
    Location:
    ?¿?
    Home Page:
    And is it a txt file or something else?
     
  5. healzer

    healzer Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jun 26, 2011
    Messages:
    2,363
    Likes Received:
    1,966
    Gender:
    Male
    Occupation:
    Marketing automation tools
    Location:
    Somewhere in Europe
    Home Page:
    it's actually a .torrent file (making my self a torrent upload bot).

    But from what I have found is that the "input" tag is very protected by browsers for security reasons so I couldn't find a way to bypass it :06:
     
  6. wowhaxor

    wowhaxor Executive VIP Premium Member

    Joined:
    Apr 28, 2007
    Messages:
    2,021
    Likes Received:
    3,353
    Location:
    ?¿?
    Home Page:
    OK

    The only one I've ever done was to read text from a .txt file and for what you're doing to make an input in my GUI where I just select the file at the start (browse) so I don't really know :(
     
    • Thanks Thanks x 1
  7. Jannes

    Jannes Newbie

    Joined:
    Jan 9, 2010
    Messages:
    35
    Likes Received:
    15
    Just quit using the browser component. Google for the WebClient class with the uploadFile method, that would get you started. Sorry can't post the urls, so you have to find the stuff yourself.

    Good luck :)
     
    • Thanks Thanks x 1
  8. healzer

    healzer Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jun 26, 2011
    Messages:
    2,363
    Likes Received:
    1,966
    Gender:
    Male
    Occupation:
    Marketing automation tools
    Location:
    Somewhere in Europe
    Home Page:
    Thanks for the information!

    Would it also be possible to load a Listbox from a website into the application for example:
    (I have done this manually and it takes a lot of time to create from a Webbrowser). But I'll try to re-create the application with The WebClient class as you told.

    Category:

    • Games
    • Video
    • Music
    • Apps
     
  9. Jannes

    Jannes Newbie

    Joined:
    Jan 9, 2010
    Messages:
    35
    Likes Received:
    15
    Well no luck with links yet, and no pm since the 15post limit.

    So we need an other way, google:

    "WebClient.UploadFile Method (String, String)"
    "UploadFileEx: C#'s WebClient.UploadFile with more functionality"

    That would get you started, make some simple php form on your localhost or something, to upload something, and then try to do it from your app. That way you could see your logs and stuff to get some more info on what's happening.

    Good luck again
     
    • Thanks Thanks x 1
  10. healzer

    healzer Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jun 26, 2011
    Messages:
    2,363
    Likes Received:
    1,966
    Gender:
    Male
    Occupation:
    Marketing automation tools
    Location:
    Somewhere in Europe
    Home Page:
    Hi, so this is how it went:

    I've spent the whole day figuring out how to make the WebClient work.

    Problem was: WebClient doesn't work with Multi-Level forms (MIME).
    So the only solution left is to use HttpWebRequest controls, but I can't find good examples/tutorials for Forms
     
  11. scriptomania

    scriptomania Junior Member

    Joined:
    Dec 28, 2010
    Messages:
    127
    Likes Received:
    249
    Occupation:
    A full time pirate at sea
    Location:
    The European capital of politics
    Here's a tip:

    download the HttpFox addon for firefox (alternatively, download any simple HTTP request viewer), make a simple form submit request through firefox and recreate the HTTP request in your application.
     
    • Thanks Thanks x 1
  12. Monrox

    Monrox Power Member

    Joined:
    Apr 9, 2010
    Messages:
    615
    Likes Received:
    579
    Must you click the browse button or is there a field as well where you could enter the path to the file that you wish to upload?
     
    • Thanks Thanks x 1
  13. healzer

    healzer Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jun 26, 2011
    Messages:
    2,363
    Likes Received:
    1,966
    Gender:
    Male
    Occupation:
    Marketing automation tools
    Location:
    Somewhere in Europe
    Home Page:
    I have the HTTP viewer thing addon for firefox, but I can't find any good examples or tutorials to make such a MultiPart form submit thingy.

    There is no field, just a browse button ( <input type="file"> )
     
  14. Monrox

    Monrox Power Member

    Joined:
    Apr 9, 2010
    Messages:
    615
    Likes Received:
    579
    Ok, is it possible to point to the actual site? PM would be fine too if you are concerned. It's kind of hard to guess what would work without the html code. If all esle fails there is always the possibility of using api calls to send messages / clicks to buttons.
     
  15. healzer

    healzer Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jun 26, 2011
    Messages:
    2,363
    Likes Received:
    1,966
    Gender:
    Male
    Occupation:
    Marketing automation tools
    Location:
    Somewhere in Europe
    Home Page:

    I have 9 Torrent sites I am making a bot to upload to (automatically).

    I have successfully made to upload to the first one (out of 9), but it takes like 2x times longer than manual because it involves SendKeys (Tab, Tab, Enter, Keyup, Enter, LOL ..., lot's of MultiThreading = Lagg)

    My first one is: hxxp://btjunkie*org/?do=upload
     
  16. Monrox

    Monrox Power Member

    Joined:
    Apr 9, 2010
    Messages:
    615
    Likes Received:
    579
    Didn't I ask you if there was a field for the file name in addition to browsing to it :)

    I did so because SendKeys is the easiest way if you don't want to investigate how to emulate POST and SUBMIT as suggested by scriptomania.

    The DOM model is complicated enough to have many quick ways to get a specific element directly but it is always better to start learning as generically as possible.

    So the source looks like this: <input type="file" name="file" size="17">
    Let's get all INPUT elements and loop through them, examining whether they contain all the attributes of the element in question. Once found, we set the focus upon it then send it the path of our file (and exit the loop).

    It is always a good idea (IMAO) to always test for more than one attribute. Some developers use IDs twice, others try to confuse bots etc.

     
    • Thanks Thanks x 1
  17. healzer

    healzer Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jun 26, 2011
    Messages:
    2,363
    Likes Received:
    1,966
    Gender:
    Male
    Occupation:
    Marketing automation tools
    Location:
    Somewhere in Europe
    Home Page:
    "gimme a sec."

    edit:

    MonRox, thanks for the Vb.net code!

    I'll just keep it to the Webbrowser at the moment and figure out how to use the Httpwebrequest thinny later.
    Thanks ! :D +rep

     
    Last edited: Aug 8, 2011
  18. healzer

    healzer Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jun 26, 2011
    Messages:
    2,363
    Likes Received:
    1,966
    Gender:
    Male
    Occupation:
    Marketing automation tools
    Location:
    Somewhere in Europe
    Home Page:
    Owkay; SITE #1 COMPLETE !! :D

    I had over thousands of errors and fails just to make a 90%-semi-automatic TorrentUploading bot to BTjunkie alone, only the captcha is manual. and takes 10 secs approx for one file to be done, so I'm satisfied, I'll do the rest tomorow :D

    I'll share it for free on BHW when this one is finished
     
  19. Jannes

    Jannes Newbie

    Joined:
    Jan 9, 2010
    Messages:
    35
    Likes Received:
    15
    Well nice that you got it working! But I would like to say that those mime type stuff can be fixed. In one of those sites you can see they build another function to cover that stuff. It is in C# but if you rewrite it to vb you could stuff your mimetypes and stuff with it.

     
    • Thanks Thanks x 1
  20. DarkoOS

    DarkoOS Newbie

    Joined:
    Feb 8, 2010
    Messages:
    19
    Likes Received:
    6
    Occupation:
    IT Manager
    Location:
    Osijek, Croatia
    Home Page:
    Hello,

    When open dialog show you need to find window hwnd by using Function SendMessage Lib "user32.dll". Try g00gle it you have lot of examples.
    or try my code, I made ​​little program that checks whether the open dialog is open, if it is then it paste file name and path and click Open in the end.

    Code:
        Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
        Private Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long
        Public Declare Function apiFindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
        'Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByRef lParam As IntPtr) As IntPtr
        Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByRef lParam As IntPtr) As Integer
        Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wparam As Integer, ByVal lparam As System.Text.StringBuilder) As IntPtr
    
            ' Find program/dialog handle; 32770 je za dialog
            Dim hWndNotepad As IntPtr
            hWndNotepad = FindWindow("#32770", "Choose File to Upload")
            If hWndNotepad = 0 Then
                'MsgBox("nisam pronasao prozor")
                Exit Sub
            Else
                '' Find the handle of the textbox, within the Notepad window
                'Dim hWndTextbox As IntPtr
                'hWndTextbox = apiFindWindowEx(hWndNotepad, IntPtr.Zero, "Button", "Cancel")
                Dim hWndEdit As IntPtr
                hWndEdit = apiFindWindowEx(hWndNotepad, IntPtr.Zero, "ComboBoxEx32", "")
                Dim hWndEdit1 As IntPtr
                hWndEdit1 = apiFindWindowEx(hWndEdit, IntPtr.Zero, "ComboBox", "")
                Dim hWndEdit2 As IntPtr
                hWndEdit2 = apiFindWindowEx(hWndEdit1, IntPtr.Zero, "Edit", "")
                'Dim ime As String = IO.Path.GetFileName(Application.ExecutablePath)
                    'vidi jel trebaš nešto promjeniti u imenu filea
                Dim sb As New System.Text.StringBuilder(imee)
                'Dim sb As New System.Text.StringBuilder("Alcohol 120 2.0.0.1331 + Patch.rar.torrent")
                Dim WM_SETTEXT As Integer = 12 '&HC 'decimalno 12
                SendMessage(hWndEdit2, WM_SETTEXT, 0, sb)
                'C:\ULAZ\L6115.pdf
                Dim hWndTextbox As IntPtr
                hWndTextbox = apiFindWindowEx(hWndNotepad, IntPtr.Zero, "Button", "&Open")
                Dim BN_CLICKED As Integer = 245
                SendMessage(hWndTextbox, BN_CLICKED, 0, IntPtr.Zero)
                IO.File.Delete("C:\ime.txt")
                End
                Exit Sub
            End If
    
    i have my own torrent uploader that i made long time ago, but i have lot of problem with IE control, now i use http web request/response it is complicated for coding but program work lot faster, with that i upload to 21 site ;-).

    if you need any help ask me.

    and sory for my bad english.

    Darko,
     
    • Thanks Thanks x 1