Exemplo n.º 1
0
    def fetch(self,path):
        http=httplib.HTTP(self.host)
        #prepare header
        http.putrequest("GET",path)
        http.putheader("User-Agent",__file__)
        http.putheader("Host",self.host)
        http.putheader("Accept","*/*")
        http.endheaders()

        try:
            errcode,errmsg,headers=http.getreply()
        except Exception,e:
            print "Client failed error code:%s message:%s headers:%s"%(errcode,errmsg,headers)
Exemplo n.º 2
0
    def fetch(self, path):
        http = httplib.HTTP(self.host)
        # 准备头
        http.putrequest('GET', path)
        http.putheader("User-Agent", __file__)
        http.putheader('Host', self.host)
        http.putheader('Accept', '*/*')
        http.endheaders()

        try:
            errcode, errmsg, headers = http.getreply()
        except Exception, e:
            print "Client failed error code :%s message: %s, headers: %s" %(errcode, errmsg, headers)
 def grabFile(self):
     try:
         url = net.URL(JESConstants.HW_TABLE_LINK)
         if url.getPort() != -1:
             h = httplib.HTTP(url.getHost(), url.getPort())
         else:
             h = httplib.HTTP(url.getHost())
         h.putrequest('GET', url.getFile())
         h.putheader('Accept', 'text/html')
         h.putheader('Accept', 'text/plain')
         h.endheaders()
         errcode, errmsg, headers = h.getreply()
         f = h.getfile()
         data = f.read()  # Get the raw HTML
         f.close()
         return data
     except Exception:
         import sys
         a, b, c = sys.exc_info()
         print a, b, c
         print "Error in JESAddressFinder.grabFile, could not get target mail address for submission"
         return None
Exemplo n.º 4
0
 def process(self):
     print "\tSearching PGP results..."
     try:
     
         h = httplib.HTTP(self.server)
         h.putrequest('GET', "/pks/lookup?search=" + self.word + "&op=index")
         h.putheader('Host', self.hostname)
         h.putheader('User-agent', self.userAgent)
         h.endheaders()
         returncode, returnmsg, headers = h.getreply()
         self.results = h.getfile().read()
     except Exception, e:
         pass
Exemplo n.º 5
0
 def do_search_profiles(self):
     h = httplib.HTTP(self.server)
     h.putrequest(
         'GET',
         '/search?num=' + self.quantity + '&start=' + str(self.counter) +
         '&hl=en&meta=&q=site:www.google.es%20intitle:"Google%20Profile"%20"Companies%20I%27ve%20worked%20for"%20"at%20'
         + self.word + '"')
     h.putheader('Host', self.hostname)
     h.putheader('User-agent', self.userAgent)
     h.endheaders()
     returncode, returnmsg, headers = h.getreply()
     self.results = h.getfile().read()
     self.totalresults += self.results
Exemplo n.º 6
0
 def do_search(self):
     h = httplib.HTTP(self.server)
     h.putrequest(
         'GET', "/search?q=%40" + self.word + "&count=50&first=" +
         str(self.counter))
     h.putheader('Host', self.hostname)
     h.putheader('Cookie: SRCHHPGUSR=ADLT=DEMOTE&NRSLT=50')
     h.putheader('Accept-Language: en-us,en')
     h.putheader('User-agent', self.userAgent)
     h.endheaders()
     returncode, returnmsg, headers = h.getreply()
     self.results = h.getfile().read()
     self.totalresults += self.results
Exemplo n.º 7
0
 def do_search(self):
     h = httplib.HTTP(self.server)
     h.putrequest(
         'GET', "/search?num=" + self.quantity + "&start=" +
         str(self.counter) + "&hl=en&meta=&q=%40\"" + self.word + "\"")
     h.putheader('Host', self.hostname)
     h.putheader('User-agent', self.userAgent)
     h.endheaders()
     returncode, returnmsg, headers = h.getreply()
     self.results = h.getfile().read()
     self.totalresults += self.results
     print "/search?num=" + self.quantity + "&start=" + str(
         self.counter) + "&hl=en&meta=&q=%40\"" + self.word + "\""
Exemplo n.º 8
0
 def connect(self):
     try:
         h = httplib.HTTP(self.ip, self.myport)
         h.putrequest('GET', self.cmd)
         h.endheaders()
         errcode, errmsg, headers = h.getreply()
         self.file = h.getfile()
         self.connected = True
         return True
     except Exception, x:
         print x
         self.connected = False
         return False
Exemplo n.º 9
0
    def post(self, xml_str):
        """
        Post a status report to the living lab using multipart/form-data
        This is a bit on the messy side, but it does work
        """

        #print >>sys.stderr, xml_str

        self.num_reports += 1

        boundary = "------------------ThE_bOuNdArY_iS_hErE_$"
        headers = {
            "Host": self.host,
            "User-Agent": "NextShare status reporter 2009.4",
            "Content-Type": "multipart/form-data; boundary=" + boundary
        }

        base = ["--" + boundary]
        base.append(
            'Content-Disposition: form-data; name="NextShareData"; filename="NextShareData"'
        )
        base.append("Content-Type: text/xml")
        base.append("")
        base.append(xml_str)
        base.append("--" + boundary + "--")
        base.append("")
        base.append("")
        body = "\r\n".join(base)

        h = httplib.HTTP(self.host)
        h.putrequest("POST", self.path)
        h.putheader("Host", self.host)
        h.putheader("User-Agent", "NextShare status reporter 2009.4")
        h.putheader("Content-Type",
                    "multipart/form-data; boundary=" + boundary)
        h.putheader("content-length", str(len(body)))
        h.endheaders()
        h.send(body)

        errcode, errmsg, headers = h.getreply()
        #print errcode,errmsg

        if errcode != 200:
            if self.error_handler:
                try:
                    self.error_handler(errcode, h.file.read())
                except Exception, e:
                    pass
            else:
                print >> sys.stderr, "Error posting but no error handler:", errcode, h.file.read(
                )
Exemplo n.º 10
0
def PostMessage(username, password, device_id, cloud_url):
    # create HTTP basic authentication string, this consists of
    # "username:password" base64 encoded
    auth = base64.encodestring("%s:%s" % (username, password))[:-1]

    # open download file and encoded the data
    try:
        fileHandle = open(image_file, 'r')
    except IOError:
        print 'Usage: update_firmware.py <Username> <Password> <Device ID> [<Device Cloud URL>]'
        print '    Uses a local \"image.a\" to firmware download to device_id on target 0.\n'
        print '    ERROR: cannot open \"image.a\".\n'
        print '    File not found\n'
        return -1

    # build firmware download message sent to Device Cloud
    message = """<sci_request version="1.0">
        <update_firmware firmware_target="1" filename="%s">
            <targets>
                <device id="%s"/>
            </targets>
            <data>%s</data>
        </update_firmware>
    </sci_request>
    """ % (image_file, device_id, base64.encodestring(
        "%s" % fileHandle.read())[:-1])

    # to what URL to send the request with a given HTTP method
    webservice = httplib.HTTP(cloud_url, 80)
    webservice.putrequest("POST", "/ws/sci")

    # add the authorization string into the HTTP header
    webservice.putheader("Authorization", "Basic %s" % auth)
    webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
    webservice.putheader("Content-length", "%d" % len(message))
    webservice.endheaders()
    webservice.send(message)

    # get the response
    statuscode, statusmessage, header = webservice.getreply()
    response_body = webservice.getfile().read()

    # print the output to standard out
    if statuscode == 200:
        print '\nResponse:'
        print response_body
    else:
        print '\nError: %d %s' % (statuscode, statusmessage)
        print response_body

    webservice.close()
Exemplo n.º 11
0
    def do_search(self):
        h = httplib.HTTP(self.server)
        h.putrequest(
            'GET', "/search?q=%40" + self.word + "&count=50&first=" +
            str(self.counter))
        h.putheader('Host', self.hostname)
        h.putheader('Cookie: SRCHHPGUSR=ADLT=DEMOTE&NRSLT=50')
        h.putheader('Accept-Language: en-us,en')
        h.putheader('User-agent', self.userAgent)
        h.endheaders()
        returncode, returnmsg, response_headers = h.getreply()

        encoding = response_headers['content-type'].split('charset=')[-1]
        self.total_results += unicode(h.getfile().read(), encoding)
Exemplo n.º 12
0
    def do_search(self):
        h = httplib.HTTP(self.server)
        h.putrequest(
            'GET', "/search?num=" + str(self.quantity) + "&start=" +
            str(self.counter) + "&hl=en&meta=&q=site%3A123people.com%20" +
            self.word)
        h.putheader('User-agent', self.userAgent)
        h.endheaders()

        returncode, returnmsg, response_headers = h.getreply()
        encoding = response_headers['content-type'].split('charset=')[-1]
        self.last_results = unicode(h.getfile().read(), encoding)

        self.total_results += self.last_results
Exemplo n.º 13
0
    def _getXMLFromService(self, server, path):

        h = httplib.HTTP(server)
        h.putrequest('GET', path)
        h.putheader('Accept', 'text/html')
        h.putheader('Accept', 'text/plain')
        h.endheaders()
        errcode, errmsg, headers = h.getreply()
        f = h.getfile()
        data = f.read()
        f.close

        if errmsg == "OK":
            self.data = data
Exemplo n.º 14
0
 def do_search(self):
     h = httplib.HTTP(self.server)
     h.putrequest(
         'GET', "/search/web/results/?q=%40" + self.word +
         "&elements_per_page=50&start_index=" + str(self.counter))
     h.putheader('Host', self.hostname)
     h.putheader(
         'Referer', "http://" + self.hostname +
         "/search/web/results/?q=%40" + self.word)
     h.putheader('User-agent', self.userAgent)
     h.endheaders()
     returncode, returnmsg, headers = h.getreply()
     self.results = h.getfile().read()
     self.totalresults += self.results
Exemplo n.º 15
0
 def getPage(self, url):
     sys.stderr.write("Opening Page: %s" % (url))
     parsed = urlparse.urlparse(url)
     self.httplib_inst = httplib.HTTP(parsed.netloc)
     self.httplib_inst.putrequest('GET', parsed.path)
     self.httplib_inst.putheader('Host', parsed.netloc)
     self.httplib_inst.putheader('Accept', 'text/html')
     self.httplib_inst.putheader('User-agent', self.UserAgent)
     try:
         self.httplib_inst.endheaders()
         code, msg, headers = self.httplib_inst.getreply()
     except socket.error, e:
         return (False,
                 'Socket Error: Could not create connection to ' + url)
Exemplo n.º 16
0
    def do_search_profiles(self):
        h = httplib.HTTP(self.server)
        h.putrequest(
            'GET', '/search?num=' + str(self.quantity) + '&start=' +
            str(self.counter) +
            '&hl=en&meta=&q=site:www.google.com%20intitle:"Google%20Profile"%20"Companies%20I%27ve%20worked%20for"%20"at%20'
            + self.word + '"')
        h.putheader('Host', self.hostname)
        h.putheader('User-agent', self.userAgent)
        h.endheaders()

        returncode, returnmsg, response_headers = h.getreply()
        encoding = response_headers['content-type'].split('charset=')[-1]
        self.total_results += unicode(h.getfile().read(), encoding)
Exemplo n.º 17
0
def tester(path):

    try:  # make a http HEAD request
        h = httplib.HTTP(host.split("/", 1)[0], int(port))
        h.putrequest("GET", "/" + path.split("/", 1)[1])
        h.putheader("Host", host.split("/", 1)[0])
        h.endheaders()
        status, reason, headers = h.getreply()
        if verbose == 1:
            print "[+]", status, reason, ":", "/" + path.split("/", 1)[1]
        return status, reason, headers.get("Server")
    except (), msg:
        print "[-] Error Occurred\n", msg
        sys.exit(1)
Exemplo n.º 18
0
def runattack(apath, shell):
    proxy = globals()['proxy']
    host = globals()['host']
    path = globals()['joomlapath']
    p404 = globals()['p404']
    #print "Apath:",apath,"- Shell:",shell
    if proxy:
        h = httplib.HTTP(proxy)
        h.putrequest("GET", "http://" + host + "/" + path + "/" + apath)
    else:
        h = httplib.HTTP(host)
        h.putrequest("HEAD", "/" + path + "/" + apath)
    h.putheader("Host", host)
    h.endheaders()
    try:
        status, reason, headers = h.getreply()
        if status == 200:
            print 'Found: ' + apath + ': Use Shell: ' + shell
        elif p404:
            print 'Not Found:', apath, status, reason
    except (), msg:
        print "Error Occurred:", msg
        pass
Exemplo n.º 19
0
    def upload(self, image, aid=None, caption=None, size=(604, 1024)):
        """Facebook API call. See http://developers.facebook.com/documentation.php?v=1.0&method=photos.upload

        size -- an optional size (width, height) to resize the image to before uploading. Resizes by default
                to Facebook's maximum display width of 604.
        """
        args = {}

        if aid is not None:
            args['aid'] = aid

        if caption is not None:
            args['caption'] = caption

        args = self._client._build_post_args('facebook.photos.upload', self._client._add_session_args(args))

        try:
            import cStringIO as StringIO
        except ImportError:
            import StringIO

        try:
            import Image
        except ImportError:
            data = StringIO.StringIO(open(image, 'rb').read())
        else:
            img = Image.open(image)
            if size:
                img.thumbnail(size, Image.ANTIALIAS)
            data = StringIO.StringIO()
            img.save(data, img.format)

        content_type, body = self.__encode_multipart_formdata(list(args.items()), [(image, data)])
        h = httplib.HTTP('api.facebook.com')
        h.putrequest('POST', '/restserver.php')
        h.putheader('Content-Type', content_type)
        h.putheader('Content-Length', str(len(body)))
        h.putheader('MIME-Version', '1.0')
        h.putheader('User-Agent', 'PyFacebook Client Library')
        h.endheaders()
        h.send(body)

        reply = h.getreply()

        if reply[0] != 200:
            raise Exception('Error uploading photo: Facebook returned HTTP %s (%s)' % (reply[0], reply[1]))

        response = h.file.read()

        return self._client._parse_response(response, 'facebook.photos.upload')
Exemplo n.º 20
0
    def __init__(self, url):
        self._url = urlparse.urlparse(url)

        h = httplib.HTTP(self._url.netloc)
        h.putrequest('GET', self._url.path)
        h.endheaders()
        errcode, errmsg, headers = h.getreply()

        if errcode == 200:
            ndx = headers["content-type"].find('=') + 1
            self._boundary = headers["content-type"][ndx:]
            self._fh = h.getfile()
        else:
            raise RuntimeError("HTTP %d: %s" % (errcode, errmsg))
Exemplo n.º 21
0
def GetOAuthToken(key, secret):
	conn = httplib.HTTP(host)
	conn.putrequest('POST', '/oauth/token')
	conn.putheader("Content-type", "application/x-www-form-urlencoded")
	
	auth = base64.encodestring('%s:%s' % (key, secret)).replace('\n', '')
	conn.putheader("Authorization", "Basic %s" % auth)
	conn.endheaders()
	conn.send(message)
	statuscode, statusmessage, header = conn.getreply()	
	
	res = conn.getfile().read()
	#return the access token from the json response
	return res
Exemplo n.º 22
0
 def doRequest(self):
     URL = self.getConfig("pushUrl")
     request = self.getXmlData()
     webservice = httplib.HTTP(URL)
     webservice.putrequest("POST", self.getConfig("pushId"))
     webservice.putheader("Host", URL)
     webservice.putheader("Content-type", "text/xml")
     webservice.putheader("X-NotificationClass", "2")
     webservice.putheader("X-WindowsPhone-Target", "toast")
     webservice.putheader("Content-length", "%d" % len(request))
     webservice.endheaders()
     webservice.send(request)
     webservice.close()
     self.setStorage("LAST_NOTIFY", time.time())
Exemplo n.º 23
0
 def do_search(self):
     h = httplib.HTTP(self.server)
     h.putrequest(
         'GET', "/s?wd=%40" + self.word + "&rn=100&pn=" + str(self.counter))
     h.putheader('Host', self.hostname)
     h.putheader(
         'Cookie: H_PS_PSSID=4454_1421_4414_4261_4202_4587; BAIDUID=ABE16F3C528AB718BFDBAAAA76626AC3:SL=0:NR=100:FG=1; BDRCVFR[feWj1Vr5u3D]=mk3SLVN4HKm; sug=3; bdime=0; BD_TMP_CK=true'
     )
     h.putheader('Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3')
     h.putheader('User-agent', self.userAgent)
     h.endheaders()
     returncode, returnmsg, headers = h.getreply()
     self.results = h.getfile().read()
     self.totalresults += self.results
Exemplo n.º 24
0
    def fetch(self):
        conn = httplib.HTTP(self.remote_host, port=8888)

        # Prepare Header
        conn.putrequest("GET", REMOTE_PATH)
        conn.putheader("User_agent", __file__)
        conn.putheader("Host", self.remote_host)
        conn.putheader("Accept", "*/*")
        conn.endheaders()
        try:
            errcode, errmsg, headers = conn.getreply()
        except Exception, e:
            print "Client failed error code: %s message: %s, headers: %s" % (
                errcode, errmsg, headers)
Exemplo n.º 25
0
def post_multipart(host, selector, fields, files):
    # Adapted from http://code.activestate.com/recipes/146306-http-client-to-post-using-multipartform-data/
    content_type, body = encode_multipart_formdata(fields, files)
    h = httplib.HTTP(host)
    h.putrequest('POST', selector)
    h.putheader('host', host)
    h.putheader('referer', 'http://www.tineye.com/')
    h.putheader('User-Agent: nautilus-tineye-plugin')
    h.putheader('content-type', content_type)
    h.putheader('content-length', str(len(body)))
    h.endheaders()
    h.send(body)
    errcode, errmsg, headers = h.getreply()
    return headers.__str__()
Exemplo n.º 26
0
 def soapRequest(self, host, SoapMessage):
     webservice = httplib.HTTP(host)
     webservice.putrequest("POST", "/defaultroot/xfservices/GeneralWeb")
     webservice.putheader("Host", host)
     webservice.putheader("User-Agent",
                          "Apache-HttpClient/4.1.1 (java 1.5)")
     webservice.putheader("Content-Type", "text/xml; charset=\"UTF-8\"")
     webservice.putheader("Content-Length", "%d" % len(SoapMessage))
     webservice.putheader("SOAPAction", "")
     webservice.endheaders()
     webservice.send(SoapMessage)
     webservice.getreply()
     reply = webservice.getfile().read()
     return reply
Exemplo n.º 27
0
def prueba():
    h = httplib.HTTP('www.cwi.nl')
    h.putrequest('GET', '/index.html')
    h.putheader('Accept', 'text/html')
    h.putheader('Accept', 'text/plain')
    h.endheaders()

    errcode, errmsg, headers = h.getreply()

    print(errcode)
    f = h.getfile()
    data = f.read()
    print(data)
    f.close()
Exemplo n.º 28
0
	def run_search(self):
		try:
			con = httplib.HTTP(self.server)
			con.putrequest('GET', '/search?text=%40'+self.keyword+"&numdoc=100&lr=100")
			con.putheader('Host', self.host)
			con.putheader('User-agent', self.u_agent)
			con.endheaders()
			# return code,messagge and header
			returncode, returnmsg, header = con.getreply()
			self.results = con.getfile().read()
			self.tresult += self.results
		except Exception as err: 
			print "\t   |"
			print "\t   |__"+self.r+" Server not found!!\n"+self.t
Exemplo n.º 29
0
    def httplib(self, server, query, cookie=None):
        try:
            con = httplib.HTTP(server)
            con.putrequest('GET', query)
            con.putheader("Host", server)
            if cookie != None:
                con.putheader("Cookie", cookie)
            con.putheader("User-agent", self.user_agent)
            con.endheaders()

            returncode, returnmsg, headrs = con.getreply()
            return con.getfile().read()
        except Exception as error:
            return error
Exemplo n.º 30
0
    def do_search(self):
        h = httplib.HTTP(self.server)

        #Dogpile is hardcoded to return 10 results
        h.putrequest(
            'GET', "/search/web?qsi=" + str(self.counter) + "&q=\"%40" +
            self.word + "\"")
        h.putheader('Host', self.hostname)
        h.putheader('User-agent', self.userAgent)
        h.endheaders()

        returncode, returnmsg, response_headers = h.getreply()
        encoding = response_headers['content-type'].split('charset=')[-1]
        self.total_results += unicode(h.getfile().read(), encoding)