473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

format string vulnerability problem

tom
Im trying understand format string vulnerability. Source along
Erickson's HACKING: The Art of Exploitation.
#include <stdlib.h>

int main(int argc, char *argv[]){
char text[1024];
static int testVal = -72;

if(argc < 2){
printf("Usage: %s <text\n", argv[0]);
exit(0);
}
strcpy(text, argv[1]);

printf("Right way: \n");
//right way to print
printf("%s", text);
printf("\nWrong way:\n");
//wrong way to print
printf(text);

printf("\n");

//debug
printf("\n[*] testVal @ 0x%08x = %d (0x%08x)hex \n", &testVal, testVal,
testVal);

exit(0);
}

Im trying to overwrite testval:
../fmt_vuln `printf "\x20\x97\x04\x08"`%x.%x.%x%n
Right way:
%x.%x.%x%n
Wrong way:
bfbfe748.b7ff3de7.b80016a4
[*] testVal @ 0x08049720 = -72 (0xffffffb8)hex
Know somebody why didn't it work?
Thanks for answers.
--
TP
Feb 11 '07 #1
10 2184
tom wrote:
Im trying understand format string vulnerability. Source along
Erickson's HACKING: The Art of Exploitation.
[... much undefined behavior snipped ...]
Know somebody why didn't it work?
Because undefined behavior is "undefined." The C language
makes no guarantees at all about what your code will do, so it
is silly to expect an explanation of its behavior in terms of C.
The behavior may make sense in terms of a specific implementation
of C, but (1) you didn't reveal what implementation you used and
(2) even if you had, nobody would care much.

If this Erickson states that your broken program "will"
behave in thus-and-such a way, he's wrong.

--
Eric Sosman
es*****@acm-dot-org.invalid
Feb 11 '07 #2
tom wrote:
Im trying understand format string vulnerability. Source along
Erickson's HACKING: The Art of Exploitation.
#include <stdlib.h>
Don't forget to include <stdio.hand <string.h>.
int main(int argc, char *argv[]){
char text[1024];
static int testVal = -72;

if(argc < 2){
printf("Usage: %s <text\n", argv[0]);
exit(0);
}
strcpy(text, argv[1]);
If you're looking to cause problems, why not just overflow the buffer
here? If you already tried that earlier, and figured out how that
works, you should really fix this part of the code now.
printf("Right way: \n");
//right way to print
printf("%s", text);
printf("\nWrong way:\n");
//wrong way to print
printf(text);

printf("\n");

//debug
printf("\n[*] testVal @ 0x%08x = %d (0x%08x)hex \n", &testVal, testVal,
testVal);
testVal is never modified after initialisation, so it makes sense for
some compilers to just load a constant here, rather than re-reading
the variable.
exit(0);
}

Im trying to overwrite testval:
./fmt_vuln `printf "\x20\x97\x04\x08"`%x.%x.%x%n
As far as standard C is concerned, the behaviour is undefined.
Different implementations will behave differently. Even on a specific
system, the exact behaviour will likely depend on your compiler's
optimisation level and other compiler options. For example, some
systems provide built-in protection against exactly these sorts of
attacks.

Feb 11 '07 #3
tom
Eric Sosman wrote:
tom wrote:
>Im trying understand format string vulnerability. Source along
Erickson's HACKING: The Art of Exploitation.
[... much undefined behavior snipped ...]
Know somebody why didn't it work?

Because undefined behavior is "undefined." The C language
makes no guarantees at all about what your code will do, so it
is silly to expect an explanation of its behavior in terms of C.
The behavior may make sense in terms of a specific implementation
of C, but (1) you didn't reveal what implementation you used and
(2) even if you had, nobody would care much.
(1) $ uname -a
Linux a03-0634b 2.6.16.9 #2 Mon Jun 19 00:29:11 CEST 2006 i686 GNU/Linux
$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit
--enable-clocale=gnu --enable-libstdcxx-debug
--enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre
--enable-mpfr --disable-werror --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)

Is any possibility to try it. In Erickson's book isn't mention about
compiler, or C implemenatation. Only about OS, gentoo.
If this Erickson states that your broken program "will"
behave in thus-and-such a way, he's wrong.
Thanks.

--
S pozdravem Tomás Pelka
Feb 11 '07 #4
tom
Harald van Dijk wrote:
tom wrote:
>Im trying understand format string vulnerability. Source along
Erickson's HACKING: The Art of Exploitation.
#include <stdlib.h>

Don't forget to include <stdio.hand <string.h>.
fixed
>int main(int argc, char *argv[]){
char text[1024];
static int testVal = -72;

if(argc < 2){
printf("Usage: %s <text\n", argv[0]);
exit(0);
}
strcpy(text, argv[1]);

If you're looking to cause problems, why not just overflow the buffer
here? If you already tried that earlier, and figured out how that
works, you should really fix this part of the code now.
It is universal source code, not only for writing. See
http://www.acm.uiuc.edu/sigmil/talks...ormat_strings/,
item 4.
>
>printf("Right way: \n");
//right way to print
printf("%s", text);
printf("\nWrong way:\n");
//wrong way to print
printf(text);

printf("\n");

//debug
printf("\n[*] testVal @ 0x%08x = %d (0x%08x)hex \n", &testVal, testVal,
testVal);

testVal is never modified after initialisation, so it makes sense for
some compilers to just load a constant here, rather than re-reading
the variable.
>exit(0);
}

Im trying to overwrite testval:
./fmt_vuln `printf "\x20\x97\x04\x08"`%x.%x.%x%n

As far as standard C is concerned, the behaviour is undefined.
Different implementations will behave differently. Even on a specific
system, the exact behaviour will likely depend on your compiler's
optimisation level and other compiler options. For example, some
systems provide built-in protection against exactly these sorts of
attacks.
How can i detect this protection?

Thanks for explanation.

--
TP
Feb 11 '07 #5
tom wrote:
Harald van Dijk wrote:
tom wrote:
Im trying to overwrite testval:
./fmt_vuln `printf "\x20\x97\x04\x08"`%x.%x.%x%n
As far as standard C is concerned, the behaviour is undefined.
Different implementations will behave differently. Even on a specific
system, the exact behaviour will likely depend on your compiler's
optimisation level and other compiler options. For example, some
systems provide built-in protection against exactly these sorts of
attacks.
How can i detect this protection?

Thanks for explanation.
>From a program, you cannot and should not reliably detect such
protection. As the user, read your system's documentation.

Feb 11 '07 #6
On Sun, 11 Feb 2007 16:46:46 +0100, in comp.lang.c , tom
<to******@atlas.czwrote:
>Eric Sosman wrote:
>tom wrote:
>>Im trying understand format string vulnerability. Source along
Erickson's HACKING: The Art of Exploitation.
[... much undefined behavior snipped ...]
Know somebody why didn't it work?

Because undefined behavior is "undefined." The C language
makes no guarantees at all about what your code will do, so it
is silly to expect an explanation of its behavior in terms of C.
>The behavior may make sense in terms of a specific implementation
of C, but (1) you didn't reveal what implementation you used and
(2) even if you had, nobody would care much.
snip details of his implementation
>
Is any possibility to try it.
Did you notice (2) above? The reason Eric mentioned this is because
CLC discusses portable standard C. Your code fragment is incorrect,
broken and nonportable.
>In Erickson's book isn't mention about
compiler, or C implemenatation. Only about OS, gentoo.
I would suggest you throw the book away, or ask the author to explain.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Feb 11 '07 #7
On Sun, 11 Feb 2007 16:56:00 +0100, in comp.lang.c , tom
<to******@atlas.czwrote:
>Harald van D?k wrote:
>tom wrote:
As far as standard C is concerned, the behaviour is undefined.
Different implementations will behave differently. Even on a specific
system, the exact behaviour will likely depend on your compiler's
optimisation level and other compiler options. For example, some
systems provide built-in protection against exactly these sorts of
attacks.
How can i detect this protection?
Why would you want to? Its there to protect you and your customers.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Feb 11 '07 #8
tom <to******@atlas.czwrites:
Eric Sosman wrote:
>tom wrote:
>>Im trying understand format string vulnerability. Source along
Erickson's HACKING: The Art of Exploitation.
[... much undefined behavior snipped ...]
Know somebody why didn't it work?

Because undefined behavior is "undefined." The C language
makes no guarantees at all about what your code will do, so it
is silly to expect an explanation of its behavior in terms of C.
The behavior may make sense in terms of a specific implementation
of C, but (1) you didn't reveal what implementation you used and
(2) even if you had, nobody would care much.
(1) $ uname -a
Linux a03-0634b 2.6.16.9 #2 Mon Jun 19 00:29:11 CEST 2006 i686 GNU/Linux
[snip]
Is any possibility to try it. In Erickson's book isn't mention about
compiler, or C implemenatation. Only about OS, gentoo.
[...]

Then whatever Erickson is trying to do is OS-specific, and not
something we can talk about here. A Linux-specific newsgroup would be
more helpful.

Incidentally, if you're trying to learn about the theory of
exploitation, either just for knowledge or to guard against it, that's
great. If your goal is to create and spread your own viruses or other
malware, I hope that nobody helps you; if you succeed in doing so, I
hope that you're caught and punished.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 11 '07 #9
tom
Keith Thompson wrote:
tom <to******@atlas.czwrites:
>Eric Sosman wrote:
>>tom wrote:
Im trying understand format string vulnerability. Source along
Erickson's HACKING: The Art of Exploitation.
[... much undefined behavior snipped ...]
Know somebody why didn't it work?
Because undefined behavior is "undefined." The C language
makes no guarantees at all about what your code will do, so it
is silly to expect an explanation of its behavior in terms of C.
The behavior may make sense in terms of a specific implementation
of C, but (1) you didn't reveal what implementation you used and
(2) even if you had, nobody would care much.
(1) $ uname -a
Linux a03-0634b 2.6.16.9 #2 Mon Jun 19 00:29:11 CEST 2006 i686 GNU/Linux
[snip]
>Is any possibility to try it. In Erickson's book isn't mention about
compiler, or C implemenatation. Only about OS, gentoo.
[...]

Then whatever Erickson is trying to do is OS-specific, and not
something we can talk about here. A Linux-specific newsgroup would be
more helpful.
Thanks i'll try it.
>
Incidentally, if you're trying to learn about the theory of
exploitation, either just for knowledge or to guard against it, that's
great. If your goal is to create and spread your own viruses or other
malware, I hope that nobody helps you; if you succeed in doing so, I
hope that you're caught and punished.
No i'm a student, it's a school project. I am not a cracker. My goal is
show that this problems are real.

--
TP
Feb 12 '07 #10
tom
Mark McIntyre wrote:
On Sun, 11 Feb 2007 16:46:46 +0100, in comp.lang.c , tom
<to******@atlas.czwrote:
>Eric Sosman wrote:
>>tom wrote:
Im trying understand format string vulnerability. Source along
Erickson's HACKING: The Art of Exploitation.
[... much undefined behavior snipped ...]
Know somebody why didn't it work?
Because undefined behavior is "undefined." The C language
makes no guarantees at all about what your code will do, so it
is silly to expect an explanation of its behavior in terms of C.
>>The behavior may make sense in terms of a specific implementation
of C, but (1) you didn't reveal what implementation you used and
(2) even if you had, nobody would care much.

snip details of his implementation
>Is any possibility to try it.

Did you notice (2) above? The reason Eric mentioned this is because
CLC discusses portable standard C. Your code fragment is incorrect,
broken and nonportable.
>In Erickson's book isn't mention about
compiler, or C implemenatation. Only about OS, gentoo.

I would suggest you throw the book away, or ask the author to explain.
I'm afraid i havn't a contact to the author. My book is not original
edition, it is a Czech translation.

--
S pozdravem Tomás Pelka
Feb 12 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Tim Tyler | last post by:
Today's: "Directory Traversal Vulnerability": - http://secunia.com/advisories/10955/ More evidence tht PHP was hacked together rapidly without a great deal of thought being given to security....
3
by: Simon Hadler | last post by:
Hi was asking some questions about this in alt.php but some didn't get answered. Yes I have read an awful lot now about php security and different advisories and Idon't mind being called a...
3
by: Boz | last post by:
Hi, I am trying to use string.Format() to output the value of a double. double da = 100000000000.99994; double db = 100000000000.9994; double dc = 100000000000.994; double dd =...
2
by: Bob | last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure out what I am doing wrong. Given the following setup code: string str = { "one", "two", "three", "four" }; double...
9
by: Eric_Dexter | last post by:
http://www.ddj.com/184405774;jsessionid=BDDEMUGJOPXUMQSNDLQCKHSCJUNN2JVN I saw a warning from homeland security about this. I only comment on the because I am trying to use os.system('command1...
7
by: Carroll, Barry | last post by:
Greetings: Personally, I don't think top-posting is the most annoying newsgroup habit. I think it's making a big fuss about minor inconveniences. One of the nicest things about being human...
5
by: Norm | last post by:
Does anyone have any suggestions for securing against this vulnerability: http://nvd.nist.gov/nvd.cfm?cvename=CVE-2007-1027 Fixes are not yet available from IBM. They will be in FP2 for V9...
1
by: Cat | last post by:
Hi. Would you recommend a ASP (IIS) web server vulnerability scanner? If I install the all the updates from Microsoft, then I don't need vulnerability scanners? I was on a chat, I installed all...
5
by: =?Utf-8?B?ZWdzZGFy?= | last post by:
Hi, On ASP 3.0 I was able to create a file conn.vbs where the connection string lines to the db resides in, how can i do the same on ASP.Net? The reason of this is to avoid modify the line in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.