I can say what not to do: never do something to undermine or expose your boss no matter how incompetent he is.
Personally I let my boss take all credit for my work (not really, just make everything I can in order to get him promoted). When he gets promoted he is likely to carry me up with him (if not I'm working for the wrong boss). It paid out several times.
To add slightly, the "worse" a manager is the more important this is. If someone wants all the credit and has the authority, you can only either help or face some degree of consequence.
The more competent and confident leadership is the more they'll work to make sure you get pushed into the spotlight for your work (sometimes against your will if you're shy or unsure). A good corporate culture will naturally make them look good when you look good.
Disclaimer: I've had the distinct pleasure of only working _with_ but never really _for_ a difficult of manager.
Personally I let my boss take all credit for my work (not really, just make everything I can in order to get him promoted). When he gets promoted he is likely to carry me up with him (if not I'm working for the wrong boss). It paid out several times.