From the Super Mario Wiki
The Counterattack is a type of attack present in the Mario & Luigi series. When some enemies attack, it can be countered by jumping on or hammering the enemy. Almost every enemy provides a hint of which character it is going to attack (and thus which one needs to perform the counter). The counterattack's power is the same as a failed attack on the player's turn.
Mario and Luigi counterattack using their Hammers and their jump ability; in Mario & Luigi: Bowser's Inside Story, Bowser's counterattack moves are punching and ducking in his shell. When there is a Giant Bowser battle, Bowser's counterattacks are punches, as with his normal form, and fireballs. If the player has someone's attack powered up, it will also boost their counterattack's power.