A command-line tool to interact with TCP sockets opened by other processes on the same Linux machine.
Allows you to search, select, and duplicate existing sockets (via pidfd_getfd
), send data or files through them, and receive data with a configurable timeout.
- List TCP sockets opened by processes, optionally filtered by PID or process name.
- Display remote IP address and port for each socket.
- Select a socket from search results to interact with.
- Send arbitrary strings or entire files into the selected socket.
- Receive data from the socket with a timeout and optionally save to a file.
- Configure receive timeout.
- Simple interactive shell interface with helpful commands.
- Linux kernel 5.6 or newer (for
pidfd_open
andpidfd_getfd
syscalls 78B1 ) - Root privileges to access other processes' file descriptors
- GCC to compile
gcc -o socket_injector socket_injector.c
Run the program as root :
Interactive CLI :
sudo ./socket_injector
Non-interactive mode :
sudo ./socket_injector --pid 3458 -f 4 --send Hello_World
-
help
Show help with available commands. -
search [pattern]
List all sockets. If a pattern is given, filter by PID or process name containing the pattern. -
select <index>
Select a socket from the last search results by its index. -
send <string>
Send a string to the selected socket. -
sendf <file>
Send the contents of a file to the selected socket. -
rec [file]
Receive data from the socket with a timeout (default 5 seconds). Iffile
is provided, save received data to it, otherwise print to stdout. Displays the number of bytes received after completion. -
timeout <seconds>
Set the receive timeout duration (in seconds). -
quit
Exit the program.
Help :
# ./js5 --help
Usage:
program [options]
Options:
-p, --pid PID Specify PID
-s, --socket FD Specify socket fd
-S, --send STRING Send string to socket
-F, --sendf FILE Send file content to socket
-r, --rec [FILE] Receive from socket, output to stdout or FILE if specified
search [pattern] Search sockets optionally filtering by pattern
-h, --help Show this help
If no arguments are provided, starts interactive shell.
Run :
> search ssh
Found 2 socket(s):
[0] PID=1234 (sshd) FD=5 -> 192.168.1.10:22
[1] PID=5678 (ssh) FD=4 -> 192.168.1.11:22
> select 0
Selected entry [0]
> send Hello World
Data sent: 11 bytes
> rec
Received 34 bytes
> quit
Bye.
- This tool requires root access to open file descriptors from other processes.
- The program duplicates the file descriptor using Linux
pidfd_getfd
syscall to reuse the same socket. - Receiving data uses
select()
with a configurable timeout to wait for incoming data. - Tested on Linux kernel 5.6+.