Code Monkey home page Code Monkey logo

netelf's People

Contributors

harryr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

netelf's Issues

Linux without memfd support

e.g. Bash on Windows, or 'Linux' zones in Solaris...

__NR_memfd_create is a preprocessor macro, so we can test for it's existence at compile-time and disable code which uses that syscall.

At runtime we already check for errno == ENOSYS, presumably Bash on Windows will act accordingly so the shm_open fallback can be run.

If shm_open fails, which is really just a wrapper around opening from /dev/shm, then the portable UNIX-like file_exec will be used.

Original commit: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=9183df25fe7b194563db3fec6dc3202a5855839c

Another interesting option is O_TMPFILE, supported since Linux 3.11, whereas memfd_create is supported only in Linux 3.17, it's unlikely that either are supported by 'Bash on Windows':

          Specifying O_EXCL in conjunction with O_TMPFILE prevents a
          temporary file from being linked into the filesystem in the
          above manner.  (Note that the meaning of O_EXCL in this case
          is different from the meaning of O_EXCL otherwise.)

          There are two main use cases for O_TMPFILE:

          *  Improved tmpfile(3) functionality: race-free creation of
             temporary files that (1) are automatically deleted when
             closed; (2) can never be reached via any pathname; (3) are
             not subject to symlink attacks; and (4) do not require the
             caller to devise unique names.

          *  Creating a file that is initially invisible, which is then
             populated with data and adjusted to have appropriate
             filesystem attributes (fchown(2), fchmod(2), fsetxattr(2),
             etc.)  before being atomically linked into the filesystem
             in a fully formed state (using linkat(2) as described
             above).

          O_TMPFILE requires support by the underlying filesystem; only
          a subset of Linux filesystems provide that support.  In the
          initial implementation, support was provided in the ext2,
          ext3, ext4, UDF, Minix, and shmem filesystems.  Support for
          other filesystems has subsequently been added as follows: XFS
          (Linux 3.15); Btrfs (Linux 3.16); F2FS (Linux 3.16); and ubifs
          (Linux 4.9)

Don't use hard-coded IP address

In _win32.c and netelf.c the default IP address and port is hard-coded.

Need to be able to customise it at compile time, either by editing a config.h file or via -D defines.

argv not passed on Windows

CreateProcess doesn't take an argv style array of pointers.

Need to concatenate & escape arguments into a single string...

Non-Linux, e.g. Solaris & FreeBSD, in-memory execution support

fexecve is defined in the IEEE Std 1003.1-2008 (POSIX.1-2008) standard, however it's not so widely supported by the libc of various different systems.

The aim is to avoid creating our own executable/library loader, and avoid ever writing to the filesystem as that leaves an audit-trail of sorts.

The underlying premise for Unix-like platforms relies having one of two options available:

  1. Have a /proc filesystem where open file descriptors can be accessed like regular files and passed to exec like normal paths.
  2. Have a libc or kernel system call which performs special handling of file descriptors to exec them directly, aka fexecve.

For Windows platforms there are two options available:

  1. Hook ntos.dll calls so when it tries to load an executable / library you can read from a buffer
  2. Re-implement the loader, e.g. MemoryModule or the various Meterpreter EXE loaders.

Man pages and related info for fexecve on non-Linux platforms:

OSX and iOS support

According to http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system

#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))

Support for running from memory on macOS works like:

https://github.com/CylanceVulnResearch/osx_runbin/blob/master/run_bin.c

This changes the executable type to MH_BUNDLE, but it uses a number of hardcoded magic strings and I don't know if they're portable across many versions, or if it'd work on iOS

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.