Skip to content

Commit

Permalink
simplify the port situation in web-security
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Sep 28, 2024
1 parent 989fb70 commit 4e2e614
Show file tree
Hide file tree
Showing 39 changed files with 58 additions and 131 deletions.
5 changes: 2 additions & 3 deletions web-security/auth-bypass-cookie/server
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ def challenge_get():
"""

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/cmdi-ls-filter/server
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ def challenge():
os.setuid(os.geteuid())
os.environ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/cmdi-ls-pipe/server
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ def challenge():
os.setuid(os.geteuid())
os.environ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/cmdi-ls-quote/server
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ def challenge():
os.setuid(os.geteuid())
os.environ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/cmdi-ls-semicolon/server
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ def challenge():
os.setuid(os.geteuid())
os.environ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/cmdi-touch-blind/server
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ def challenge():
os.setuid(os.geteuid())
os.environ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/csrf-reflected-alert/server
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/csrf-reflected-alert/victim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there. 8080 is the debug port, so you will earn a fake flag.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions web-security/level-1/server
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ def challenge(path="index.html"):
flask.abort(500, requested_path + ":" + str(e))

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/level-10/server
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/level-10/victim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there. 8080 is the debug port, so you will earn a fake flag.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions web-security/level-11/server
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/level-11/victim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there. 8080 is the debug port, so you will earn a fake flag.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions web-security/level-12/server
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/level-12/victim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there. 8080 is the debug port, so you will earn a fake flag.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions web-security/level-13/server
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/level-13/victim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there. 8080 is the debug port, so you will earn a fake flag.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions web-security/level-14/server
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/level-14/victim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there. 8080 is the debug port, so you will earn a fake flag.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions web-security/level-2/server
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ def challenge():
os.setuid(os.geteuid())
os.environ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/level-3/server
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,5 @@ def challenge_get():
"""

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/level-4/server
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ def challenge_get():
"""

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/level-5/server
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ def challenge():
"""

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/level-6/server
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ def challenge():
"""

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/level-7/server
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,5 @@ def challenge_get():
"""

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/level-8/server
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ def challenge_get():
"""

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
7 changes: 2 additions & 5 deletions web-security/level-8/victim
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ url_parsed = urllib.parse.urlparse(challenge_url)
if url_parsed.hostname != "challenge.localhost":
print("Hostname should be 'challenge.localhost'.")
sys.exit(2)
if url_parsed.port == 8080:
print("Will give fake flag for debug port (8080)...")
reward = "pwn.college{fake_flag}"
elif url_parsed.port in {None, 80}:
if url_parsed.port in {None, 80}:
reward = open("/flag").read()
else:
print("Port should be 80 (real service) or 8080 (debug port).")
print("Port should be 80.")
sys.exit(3)

print(f"Visiting {challenge_url}")
Expand Down
5 changes: 2 additions & 3 deletions web-security/level-9/server
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ def challenge_get():
"""

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
7 changes: 2 additions & 5 deletions web-security/level-9/victim
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ url_parsed = urllib.parse.urlparse(challenge_url)
if url_parsed.hostname != "challenge.localhost":
print("Hostname should be 'challenge.localhost'.")
sys.exit(2)
if url_parsed.port == 8080:
print("Will give fake flag for debug port (8080)...")
reward = "pwn.college{fake_flag}"
elif url_parsed.port in {None, 80}:
if url_parsed.port in {None, 80}:
reward = open("/flag").read()
else:
print("Port should be 80 (real service) or 8080 (debug port).")
print("Port should be 80 (real service).")
sys.exit(3)

print(f"Visiting {challenge_url}")
Expand Down
5 changes: 2 additions & 3 deletions web-security/path-traversal-2/server
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ def challenge(path="index.html"):
flask.abort(500, requested_path + ":" + str(e))

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/sqli-pin/server
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,5 @@ def challenge_get():
"""

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
5 changes: 2 additions & 3 deletions web-security/xss-exfil-cookie/server
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/xss-exfil-cookie/victim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there. 8080 is the debug port, so you will earn a fake flag.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions web-security/xss-rf-post/server
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/xss-rf-post/victim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there. 8080 is the debug port, so you will earn a fake flag.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions web-security/xss-stored-alert/server
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/xss-stored-alert/victim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there. 8080 is the debug port, so you will earn a fake flag.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down
5 changes: 2 additions & 3 deletions web-security/xss-stored-html/server
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ def challenge_get():
return page + "</body></html>"

app.secret_key = os.urandom(8)
port = 8080 if os.geteuid() else 80
app.config['SERVER_NAME'] = f"challenge.localhost:{port}"
app.run("challenge.localhost", port)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)
4 changes: 0 additions & 4 deletions web-security/xss-stored-html/victim
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ if 80 in open_ports:
print("Port 80 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()
elif 8080 in open_ports:
print("Port 8080 is open. Will connect to the service there.")
challenge_url = "http://challenge.localhost:8080/"
flag = "pwn.college{fake_flag}"
else:
print("Services don't seem to be running?")
sys.exit(1)
Expand Down

0 comments on commit 4e2e614

Please sign in to comment.