From 81b17eef0baaefa725602ac2a8d335bceccd97eb Mon Sep 17 00:00:00 2001 From: mivirl <> Date: Sat, 2 Mar 2024 19:52:35 -0600 Subject: [PATCH] server: Limit ports used to 46515-46550 --- README.md | 7 +++++-- src/server.sh | 10 +++++++++- src/start-server.sh | 4 +++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 159099a..e7a90af 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ directory to the remote system, then `cd` to that directory and run: ./busybox sh start_server.sh ``` +By default the server uses the ports 46515-46550. This can be changed in +`start_server.sh` + ### Client To deploy on the client, you'll need to transfer the `build/_output/client` @@ -56,7 +59,7 @@ directory to the remote system, then `cd` to that directory and run: Once the server is running and a client has connected, files will appear on the server in `srv/clients/` with the following naming scheme: -- `_auth-key` - Key used to authenticate clients and store files in the correct +- `_auth-key` - Key used to authenticate clients - `_files.log` - Log of files as they are received on the server - `_info.txt` - Contains basic information about the client - `_processes.log` - Log of processes as they are run on the client @@ -65,7 +68,7 @@ server in `srv/clients/` with the following naming scheme: transferred as they are written on the client - `C__commandname` - Command output, continuously transferred -Logs can be monitored as they come in using `lnav`: +Logs can be monitored as they come in using [lnav](https://lnav.org): ```sh ./lnav -r srv/clients diff --git a/src/server.sh b/src/server.sh index b6245d4..52e785a 100644 --- a/src/server.sh +++ b/src/server.sh @@ -1,5 +1,13 @@ #!./busybox sh +if [ $# -ne 2 ]; then + echo "Usage: $0 file_port_start file_port_num" + exit 1 +fi + +FILE_PORT_START=$1 +FILE_PORT_NUM=$2 + SRVDIR=$(pwd) verify_input() { @@ -124,7 +132,7 @@ while read -r COMMAND; do SLEEPTIME=0 while true; do sleep $(( RANDOM % (SLEEPTIME + 5) + 1 )) - PORT=$(( (RANDOM * 2 + RANDOM % 2) % 64511 + 1024 )) + PORT=$(( (RANDOM * 2 + RANDOM % 2) % FILE_PORT_NUM + FILE_PORT_START )) nc -w 7 -l -p "$PORT" > "$FILENAME" 2>/dev/null & NC_PID=$! # Wait for nc to fail. There seems to be a bug with busybox sh where diff --git a/src/start-server.sh b/src/start-server.sh index 80cc5cc..b150210 100644 --- a/src/start-server.sh +++ b/src/start-server.sh @@ -1,6 +1,8 @@ #!./busybox sh SRVPORT=46515 +FILE_PORT_START=46516 +FILE_PORT_NUM=45 CWD=$(pwd) # ----------------------------------------------------------------------------- @@ -8,4 +10,4 @@ CWD=$(pwd) mkdir -p "$CWD/srv/clients" cd "$CWD/srv" -tcpsvd -c 4096 0.0.0.0 "$SRVPORT" ../busybox sh ../server.sh +tcpsvd -c 4096 0.0.0.0 "$SRVPORT" ../busybox sh ../server.sh "$FILE_PORT_START" "$FILE_PORT_NUM" -- 2.39.5