Are you really blocking Windows Script Engines?

Discussion in 'malware problems & news' started by itman, Nov 7, 2017.

  1. itman

    itman Registered Member

    Joined:
    Jun 22, 2010
    Posts:
    8,593
    Location:
    U.S.A.
    Someone posted a new 0-day over at the Eset forum here: https://forum.eset.com/topic/13703-popup-951533118-blocked/

    What this bugger did among many things was create multiple copies of wscript.exe in a %AppData%/Roaming subdirectory under different .exe names. Granted most are monitoring %AppData% directories for .exe startup but in this instance, any directory could have been used.
     
  2. Minimalist

    Minimalist Registered Member

    Joined:
    Jan 6, 2014
    Posts:
    14,885
    Location:
    Slovenia, EU
    If execution from "not standard" locations is blocked, it probably wouldn't be able to run, wouldn't it? So SUA and SRP could stop it, with no problems.


    EDIT: also question about registry key that disables script engines:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Script Host\Settings

    Would it also disable running it from other locations?
     
    Last edited: Nov 7, 2017
  3. itman

    itman Registered Member

    Joined:
    Jun 22, 2010
    Posts:
    8,593
    Location:
    U.S.A.
    Well if your using whitelisting and only allowing those apps to run, then of course the malware wouldn't be able to execute.
     
  4. TairikuOkami

    TairikuOkami Registered Member

    Joined:
    Oct 10, 2005
    Posts:
    3,440
    Location:
    Slovakia
    Yes. You can copy "wscript.exe" anywhere and when you rename it and try to run it, it is blocked.
     
  5. itman

    itman Registered Member

    Joined:
    Jun 22, 2010
    Posts:
    8,593
    Location:
    U.S.A.
    According to the below, "UseWinSafer" blocks all scripts. I checked same in my Win 10 1703 build and it is indeed set to "1." So unless I am interpreting this wrong, all .ws and .js scripts are blocked from running. I will have to test this because I know in prior Win 10 builds, I could run scripts.

    However, I believe the below only applies to startups of wscript.exe not any renamed vers. of it. Will do a test.
    https://isc.sans.edu/forums/diary/Controlling JavaScript Malware Before it Runs/21171
     
  6. itman

    itman Registered Member

    Joined:
    Jun 22, 2010
    Posts:
    8,593
    Location:
    U.S.A.
    The "UseWinSafer" key does not stop wscript.exe execution. I used the Hello World .js script from the above SANS article. It ran just fine per the below screen shot:

    Hellow.png

    -EDIT- Tried the "TrustPolicy" option. That didn't work either.

    -EDIT2- This might be the problem since "UseWinSafer" only applies if SRP set. Will play with these settings tomorrow:
     
    Last edited: Nov 7, 2017
  7. Minimalist

    Minimalist Registered Member

    Joined:
    Jan 6, 2014
    Posts:
    14,885
    Location:
    Slovenia, EU
    Thnx. So setting Enabled key to 0 will add some more protection. I just have to remember to enable it each time I run PatchCleaner. Usually I have to run it twice :)
     
  8. TairikuOkami

    TairikuOkami Registered Member

    Joined:
    Oct 10, 2005
    Posts:
    3,440
    Location:
    Slovakia
    You can use bat, something like this.

    Code:
    reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v "ValidateAdminCodeSignatures" /t REG_DWORD /d "0" /f
    reg add "HKCU\Software\Microsoft\Windows Script Host\Settings" /v "Enabled" /t REG_DWORD /d "1" /f
    reg add "HKLM\Software\Microsoft\Windows Script Host\Settings" /v "Enabled" /t REG_DWORD /d "1" /f
    start "" "%ProgramFiles% (x86)\HomeDev\PatchCleaner\PatchCleaner.exe"
    pause
    reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v "ValidateAdminCodeSignatures" /t REG_DWORD /d "1" /f
    reg add "HKCU\Software\Microsoft\Windows Script Host\Settings" /v "Enabled" /t REG_DWORD /d "0" /f
    reg add "HKLM\Software\Microsoft\Windows Script Host\Settings" /v "Enabled" /t REG_DWORD /d "0" /f
     
  9. itman

    itman Registered Member

    Joined:
    Jun 22, 2010
    Posts:
    8,593
    Location:
    U.S.A.
    The "TrustPolicy" setting does indeed work as noted by below screen shot. Note that TrustPolicy is a Dword value. I also set WinSAFER setting to "0" since is only applicable if SRP or AppContainer is active. For me this is a better alternative. If malware is running a renamed ver. of wscript.exe, it is unlikely it will be using a signed script. If it attempts to run, you will get an alert of the malware activity.

    wscript_signed.png
     
  10. Peter2150

    Peter2150 Global Moderator

    Joined:
    Sep 20, 2003
    Posts:
    20,590
    For me a simple solution. I someone copies any of the script engines to a different exe, name change or not, and drops it on any disk MZwritescanner announces and blocks it.
     
  11. itman

    itman Registered Member

    Joined:
    Jun 22, 2010
    Posts:
    8,593
    Location:
    U.S.A.
    Found a better solution. Set "TrustPolicy" to a value of "1". This will alert you every time wscript.exe in any fashion is run and show you the signing status of the script. It will also allow you to run unsigned scripts if you so wish. A much better solution than always having to change registry settings each time you have an app that validity uses a wscript.exe script.

    wscript_sig_verify.png
     
  12. summerheat

    summerheat Registered Member

    Joined:
    May 16, 2015
    Posts:
    2,199
    Yeah, it's explained here.
     
  13. itman

    itman Registered Member

    Joined:
    Jun 22, 2010
    Posts:
    8,593
    Location:
    U.S.A.
    Also and predictably since nothing MS develops is 100% secure, TrustPolicy can be bypassed:
    https://msdn.microsoft.com/en-us/library/bb985985.aspx
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.