A bad cough can definitely cause pains in your ribs when you cough. There are muscles between your ribs called your intercostal muscles that are accessory muscles with breathing, and are also involved with coughing. When you breath in your diaphragm contracts and pulls your lungs down drawing air in. Also simultaneously there are muscles in your neck that help pull your chest wall up and out, and the intercostal muscles help to spread your ribs and make your thoracic cavity larger, which makes negative intra-thoracic pressure drawing air into the lungs.
When you exhale/cough the opposite process takes place where the abdominal muscles contract which increases intra-abdominal pressure pushing up on the diaphragm, and the accessory muscles (intercostals, etc) cause the chest wall to get smaller increasing the intrathoracic pressure and forcing air out. The vocal folds which normally open with inhalation and approximate for phonation close completely when coughing, so that the air builds up pressure (like a valve), then they open quickly letting a forceful rush of air out (hopefully propelling out whatever stimulated the cough reflex).
You can imagine that these muscles can all get fatigued/sore and that may be what is causing your ribs to hurt when you cough. I would recommend seeing your primary care physician
to get evaluated as to why you have a cough in the first place.