-
-
Save becauro/8f87c94380d3cde728d0000dd141a513 to your computer and use it in GitHub Desktop.
Enable/Disable ASLR on Linux
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
#!/usr/bin/env python | |
""" | |
mv aslr.py /usr/bin/aslr && chmod +x /usr/bin/aslr | |
Be careful! | |
""" | |
import os, sys | |
FLAG_ENABLE = 2 | |
FLAG_DISABLE = 0 | |
FILENAME = '/proc/sys/kernel/randomize_va_space' | |
def _write_flag(filename, flag): | |
with open(filename, 'wb') as fd: | |
fd.write("%s" % (str(flag))) | |
def enable(): | |
_write_flag(FILENAME, FLAG_ENABLE) | |
def disable(): | |
_write_flag(FILENAME, FLAG_DISABLE) | |
def main(option): | |
options = { | |
'on': enable, | |
'enable': enable, | |
'off': disable, | |
'disable': disable | |
} | |
try: | |
func = options[option] | |
except KeyError: | |
print("Invalid option! (%s)" % ('|'.join(options.keys()))) | |
quit(1) | |
func() | |
if __name__ == '__main__': | |
if os.geteuid() is not 0: | |
print("You must call this program as root!") | |
quit(1) | |
try: | |
opt = sys.argv[1] | |
except IndexError: | |
opt = None | |
main(opt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment