This is more of an electrical problem rather than a plumbing issue. But rust inside the junction box is a sign of water getting into it. You need to find the source of the water that's getting in and stop that too. It looks like there is only a bad connection inside the wire nut. Most likely due to being wet. You can try changing the wire nuts if you feel comfortable with electricity.
-
Switch the breaker to "off" and lock it out & tag it so nobody turns it on accidently.
-
Verify power is off to both wires with a meter or voltage indicator.
-
Cut back the wires until you have a good section of wire to strip and install new wire nuts. (Remove one wire nut at a time so you don't mix wires.)
If you are not comfortable with electricity please do not attempt this repair and contact someone who is.