A couple things it could be:
1. oblique (abdominal) muscles attach to the ribs laterally- strained
2. the junction where the rib ends and the cartilage begins- sprained ligaments
If you have pain with active motion (side crunches, elbow to opposite knee crunches) or passive stretching (like you described)then usually means muscle strain
P.S. I'm not a doctor, I just play one one the internet...