Skip to content

Commit

Permalink
Upgrade for nix PATH changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorNelson committed Jul 11, 2024
1 parent 98483be commit 8c692d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
1 change: 0 additions & 1 deletion access-control/level-4/bin/cat

This file was deleted.

1 change: 0 additions & 1 deletion access-control/level-5/bin/cp

This file was deleted.

47 changes: 23 additions & 24 deletions access-control/run
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def category_set_to_str(set_: int, categories: List[Category]) -> str:

def is_subset_equal(a: int, b: int) -> bool:
return (b | a) == b

LEVELS = [Level("TS", 4),
Level("S", 3),
Level("C", 2),
Expand Down Expand Up @@ -133,7 +133,7 @@ def mac_challenge(num_questions, timeout_sec, num_levels=None, num_categories=No
for i in range(num_questions):
subject_index = random.randint(0, num_levels - 1)
subject_set = random.randint(0, max_category_set - 1)
subject_set_str = category_set_to_str(subject_set, categories)
subject_set_str = category_set_to_str(subject_set, categories)

object_index = random.randint(0, num_levels - 1)
object_set = random.randint(0, max_category_set - 1)
Expand Down Expand Up @@ -174,12 +174,8 @@ def mac_challenge(num_questions, timeout_sec, num_levels=None, num_categories=No
else:
print("Incorrect!")
exit(-1)

success()





def level1():
"""
Expand All @@ -190,10 +186,10 @@ def level1():

print("Before:")
os.system(f"/bin/ls -la {flag_file}")

shutil.chown(flag_file, user=user)
os.chmod(flag_file, 0o400)

print("After:")
os.system(f"/bin/ls -la {flag_file}")

Expand All @@ -206,10 +202,10 @@ def level2():

print("Before:")
os.system(f"/bin/ls -la {flag_file}")

shutil.chown(flag_file, group=user)
os.chmod(flag_file, 0o040)

print("After:")
os.system(f"/bin/ls -la {flag_file}")

Expand All @@ -223,10 +219,10 @@ def level3():

print("Before:")
os.system(f"/bin/ls -la {flag_file}")

shutil.chown(flag_file, user=user)
os.chmod(flag_file, 0o000)

print("After:")
os.system(f"/bin/ls -la {flag_file}")

Expand All @@ -240,8 +236,11 @@ def level4():
print("Before:")
os.system(f"/bin/ls -la /bin/cat")

# create a symlink
os.chmod("/bin/cat", 0o4755)

os.mkdir("/challenge/bin")
os.symlink("/bin/cat", "/challenge/bin/cat")

print("After:")
os.system(f"/bin/ls -la /bin/cat")

Expand All @@ -260,7 +259,9 @@ def level5():
os.system(f"/bin/ls -la /bin/cp")

os.chmod("/bin/cp", 0o4755)

os.mkdir("/challenge/bin")
os.symlink("/bin/cp", "/challenge/bin/cp")

print("After:")
os.system(f"/bin/ls -la /bin/cp")

Expand All @@ -270,7 +271,7 @@ def level6():
The flag file is owned by root and a new group.
Hint: Search for how to join a group with a password.
Hint: Search for how to join a group with a password.
"""

print("Before:")
Expand All @@ -281,10 +282,10 @@ def level6():

# create group with password
os.system(f"/usr/sbin/groupadd -p $(/usr/bin/openssl passwd -1 {new_password}) {new_group}")

shutil.chown(flag_file, group=new_group)
os.chmod(flag_file, 0o040)

print("After:")
os.system(f"/bin/ls -la {flag_file}")

Expand Down Expand Up @@ -438,31 +439,31 @@ def level13():
"""
In this challenge you'll be answering questions about the standard Bell–LaPadula model of Mandatory Access Control.
Answer the question about the model to get the flag.
Answer the question about the model to get the flag.
"""
mac_challenge(1, 120, num_categories=0)

def level14():
"""
In this challenge you'll be answering questions about the standard Bell–LaPadula model of Mandatory Access Control.
Answer the questions about the model to get the flag.
Answer the questions about the model to get the flag.
"""
mac_challenge(5, 120, num_categories=0)

def level15():
"""
In this challenge you'll be answering questions about the category-based Bell–LaPadula model of Mandatory Access Control.
Answer the question about the model to get the flag.
Answer the question about the model to get the flag.
"""
mac_challenge(1, 120)

def level16():
"""
In this challenge you'll be answering questions about the category-based Bell–LaPadula model of Mandatory Access Control.
Answer the questions about the model to get the flag.
Answer the questions about the model to get the flag.
"""
mac_challenge(5, 120)

Expand Down Expand Up @@ -512,7 +513,6 @@ def level19():

mac_challenge(128, 1, custom_levels=levels, custom_categories=categories, use_flag_seed=False)


def challenge():
challenge_level = globals()[f"level{level}"]
description = textwrap.dedent(challenge_level.__doc__)
Expand All @@ -526,5 +526,4 @@ def challenge():

challenge_level()


challenge()

0 comments on commit 8c692d1

Please sign in to comment.