Is ducking legal in fencing, or can you get carded for a crouching counterattack?
Yes, ducking is legal in all three weapons. The rules say plainly that displacing the target and ducking are allowed, even if your free hand or the knee of your back leg touches the strip while you do it. What can get you carded is not the duck itself but what your body does during it: covering valid target with something that is not target, turning your back on your opponent, or falling on purpose to avoid the hit.
In foil the real risk is covering. If you drop your head so the mask, which is off target above the bib, ends up in front of your chest, or you crouch so deep your knees shield your torso, that is covering: a yellow card, and any touch you made is annulled. If the opponent's hit lands on the part that covered the target, the referee can award it to them. Turning your back is a yellow card with your touch annulled in every weapon. A touch made during or after a fall is annulled, and falling on purpose to avoid a hit is a yellow. There is no rule against showing the back of your head.
In sabre the whole upper body is target, head and arms included, so a duck mainly gets you under head cuts, and the same covering rule applies if your legs come up in front of your torso. In épée there is no off-target area to cover with, so a duck is never a covering offense; it is simply a timing gamble against a downward hit to your mask or back. In foil and sabre, remember right of way: if you duck and counter and both lights go on, a correct attack wins, because the rules treat a failed dodge as you being hit. The duck only pays when the attack misses completely.
Done well, it is a leg move. Drop straight down by bending your knees, keep your torso upright and your eyes on your opponent, and have your point already traveling to target. Do not fold forward or bow your head, which invites a hit to the back and risks a covering call in foil. Save it for an opponent who keeps attacking high, and use it once or twice a bout at most: it is hard to recover from if it fails, a sharp opponent will wait and hit low once they have seen it, and deep crouching is hard on the knees.