1

Something annoying that has started each time I open up Windows Subsystem for Linux 1 (WSL1) is that I get the following notification from Windows Defender (I'm using Windows 10).

It says a threat was detected, called SettingsModifier:Win32/HostsFileHijack. This only has ever occurred when I start using WSL1 (i.e. when I open up the windows terminal). It says the affected item was C:\Users\MYUSERNAME\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\etc\hosts

Is there a way I can make this stop complaining each time I start using WSL1? I tried adding the file SettingsModifier:Win32/HostsFileHijack to the exclusions in Windows Defender but when I do it tells me You can't open this location using this program.

12
  • I have WSL running (Kali) and Windows Defender running and no conflicts. Whitelist the file / app in WD that is causing the issue.
    – John
    Mar 27, 2021 at 13:38
  • You should report this to Microsoft. // Maybe you can exclude the entire package folder?
    – Daniel B
    Mar 27, 2021 at 13:44
  • @John I'd like to but I don't know how. I tried adding it to the exclusions got the error message I mentioned in the post.
    – Nukesub
    Mar 27, 2021 at 13:48
  • I have looked around WD and do not see a way to handle WSL. I will keep looking.
    – John
    Mar 27, 2021 at 13:56
  • The /etc/hosts in a WSL instance is auto-generated, so it does seem odd that Defender would complain about the one in WSL1, but not the Windows master. At least in my case, the auto-generated one is identical for both WSL1 and WSL2, and includes 127.0.0.1 as localhost, 127.0.1.1` as the Windows hostname, the contents of C:\Windows\System32\drivers\etc\hosts, and some IPv6 default entries. What does your look like? Mar 27, 2021 at 14:37

1 Answer 1

1

WSL usually autogenerates /etc/hosts, and it seems to do so using several sources:

  • Some programmatically generated entries for localhost and aliases
  • The contents of your Windows host file
  • Some IPv6 "nice-to-haves" for localhost and multicast.

It's odd that your WSL /etc/hosts is triggering Windows Defender, but your Windows one is not. Have you by any chance already added C:\Windows\System32\drivers\etc\hosts to the Windows Defender exclusions? Are you using it to suppress Windows telemetry or anything like that?

Edit/Update: Conclusion in the comments is that Spybot Anti-Beacon is likely the culprit that was adding anti-telemetry host entries. This triggers a Windows Defender warning on SettingsModifier:Win32/HostsFileHijack, which is excluded for the Windows host file. However, since the WSL /etc/hosts is auto-generated, it can't be found/opened to be excluded.

At least we can turn off the auto-generation, and you can try to create your own. To turn off auto-generation:

  • Inside the WSL instance, create or edit /etc/wsl.conf
  • Add the following section:
    [network]
    generateHosts = false
    
  • Exit the session
  • Run wsl --terminate <distroname> (where is the name of your instance)
  • Restart WSL
  • Create your own /etc/hosts (preferably as root under sudo) with, at a minimum:
    127.0.0.1    localhost
    127.0.1.1    Yourwindowshostname.local   Your_windows_machine_name
    
    And anything else that you need from your Windows hosts file (if anything), not including, of course, any telemetry blocking entries.

Hopefully that will take care of the error.

4
  • Now that you mention "suppressing telemetry" - I do use Spybot Anti-Beacon and have a setting enabled that blocks telemetry via hosts. Could that be what is causing the issue?
    – Nukesub
    Mar 27, 2021 at 18:51
  • Absolutely. I asked because when I searched on that malware signature, one of the first results mentioned that blocking Windows telemetry and ads will trigger it. It sounds like Anti-Beacon is able to exclude the Windows host file, but when WSL tries to auto-generate its version based on the Windows one, it triggers the Defender warning as well. The solution should still be to disable the auto-generation, or maybe you can turn off that Anti-Beacon feature? Mar 27, 2021 at 19:59
  • Thank you for explaining all that. What will be the consequence of turning off auto-generation?
    – Nukesub
    Mar 27, 2021 at 22:35
  • When you turn off auto-generation, you should create your own /etc/hosts. I'll add a minimal version to the answer. Mar 27, 2021 at 22:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .