Depends on whether the attack is directed at you, at someone else nearby, or is just a racist/hateful person's rant at the world.
I tend to ignore hateful rants unless it's someone who might actually care about my opinion. If it's a friend or a relative, I try for some variant on "Hey dude, that's not cool, and it's not true either" (vary for the situation, of course!) - I don't expect it will change their mind, but it might make them more aware that not everyone agrees with them. I'm happy to say I've only had to do this a few times, though.
Right now, my usual comment starts with "Wow, what century are you IN?" and includes a point or two they probably would rather ignore (most illegal immigrants were legal when they came here / women can be scientists too now, did you know? / gay people are parents too / black men aren't criminals for having bad taste in urban fashion any more than white men are / etc).
99% of the time, whatever it is I felt I needed to speak up about was something mild, insinuated, or otherwise not particularly blatant, though. In those cases I try to just focus on the comment at hand - "I'm glad you approve, but you do realize that 'Christian' isn't a synonym for 'moral,' right?" and then try to move on. Usually it's a racist/bigoted/hateful comment from a non-racist/bigoted/hateful person, and I see no need to vilify them for it. I know I've said some stupid stuff too (both things I've said out of ignorance and things I've said without thinking it through or realizing how it would sound).