Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6208623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:50:22+00:00 2026-05-24T05:50:22+00:00

I came across this code showing format string exploitation while reading this article. #include

  • 0

I came across this code showing format string exploitation while reading this article.

#include <stdio.h>

int main(void)
{
char secret[]="hack.se is lame";
char buffer[512];
char target[512];

printf("secret = %pn",&secret);

fgets(buffer,512,stdin);
snprintf(target,512,buffer);
printf("%s",target);
}

Executing it with following input

[root@knark]$ ./a.out
secret = 0xbffffc68
AAAA%x %x %x %x %x %x %x //Input given
AAAA4013fe20 0 0 0 41414141 33313034 30326566
- [root@knark]$ 

What I understand till now is the sequence of %x‘s will keep on printing the values at addresses above current %esp (I’m assuming that stack is growing downwards towards lower address).

What I’m unable to understand is the input given is stored in buffer array which can’t be less than 512 bytes away from current %esp. So, how can the output contain 41414141 (the hex representation of AAAA) just after the 4 %x, i.e, just above the 4 addresses of current %esp. I tried hard to stare at assembly code too but I think I couldn’t follow the manipulation of strings on stack.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:50:23+00:00Added an answer on May 24, 2026 at 5:50 am

    On entry to snprintf, the stack has the following:

    0xbfd257d0:     0xxxxxxxxx      0xxxxxxxxx      0xxxxxxxxx      0x080484d5
    0xbfd257e0:     0xbfd25800      0x00000200      0xbfd25a00      0x00000000
    0xbfd257f0:     0x00000000      0x00000000      0x00000000      0x00000000
    0xbfd25800:     0x00000000      0x00000040      0xb7f22f2c      0x00000000
    0xbfd25810:     0x00000000      0x00000000      0x00000000      0x00000000
    
    0xbfd25800 -> target (initially 0x00000000 0x00000040 ...)
    ...        -> garbage
    0xbfd257e8 -> pointer to buffer
    0xbfd257e4 -> 512
    0xbfd257e0 -> pointer to target
    0xbfd257df -> return address
    

    target gets overwritten with the result of snprintf before snprintf gets to use its words as arguments: It first writes “AAAA” (0x41414141) at 0xbfd25800, then “%x” reads the value at 0xbfd257ec and writes it at 0xbfd25804, …, then “%x” reads the value at 0xbfd25800 (0x41414141) and writes it at 0xbfd25814, …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this code: #include<stdio.h> void main() { int x; float t; scanf(%f,&t);
I came across this code accidentally: #include<stdio.h> int main() { int i; int array[3];
While writing some code i came across this issue: #include <iostream> class random {
I came across this code: int main() { int i=1,j=2,k=0,m=0; m = ++i ||
in the book i'm learning from i came across this code snippit: while (i
Today I came across this question: you have a code static int counter =
I came across this code today whilst reading Accelerated GWT (Gupta) - page 151
I came across this piece of code on a website. main(i) { gets(&i); puts();
I came across this code while working through code-analysis warnings on our code base.
I was reading about flag enums and bitwise operators, and came across this code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.