Need help for Python packet replicate

deathx01

Registered Member
Joined
Oct 23, 2012
Messages
97
Reaction score
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.
 
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
 
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
 
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.

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
 
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
 
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 !
 
Javascript calls post method that probably calls the same file which then activates logic to process multipart post request.
Check this out: http://docs.python-requests.org/en/latest/user/advanced/
 
I was also looking for the solution like this so i think i can do this on my own now.
 
hey , i wan to learn Phython , can you please give me the source , where i can start learning or place of free tutorials
 
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.
 
hey , i wan to learn Phython , can you please give me the source , where i can start learning or place of free tutorials
Google up "Learn Python the Hard Way". There's a free HTML version. Best Python book I've read so far.
 
Back
Top