-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
99 lines (99 loc) · 4.06 KB
/
test
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import subprocess
import sys
import urllib.request
import dns.resolver
import os
print("Test Suite fot ACME Corp Network Policy")
print("")
print("____________ ASSIGNMENT 2 Tests ____________")
print("____________________________________________")
print("")
print("- Checking for DNS Reachability")
resolver=dns.resolver.Resolver()
resolver.timeout=3
resolver.lifetime=3
resolver.nameservers=['8.8.8.8']
print("")
print("[*] Checking for non authorized DNS reachability:")
try:
answer=resolver.query('github.com')
print("Test Failed, Github's IP :",answer[0].to_text())
except dns.exception.Timeout:
print("Test passed, Blocked Query")
resolver.nameservers=['100.100.1.2']
print("")
print("[*] Checking for authorized DNS 100.100.1.2 reachability:")
try:
answer=resolver.query('github.com')
print("Test passed, Github's IP :",answer[0].to_text())
except dns.exception.Timeout:
print("Test Failed, Blocked")
print("")
print("- Checking for SSH connection to the Domain Controller")
print("Note: Please, if prompted for user password via ssh press 3 times the enter key to go ahead with the tests")
ssh=subprocess.Popen(["ssh","-o"," ConnectTimeout=6","100.100.1.2"],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
result=ssh.stdout.readlines()
print("")
if result==[]:
error=ssh.stderr.readlines()
if "Permission denied" in str(error[0]):
print("Test passed, connection to SSH available")
elif "Connection timed out" in str(error[0]):
print("Test Failed, can't connect to SSH")
else:
print("Test Passed")
print("")
print("- Checking HTTP/HTTPS connections to the Internet")
res=urllib.request.urlopen("http://github.com",timeout=5).read()
if res:
print("Test passed, HTTP/HTTPS allowed for this host")
print("")
print("- Checking HTTP/HTTPS connection via proxy :")
res = os.system("wget https://github.com")
if res == 0:
print("Test Passed, github.com main page downloaded in index.html via Proxy")
else:
print("Test failed, cannot connect to github via proxy")
print("")
print("____________ ASSIGNMENT 3 Tests ____________")
print("____________________________________________")
print("In Assignment 3 there is no possibility for the Clients Net hosts to surf the internet without using the proxy. Moreover the Proxy, differently from assignment 2, has user/pass login required.")
print("")
print("- Checking correct Proxy with credentials connectivity")
print("")
print("[*] Test for HTTP/HTTPS connection via proxy witout credentials:")
res = os.system("wget -e use_proxy=yes -e https_proxy=https://100.100.6.3:3128 https://www.github.com")
if res == 0:
print("Test failed, github.com main page downloaded in index.html via Proxy without creds, it should not be possible")
else:
print("Test passed, cannot connect to github via proxy without credentials")
print("")
print("[*] Test for HTTP/HTTPS connection via proxy with credentials:")
res = os.system("wget -e use_proxy=yes -e https_proxy=https://becca:[email protected]:3128 https://www.github.com")
if res == 0:
print("Test Passed, github.com main page downloaded in index.html via Proxy")
else:
print("Test failed, cannot connect to github via proxy")
print("")
print("[*]Test for HTTP/HTTPS connections to the Internet without proxy :")
res=urllib.request.urlopen("http://github.com",timeout=5).read()
if res:
print("Test failed, HTTP/HTTPS allowed without proxy, it should not be possible")
else:
print("Test passed, HTTP/HTTPS is not allowed for this host")
print("")
print("- Checking for correct VPN Routing and Firewalling")
ifaces=os.listdir('/sys/class/net')
if "tun0" in ifaces:
print("VPN connected, it is possible to perform the tests")
print("[*] Trying to connect to query the DNS Server at 100.100.1.2")
try:
answer=resolver.query('github.com')
print("Test passed, Github's IP :",answer[0].to_text())
except dns.exception.Timeout:
Print("Test Failed, Blocked")
res=urllib.request.urlopen("http://100.100.1.2",timeout=5).read()
if res:
print("Test passed, HTTP/HTTPS allowed for this host")
else:
print("VPN is not connected, tests will not be performed")