First, install cdrdao – if you use macports:
sudo port install cdrdao
To rip the CD to an image:
sudo cdrdao read-cd --device IODVDServices file.toc
To write the image back to CD:
sudo cdrdao write --device IODVDServices file.toc
Make sure that the CD isn’t mounted before reading, use disk utility to make sure.