DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Avoiding Vulnerabilities in Software Development
  • 5 Important Software Vulnerabilities

Trending

  • Unleashing the Power of Microservices With Spring Cloud
  • Development of Custom Web Applications Within SAP Business Technology Platform
  • New Free Tool From Contrast Security Makes API Security Testing Fast and Easy
  • Decoding the Differences: Continuous Integration, Delivery and Deployment
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Anatomy of an Exploit: Stack Smashing and Registers

Anatomy of an Exploit: Stack Smashing and Registers

Christopher Lamb talks stack smashing again, building off an image of a stack to discuss storing data and about being the boss in a buffer overflow situation.

Christopher Lamb user avatar by
Christopher Lamb
·
Jul. 20, 16 · Opinion
Like (1)
Save
Tweet
Share
3.35K Views

Join the DZone community and get the full member experience.

Join For Free

So in my last piece on buffer overflows and stack smashing, I didn't really discuss why the return pointer's important. I'm going to try to fix that today.

First, let's pull up that image of a typical stack again:

Image title

Above, we have the stack in a typical program (again!). Original image By R. S. Shaw (own work, Public Domain, https://commons.wikimedia.org/w/index.php?curid=1956587)

So what is this "return address" and why do I care?

Calling Conventions

Remember from the first piece that the stack is set up this way by convention; there's no reason to set the stack up this way other than somebody, at some time, decided this is how they wanted to do it. That's it. When whoever it was came up with this particular design (or convention, as we call it today), they knew they needed to do a couple of things.

First, they needed to store a couple of things. Second, they needed to store the arguments passed to a given function. We pass arguments to functions—it's what we do—and we need to store the data somewhere. All those nifty argument lists we're accustomed to, with various data types, are really just shoved into allocated stack memory as ones and zeros. Those exact ones and zeros are based on the data type, but at the end of the day, it's all just a mess of binary.

We likewise need to store local variables. And we need some way to return to the caller when we're finished—that's where the return address comes in. Keep in mind, it doesn't really matter that much where we store that return address. If I can allocate a buffer on the stack, I can overwrite that return pointer.

(Or, at least, a return pointer. I don't need to get control of the pointer associated with my current function; a pointer associated with the calling function is okay too).

So why is this address important?

Read the Instructions!

Computers have a specific register that holds the address of the next instruction. On x86, this is the EIP register. This is how the processor keeps track of where it is and what it's doing. And programs can write and read to that register via various assembly commands. So what happens when you call a function? Well, you need to set up the stack, and then you branch out to the function's address. This is what really happens behind the scenes, and the compiler will take care of all this left over junk for you. Basically, you reserve space for the parameters to a function—in this case, DrawLine(.)—and then you save the address you'll start executing from when the function is completed. Then you allocate stack space for local variables. In normal operation, you save the return address, execute the function, and return to the return address.

In a buffer overflow situation though, you inject code into the locally variable space on the stack and overwrite the return address with whatever address you want. That's right, you're the boss! use whatever address you want to. Then, when the function completes, it'll start executing from wherever you've told it to.

In a classic buffer overflow exploit, we'll insert and address that points at the next word (or the word just after that) as we've been able to write our own code there. So now, we've told the processor to begin to execute our injected code.

This is why that return address is important, and why it exists in the first place.

Buffer overflow

Opinions expressed by DZone contributors are their own.

Related

  • Avoiding Vulnerabilities in Software Development
  • 5 Important Software Vulnerabilities

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: