Energetic electrons of terrestrial origin behind the bow shock and upstream in the solar wind