Update: the question was modified to determine how to tell if the request is legal, and how to protect oneself. The advice below was for if the request is obviously illegal. Here is one way to determine if the action is legal and to protect oneself at the some time, although it isn't foolproof:
- Ask your boss for written directions on what needs to be done and why. If the boss gives it to you without any hesitation, then the boss doesn't see anything wrong it with, nor does he consider there any danger to himself by asking you to do it.
- If the boss refuses to give you anything in writing, then consider the original advice:
It is unethical, it could be illegal, and it will certainly compromise your integrity. It's also possible that even with the fix that the audit will find the problem, and evidence of trying to cover it up. In that case, you will be the first offered as guilty, from all of those above you.
But, you're also in a situation where if you don't do it, you lose your job. You have to consider the pros and cons, and some of those will be weighted by how important you consider your own integrity, and how precarious your life will be without this job. Be sure to weigh in the possibility that you lose your job, even if you do it. Consider also the long term effects on yourself, not just the short term.
I would consider this serious enough to walk away from, and let someone else do it, and that would not be an overreaction. (Or get the written instructions, as in the question mentioned in the comments.) However, that is just an opinion of one person, who isn't you.
We often hit ethical decisions (usually without such dire consequences), and sometimes we're in a position to fight the situation and sometimes we are not. You have to determine if you are in a position where you can fight it.