I've been solving some crackmes, and every file that I download, in the "instructions" says: "Patching is obviously not allowed". What does that mean? And how does one patch a file?
Following quote comes from unix.stackexchange:
To patch a file means to modify it, with the connotation that the modification is generally small.
So, patching the executable is a process of changing its content usually performed for changing its original behaviour.
Patching is obviously not allowed means that the author of a particular crackme wants you to crack it without modifying its content. For instance, consider a simple program:
printf(“Congratulations, you have cracked it!\n”);
printf(“Wrong password! Try again!\n”);
Of course one can patch it so that it always prints the "Congratulations [...]" message, but the point of this very simple crackme is to actually find that password somehow (by finding decryption key for example).
Generally, to patch a file, you want to:
- Find the place / instruction you want to change (it may be
jzas @Axel Munoz said, but it may be a
jmpto the location containing the code you want to be executed as well).
- Find out what is the machine code representing the instruction you want to put there - it can be done by first compiling the program written in assembly and then disassembling it. If you are working on x86 architecture, you can use this site as well.
- Open the binary in a hex editor, find the offset where you want to put your code and just paste the machine code you obtained in the previous step.
The term "patching a [binary]" means to modify the instruction set. For example if there is a conditional jump that requires some memory to be set to a specific value, instead of modifying the memory, which might be the objective of the crackme, I could simply patch the binary to always take that jump (either by changing the condition of the jump from
jz). Patching through a debugger easily allows me to change the instruction, save the new binary, and then run it.