diff --git a/tanner/api/api.py b/tanner/api/api.py index 46b09f44..acab5912 100644 --- a/tanner/api/api.py +++ b/tanner/api/api.py @@ -43,7 +43,7 @@ async def return_snare_info(self, uuid, count=-1): query_res = [] try: query_res = await self.redis_client.zrevrangebyscore( - uuid, offset=0, count=count + uuid, offset=0, count=count, encoding='utf-8' ) except aioredis.ProtocolError as connection_error: self.logger.error('Can not connect to redis %s', connection_error) diff --git a/tanner/session_analyzer.py b/tanner/session_analyzer.py index 96b4c72a..5bbb04fc 100644 --- a/tanner/session_analyzer.py +++ b/tanner/session_analyzer.py @@ -19,8 +19,7 @@ async def analyze(self, session_key, redis_client): session = None await asyncio.sleep(1, loop=self._loop) try: - session = await redis_client.execute('get', session_key) - session = json.loads(session) + session = await redis_client.get(session_key, encoding='utf-8') except (aioredis.ProtocolError, TypeError, ValueError) as error: self.logger.error('Can\'t get session for analyze: %s', error) else: @@ -143,16 +142,17 @@ async def detect_crawler(self, stats, bots_owner, crawler_hosts): if stats['requests_in_second'] > 10: if stats['referer'] is not None: return (0.0, 0.5) - if stats['user_agent'] in bots_owner: + if stats['user_agent'] is not None and stats['user_agent'] in bots_owner: return (0.85, 0.15) return (0.5, 0.85) - if stats['user_agent'] in bots_owner: + if stats['user_agent'] is not None and stats['user_agent'] in bots_owner: hostname, _, _ = await self._loop.run_in_executor( None, socket.gethostbyaddr, stats['peer_ip'] ) - for crawler_host in crawler_hosts: - if crawler_host in hostname: - return (0.75, 0.15) + if hostname is not None: + for crawler_host in crawler_hosts: + if crawler_host in hostname: + return (0.75, 0.15) return (0.25, 0.15) return (0.0, 0.0) @@ -161,13 +161,14 @@ async def detect_attacker(self, stats, bots_owner, crawler_hosts, attacks): return 1.0 if stats['requests_in_second'] > 10: return 0.0 - if stats['user_agent'] in bots_owner: + if stats['user_agent'] is not None and stats['user_agent'] in bots_owner: hostname, _, _ = await self._loop.run_in_executor( None, socket.gethostbyaddr, stats['peer_ip'] ) - for crawler_host in crawler_hosts: - if crawler_host in hostname: - return 0.25 + if hostname is not None: + for crawler_host in crawler_hosts: + if crawler_host in hostname: + return 0.25 return 0.75 if stats['hidden_links'] > 0: return 0.5