Thread: If the address ESP for every program is equal?

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    50

    If the address ESP for every program is equal?

    I read a book,it said:
    In Linux Shell,the address for ESP every program
    is equal,and it supportes the codes:
    Code:
    unsigned long get_sp()
    {
    __asm__("movl %esp,%eax");
    }
    and then I add this codes in my two programs,and
    I insert it on the start about the function main() ,
    but I find they get different value,how to explain?
    (I first run in Shell:echo "0" >/proc/sys/kernel/randomize_va_space)

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Your book is old.

    Address space randomisation is new-ish - primarily designed to stop stupid script kiddies from trying buffer overflow / code injection.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    But seriously, you need to find another direction for your curiosity.
    You're not learning C or C++, you're just out to grab hacking information - nothing more.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by leetow2003 View Post
    (I first run in Shell:echo "0" >/proc/sys/kernel/randomize_va_space)
    Hmm, that works for me, but you need root permissions to do it. Did you check to see that it was set?

    root~/C
    »cat /proc/sys/kernel/randomize_va_space
    0
    root~/C
    »./a.out
    4294958384
    root~/C
    »./a.out
    4294958384
    root~/C
    »./a.out
    4294958384
    root~/C
    »echo 2 > /proc/sys/kernel/randomize_va_space
    root~/C
    »cat /proc/sys/kernel/randomize_va_space
    2
    root~/C
    »./a.out
    4120804800
    root~/C
    »./a.out
    705018288
    root~/C
    »./a.out
    3830575680

    W/ custom x64 kernel, v.3.0.6

    Quote Originally Posted by Salem View Post
    you're just out to grab hacking information - nothing more.
    I could see it being worth knowing once in a blue moon.
    Last edited by MK27; 04-08-2012 at 06:38 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Address database program help
    By zonen in forum C++ Programming
    Replies: 1
    Last Post: 10-11-2011, 11:14 PM
  2. Internal IP address program
    By John87412897 in forum Networking/Device Communication
    Replies: 4
    Last Post: 08-19-2008, 04:57 AM
  3. Get the program's address
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 08-23-2006, 12:37 AM
  4. Address program
    By Siggy in forum C++ Programming
    Replies: 3
    Last Post: 07-01-2004, 01:03 AM
  5. Address Book program
    By sundeeptuteja in forum C++ Programming
    Replies: 0
    Last Post: 07-28-2002, 02:08 AM