title: How get base address its shared library?
body: <p>i want to get address of testlib.so from libc.so.6 base address.(because of ASLR)</p>
  
  <p><code>testlib.so</code> is shared library.</p>
  
  <pre><code>gcc -o ./testlib.so ./testlib.c -fPIC -shared -ldl
  </code></pre>
  
  <p>i makied python code to find memory mapping status.</p>
  
  <pre><code>from ctypes import *
  
  #libc = CDLL('libc.so.6')
  libc = CDLL('/lib/x86_64-linux-gnu/libc.so.6')
  test = CDLL('./testlib.so')
  
  print libc
  print test
  </code></pre>
  
  <p>and result</p>
  
  <pre><code>&lt;CDLL '/lib/x86_64-linux-gnu/libc.so.6', handle 7f17750a09b0 at 7f1774f40210&gt;
  &lt;CDLL './testlib.so', handle 15b6ea0 at 7f1774f40550&gt;
  </code></pre>
  
  <p>memory status when running this code.</p>
  
  <pre><code>      Start Addr           End Addr       Size     Offset objfile
          0x400000           0x6ea000   0x2ea000        0x0 /usr/bin/python2.7
          0x8e9000           0x8eb000     0x2000   0x2e9000 /usr/bin/python2.7
          0x8eb000           0x962000    0x77000   0x2eb000 /usr/bin/python2.7
          0x962000           0xa6f000   0x10d000        0x0 [heap]
    0x7ffff63e1000     0x7ffff6483000    0xa2000        0x0 /home/wwwlk/Downloads/testlib.so
    ^ target address
    0x7ffff6483000     0x7ffff6682000   0x1ff000    0xa2000 /home/wwwlk/Downloads/testlib.so
    0x7ffff6682000     0x7ffff6683000     0x1000    0xa1000 /home/wwwlk/Downloads/testlib.so
    0x7ffff6683000     0x7ffff6684000     0x1000    0xa2000 /home/wwwlk/Downloads/testlib.so
    ...
    0x7ffff77f0000     0x7ffff79b0000   0x1c0000        0x0 /lib/x86_64-linux-gnu/libc-2.23.so
    ^ libc.so.6 address
    0x7ffff79b0000     0x7ffff7bb0000   0x200000   0x1c0000 /lib/x86_64-linux-gnu/libc-2.23.so
    0x7ffff7bb0000     0x7ffff7bb4000     0x4000   0x1c0000 /lib/x86_64-linux-gnu/libc-2.23.so
    0x7ffff7bb4000     0x7ffff7bb6000     0x2000   0x1c4000 /lib/x86_64-linux-gnu/libc-2.23.so
    0x7ffff7bb6000     0x7ffff7bba000     0x4000        0x0 
    ...
    0x7ffff7ff8000     0x7ffff7ffa000     0x2000        0x0 [vvar]
    0x7ffff7ffa000     0x7ffff7ffc000     0x2000        0x0 [vdso]
    0x7ffff7ffc000     0x7ffff7ffd000     0x1000    0x25000 /lib/x86_64-linux-gnu/ld-2.23.so
    0x7ffff7ffd000     0x7ffff7ffe000     0x1000    0x26000 /lib/x86_64-linux-gnu/ld-2.23.so
    0x7ffff7ffe000     0x7ffff7fff000     0x1000        0x0 
    0x7ffffffde000     0x7ffffffff000    0x21000        0x0 [stack]
    ...
  </code></pre>
  
  <p>i calculated the offset memory, but it was not run. what technic is needed here?</p>