Finding of normal of intersected object

When I have my sphere hit by tube, I want to get one or more of the triangles i've intersected.  For those triangles, how would I find their normal.

Or how would I cast a ray into the certain direction I want to move and if the ray hits something within a certain distance, calculate a new random direction and cast a new ray until I find a possible direction.

My question is, what code is needed to implement either of the two ideas?