is it possible to change a material depending on whether it is intersecting with another object?
An update, thanks to moonboots comments:

It is possible using Cycles:



The shader simply tests if the transparent depth is at least 1 as the cube is transparent but also we don't want more than one (as if not the cube shape may appear in non ortho views):