-
-
Notifications
You must be signed in to change notification settings - Fork 508
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
TorBot GUI #152
TorBot GUI #152
Changes from 36 commits
d69ade6
cfdb4c3
e055ab1
d43521a
81a3316
6d54348
e119490
d52b5a6
30b82d7
d725b11
06ef3be
36f0f86
941e8fe
66b1376
2a08689
dc5636b
540e68e
a143d36
9bbe784
0c14198
d8c42f8
f994c3c
31ba103
f5a3b14
9b1ff79
200917d
85cc2aa
9265007
aa70a9a
43dd359
1989da5
622a931
54515e9
71594bf
e9032c7
e33e272
fcf739d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
flake8: | ||
enabled: true | ||
enabled: true | ||
eslint: | ||
enbaled: true | ||
config_file: ./ui/.eslintrc.json | ||
jshint: | ||
enabled: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if [ -f ../torBot.py ]; then | ||
python3 ../torBot.py --server | ||
fi | ||
if [ -f torBot.py ]; then | ||
python3 torBot.py --server | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Module contains onion proxy related code | ||
""" | ||
import requests | ||
|
||
proxies = { | ||
'http': 'socks5h://localhost:9050', | ||
'https': 'socks5h://localhost:9050' | ||
} | ||
|
||
session = requests.session() | ||
session.proxies = proxies | ||
|
||
|
||
def set_proxy(host, port): | ||
""" | ||
Sets host and port for tor proxies being used when performing | ||
irequests to onion domains. | ||
|
||
Args: | ||
host (string): host name or IP Address | ||
port (string): port number | ||
""" | ||
global proxies # Allows us to modify global variable directly | ||
global session | ||
proxies = { | ||
'http': 'socks5h://' + host + ':' + port, | ||
'https': 'socks5h://' + host + ':' + port | ||
} | ||
session.proxies = proxies | ||
|
||
|
||
def proxy_get(url, headers=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
""" | ||
Peforms GET request using socks5 proxy | ||
|
||
Args: | ||
url (string): url to retreive | ||
headers (dict): mapping of headers for requests | ||
""" | ||
if headers: | ||
return session.get(url, headers=headers) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line at end of file |
||
return session.get(url) | ||
|
||
|
||
def proxy_head(url, timeout=10, headers=None): | ||
""" | ||
Peforms HEAD request using socks5 proxy | ||
|
||
Args: | ||
url (string): url to retreive | ||
headers (dict): mapping of headers for requests | ||
""" | ||
if headers: | ||
return session.head(url, timeout=timeout, headers=headers) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line at end of file |
||
return session.head(url, timeout=timeout) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
""" | ||
Module contains WebSocket server | ||
""" | ||
|
||
# Built-in Imports | ||
import asyncio | ||
import json | ||
import logging | ||
|
||
# Third Party Imports | ||
import tldextract | ||
import websockets | ||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
# Local Imports | ||
from .link import LinkNode | ||
from .proxy import proxy_get, proxy_head | ||
|
||
|
||
# Setting up logging format | ||
# Logs include {time} {loglevel} {logmessage} | ||
logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', | ||
level=logging.INFO, | ||
datefmt='%Y-%m-%d %H:%M:%S') | ||
|
||
|
||
async def handle_msg(websocket, path): | ||
""" | ||
Handles incoming WebSocket messages from front-end. | ||
The appropriate action is taken based on the message. | ||
|
||
Args: | ||
websocket (websockets.protocol): websocket connection being used | ||
path (string): contains origin of websocket message | ||
""" | ||
msg = await websocket.recv() | ||
data = json.loads(msg) # Load JSON response from front-end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at least two spaces before inline comment |
||
url = data['url'] | ||
# action determines what we will do with the url | ||
action = data['action'] | ||
if action == 'get_links': | ||
async for link in get_links(url): | ||
response = json.dumps(link) | ||
await websocket.send(response) | ||
elif action == 'get_info': | ||
headers = get_response_headers(url) | ||
response = json.dumps(headers) | ||
await websocket.send(response) | ||
|
||
|
||
def get_response_headers(url): | ||
response = requests.head(url) | ||
return dict(response.headers) | ||
|
||
async def get_links(url): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
""" | ||
Get links from url | ||
|
||
Args: | ||
url (string): url to get links from | ||
Returns: | ||
links (list): list containing links | ||
""" | ||
ext = tldextract.extract(url) | ||
tor = ext.domain == 'onion' or ext.suffix == 'onion' | ||
|
||
# If there's an error with the url then we return it to be logged and sent | ||
try: | ||
if tor: | ||
response = proxy_get(url) | ||
else: | ||
response = requests.get(url) | ||
except Exception as err: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||
# We'd like to keep the error so the front-end knows why the intial | ||
# request failed. | ||
yield {'name': url, 'status': False, 'error': str(err)} | ||
return | ||
|
||
soup = BeautifulSoup(response.text, 'html.parser') | ||
anchor_tags = soup.find_all('a') # Anchor tags contain links | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at least two spaces before inline comment |
||
for anchor in anchor_tags: | ||
link = anchor.get('href') | ||
if link and LinkNode.valid_link(link): | ||
try: | ||
# Returns true if status_code is less than 400, false if not | ||
# A status of false indicates a bad link to the front end | ||
# while a status of true indicates a good link | ||
if tor: | ||
status = proxy_head(link, timeout=5).ok | ||
else: | ||
status = requests.head(link, timeout=5).ok | ||
yield {'name': link, 'status': status} | ||
except Exception as err: | ||
# If there's an exception then we assume the link is bad | ||
yield {'name': link, 'status': False} | ||
|
||
def start_wsserver(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
""" | ||
Starts WebSocketServer | ||
""" | ||
logging.info('Starting WSServer on address localhost:8080') | ||
start_server = websockets.serve(handle_msg, 'localhost', '8080') | ||
# Asynchronously runs server forever | ||
asyncio.get_event_loop().run_until_complete(start_server) | ||
asyncio.get_event_loop().run_forever() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ pyinstaller==3.4.0 | |
ete3==3.1.1 | ||
PyQt5==5.11.3 | ||
validators==0.12.2 | ||
websockets==7.0.0 | ||
tldextract==2.2.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"browser": true, | ||
"commonjs": true, | ||
"es6": true | ||
}, | ||
"extends": ["plugin:react/recommended","eslint:recommended"], | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"react" | ||
], | ||
"rules": { | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (150 > 79 characters)