Repository: pwndbg/pwndbg

Issue:
"aslr" Command Always Showing "ASLR OFF "
<!--
Before reporting a new issue, make sure that we do not have any duplicates already open.
If there is one it might be good to take part in the discussion there.

Please make sure you have checked that the issue persists on LATEST pwndbg version.

Below is a template for BUG REPORTS.
Don't include it if this is a FEATURE REQUEST.
-->


### Description
"aslr" command should show current ASLR setting when it's typed without any option or argument. But it always shows "ASLR OFF" no matter what the current ASLR setting is. For some reasons, modifying "vmmap.aslr=False" to "vmmap.aslr = True" on line 438 of pwndbg/vmmap.py seems to fix the bug.
<!--
Briefly describe the problem you are having in a few paragraphs.
-->

### Steps to reproduce
Launch gdb and type "aslr"  at the prompt.
<!--
What do we have to do to reproduce the problem?
If this is connected to particular C/asm code, 
please provide the smallest C code that reproduces the issue.
-->

### My setup
Gdb:      9.2
Python:   3.8.5 [GCC 10.2.0]
Pwndbg:   1.1.0 
Capstone: 4.0.1024
Unicorn:  1.0.2
Operating System:  Kali GNU/Linux 2020.3 64 bits
<!--
Show us your gdb/python/pwndbg/OS/IDA Pro version (depending on your case).

NOTE: We are currently supporting only Ubuntu installations.
It is known that pwndbg is not fully working e.g. on Arch Linux (the heap stuff is not working there).
If you would like to change this situation - help us improving pwndbg and supporting other distros!

This can be displayed in pwndbg through `version` command.

If it is somehow unavailable, use:
* `show version` - for gdb
* `py import sys; print(sys.version)` - for python
* pwndbg version/git commit id
-->



Discussion:

Resolving patch:
diff --git a/pwndbg/commands/aslr.py b/pwndbg/commands/aslr.py
--- a/pwndbg/commands/aslr.py
+++ b/pwndbg/commands/aslr.py
@@ -12,17 +12,16 @@
 
 options = {'on':'off', 'off':'on'}
 
-parser = argparse.ArgumentParser(description='Inspect or modify ASLR status')
+parser = argparse.ArgumentParser(description='''
+Check the current ASLR status, or turn it on/off.
+
+Does not take effect until the program is restarted.
+''')
 parser.add_argument('state', nargs='?', type=str, choices=options,
                     help="Turn ASLR on or off (takes effect when target is started)")
 
 @pwndbg.commands.ArgparsedCommand(parser)
 def aslr(state=None):
-    """
-    Check the current ASLR status, or turn it on/off.
-
-    Does not take effect until the program is restarted.
-    """
     if state:
         gdb.execute('set disable-randomization %s' % options[state], 
                     from_tty=False, to_string=True)
@@ -30,10 +29,10 @@ def aslr(state=None):
         if pwndbg.proc.alive:
             print("Change will take effect when the process restarts")
 
-    aslr = pwndbg.vmmap.check_aslr()
+    aslr, method = pwndbg.vmmap.check_aslr()
     status = message.off('OFF')
 
     if aslr:
         status = message.on('ON')
 
-    print("ASLR is %s" % status)
+    print("ASLR is %s (%s)" % (status, method))
diff --git a/pwndbg/vmmap.py b/pwndbg/vmmap.py
--- a/pwndbg/vmmap.py
+++ b/pwndbg/vmmap.py
@@ -444,7 +444,7 @@ def check_aslr():
         data = pwndbg.file.get('/proc/sys/kernel/randomize_va_space')
         if b'0' in data:
             vmmap.aslr = False
-            return vmmap.aslr
+            return vmmap.aslr, 'kernel.randomize_va_space == 0'
     except Exception as e:
         print("Could not check ASLR: Couldn't get randomize_va_space")
         pass
@@ -456,7 +456,7 @@ def check_aslr():
             personality = int(data, 16)
             if personality & 0x40000 == 0:
                 vmmap.aslr = True
-            return vmmap.aslr
+            return vmmap.aslr, 'read status from process\' personality'
         except:
             print("Could not check ASLR: Couldn't get personality")
             pass
@@ -469,7 +469,7 @@ def check_aslr():
     if "is off." in output:
         vmmap.aslr = True
 
-    return vmmap.aslr
+    return vmmap.aslr, 'show disable-randomization'
 
 @pwndbg.events.cont
 def mark_pc_as_executable():


Test patch: