Giter Site home page Giter Site logo

Store the switch.py rootfs files somewhere else or remove their /etc/shadow files for security reasons. about wsl-distribution-switcher HOT 5 CLOSED

rolisoft avatar rolisoft commented on July 19, 2024
Store the switch.py rootfs files somewhere else or remove their /etc/shadow files for security reasons.

from wsl-distribution-switcher.

Comments (5)

RoliSoft avatar RoliSoft commented on July 19, 2024 1

I was about to create a separate directory for rootfs-s and just set chown root:root chmod 000 on it, this way at least you would need root to go into the directory. However, interestingly, lxattrb doesn't work on these directories for some reason:

RoliSoft@ROLISOFT-PC ...arch-rootfs $ ls -la /etc/passwd
-rw-r--r-- 1 root root 1388 Oct 23 12:37 /etc/passwd
RoliSoft@ROLISOFT-PC ...arch-rootfs $ ls -la etc/passwd
-rwxrwxrwx 1 root root 782 Oct 23 01:53 etc/passwd
RoliSoft@ROLISOFT-PC ...arch-rootfs $ getfattr -d etc/passwd
# file: etc/passwd
user.lxattrb=0sAAABAKSBAAAAAAAAAAAAAAAAAACY95MnfKKbJyx0ySfs7QtYAAAAAOztC1gAAAAA7O0LWAAAAAA=

As you can see, the non-active etc/passwd has the correct attributes, but is still displayed with 777 permissions.

Created a file on my desktop from Windows, tried to set 000 on it, and all it did was set the read-only attribute on the file:

RoliSoft@ROLISOFT-PC ≈ $ ls -la asd.txt
-rwxrwxrwx 1 root root 1929 Apr  5  2016 asd.txt
RoliSoft@ROLISOFT-PC ≈ $ chmod 000 asd.txt
RoliSoft@ROLISOFT-PC ≈ $ ls -la asd.txt
-r-xr-xr-x 1 root root 1929 Apr  5  2016 asd.txt

I'll continue experimenting. Maybe I can do something using Windows permissions which would not allow WSL to go into that directory, yet my script can work with it freely, preferably without admin rights.

from wsl-distribution-switcher.

fpqc avatar fpqc commented on July 19, 2024

Nevermind, Roli, there are bigger problems with protecting the shadowfile now since 14951:
microsoft/WSL#1240

from wsl-distribution-switcher.

RoliSoft avatar RoliSoft commented on July 19, 2024

As long as you are the owner of the folder (which you are, since it's under your AppData) you can grant or deny yourself permission, and that will also work under WSL:

> icacls rootfs_pritunl_archlinux_latest /deny RoliSoft:F
processed file: rootfs_pritunl_archlinux_latest
Successfully processed 1 files; Failed processing 0 files

> bash -c "ls -la /mnt/c/Users/RoliSoft/AppData/Local/lxss/rootfs_pritunl_archlinux_latest"
ls: cannot open directory '/mnt/c/Users/RoliSoft/AppData/Local/lxss/rootfs_pritunl_archlinux_latest': Permission denied

> icacls rootfs_pritunl_archlinux_latest /grant RoliSoft:F
processed file: rootfs_pritunl_archlinux_latest
Successfully processed 1 files; Failed processing 0 files

> bash -c "ls -la /mnt/c/Users/RoliSoft/AppData/Local/lxss/rootfs_pritunl_archlinux_latest"
total 76
drwxrwxrwx 2 root root     0 Oct 23 01:51 .
drwxrwxrwx 2 root root     0 Oct 24 21:47 ..
-rwxrwxrwx 1 root root    26 Oct 23 01:51 .switch_label
[...]

Unfortunately, under newer WSL which supports running Windows commands, you can just run the icacls.exe command yourself, and give yourself permissions again...

I don't think this issue can be solved on my end, other than just making sure the switcher will always sync the passwd/shadow, therefore overwriting any malicious changes.

from wsl-distribution-switcher.

RoliSoft avatar RoliSoft commented on July 19, 2024

Alternatively, I could introduce an optional "elevated security" option, which requires the scripts to run under admin, and would change the ownership of the non-active rootfs folders to something other than the regular user, so you won't be able to use icacls under WSL.

But, you can run WSL as admin, (as Windows Admin, not root) at which point you can use icacls again.

from wsl-distribution-switcher.

fpqc avatar fpqc commented on July 19, 2024

Yeah, force-syncing will work.

from wsl-distribution-switcher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.