The 2006 Underhanded C Contest Begins 232
Xcott Craver writes "The second annual Underhanded C Code Contest is live as of April 4th, and runs until July 4th. The object is to write malicious C code that looks perfectly readable and innocent under informal inspection of the source."
I Win (Score:5, Funny)
In this contest you must write code that is as readable, clear, innocent and straightforward as possible, and yet it must fail to perform at its apparent function. To be more specific, it should do something subtly evil.
system("c:\Program Files\Internet Explorer\iexplore.exe");Where's my prize?
--
"Man Bites Dog
Then Bites Self"
Re:I Win (Score:2, Funny)
Where's my prize?
I don't think you read the task description very good, it said:
"it should do something subtly evil"
Re:I Win (Score:2, Informative)
Re:I Win (Score:2)
Re:I Win (Score:2)
I'm not sure what the \P, \I, and \i escape characters do, but I think you were looking for this:
system("c:\\Program Files\\Internet Explorer\\iexplore.exe");
Re:I Win (Score:4, Funny)
Read the conditions of the contest clearly. You obviously lose.
Re:I Win (Score:2)
Re:I Win (Score:2)
Re:I Win (Score:2)
Also, IE is not SUBTLY evil.
Re:I Win (Score:2)
must be better than a D if most of you could not figure that out.
Can someone explain this to me? (Score:3, Interesting)
I understand about making source code available helps in a secure system, but what if that code has evil code...made to look innocent upon inspection....written into it?
I know that showing how to crack into a system, or how to write a virus actually helps in the long run as it exposes weaknesses that can and should be patched and closed. But what does having people practice hiding malicious code do for us?
Just wondering. I find this stuff fascinating....though not fascinating enough to actually learn how to do it!
Re:Can someone explain this to me? (Score:5, Insightful)
2. It's fun.
Re:Can someone explain this to me? (Score:5, Funny)
Um, I think your signature should be number three:
:)
Re:Can someone explain this to me? (Score:3, Funny)
IOW, it helps folks learn to spot these 'bugs' more readily.
Re:Can someone explain this to me? (Score:5, Insightful)
On the other hand, I think it does teach us a thing or two about what to look for when reviewing code. I know I've learned a lot about sneaky coding practices since it started. I learned C in the 1980s and thought I was pretty knowledgeable by now, but I actually didn't know about ASCII trigraphs until last year. X
Re:Can someone explain this to me? (Score:4, Funny)
This has been the crackpot conspiracy theory of the day.
(Why yes, I'm bored! Why do you ask?)
Re:Can someone explain this to me? (Score:5, Funny)
Re:Can someone explain this to me? (Score:2)
That's it. I'm writing a program that will determine that. I'll post the code to /. as soon as it's done.
Re:Can someone explain this to me? (Score:2)
No need to go to all this trouble for that, surely? Why, they could just check the evil bit!
Re:Can someone explain this to me? (Score:2)
It's also very difficult to tell what would be regarded as malicious/evil code anyway, since obviously you want some programs to be able to delete files and access hardware etc - guess when you start leaking a lot of memory, or trying to execute buffer overflows etc is when it gets obvious that your program is attempting to do d
Re:Can someone explain this to me? (Score:5, Insightful)
I understand about making source code available helps in a secure system, but what if that code has evil code...made to look innocent upon inspection....written into it?
I think you've highlighted the point right there. By getting the community to find ways to write code of this fashion, you're simultaneously getting them to learn to read code better (or at least that would be my hope). If I know how to write code in a fashion that looks innocent but brings with it not-so-innocent consequences, then hopefully I know how to tell when someone else is doing the same thing.
Re:Can someone explain this to me? (Score:5, Insightful)
This problem arises whenever you need to use software for an application that must be secure. One famous case of tampering was by the CIA; control software for a Soviet oil pipeline purchased in the West was modified to fail upon a remote command [msn.com] causing a massive explosion.
One hypothetical scenario: Diebold [diebold.com] decide to act on their CEO's promise to deliver the election to the Republican party by making a small modification to their voting machines [diebold.com]. If they can use the techniques this contest is looking for they would write the code so that it would escape even scrutiny by an outside agency (say, the government).
In general, the idea of the contest is to showcase ways of breaking security and therefore perhaps ways to overcome them.
This was inspired by ... (Score:2)
Re:Can someone explain this to me? (Score:2)
In Diebold's case, I'm not willing to ascribe to incompetence that which can be explained by malice.
Voting Fraud - KISS (Score:2)
Personally, I'd go Occam's Razor on that issue and say that there's been a few hundred more years of mechanical voting fraud to fall back on rather than messing with software. Why do you think the dead rise again every few years to vote?
Re:Voting Fraud - KISS (Score:2)
Cause the queue to hell is backed up with dead politicians.
Rich
Re:Can someone explain this to me? (Score:3, Insightful)
The Trans-Sib pipeline control system was developed by a UK company. It used MC6800s and was written in assembler. The stuff was so unstable anyway due to the hand coded networking that deliberate interference would hve been picked up during the shake down (the code was continually being rewritten and EPROMs reblown).
Re:Can someone explain this to me? (Score:2)
Most likely a case of a typical megalomaniac ex-Intelligence blow hard trying to take credit for the Sun rising in the West, in his highly incredulous "memoir".
If any of that crap was true, Russia would be suing for damages, which under international law they would be entitled to, since they actually bought that stuff for their pipeline legitimately, and would be using that idiot's book as Exhibit A.
On an unrelated note, I wonder when will some more e
Re:Can someone explain this to me? (Score:2)
No, that is one of the many versions of the story. Some others have the Russians buying the software/hardware from the UK, Germany, France, whomever. Yet others claim it was run on clone PDP-11s/IBM mainframes/what not. Even the explosion itself is highly questionable, as Russians claim t
Re:Can someone explain this to me? (Score:2)
Shouldn't the CIA be held responsible for criminal behavior like this?
Re:Not really (Score:2)
The story is pretty much proven bullshit, and it keeps changing constantly. In some versions the Russians bought the software from the US, UK, you name it, in some others they stole it, it was written in Assembler running on MC6800, In C on PDP-11s, on IBM mainframes, on Russian clones of PDPs/main
Re:Can someone explain this to me? (Score:4, Insightful)
The "many eyes" theory can only work in practice if there are indeed many eyes reviewing the source code and those eyes can see any problems. That doesn't just mean accidental bugs, or portability/future-proofing concerns, or a poor choice of data structures and algorithms leading to a performance hit. It also means spotting the devious and subtle attacks.
Just imagine what would happen if a major OSS project like Apache or Linux accepted a "useful" patch that contained a backdoor that wasn't identified, and this then got distributed worldwide. A significant number of people believe, erroneously, that using OSS inherently makes them safer because of the many eyes theory. These people will happily download and build the updated code, or install prebuilt binaries with correct checksums, completely oblivious to the fact that they just stuck a major security hole in their system.
Thus it's important for those who review submissions to software development projects - OSS, commercial or otherwise - to be very aware of these possibilities, and likewise for anyone else who contributes to them so they can spot a problem if they come across it.
Re:Can someone explain this to me? (Score:2)
Re:Can someone explain this to me? (Score:2, Offtopic)
We were initially inspired by Daniel Horn's Obfuscated V contest in the fall of 2004. I was greatly impressed to see how even a short program to simply count characters in a text file can be made to fail, and fail only on one specific day.
The longer answer is that my research interests are in covert behavior: detecting it, and getting past people who try to detect it.
The prize is $100.00, I think it should be more IMHO.
Re:Can someone explain this to me? (Score:2)
In a fun and harmless way this makes public the techniques until now used only by people with malice. It's really the same as showing how to crack a system, but here the system is "code auditors", and just like the system will close the holes and fix the bugs, the auditors will also improve.
(this is partly a summary of other comments, in what I think is more focused an
Re:Can someone explain this to me? (Score:3, Funny)
Re:Can someone explain this to me? (Score:2)
Put your hands over your ears and sing this song:
"La la la! All C code is secure! Strcpy is perfectly safe! if (uid = 0) is a harmless typo! La la la!"
This isn't about _practising_ how to write evil code, it's getting to know what kind of evil is possible so that you can recognize it when you see it later. The best possible outcome of this sort of event is for one of the observers to say "Ohh... I never know that you could do _that_" during the contest and then, a few
Re:Can someone explain this to me? (Score:2, Redundant)
Think about it this way. You're the head dev on a big software project and are in charge of committing changes that the other programmers have made to the code base into the repository. You screen all the pieces of code to make sure they are reasonable before they get merged, right? Well, if you don't know anything about clever techniques that can be used to hide backdoors and other malicious code, one could sneak by you. Nobody finds the bad code un
Re:Can someone explain this to me? (Score:2)
Simple. It'll kill the language off completely. Time to put it out of it's misery I guess.
The process has already started with the latest versions of C++, virtually all the standard functions are being deprecated and replaced with ones that include target buffer size limits, forcing you to either ignore massive lists of complier warnings, to turn off the warnings, or to macro replace the functions with ones that will likely hardcode the limits to possibly inappropriate values, thereby making them behave
Re:Can someone explain this to me? (Score:2)
I know... (Score:5, Funny)
And then I'll get sued by Sony for copyright infringement.
Weird and has very little to do with C (Score:4, Interesting)
It depends way too much on things like the compiler being used, the optimization level, the actual hardware (how do they compare program run-time if the two OSes in question run on very different CPUs ?), and so on, than on actual C.
Re:Weird and has very little to do with C (Score:2)
Re:Weird and has very little to do with C (Score:2)
If you do it right, it's entirely dependant on the actual C code (and its interaction with the OS/CPU). There's no compiler flag in the world that can turn an O(n!) program into an O(n) one.
Re:That's invalid (Score:2)
Re:That's invalid (Score:2)
Any code (Score:2, Insightful)
Looks innocent, is malicious.
Potential for malice? (Score:2, Interesting)
Re:Potential for malice? (Score:3, Informative)
Saying that this "helps the bad guys" (not that you did) misses the point. We know there are bad guys out there. This becomes an awareness campaign.
There are several documented cases of stuff like this happening. Both ATI and nVidia (the graphics card companies) added code to their drivers to cheat [extremetech.com] -- take "shortcuts" when certain benchmark programs were running
Re:Potential for malice? (Score:2)
can't wait for the results (Score:2)
}
Lucid Programming? (Score:3, Interesting)
A related contest I would like to see is a lucid programming contest. Given some small but insidiously tricky task, write a program in the language of your choice which solves the problem correctly and which is easy for someone else to understand. It would be interesting to discover which languages excel at this task and what sorts of patterns emerge when emphasis is placed on clarity.
Re:Lucid Programming? (Score:2)
(loop (print (eval (read) ) ) )
My entry! (Score:4, Funny)
main() {
printf("hello, world\n");
}
My entry -- the world's last C bug (Score:5, Funny)
An oldie but goodie . . .
while (1){
status = GetRadarInfo();
if (status = 1)
LaunchMissiles();
}
Re:My entry -- the world's last C bug (Score:4, Funny)
Compiler says (Score:2)
collect2: ld returned 1 exit status
Re:Compiler says (Score:3, Funny)
Re:My entry -- the world's last C bug (Score:5, Insightful)
Look again. This time, look for any extra semi-colons that shouldn't be there. The responder's joke was an improvement on the original, and would not have been flagged by an optional compiler warning (at least in the case of gcc).
if(status == 1);
Beta?? (Score:2)
Just another item on my list (Score:2)
Just another item on my list of reasons I hate C-language. And I first started uisng C in 1977.
Is this the sort of thing they're looking for? (Score:3, Interesting)
main()
{
char stuf[80];
while(1)
{
fputs("Enter something: ", stdout);
fflush(stdout);
gets(stuf);
fputs("You have entered ", stdout);
printf(stuf);
}
}
silly (and looks innocent enough) but closer inspection will reveal nastyness...
Dangerous and suspicious looking (Score:4, Insightful)
Your code is dangerous, but it has to be exploited by a knowledgable user. I think what they're looking for in the Underhanded C Contest is code that exploits itself. But for the purpose of being pendantic, i'll bite... =)
Re:Is this the sort of thing they're looking for? (Score:4, Informative)
printf(stuf) is dangerous because "stuf" is being used as the format specifier to printf.
Now, normally you use printf like this: printf("%s", stuf), which says to print the string contained in stuf to stdout. But with the printf(stuf) line, you can carefuly craft what is in stuf to make it execute arbitrary code. The key to doing this lies in the %n specifier.
If you were to do printf("Ha!%n",&some_int), then not only would the word "Ha!" be printed to the screen, but the contents of some_int would get set to 3, since that's how many characters were printed and that's what %n is telling it to do.
Now, say I pass in "%X" as stuf. My output will be a number. What number is that? Why, it's the return address of printf, because %X is really telling it to print the contents of the next address on the stack, and that address happens to be a return address (since we didn't pass in real arguments to printf). If I therefore carefully craft my string, I can not only overwrite that return addres using %n, but I can overwrite it with a pointer to a location which will be executed when printf returns by varying the length of my string. And I can easily vary the length of my string by doing some things like %.1234x in there, which will happily stick 1234 characters in my string easily and add 1234 to n.
Once I know the return address, I can work out where my string buffer is actually being stored, and then I can include my exploit code in that string itself, and execute it right from there.
Short version is that passing format specifier strings to printf as anything other than literals is dangerous unless you know exactly what the format specifier string really is.
Seems ominous (Score:2)
int main( void )
{
printf("Goodbye, world!");
}
So who wants to talk strategy? (Score:4, Interesting)
I think, with creative use of bad programming, you could corrupt either the salt or the calculation of the hash function in such a way as to guarantee that for a target OS the hash-table performance would degrade into worst-case. So if you took your borked hash table, and used it to implement an associative array, the fairly trivial read in stdin, increment fields in associative array, sort array in order code could be made to perform at average time complexity in non-targetted OSes and worst-case time complexity in your target OS. Assuming you pick an O(n log n) sort algorithm, if you manage to "accidentally" make each of those n's actually polynomial complexity (heck, n^2 even) the computer should essentially blow up on non-trivial data sets. Its late in the evening and I haven't thought through this very much, but one way would be to use utsname's sysname thing as part of your "random data" to make the salt. That sounds a little obvious though. Maybe there's some obscure function somewhere for getting dates or times or something that I can exploit format of the returned data to reveal the difference between OSes, as that would be a lot harder to detect ("oh, seeding a hash function with a date and some magic numbers, nothing wrong with that").
Anybody got any ideas or corrections to share? Its been a while since I've taken data structures, and I've got essentially no ideas for obscure functions revealing system differences to exploit (C isn't my bag).
Re:So who wants to talk strategy? (Score:2)
Re:So who wants to talk strategy? (Score:2)
Finally. (Score:2)
This is more than malicios code. (Score:2)
ways to attack the OS (Score:2)
since you can't rely on architecture, and can't attack stuff like endian-ness, you need to hit the nuances of the OS. One way I can think of is exploit size differences of stuff like wchar_t, since it's 4 bytes on most newer flavors of BSD (e.
Re:LAMP (Score:2)
Re:LAMP (Score:2)
LAMP is certainly a great tool. It's very practical and useful.
As for a beginner language? Hmm. I always kind of wince when people get their programming feet wet with web-based development. There are so many issues involved with web development (browser issues, the interplay between database/server-side scripting/client-side scripting/etc) and several d
Re:I'll submit the source code for... (Score:2, Funny)
Oh darn, it's not written in C.
Hey Windows XP and Vista are great examples of how powerful and fast VB.NET is!
You cant write as robust of a Operating system in Python or Ruby!
Re:I'll submit the source code for... (Score:2)
Maybe I am missing the joke, if so wouldn't be the first time.
TFA says (Score:2)
Re:I'll submit the source code for... (Score:2)
Actually, the kernel of Windows is written in a smattering of machine language and C. The Windows API (not MFC) is also in C.
Besides, the contest is to create a program that will perform miserably on a "competitor's" OS without the malicious, anti-competitive part of the code being obvious or anything other than innocent-looking.
Re:Fun idea, but... (Score:3, Interesting)
Re:Any C code is potentially malicious (Score:2)
This is a hilarious insight into other programmers points of view, but they'll have a hard time writing anything vastly efficient, especially at a lower level (say system drivers).
Re:Any C code is potentially malicious (Score:2)
Re:Any C code is potentially malicious (Score:2, Insightful)
Re:Any C code is potentially malicious (Score:2)
Maybe not... on many OS's, the memory isn't actually allocated until you read or write it. So e.g. in Linux/Unix, your task would quickly run out of address space and be killed, but the rest of the OS wouldn't notice much difference.
Now if you were to allocate and clear memory in a loop, that would cause more trouble.
Re:Any C code is potentially malicious (Score:2)
Re:Any C code is potentially malicious (Score:3, Informative)
Re:Any C code is potentially malicious (Score:2, Insightful)
Pointers POINT to arbitrary memory locations. References do not. You cannot recast a reference to an arbitrary type, you can't put arbitrary data at a reference location, you cannot reseat a reference with a new instance, you cannot do pointer arithmetic with references.
It happens that pointers can be like as references, among many other things. This does not make references into pointers.
Re:Any C code is potentially malicious (Score:2, Flamebait)
Undisciplined use of pointers is going to cause bugs. But since undisciplined coding itself causes bugs, who the fsck cares? The solution isn't to ban pointers, but to start beating undisciplined coders over the head. I'm not saying you have to use pointers, but if you are avoiding them because of fear, it's time to lea
Re:I love this (Score:5, Interesting)
I actually just thought that I'll whip something up for the contest. You know, first I'll just make the basic program and try to figure out how to sneak something in. It took me 10 minutes to realize that I have no fucking clue what I'm doing.
"How do I read from stdin?"
"How do I allocate without too much overhead for it?"
"Wait, I really shouldn't be doing this in the main function. Perhaps I'll make a separate function. Now, hmm.. How do I define a function which takes a reference to an array of char pointers, and what else do I need to know to reallocate the array"
"Oh right. It also needs to be separated by spaces too, not just newlines"
"I wish there was a nice library function 'char *readfile(stream)' in ANSI C"
"Shit. Real programming is hard!"
I hereby turn in my coding gloves, and don the pink fluffy Java gloves I have actually worn for some time against my will.
Re:I love this (Score:2, Insightful)
Example 1: In my senior year of college, I took an AI class. The professor allowed us to do homework in C, LISP, or Java. My parter and I avoided LISP because we didn't see any benefit in learning it. We chose Java instead of C because we needed many
Re:I love this (Score:2)
Yes, but it would do the same 10-second query regardless of the OS. Now, can you find a way to make the query take longer on one OS than another? That's the goal. Not just degrading performance, but making it OS specific.
Re:I love this (Score:2, Informative)
"How do I allocate without too much overhead for it?"
"Wait, I really shouldn't be doing this in the main function. Perhaps I'll make a separate function."
Easy.
Re:I love this (Score:2)
cin is part of the C++ STL... doesn't have anything to do with a C contest. Go back to CS 100 and study hard.
Ahh, allocate an array? Well, in C, arrays are statically sized, but you could create a new, larger one and copy a full one into it. Or you could use the vector data type from the C++ STL. Again, often learned in CS 100.
Allocate/deallocate memory using malloc/free. This allows your program to s
Re:I love this (Score:2)
Re:I love this (Score:2)
> Again, try getline. Really, none of this is hard, unless I miss your intentions.
His intentions are clear. ANSI C. Right there in the sentence you quoted. getline is C++.
Now post C code for implementing the same functionality, making sure it's O(n log n) in time or better, where n is the number of characters in the stream, which you don't know in advance. The parent obviously recognizes this as a nontrivial problem,
Re:real programming ? (Score:2)
It's what Real Programmers write, like Mel. [foldoc.org] If you've never heard of him, follow the link, read and be humbled by his genius.
Re:C vs. Java, and some observations on the code (Score:2)
However, according to the FAQ, you can submit solutions in other languages, so why not try your hand at Java? I've actually got an idea for this contest that uses OCaml, which is just as tight as Java with regard to these tricks. I just have to work a couple of small details first.
Re:C vs. Java, and some observations on the code (Score:2)
The FAQ does not say this, and I certainly won't feel any obligation to install different compilers and interpreters because somebody submitted code in SML/NJ (or one of the other, inferior functional languages. Smiley.)
The FAQ says that we'll accept C++, which is about as close as we get to being inclusive.
X
Re:C vs. Java, and some observations on the code (Score:2)
Can I use C++ instead of C?
If you actually want to do something like that, then sure.
No COBOL, please.
Which to me reads as "Sure. We will accept other languages. Well... not COBOL."
You may want to rewrite it in a more specific manner if you want to limit the languages involved.
Re:C vs. Java, and some observations on the code (Score:2)
The contest involves opening a file - that's just begging you to take the path (to construct the output file name) and check path separator or initial character while doing so.
The trick would be to detect different Unix systems (in Java or other) without being obvious.
Re:C vs. Java, and some observations on the code (Score:2)
No, the program reads from stdin and writes to stdout. Its function is basically the equivalent of that Unix command string on the main page.
X
Re:C vs. Java, and some observations on the code (Score:2)
That may be *legal* C/C++ code, but IMHO it ain't *moral*.
I always crank up my compiler warning level to 11 (and then set "treat warnings as errors") to warn about this sort of stuff.
"But, but, but, that's legal!" you cry. "And it makes for more-efficient code!"
Well, I submit to you that
(1) modern optimizing compilers really make this sort of code-squeaking an exercise in obsessiveness, and
(2) if you REALLY want/need to use