/parasite

parasite? live on another process.

Primary LanguageC

# Parasite - live along side a process. Die when it dies.

## Example: Serving a HTTP from /bin/sleep.

    % PARASITE_RUBY=./sinatra-example.rb LD_PRELOAD=./parasite.so sleep 360
    Parasite initialized by hooking 'malloc'
    == Sinatra/1.1.0 has taken the stage on 4567 for development with backup from Thin
    >> Thin web server (v1.2.7 codename No Hup)
    >> Maximum connections set to 1024
    >> Listening on 0.0.0.0:4567, CTRL+C to stop
    127.0.0.1 - - [01/Feb/2011 19:10:25] "GET / HTTP/1.1" 200 12 0.0019
    127.0.0.1 - - [01/Feb/2011 19:10:25] "GET /favicon.ico HTTP/1.1" 404 420 0.0008


    % curl localhost:4567; echo
    User time: 0.78<br>
    System time: 0.16


## Possible use cases:

* Expose internal-process data from any process over HTTP, etc, without needing
  to modify said program - and without requiring root access necessarily to access it.
* Allow coordinated handoff of server sockets without modifying the main
  program (this will be tricky, but should work nicely)
* Embed a script runtime (ruby, python, perl, nodejs, etc) into any running program.

## Example: Inspect netcat's socket.

% PARASITE_RUBY=irb-example.rb LD_PRELOAD=./parasite.so nc -l 192.168.0.97 8888
Parasite initialized by hooking 'malloc'
>> require "socket"
=> true
>> sock = Socket.for_fd(3)
=> #<Socket:0x7f8a795833c8>
>> port, address = Socket.unpack_sockaddr_in(sock.getsockname)
=> [8888, "192.168.0.97"]