-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirewall.html
166 lines (151 loc) · 5.08 KB
/
firewall.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<DOCTYPE HTML>
<html>
<head>
<title>
Firewall Border Control
</title>
<meta charset="utf-8">
</head>
<body>
Your IP: <span id="YourIP"></span> <br>
Source IP: <span id="SourceIP"></span> <br>
Destination IP: <span id="DestinationIP"></span> <br>
Source Port: <span id="SourcePort"></span> <br>
Destination Port: <span id="DestinationPort"></span> <br>
Rules: Deny packets not meant for us <br>
<span id="Rule2"></span> <span id ="AllowFrom"></span> <br>
<button type="button" onclick="check('allow')" id="accept">Accept</button>
<button type="button" onclick="check('deny')" id="deny">Deny</button> <br>
Score: <span id ="Score"> </span> <br>
Lives: <span id ="Lives"> </span> <br>
<span id="Message"> </span>
</body>
<script>
var SourceIPList = [];
var DestIPList = [];
var portList = [23, 80, 443, 20, 21];
function chooseIP(score){
if (document.getElementById("YourIP").innerHTML.length == 0) {
document.getElementById("YourIP").innerHTML = get_random(DestIPList);
}
document.getElementById('SourceIP').innerHTML = get_random(SourceIPList);
document.getElementById('DestinationIP').innerHTML = get_random(DestIPList);
if (score == 9 && document.getElementById('AllowFrom').innerHTML.length == 0) {
document.getElementById("Rule2").innerHTML = "Allow packets from the IP ";
document.getElementById("AllowFrom").innerHTML = get_random(SourceIPList);
}
}
function choosePorts(score) {
document.getElementById("SourcePort").innerHTML = get_random(portList);
document.getElementById("DestinationPort").innerHTML = get_random(portList);
}
function randomIP() {
return (Math.floor(Math.random() * 255) + 1)+"."+(Math.floor(Math.random() * 255))+"."+(Math.floor(Math.random() * 255))+"."+(Math.floor(Math.random() * 255));
}
function get_random (list) {
return list[Math.floor((Math.random()*list.length))];
}
window.onload = function() {
document.getElementById("Score").innerHTML = 0;
document.getElementById("Lives").innerHTML = 3;
let ip1 = randomIP();
let ip2 = randomIP();
let ip3 = randomIP();
let ip4 = randomIP();
let ip5 = randomIP();
let ip6 = randomIP();
DestIPList.push(ip1);
DestIPList.push(ip2);
DestIPList.push(ip3);
SourceIPList.push(ip4);
SourceIPList.push(ip5);
SourceIPList.push(ip6);
chooseIP(0);
choosePorts();
};
function check(button) {
var flagarray = []
var current_score = document.getElementById("Score").innerHTML;
var new_score = document.getElementById("Score").innerHTML;
flag1 = stage1check(button);
if (current_score >= 10) {
flag2 = stage2check(button)
if (flag1 == 0) { //Meant for us, and let in
if (flag2 == 0 || flag2 == 1) { //Done right thing based on source
document.getElementById("Message").innerHTML = "Correct";
new_score ++;
}
else if (flag2 == 2 || flag2 == 3) { //Done wrong thing based on source
document.getElementById("Message").innerHTML = "Is this a source we let in?";
document.getElementById("Lives").innerHTML --;
}
}
else if (flag1 == 1) { //Not for us, not let in
document.getElementById("Message").innerHTML = "Correct";
new_score ++;
}
else if (flag1 == 2) { //Not meant for us, let in
document.getElementById("Message").innerHTML = "Was this packet meants for us?"
document.getElementById("Lives").innerHTML --;
}
else { //Meant for us, not let in
if (flag2 == 1) { //Source wasn't valid, so don't let in
document.getElementById("Message").innerHTML = "Correct";
new_score ++;
}
else { //Source was either valid or dealt with incorrectly
document.getElementById("Message").innerHTML = "Check the source and destination and try again";
document.getElementById("Lives").innerHTML --;
}
}
}
else {
if (flag1 == 2 || flag1 == 3) {
document.getElementById("Message").innerHTML = "Is the destination the same as our IP?";
document.getElementById("Lives").innerHTML --;
}
else {
document.getElementById("Message").innerHTML = "Correct!";
new_score ++
}
}
if (current_score != new_score) {
document.getElementById("Score").innerHTML = new_score;
chooseIP(current_score);
choosePorts();
}
}
function stage1check(button) {
var ourIP = document.getElementById("YourIP").innerHTML;
var destination = document.getElementById("DestinationIP").innerHTML;
if (ourIP == destination && button == 'allow') {
return 0;
}
else if (ourIP != destination && button == 'deny') {
return 1;
}
else if (ourIP != destination && button == 'allow') {
return 2;
}
else {
return 3;
}
}
function stage2check(button) {
var source = document.getElementById('SourceIP').innerHTML;
var allow = document.getElementById("AllowFrom").innerHTML;
if (source == allow && button == 'allow') {
return 0;
}
else if (source != allow && button == 'deny') {
return 1;
}
else if (source != allow && button == 'allow') {
return 2;
}
else {
return 3;
}
}
</script>
</html>