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

Need help for Python packet replicate

Discussion in 'Other Languages' started by deathx01, Oct 31, 2012.

  1. deathx01

    deathx01 Registered Member

    Joined:
    Oct 23, 2012
    Messages:
    91
    Likes Received:
    21
    I need some help to upload a file to a website using packet replicate in python language. I have seen some tutorial , people are using "requests" modules or urllib2, but I dont understand how to do it. I am a beginner in packet analyse and replicate. I think i need to analyse the packets of the website ( maybe using ethereal) and reproduce the same packet that the website is using. If you have any cue's or link that can help me out , i'lll be really thanksfull.
     
  2. closedCaption

    closedCaption Regular Member

    Joined:
    Oct 3, 2011
    Messages:
    289
    Likes Received:
    111
    First lets sort terminology. Packet replicate would involve going down to bare network functions, and use sockets to manually assemble packets. This is possible in Python (using Pcapy), but you don't need to go that far. What you are talking here is request replication. In simple terms, when you are surfing Web, your browser sends POST/GET requests with some parameters that decide what you want to fetch. You need to emulate those requests (with parameters) to produce desired result.
    In your case, uploading a file can be done in this manner: http://www.doughellmann.com/PyMOTW/urllib2/#uploading-files
     
    • Thanks Thanks x 2
  3. closedCaption

    closedCaption Regular Member

    Joined:
    Oct 3, 2011
    Messages:
    289
    Likes Received:
    111
    BTW, use Fiddler to capture and analyse packets, its user friendly.
     
  4. deathx01

    deathx01 Registered Member

    Joined:
    Oct 23, 2012
    Messages:
    91
    Likes Received:
    21
    I was using Firebug to see the get/post , i'll give a try ! Thanks ! I have a question , how to find what type of http auth is using a website , for example google. I want to login in using http requests but i dont know witch type of http auth he is using ( form, basic , digest ) ... :) Thanks
     
  5. closedCaption

    closedCaption Regular Member

    Joined:
    Oct 3, 2011
    Messages:
    289
    Likes Received:
    111
    Fiddler is more powerful then Firebug.

    Unless site is lost in time, they usually use form auth, via POST request. If dialog box pops up, it is usually basic auth.

    Set Fiddler so it sends its own certificate to your browser. This way you will see what are the name of the fields that send auth data.

     
  6. matessim

    matessim Junior Member

    Joined:
    Nov 22, 2008
    Messages:
    164
    Likes Received:
    72
    Occupation:
    Being funny and kind to puppies
    Location:
    UT 2003
    I suggest you read the requests module documentation.

    Also, for analyzing software communication and mocking it picking up wireshark and knowing how to use it could be a good idea, don't know about Fiddler due to the fact i never used it
     
    • Thanks Thanks x 1
  7. deathx01

    deathx01 Registered Member

    Joined:
    Oct 23, 2012
    Messages:
    91
    Likes Received:
    21
    I have been practicing the past week with good result. But 2 problems remains, i dont know where to start when website is using https for auth, like google for example. I try it with python module requests , mechanize, urllib2, but i cant get it. And after how upload a file when we are in https connection, and when the uploading is made trought an "explorer dialog browser" with no form object only "onclick" that activate javascript. And i think i need to handle cookies too , requests and urllib2 seem can do it , but what's the step for handeling such cookies :)... Txs for your time !
     
  8. closedCaption

    closedCaption Regular Member

    Joined:
    Oct 3, 2011
    Messages:
    289
    Likes Received:
    111
    • Thanks Thanks x 1
  9. queenmery

    queenmery Power Member

    Joined:
    Jan 18, 2011
    Messages:
    501
    Likes Received:
    30
    Occupation:
    Student
    Location:
    BANGLADESH
    I was also looking for the solution like this so i think i can do this on my own now.
     
  10. cycoshas

    cycoshas Regular Member

    Joined:
    Jan 2, 2012
    Messages:
    241
    Likes Received:
    59
    Home Page:
    hey , i wan to learn Phython , can you please give me the source , where i can start learning or place of free tutorials
     
  11. closedCaption

    closedCaption Regular Member

    Joined:
    Oct 3, 2011
    Messages:
    289
    Likes Received:
    111
    Try Google for a change.

     
  12. pedrosilva

    pedrosilva Registered Member

    Joined:
    Feb 27, 2013
    Messages:
    51
    Likes Received:
    1
    The best way for this would be to use jmeter (and java) it's simpler to work with requests that way. PM me if you need some introduction to jmeter ;)
    Its very simple to make requests , keep cookies, sessions etc with it.
     
  13. bkshock

    bkshock Newbie

    Joined:
    Mar 13, 2012
    Messages:
    30
    Likes Received:
    12
    Google up "Learn Python the Hard Way". There's a free HTML version. Best Python book I've read so far.