Skip to content

Instantly share code, notes, and snippets.

@tjmonsi
Last active December 29, 2023 13:34
Show Gist options
  • Save tjmonsi/e20b219a4bcaee5dda3f1edb74a9a19c to your computer and use it in GitHub Desktop.
Save tjmonsi/e20b219a4bcaee5dda3f1edb74a9a19c to your computer and use it in GitHub Desktop.
Find the etc/passwd given a file/folder location
// USAGE:
// tjx_get_etc_passwd(file)
// parameters: file is type File
tjx_get_etc_passwd = function(file)
print("Starting search at: " + file.path)
_gotoroot = function(folder)
if folder.parent then
return _gotoroot(folder.parent)
end if
return folder
end function
root = _gotoroot(file)
folders = root.get_folders
for folder in folders
if folder.name == "etc" then
if not folder.has_permission("r") then
print("Can't access /etc")
return
end if
files = folder.get_files
for file in files
if file.name == "passwd" then
if file.has_permission("r") then
print("Found /etc/passwd. Getting contents...")
return file.get_content
else
print("Can't access /etc/passwd")
return
end if
end if
end for
end if
end for
end function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment