Esempio n. 1
0
	def searchOnVT(self, text):
		ret = {}
		resp, error = Req().request(self.app.config['googlesearch'] % quote('site:virustotal.com "%s"' % text))
		if not error:
			for item in re.findall(r'<li class="g">.*?</li>', resp.read()):
				url, date = item.split('</h3>')
				date = re.search(r'(\d{1,2}\s+\w{3}\s+\d{2,4})|(\d)\s+days?\s+ago', date, re.I)
				url = re.search(r'resource=([a-f0-9]{32,})|file/([a-f0-9]{32,})|scan/([a-f0-9]{32,})|analisis/([a-f0-9]{32,})', unquote(url), re.I)
				if url and date:
					url = filter(lambda u: u != None, url.groups())[0].lower()
					if not ret.has_key(url):
						ret[url] = self.__dateFormat(date.groups())
			items = [i[0] for i in sorted(ret.iteritems(), key = operator.itemgetter(1))[::-1]][:self.app.config['googlemaxresults']]
			return (self.searchInDB(items), resp.response.code)
		else:
			return ('Unable to connect to www.google.com. ' + error, 503)
Esempio n. 2
0
	def __readJSON(self, url, data = {}):
		resp, error = Req().request(url, data)
		if not error:
			data = resp.read()
			return (json.loads(data) if self.parseJSON else data, resp.response.code)
		return (error, 503)