17
1
The point of this puzzle is to learn how a malicious code can be hidden and discovered in a program.
A person is asking the question:
Plz give me some code that how can I search a file may be in Present Directory or in its Sub-Directories.
(This is a variant of a real question I've seen posted on one site.)
To be more specific: The OP wants you to write a program that accepts a string and a directory. It will traverse all files in the directory and recursively all its subdirectories. For each file it will check if the file contains the string, and if it does, will print the name of the file. (The program can have additional features as long as they are relevant to the main goal, if you wish.) There are no requirements on the traversal order.
However, the main task of this puzzle is to hide into the program additional code that will make a fool of the person that asks for the program in the eyes of its users/colleagues/boss/etc. For example, print a humiliating text at some point, such as: The author of the program doesn't know how to program, should return his/her diploma and get fired. Be creative.
Rules:
- The solution must not be harmful (except making fool of the OP, of course). It must not do any irreversible damage to end users (no stuff like
rm -rf
)! Such solutions will be disqualified. - The trolling stuff should be hidden so that the OP won't find it easily.
- It shouldn't be obvious that you're trolling the OP. The code should look genuine.
- The solution must come with a proper explanation how it trolls the OP so that everybody can learn something from your solution. The explanation should be hidden in a hidden-until-you-click text (spoilers). When judging, try to discover the trolling without looking at the explanation and vote for those that are difficult to discover.
- Also try to hide the trolling from the OP if (s)he tries to run the code a few times. Perhaps start trolling only after a particular date, or under some conditions that a sloppy programmer won't test. Be creative and don't forget to explain the trick.
- Don't just create a script using existing tools such as
grep
orfind
. Write the program from scratch. Better avoid libraries and prefer low-level calls - this will make the code more complex and gives you the opportunity to hide the evil stuff there.
This is a popularity-contest. Please judge according the above points.
3I'm voting to close this question as off-topic because it is [tag:underhanded]. – Erik the Outgolfer – 2016-06-07T15:17:49.737
I'm voting to close this question as off-topic because It's code trolling. – James – 2016-06-07T17:00:06.237
6How does "will make a fool of the person that asks for the program in the eyes of its users/colleagues/boss." and "should return his/her diploma and get fired." square with "The solution must not be harmful, must not do any damage to its users"? – emory – 2014-01-01T21:34:16.567
I appreciate that you've put in more effort than most posters of "trolling" questions, but all questions on this site should have a clear specification and "how can I search a file may be in present directory" is nowhere near meeting that standard. (Whether any code-trolling question can meet that standard is a separate issue).
– Peter Taylor – 2014-01-01T22:01:05.373@PeterTaylor I tried to give a more specific assignment. If you have more specific suggestions, I'll appreciate them. – Petr Pudlák – 2014-01-01T22:42:21.087
"Hide evil code" - evil implies harmful.
– syb0rg – 2014-01-01T22:46:43.0302@emory the coder is not the user. Humiliating the coder in front of his fellow coders without effecting the clients is possible. – Cruncher – 2014-01-02T18:10:12.373