Code Monkey home page Code Monkey logo

sftp-server-chroot's Introduction

This allows using openssh's sftp-server in chroot mode without sshd or modifying their source-code.

Why?

When doing reverse-sshfs using ncat and ssh port forwarding you have to trust the server to not hijack your sshfs call to gain access to your whole system. This prevents that by limiting sftp-server's access using kernel functionality.

How does it work?

sshd includes the same code as sftp-server in their binary but neither provides the sftp-functionality as a library.

Both call the function sftp_server_main passing the current user's struct passwd as an argument. sshd does the chroot before calling that function. You could also do the chroot before starting sftp-server but that would require making all the dependencies (linker, shared library, /dev/null) available in there.

So instead, I wrote a small preload library which uses sftp-server's initial getpwuid call to do the chroot and return a struct passwd for the user that you initially inteded to run the server at(chroot needs root permissions).

How to run

The specifics differ depending on your setup but the minimum you have to do is set some environment variables:

  • export LD_PRELOAD="/path/to/libsftp_server_chroot_preload.so"
  • export SFTP_CHROOT_DIR="/path/to/shared/directory"
  • export SFTP_UID="DESIRED_UID"

After chrooting, the process drops it's user and group privileges to that of the user with the UID DESIRED_UID.

sftp-server-chroot's People

Contributors

m1cha avatar

Watchers

 avatar

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.