aboutsummaryrefslogtreecommitdiffstats
path: root/broken/propagate/src/cli_fe_http.py
blob: 40b73736ac1b457b047a40fa6c7487d1252d4f76 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import httplib
import urllib
import optparse
import Cookie
"""
    Christian
	Usage: The following program reads strings from the standard input 
		   and sends them to the server ([host] [port]) in the POST 
		   request on URL  [url] in field 'cmd'.
		   The result is read from the COOKIE "result" and displayed.
"""
def send_cmd_http_post(host, port=80, base64command="base64command", url="/test.php"):
	headers = { "Content-type": "application/x-www-form-urlencoded" }
	params = urllib.urlencode({'cmd': base64command})
	conn = httplib.HTTPConnection(host, port)
	conn.request("POST", url, params, headers)
	response = conn.getresponse()
	
	response_headers = dict(response.getheaders())
	if ('set-cookie' in response_headers):
		cookie = Cookie.BaseCookie(response_headers['set-cookie'])
		return cookie["result"].value
	return "result-cookie-not-found"
	
if __name__ == '__main__':
	usage = "usage: %prog host port url"
	parser = optparse.OptionParser(usage=usage)
	(options, args) = parser.parse_args()
	if len(args) != 3:
		parser.error("incorrect number of arguments")
	host, port, url = args
	while (True):
		base64command = raw_input()
		print send_cmd_http_post(host, int(port), base64command, url)