0

I am having some problems with python. If I use IE to POST data to a page using a simple form, I get the following

POST /automa/auth.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://maroon5/automa/login.php
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: maroon5
Content-Length: 44
Connection: Keep-Alive
Cache-Control: no-cache
fuser=jchaney&fpassword=n0p@ss&Submit=Submit

HTTP/1.1 200 OK
Date: Wed, 01 Apr 2009 20:32:59 GMT
Server: Apache/2.2.9 (Fedora)
X-Powered-By: PHP/5.2.6
Content-Length: 355
Connection: close
Content-Type: text/html; charset=UTF-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Automa - Form Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>Data is jchaney and n0p@ss</body>
</html>

But if I try the samething using the following script.

#!/usr/bin/python2
"""Connect and login
"""
import urllib
import urllib2
import httplib
params = urllib.urlencode({'fuser': 'jchaney', 'fpassword': 'n0p@ss'\
, 'submit': 'submit'})
headers = {"Content-type": "application/x-www-form-urlencoded",\
"Accept": "text/plain"}
conn = httplib.HTTPConnection('192.168.1.90:80')
conn.request("POST", "automa/auth.php", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()

I get a 400 Bad Request fault, see dump.

POST automa/auth.php HTTP/1.1
Host: 192.168.1.90
Accept-Encoding: identity
Content-Length: 46
Content-type: application/x-www-form-urlencoded
Accept: text/plain
fuser=jchaney&fpassword=n0p%40ss&submit=submit

HTTP/1.1 400 Bad Request
Date: Wed, 01 Apr 2009 20:18:27 GMT
Server: Apache/2.2.9 (Fedora)
Content-Length: 303
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.2.9 (Fedora) Server at 192.168.1.90 Port 80</address>
</body></html>

I am not sure what I am doing wrong in my code.
Thank you for any ideas.

2
Contributors
4
Replies
8
Views
8 Years
Discussion Span
Last Post by chaney44145
0

The passwords are fake and the system is intraneted, no external connections to the test box. Thank you for the concern though.

0

More information about error.
I set the httpd.conf error logging to debug and re-ran the script.
Results were:
[error] [client 192.168.1.153] Invalid URI in request POST automa/auth.php HTTP/1.1, referer:

Is there something special in the header that I am missing?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.