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

VPN Fixes + Sanity Checking #282

Open
wants to merge 76 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
e047d8e
purevpn and ipvanish, getting ip addresses of vpns sometimes lead to …
arianniaki Jun 28, 2017
1565476
adding log info when gethostname fails
arianniaki Jun 30, 2017
4e5af1f
HMA vpn structure fixed to fetch updated config file
arianniaki Jun 30, 2017
b94f1cc
fixed fetching the configs file for ipvanish
arianniaki Jul 7, 2017
c925cd4
log messages modified for all vpn proxies
arianniaki Jul 11, 2017
e63de02
log messages fixed
arianniaki Jul 11, 2017
871181f
Initial changes for sanity check module added
arianniaki Jul 12, 2017
347fa65
sanity check must be done before the reduce asn list
arianniaki Jul 13, 2017
3164ade
add arg for sanity check
grace71 Jul 15, 2017
eb26a35
move code under sanity check arg
grace71 Jul 16, 2017
845995c
add geo-sanity check module
grace71 Jul 16, 2017
1dcc045
combine sanity module and cli.py
grace71 Jul 16, 2017
739b509
get anchors before for loop
grace71 Jul 16, 2017
4c20719
some update
grace71 Jul 16, 2017
f8857c9
decouple ping and sanity check
grace71 Jul 17, 2017
0ffedcc
store sanity results as a file
grace71 Jul 19, 2017
f8d0182
add logging info & LICENSE
grace71 Jul 19, 2017
579b557
add timestamp for RIPE anchors monthly update
grace71 Jul 19, 2017
ba2dfa2
fix to deal with -1 in sanity check
grace71 Jul 19, 2017
35924fe
fix minor errors
grace71 Jul 21, 2017
84d5630
added downloader for map file
arianniaki Aug 2, 2017
93716ab
try block added for fetching map shape file
arianniaki Aug 2, 2017
9f76634
map shape file download (completed)
arianniaki Aug 2, 2017
fcb26e0
fixed a bug where servers.txt would be in the configs folder
arianniaki Aug 2, 2017
5fada31
fixed the previous bug completeley. purevpn had server in the name of…
arianniaki Aug 2, 2017
53ad69c
hostname resolution doesnt happen in the create configs anymore
arianniaki Aug 2, 2017
ff3c8d7
name resolution happens at sanity check instead of creating vpn confi…
arianniaki Aug 2, 2017
7ced45f
hostname resolution happens at sanity check instead of when creating …
arianniaki Aug 2, 2017
ab29b81
hash file of ovpn files added
arianniaki Aug 7, 2017
6941a61
update configs parameter added, reading configs pickle file added to …
arianniaki Aug 7, 2017
044e6d6
determine the update/add/delete vpn's in hma by comparing with the co…
arianniaki Aug 7, 2017
d519f41
new hash config file and server.txt file is written
arianniaki Aug 7, 2017
71bdd6c
add vpn config list implemented and all list of vp changes is returned
arianniaki Aug 7, 2017
db54733
remove/update/add vpn configs added in cli.py
arianniaki Aug 7, 2017
0898652
new configs created for new vps and in case the filenames are the sam…
arianniaki Aug 8, 2017
41595a4
fixed a bug where hostname was a tuple of filename and extension rath…
Aug 9, 2017
bed8b1d
removing new vpn configs folder when update is finished
Aug 9, 2017
0c98f71
update configs for ipvanish added
Aug 9, 2017
e6e2556
updated vpns directory shouldn't be deleted in the vpnprovider.py code
Aug 9, 2017
2a089dc
ipvanish update vpn config merged with cli.py
Aug 9, 2017
8866f0f
optimize the sanity checker
grace71 Aug 12, 2017
bd7128b
update vpn parameter added for purevpn
Aug 14, 2017
2cdb34a
Merge branch 'vpn_fixes' of https://github.com/arianniaki/centinel in…
Aug 14, 2017
3f43cad
adding return value to the update config function
arianniaki Aug 14, 2017
3bc4946
removing new vpns folder fetched for the update
arianniaki Aug 14, 2017
46cdd8b
changes to add custom_meta to configs file added
arianniaki Aug 14, 2017
cc93ca2
custom meta successfully added in confgis for each vp
arianniaki Aug 15, 2017
e503b6c
fix anchor parsing part to get city, country info
grace71 Sep 15, 2017
b4e9ed1
fix problem: by stopping openvpn properly
grace71 Sep 22, 2017
35164b5
speed up probing
grace71 Oct 24, 2017
f98dcfc
move getting gps part to probe.py
grace71 Oct 24, 2017
cafc62c
use RIPE API to get an anchors list
grace71 Oct 24, 2017
52437eb
change cli.py to run ripe api
grace71 Oct 24, 2017
653bc62
clean up probe part
grace71 Oct 24, 2017
2f7b845
clean up sanity check part
grace71 Oct 25, 2017
13c32c0
move sending pings to probe.py
grace71 Oct 25, 2017
ef52c1a
remove unnecessary config addition part
grace71 Oct 26, 2017
c92ad07
collect info for analysis
grace71 Oct 27, 2017
8c98199
erro msq
grace71 Oct 27, 2017
ff4348b
fix minor errors
grace71 Oct 27, 2017
ea8938f
Fix indents
grace71 Apr 19, 2018
31e03d0
Creat configs for other VP
grace71 Apr 29, 2018
2b7e5da
Fast enough not to store anchors lists
grace71 Apr 29, 2018
d7e0ad9
Subtract ping time from local to vp
grace71 Apr 29, 2018
e40f20b
Store online anchors list
grace71 Apr 29, 2018
d83574b
Move code to geosanity.py
grace71 Apr 30, 2018
b6202f5
Add column name for ping results
grace71 Apr 30, 2018
3229144
Finish geosanity.py
grace71 Apr 30, 2018
fa9f423
Change fname of landmark
grace71 May 2, 2018
a3c3d42
Store ping both to anchor and to proxy
grace71 May 5, 2018
3d3f0e1
Change vp_info format
grace71 May 9, 2018
cea8ada
Clean up codes for sanity check with speed
grace71 May 9, 2018
98ba2cb
Can't pickle staticmethod
grace71 May 9, 2018
11ec5ec
Fix errors
grace71 May 9, 2018
8768366
Handle geopy error and missed country code
grace71 May 10, 2018
16e8f89
Convert ms to second
grace71 May 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
135 changes: 91 additions & 44 deletions centinel/vpn/hma.py
Expand Up @@ -5,56 +5,103 @@
import os
import requests
import sys
import shutil
import logging
import socket
import zipfile
import urllib2


def unzip(source_filename, dest_dir):
with zipfile.ZipFile(source_filename) as zf:
zf.extractall(dest_dir)

def create_config_files(directory):
"""Create all available VPN configuration files in the given directory
"""
Initialize directory ready for vpn walker
:param directory: the path where you want this to happen
:return:
"""
config_zip_url = "https://hidemyass.com/vpn-config/vpn-configs.zip"

if not os.path.exists(directory):
os.makedirs(directory)

logging.info("Starting to download hma config file zip")

zip_response = urllib2.urlopen(config_zip_url)
zip_content = zip_response.read()
zip_path = os.path.join(directory, '../vpn-configs.zip')

Note: I am basically just following along with what their script
client does
with open(zip_path,'w') as f:
f.write(zip_content)
logging.info("Extracting zip file")
unzip(zip_path, os.path.join(directory, '../'))

ca_url = "https://vpn.hidemyass.com/vpn-config/keys/ca.crt"
hmauserauth_url = "https://vpn.hidemyass.com/vpn-config/keys/hmauser.crt"
hmauserkey_url = "https://vpn.hidemyass.com/vpn-config/keys/hmauser.key"

ca_response = urllib2.urlopen(ca_url)
ca_content = ca_response.read()
with open(os.path.join(directory, '../ca.crt'), 'w') as f:
f.write(ca_content)

"""
# get the config file template
template_url = ("https://securenetconnection.com/vpnconfig/"
"openvpn-template.ovpn")
resp = requests.get(template_url)
resp.raise_for_status()
template = resp.content

# get the available servers and create a config file for each server
server_url = ("https://securenetconnection.com/vpnconfig/"
"servers-cli.php")
resp = requests.get(server_url)
resp.raise_for_status()
servers = resp.content.split("\n")
response_userauth = urllib2.urlopen(hmauserauth_url)
userauth_content = response_userauth.read()
with open(os.path.join(directory, '../hmauser.key'), 'w') as f:
f.write(userauth_content)

if not os.path.exists(directory):
os.makedirs(directory)
with open(os.path.join(directory, "servers.txt"), 'w') as f:
f.write(resp.content)

for server_line in servers:
if server_line.strip() == "":
continue
server_line = server_line.split("|")
try:
ip, desc, country, udp_sup, tcp_sup = server_line
except ValueError:
ip, desc, country, udp_sup, tcp_sup, no_rand = server_line
with open(os.path.join(directory, ip + ".ovpn"), 'w') as file_o:
file_o.write(template)
# create tcp if available, else udp
tcp_sup = tcp_sup.strip()
if tcp_sup:
port, proto = 443, "tcp"
else:
port, proto = 53, "udp"
file_o.write("remote {0} {1}\n".format(ip, port))
file_o.write("proto {0}\n".format(proto))
# add automatic dns server update
file_o.write("up /etc/openvpn/update-resolv-conf\n")
file_o.write("down /etc/openvpn/update-resolv-conf\n")
response_userkey = urllib2.urlopen(hmauserkey_url)
userkey_content = response_userkey.read()
with open(os.path.join(directory, '../hmauser.key'), 'w') as f:
f.write(userkey_content)

# remove zip file
os.remove(zip_path)

# move all config files to /vpns
orig_path = os.path.join(directory, '../TCP')

server_country = {}
for filename in os.listdir(orig_path):
if filename.endswith('.ovpn'):
country = filename.split('.')[0]
file_path = os.path.join(orig_path, filename)
lines = [line.rstrip('\n') for line in open(file_path)]

ip = ""
for line in lines:
if line.startswith('remote'):
hostname = line.split(' ')[1]
try:
ip = socket.gethostbyname(hostname)
break
except socket.gaierror:
logging.info("Hostname %s failed" %hostname)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with Failed to resolve %s.

continue
if len(ip) > 0:
new_path = os.path.join(directory, ip + '.ovpn')
shutil.copyfile(file_path, new_path)
server_country[ip] = country

# remove extracted folder
shutil.rmtree(os.path.join(directory, '../TCP'))
shutil.rmtree(os.path.join(directory, '../UDP'))

# add dns update options to each file
logging.info("Appending DNS update options")
for filename in os.listdir(directory):
file_path = os.path.join(directory, filename)
with open(file_path, 'a') as f:
f.write('\n')
f.write('up /etc/openvpn/update-resolv-conf\n')
f.write('down /etc/openvpn/update-resolv-conf\n')


print os.path.join(directory, 'servers.txt'), len(server_country)
with open(os.path.join(directory, 'servers.txt'), 'w') as f:
for ip in server_country:
f.write('|'.join([ip, server_country[ip]]) + '\n')

if __name__ == "__main__":
if len(sys.argv) != 2:
Expand Down
18 changes: 13 additions & 5 deletions centinel/vpn/ipvanish.py
Expand Up @@ -6,7 +6,7 @@
import sys
import urllib
import zipfile

import urllib2

def unzip(source_filename, dest_dir):
with zipfile.ZipFile(source_filename) as zf:
Expand All @@ -26,13 +26,16 @@ def create_config_files(directory):
os.makedirs(directory)

logging.info("Starting to download IPVanish config file zip")
url_opener = urllib.URLopener()
zip_response = urllib2.urlopen(config_zip_url)
zip_content = zip_response.read()
zip_path = os.path.join(directory, '../configs.zip')
unzip_path = os.path.join(directory, '../unzipped')

if not os.path.exists(unzip_path):
os.makedirs(unzip_path)
with open(zip_path, 'w') as f:
f.write(zip_content)

url_opener.retrieve(config_zip_url, zip_path)
logging.info("Extracting zip file")
unzip(zip_path, unzip_path)

Expand All @@ -57,8 +60,13 @@ def create_config_files(directory):
for line in lines:
if line.startswith('remote'):
hostname = line.split(' ')[1]
ip = socket.gethostbyname(hostname)
break
# added because gethostbyname will fail on some hostnames
try:
ip = socket.gethostbyname(hostname)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will entirely ignore cases where this happens. It would be better to print a log message to describe what happens and which domain name failed to resolve.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arianniaki I see your comment.

break
except socket.gaierror:
logging.info("Hostname %s failed" %hostname)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Failed to resolve %s

continue

if len(ip) > 0:
new_path = os.path.join(directory, ip + '.ovpn')
Expand Down
9 changes: 7 additions & 2 deletions centinel/vpn/purevpn.py
Expand Up @@ -56,8 +56,13 @@ def create_config_files(directory):
for line in lines:
if line.startswith('remote'):
hostname = line.split(' ')[1]
ip = socket.gethostbyname(hostname)
break
# added because gethostbyname will fail on some hostnames
try:
ip = socket.gethostbyname(hostname)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, leave a log message saying what happened and what failed to parse.

break
except socket.gaierror:
logging.info("Hostname %s failed" %hostname)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

continue

if len(ip) > 0:
new_path = os.path.join(directory, ip + '.ovpn')
Expand Down