forked from ketaminekid423/SprayingToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aerosol.py
executable file
·82 lines (67 loc) · 2.47 KB
/
aerosol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import lxml.html
import asyncio
import json
import boto3
import signal
import os
from core.utils.messages import print_info, print_good
from mitmproxy import http, ctx
#from IPython import embed
class Aerosol:
def __init__(self):
self.words = set()
self.comprehend = None
self.loop = asyncio.get_event_loop()
for sig in (signal.SIGINT, signal.SIGTERM):
self.loop.add_signal_handler(sig, self.shutdown)
def load(self, loader):
loader.add_option(
name="target",
typespec=str,
default='',
help="Target domain or URL"
)
loader.add_option(
name="language",
typespec=str,
default='en',
help='text language'
)
loader.add_option(
name='aws_region',
typespec=str,
default='us-east-1',
help='AWS region'
)
def running(self):
if not self.comprehend:
self.comprehend = boto3.client(
service_name='comprehend',
region_name=ctx.options.aws_region,
aws_access_key_id=os.environ['AWS_ACCESS_KEY'],
aws_secret_access_key=os.environ['AWS_SECRET_KEY']
)
def response(self, flow: http.HTTPFlow) -> None:
try:
if "html" in flow.response.headers["Content-Type"] and len(flow.response.content):
if ctx.options.target in flow.request.host:
html = lxml.html.fromstring(flow.response.content)
the_best_words = set(html.xpath('//text()'))
ctx.log.info(print_good(f"Got {len(the_best_words)} words, the best words..."))
self.words |= the_best_words
except KeyError:
pass
def shutdown(self):
if len(self.words):
text = ' '.join(self.words)
ctx.log.info(print_info('Calling DetectKeyPhrases'))
ctx.log.info(json.dumps(self.comprehend.detect_key_phrases(Text=text, LanguageCode=ctx.options.language), sort_keys=True, indent=4))
ctx.log.info(print_info('Calling DetectEntities'))
ctx.log.info(json.dumps(self.comprehend.detect_entities(Text=text, LanguageCode=ctx.options.language), sort_keys=True, indent=4))
self.loop.stop()
pending = asyncio.Task.all_tasks()
self.loop.run_until_complete(asyncio.gather(*pending))
addons = [
Aerosol()
]