Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tanner develop fixes phase #2 #263

Merged
merged 4 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tanner/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 12 additions & 11 deletions tanner/session_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down