Last active
December 29, 2023 13:34
-
-
Save tjmonsi/e20b219a4bcaee5dda3f1edb74a9a19c to your computer and use it in GitHub Desktop.
Find the etc/passwd given a file/folder location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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