Skip to content

Commit

Permalink
PEP-8 fixes (#191)
Browse files Browse the repository at this point in the history
Fix #191
  • Loading branch information
rjt-gupta authored and rnehra01 committed Mar 14, 2019
1 parent 6b8b692 commit 35846cd
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 17 deletions.
4 changes: 2 additions & 2 deletions snare/cloner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, root, max_depth, css_validate):
self.max_depth = max_depth
self.moved_root = None
if len(self.root.host) < 4:
sys.exit('invalid taget {}'.format(self.root.host))
sys.exit('invalid target {}'.format(self.root.host))
self.target_path = '/opt/snare/pages/{}'.format(self.root.host)

if not os.path.exists(self.target_path):
Expand Down Expand Up @@ -157,7 +157,7 @@ async def get_body(self, session):
if not carved_url.is_absolute():
carved_url = self.root.join(carved_url)
if carved_url.human_repr() not in self.visited_urls:
await self.new_urls.put((carved_url, level+1))
await self.new_urls.put((carved_url, level + 1))

async def get_root_host(self):
try:
Expand Down
1 change: 1 addition & 0 deletions snare/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def error_middleware(request, handler):
if override:
return await override(request)
raise

return error_middleware

def setup_middlewares(self, app):
Expand Down
4 changes: 2 additions & 2 deletions snare/tanner_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create_data(self, request, response_status):
data['method'] = request.method
data['headers'] = header
data['path'] = request.path_qs
if ('Cookie' in header):
if 'Cookie' in header:
data['cookies'] = {
cookie.split('=')[0]: cookie.split('=')[1] for cookie in header['Cookie'].split(';')
}
Expand Down Expand Up @@ -123,4 +123,4 @@ async def parse_tanner_response(self, requested_name, detection):
payload_content = detection['payload']
status_code = payload_content['status_code']

return (content, content_type, headers, status_code)
return content, content_type, headers, status_code
Empty file modified snare/tests/test_add_meta_tag.py
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions snare/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_converter(self):
s = json.load(f)
self.hname1 = s['index.html']['hash']
self.hname2 = s['depth/page.html']['hash']
assert(os.path.exists(self.page_path + self.hname1) and
os.path.exists(self.page_path + self.hname2))
assert (os.path.exists(self.page_path + self.hname1) and
os.path.exists(self.page_path + self.hname2))

def tearDown(self):
shutil.rmtree('/tmp/test')
2 changes: 1 addition & 1 deletion snare/tests/test_create_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUp(self):
os.makedirs(self.main_page_path)
page_dir = self.main_page_path.rsplit('/')[-1]
args = run_args.parse_args(['--page-dir', page_dir])
snare_uuid = ('9c10172f-7ce2-4fb4-b1c6-abc70141db56').encode('utf-8')
snare_uuid = '9c10172f-7ce2-4fb4-b1c6-abc70141db56'.encode('utf-8')
args.no_dorks = True
self.handler = TannerHandler(args, meta, snare_uuid)
headers = {
Expand Down
5 changes: 4 additions & 1 deletion snare/tests/test_get_dorks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUp(self):
timer=None, request_info=None, traces=None, loop=self.loop,
session=None
)
)
)
no_dorks = True
tanner = "tanner.mushmush.org"
self.handler = HtmlHandler(no_dorks, tanner)
Expand All @@ -32,6 +32,7 @@ def test_get_dorks(self):

async def test():
self.data = await self.handler.get_dorks()

self.loop.run_until_complete(test())
aiohttp.ClientSession.get.assert_called_with('http://tanner.mushmush.org:8090/dorks', timeout=10.0)

Expand All @@ -40,6 +41,7 @@ def test_return_dorks(self):

async def test():
self.data = await self.handler.get_dorks()

self.loop.run_until_complete(test())
self.assertEquals(self.data, self.dorks['response']['dorks'])

Expand All @@ -48,6 +50,7 @@ def test_return_dorks_exception(self):

async def test():
self.data = await self.handler.get_dorks()

with self.assertRaises(Exception):
self.loop.run_until_complete(test())

Expand Down
3 changes: 3 additions & 0 deletions snare/tests/test_handle_html_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_handle_content(self):

async def test():
self.return_content = await self.handler.handle_content(self.content)

self.loop.run_until_complete(test())
soup = BeautifulSoup(self.return_content, "html.parser")
return_content = soup.decode("utf-8")
Expand All @@ -46,6 +47,7 @@ def test_handle_content_no_dorks(self):

async def test():
self.return_content = await self.handler.handle_content(self.content)

self.loop.run_until_complete(test())
soup = BeautifulSoup(self.return_content, "html.parser")
self.return_content = soup.decode("utf-8")
Expand All @@ -57,6 +59,7 @@ def test_handle_content_exception(self):

async def test():
self.return_content = await self.handler.handle_content(self.content)

with self.assertRaises(IndexError):
self.loop.run_until_complete(test())

Expand Down
10 changes: 5 additions & 5 deletions snare/tests/test_handle_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
os.makedirs(self.main_page_path)
self.page_dir = self.main_page_path.rsplit('/')[-1]
args = run_args.parse_args(['--page-dir', self.page_dir])
uuid = ('9c10172f-7ce2-4fb4-b1c6-abc70141db56').encode('utf-8')
uuid = '9c10172f-7ce2-4fb4-b1c6-abc70141db56'.encode('utf-8')
args.tanner = 'tanner.mushmush.org'
args.no_dorks = True
args.server_header = "test_server"
Expand Down Expand Up @@ -66,30 +66,30 @@ def setUp(self):
return_value=(self.content, self.content_type, self.data['headers'], self.data['headers']['status']))

def test_create_request_data(self):

async def test():
await self.handler.handle_request(self.request)

self.loop.run_until_complete(test())
self.handler.tanner_handler.create_data.assert_called_with(self.request, 200)

def test_submit_request_data(self):

async def test():
await self.handler.handle_request(self.request)

self.loop.run_until_complete(test())
self.handler.tanner_handler.submit_data.assert_called_with(self.data)

def test_submit_request_slurp(self):

async def test():
await self.handler.handle_request(self.request)

self.loop.run_until_complete(test())
self.handler.submit_slurp.assert_called_with(self.request.path_qs)

def test_parse_response(self):

async def test():
await self.handler.handle_request(self.request)

self.loop.run_until_complete(test())
self.handler.tanner_handler.parse_tanner_response.assert_called_with(self.request.path_qs, {'type': 1})

Expand Down
5 changes: 5 additions & 0 deletions snare/tests/test_parse_tanner_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_parse_type_one(self):
async def test():
(self.res1, self.res2,
self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection)

self.loop.run_until_complete(test())
real_result = [self.res1, self.res2, self.res3, self.res4]
expected_result = [self.page_content, self.content_type, {}, 200]
Expand All @@ -66,6 +67,7 @@ def test_parse_type_two(self):
async def test():
(self.res1, self.res2,
self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection)

self.loop.run_until_complete(test())
real_result = [self.res1, self.res2, self.res3, self.res4]
expected_result = [self.expected_content, self.content_type, {}, 200]
Expand All @@ -85,6 +87,7 @@ def test_parse_type_three(self):
async def test():
(self.res1, self.res2,
self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection)

self.loop.run_until_complete(test())
real_result = [self.res1, self.res2, self.res3, self.res4]
expected_result = [self.expected_content, None, {}, 200]
Expand All @@ -98,6 +101,7 @@ def test_call_handle_html(self):
async def test():
(self.res1, self.res2,
self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection)

self.loop.run_until_complete(test())
self.handler.html_handler.handle_content.assert_called_with(self.call_content)

Expand All @@ -109,6 +113,7 @@ def test_parse_exception(self):
async def test():
(self.res1, self.res2,
self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection)

with self.assertRaises(KeyError):
self.loop.run_until_complete(test())

Expand Down
5 changes: 4 additions & 1 deletion snare/tests/test_submit_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def setUp(self):
timer=None, request_info=None, traces=None, loop=self.loop,
session=None
)
)
)
uuid = "test_uuid"
args.tanner = "tanner.mushmush.org"
args.no_dorks = True
Expand All @@ -50,6 +50,7 @@ def test_post_data(self):

async def test():
self.result = await self.handler.submit_data(self.data)

self.loop.run_until_complete(test())
aiohttp.ClientSession.post.assert_called_with(
'http://tanner.mushmush.org:8090/event', data=json.dumps(self.data), timeout=10.0
Expand All @@ -60,6 +61,7 @@ def test_event_result(self):

async def test():
self.result = await self.handler.submit_data(self.data)

self.loop.run_until_complete(test())
self.assertEquals(self.result, dict(detection={'type': 1}, sess_uuid="test_uuid"))

Expand All @@ -68,6 +70,7 @@ def test_event_result_exception(self):

async def test():
self.result = await self.handler.submit_data(self.data)

with self.assertRaises(Exception):
self.loop.run_until_complete(test())

Expand Down
2 changes: 1 addition & 1 deletion snare/utils/page_path_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ def directory_generator(size=9, chars=string.ascii_lowercase + string.digits):

def generate_unique_path():
path = '/opt/snare/pages/' + directory_generator()
while(os.path.exists(path)):
while os.path.exists(path):
path = '/opt/snare/pages/' + directory_generator()
return path
4 changes: 2 additions & 2 deletions snare/utils/snare_helpers.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def add_meta_tag(page_dir, index_page, config):
main_page = main.read()
soup = BeautifulSoup(main_page, 'html.parser')

if (google_content and soup.find("meta", attrs={"name": "google-site-verification"}) is None):
if google_content and soup.find("meta", attrs={"name": "google-site-verification"}) is None:
google_meta = soup.new_tag('meta')
google_meta.attrs['name'] = 'google-site-verification'
google_meta.attrs['content'] = google_content
soup.head.append(google_meta)
if (bing_content and soup.find("meta", attrs={"name": "msvalidate.01"}) is None):
if bing_content and soup.find("meta", attrs={"name": "msvalidate.01"}) is None:
bing_meta = soup.new_tag('meta')
bing_meta.attrs['name'] = 'msvalidate.01'
bing_meta.attrs['content'] = bing_content
Expand Down

0 comments on commit 35846cd

Please sign in to comment.