Open madebydavid opened 3 years ago
This can be prevented with a setuid
# Open the web browser
def open_browser():
time.sleep(3)
os.setuid(1000)
webbrowser.open_new('http://localhost:%d/index.html' % port)
threading.Thread(target=open_browser).start()
However, we need to determine which uid to use
Also, this fix results in a "Permission denied" when you enter the correct password as the uid the process has switched to does not have permissions to open the flag.txt file.
patch:
rom dae8b1aa69fb1330ac49ac9341eba2f3dab97b50 Mon Sep 17 00:00:00 2001
From: Wizzie Wizzie Computer Coding Club <sutherland.dave@gmail.com>
Date: Sat, 31 Oct 2020 15:29:18 +0000
Subject: [PATCH] Resolves #1
---
lesson-13/get-flag.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lesson-13/get-flag.py b/lesson-13/get-flag.py
index fa5cb1a..13d73bf 100755
--- a/lesson-13/get-flag.py
+++ b/lesson-13/get-flag.py
@@ -21,6 +21,9 @@ next(csv_data) # skip the first row
for row in csv_data:
user_passwords[row[0]] = row[1]
+# Read the flag file contents into a variable
+flag_file = open('../flag.txt')
+flag = flag_file.read()
class BankHTTP(http.server.SimpleHTTPRequestHandler):
def do_POST(self):
@@ -43,8 +46,6 @@ class BankHTTP(http.server.SimpleHTTPRequestHandler):
raise Exception('Invalid password')
# Return the flag
- flag_file = open('../flag.txt')
- flag = flag_file.read()
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
@@ -68,5 +69,6 @@ threading.Thread(target=bank_server.serve_forever).start()
# Open the web browser
def open_browser():
time.sleep(3)
+ os.setuid(os.getuid()) # to avoid running browser as root
webbrowser.open_new('http://localhost:%d/index.html' % port)
threading.Thread(target=open_browser).start()
--
2.11.0