Add screensaver auto-lock, lynx/gsocket/apexrc defaults, htoprc, and Bantam updates

This commit is contained in:
Luxferre committed 2026-11-23 09:31:00 +02:00
1 parent b7dca4f15f
commit c12ed68d19
36 files changed
+1421 -75

No files matched your search

+164
View File
@@ -0,0 +1,164 @@
#!/usr/bin/env bash
# A wrapper script to do this (esentially):
# Server:
# $ gs-netcat -s MySecret -l -e "/usr/bin/rsync --server -vlogDtpr --partial ."
# Client:
# $ rsync -aP -e "gs-netcat -s MySecret --" test4k.dat 127.1:.
GS_NETCAT_BIN="gs-netcat"
RSYNC_SERVER_DEFAULTS="--server -logtprR --safe-links --partial"
# -D special devices
# -g preserver group (may need root)
# -p preserve permissions
# -r recursive into directories
# -R use relative path names
# If client uses '-a' then server must use '-g'
# If client uses '-R' then server must use '-R'
# RSYNC_SERVER_DEFAULTS="--server -lotpr --partial"
# RSYNC_SERVER_DEFAULTS="--server -lotpr --partial"
# RSYNC_SERVER_DEFAULTS="--server -logDtprRe.iLsfxCIvu --partial"
RSYNC_CLIENT_DEFAULTS="-ahPRv"
# Try to use the gs-netcat that's in the same path as this binary first.
BIN="$(cd "$(dirname "${0}")" || exit; pwd)/${GS_NETCAT_BIN}"
[[ -f "${BIN}" ]] && GS_NETCAT_BIN="${BIN}"
command -v "${GS_NETCAT_BIN}" >/dev/null 2>&1 || { echo >&2 "${GS_NETCAT_BIN} not found. Check PATH=?"; exit 1; }
command -v rsync >/dev/null 2>&1 || { echo >&2 "rsync not found. Try 'apt-get install rsync' or check PATH=?"; exit 1; }
usage()
{
echo "blitz [-k file] [-s password] [-l] [FILES ...]
-l Server Mode.
-s <secret> Secret (e.g. password).
-k <file> Read Secret from file.
-f <list> Read list of file names from FILE [or - for stdin]
-o RSOPT=val Options passed to rsync.
Example:
$ blitz -s MySecret -l # Server
$ blitz -s MySecret *.dat # Client
...limiting transfer rate to 10kB/sec
$ blitz -s MySecret -o 'RSOPT=--bwlimit=10 -v' /etc/*.conf *.dat
...reading the file list from standard-in
$ cd /etc
$ find . -name '*.mp3' | blitz -s MySecret -f -
...limit the amount of path information by inserting a dot and slash
$ blitz -s MySecret ~/tools/./upx/mp3
See 'man gs-netcat' and 'man rsync' for more options."
exit 0
}
read_password()
{
printf >&2 "Enter Secret (or press Enter to generate): "
read -r password
if [[ -z "${password}" ]]; then
password=$(${GS_NETCAT_BIN} -g)
fi
echo "${password}" | tr -d "[:space:]"
}
# remove -o from parameter list.
# Remove -s/-k from parameter list
# Copy all other
OPTERR=0
FL_NEED_PASSWORD=1
# Check if -s or -k is already supplied in environment and dont ask again.
[[ "$GSOCKET_ARGS" =~ ^'-s' ]] && unset FL_NEED_PASSWORD
[[ "$GSOCKET_ARGS" =~ ' -s' ]] && unset FL_NEED_PASSWORD
[[ "$GSOCKET_ARGS" =~ ^'-k' ]] && unset FL_NEED_PASSWORD
[[ "$GSOCKET_ARGS" =~ ' -k' ]] && unset FL_NEED_PASSWORD
# Current options are options for gs-netcat followed by a list of files. We
# need to split off the gs-netcat options (all but -o/-s/-k) without the
# files. To do so we need to know which gs-netcat options takes an argument
# at add those to getopts's optstring (such as -L <logfile>).
# These are caught by '*'.
# All single options (e.g. -w etc) are caught by '\?'.
# shellcheck disable=SC2220 # Invalid flags are not handled. Add a *) case.
while getopts ":hgls:k:o:L:f:" opt; do
case ${opt} in
o )
RSYNC_ARGS+=${OPTARG//RSOPT=/}
RSYNC_ARGS+=" "
;;
s )
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$OPTARG" # Add to end of array
unset FL_NEED_PASSWORD
;;
k )
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-k" # Add to end of array
KFILE=$(cd "$(dirname "$OPTARG")" && pwd)/$(basename "$OPTARG")
[[ -f "${KFILE}" ]] || { echo >&2 "File not found: ${KFILE}"; exit 255; }
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="${KFILE}" # Add to end of array
unset FL_NEED_PASSWORD
;;
g )
"${GS_NETCAT_BIN}" -g
exit
;;
h )
usage
;;
f )
RSYNC_ARGS+="--files-from=${OPTARG} . "
IS_FILES_FROM=1
;;
l )
IS_SERVER=1
ARGS_NEW[${#ARGS_NEW[@]}]="-l" # Add to end of array
;;
\? )
# UNKNOWN option. Handle before '*' (e.g. -l)
ARGS_NEW[${#ARGS_NEW[@]}]="-${OPTARG}" # Add to end of array
;;
* )
# Other (known opts from opstring) w parameters (e.g. -L <file>)
ARGS_NEW[${#ARGS_NEW[@]}]="-${opt}" # Add to end of array
ARGS_NEW[${#ARGS_NEW[@]}]="${OPTARG}" # Add to end of array
;;
esac
done
if [[ -z ${IS_SERVER} ]]; then
# CLIENT
shift $((OPTIND -1)) # list of files...
# echo "Remaining (files): $*"
[[ -z $* ]] && [[ -z $IS_FILES_FROM ]] && { echo >&2 "ERROR: No files specified."; usage; }
[[ -n $* ]] && [[ -n $IS_FILES_FROM ]] && { echo >&2 "ERROR: Either -f FILE or FILES, but not both."; usage; }
fi
# Prepare existing GSOCKET_ARGS to take more arguments if there are any
[[ -n "$GSOCKET_ARGS" ]] && GSOCKET_ARGS+=" "
# Must read here unless -s/-k was used
if [[ -n "$FL_NEED_PASSWORD" ]]; then
password=$(read_password)
echo "=Secret :\"${password}\""
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$password" # Add to end of array
fi
echo "=Encryption : SRP-AES-256-CBC-SHA-End2End (Prime: 4096 bits)"
ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}"
# echo $OPTIND
# echo args-new : ${ARGS_NEW[@]}
# echo gsnc-env-args : \'${GSNC_ENV_ARGS[@]}\'
# echo rsync-args : ${RSYNC_ARGS}
if [[ -n ${IS_SERVER} ]]; then
# SERVER
ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}"
GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" exec "${GS_NETCAT_BIN}" "${ARGS_NEW[@]}" -e "rsync ${RSYNC_SERVER_DEFAULTS} ${RSYNC_ARGS} ."
else
# CLIENT
ARGS=" -q"
# ARGS=""
[[ -n ${ARGS_NEW[*]} ]] && ARGS+=" ${ARGS_NEW[*]}"
# shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting. ${RSYNC_ARGS} -> We want word splitting for multiple arugments.
GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" exec rsync ${RSYNC_CLIENT_DEFAULTS} -e "${GS_NETCAT_BIN}${ARGS} --" ${RSYNC_ARGS} "${@}" 127.1:.
fi
+53
View File
@@ -0,0 +1,53 @@
#! /usr/bin/env bash
# A wrapper script to do this (essentially):
# $ gs-netcat -s MySecret -l -e /usr/lib/sftp-server # Host
#
# $ export GSOCKET_ARGS="-s MySecret" # Workstation
# $ sshfs -o ServerAliveInterval=30,reconnect,attr_timeout=60,auto_cache,compression=yes,default_permissions -o ssh_command="gs-netcat --" -o idmap=user,uid="${UID}",gid="$(id -g)" x@127.1:. ~/gs-fs
# Try to use the gs-netcat that's in the same directory as this executable.
BASEDIR="$(cd "$(dirname "${0}")" || exit; pwd)"
# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location.
# shellcheck disable=SC1091 # Not following: /etc/gsocket.conf was not specified as input (see shellcheck -x)
source "${BASEDIR}/gs_funcs" 2>/dev/null || source "${BASEDIR}/../share/gsocket/gs_funcs" 2>/dev/null || { { source /etc/gsocket.conf 2>/dev/null || source "${BASEDIR}/../etc/gsocket.conf" 2>/dev/null || { echo >&2 "gsocket: gsocket.conf not found."; exit 3; } } && { source "${GS_PREFIX}/share/gsocket/gs_funcs" 2>/dev/null; } } || { echo >&2 "gsocket: gs_funcs not found"; exit 3; }
my_usage()
{
echo "${BIN_NAME} [-k file] [-s password] [-l] [mount point]"
usage "${BIN_NAME}"
exit 0
}
gs_init
do_getopt "$@"
shift $((OPTIND -1)) # Mount Point
env_arg_init
if [[ -z ${IS_SERVER} ]]; then
# CLIENT
SSHFS_OPT="ServerAliveInterval=30,reconnect,attr_timeout=60,auto_cache,compression=yes,default_permissions,idmap=user,uid=${UID},gid=$(id -g)"
# echo "Remaining (files): $*"
[[ -z "${1}" ]] && { echo >&2 "ERROR: No directory (mount point) specified."; my_usage; }
command -v sshfs >/dev/null 2>&1 || { echo >&2 "sshfs not found. Try 'apt-get install sshfs' or check PATH=?"; exit 1; }
# FUSE_OPT=",cache=yes,kernel_cache"
FUSE_OPT=""
if [[ "$OSTYPE" == "darwin"* ]]; then
# Setting 'noapplexattr' prevents 'finder' from copying.
FUSE_OPT+=",async,local,iosize=65536,noappledouble,volname=THC-"$(basename "${1}")
fi
fi
if [[ -n ${IS_SERVER} ]]; then
# SERVER
sftp_server_start
else
# CLIENT
ARGS=" -q"
[[ -n ${ARGS_NEW[*]} ]] && ARGS=" ${ARGS_NEW[*]}"
GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" sshfs -o "${SSHFS_OPT}${FUSE_OPT}" -o ssh_command="${GS_NETCAT_BIN}${ARGS} --" x@127.1:. "${1}" || exit 1
echo "Successfully mounted on ${1}."
command -v fusermount >/dev/null 2>&1 && echo "To unmount use: fusermount -zu ${1}"
fi
Binary file not shown.
+38
View File
@@ -0,0 +1,38 @@
#! /usr/bin/env bash
# A wrapper script to do this (essentially):
# $ gs-netcat -s MySecret -l -e /usr/lib/sftp-server # Host
#
# $ export GSOCKET_ARGS="-s MySecret" # Workstation
# $ sftp -D gs-netcat # Workstation
# Try to use the gs-netcat that's in the same directory as this executable.
BASEDIR="$(cd "$(dirname "${0}")" || exit; pwd)"
# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location.
# shellcheck disable=SC1091 # Not following: /etc/gsocket.conf was not specified as input (see shellcheck -x)
source "${BASEDIR}/gs_funcs" 2>/dev/null || source "${BASEDIR}/../share/gsocket/gs_funcs" 2>/dev/null || { { source /etc/gsocket.conf 2>/dev/null || source "${BASEDIR}/../etc/gsocket.conf" 2>/dev/null || { echo >&2 "gsocket: gsocket.conf not found."; exit 3; } } && { source "${GS_PREFIX}/share/gsocket/gs_funcs" 2>/dev/null; } } || { echo >&2 "gsocket: gs_funcs not found"; exit 3; }
my_usage()
{
echo "${BIN_NAME} [-k file] [-s password] [-l]"
usage "${BIN_NAME}"
exit 0
}
command -v sftp >/dev/null 2>&1 || { echo >&2 "sftp not found. Try 'apt-get install openssh' or check PATH=?"; exit 1; }
gs_init
do_getopt "$@"
shift $((OPTIND -1)) # Mount Point
env_arg_init
if [[ -n ${IS_SERVER} ]]; then
# SERVER
sftp_server_start
else
# CLIENT
ARGS=" -q"
[[ -n ${ARGS_NEW[*]} ]] && ARGS=" ${ARGS_NEW[*]}"
# shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting. ${RSYNC_ARGS} -> We want word splitting for multiple arugments.
GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}${ARGS}" exec sftp -D "${GS_NETCAT_BIN}"
fi
+389
View File
@@ -0,0 +1,389 @@
#! /usr/bin/env bash
[[ $(basename -- "$0") == "gs_funcs" ]] && { echo "Use gsocket, gs-netcat, gs-sftp, gs-mount or blitz instead."; exit 1; }
# Find a sftp-server binary
find_binary()
{
bin=$1
command -v "${bin}" && { echo "${bin}"; return; }
shift 1
for dir in "$@"; do
file="${dir}/${bin}"
if [[ -f "$file" ]]; then
echo "${file}"
return
fi
done
echo ""
return
}
read_password()
{
echo -n >&2 "${GS_PRFX}Enter Secret (or press Enter to generate): "
read -r password
if [[ -z "${password}" ]]; then
password=$(${GS_NETCAT_BIN} -g)
fi
echo "${password}" | tr -d "[:space:]"
}
# haystack1 haystack2 needle
ucheck_fail()
{
[[ "$1" =~ $3 ]] || { echo >&2 "Symbol $3 not found in sftp-server."; exit 255; }
[[ "$2" =~ $3 ]] || { echo >&2 "Symbol $3 not found (2)."; exit 255; }
}
test_sftp()
{
echo "${1}" | ./gs-sftp -k id_sec.txt -wq 2>&1 | grep -c "Permission denied"
}
first_symbol()
{
for func in "$@"; do
if [[ "$sym_sftp" =~ $func ]]; then
echo "$func "
return
fi
done
echo ">>>$*-NOT-FOUND<<< "
}
uchroot_check_sym()
{
command -v nm >/dev/null 2>&1 || { echo >&2 "chroot failed (nm not found. apt-get install binutils?). Try -U to disable."; exit 255; }
# Extract symbols from .so and sftp-server binary
if [[ "$OSTYPE" == "darwin"* ]]; then
# on OSX remove the starting "_" from symboles
sym_sftp="$(nm -pu "${SFTP_SERVER_BIN}" | sed 's/^_//g')"
sym_uchr="$(nm -p "${UCHROOT_BIN}" | grep " T " | sed 's/^_//g')"
elif [[ "$OSTYPE" == "solaris"* ]]; then
sym_sftp="$(nm -Du "${SFTP_SERVER_BIN}")"
sym_uchr="$(nm -p "${UCHROOT_BIN}" | grep " T ")"
else
sym_sftp="$(nm -Du "${SFTP_SERVER_BIN}")"
sym_uchr="$(nm -D "${UCHROOT_BIN}" | grep " T ")"
fi
[[ -n "$sym_uchr" ]] || { echo >&2 "chroot self-test failed (nm bad1). Try -U to disable."; exit 255; }
[[ -n "$sym_sftp" ]] || { echo >&2 "chroot self-test failed (nm bad2). Try -U to disable."; exit 255; }
funclist+=$(first_symbol lstat\$INODE64 __lxstat64 __lxstat lstat64 lstat)
funclist+=$(first_symbol stat\$INODE64 __xstat64 __xstat stat64 stat)
funclist+=$(first_symbol opendir\$INODE64 opendir64 opendir)
funclist+=$(first_symbol open64 open)
if [[ ! "$OSTYPE" == "solaris2.10"* ]]; then
# On solaris 10 the stock OpenSSH install does not use statvfs64 (older version)
funclist+=$(first_symbol statvfs64 statvfs)
fi
[[ "${funclist}" =~ "NOT-FOUND"* ]] && { echo >&2 "Missing symbol...${funclist}"; exit 255; }
funclist+="chmod link mkdir rename rmdir symlink unlink"
# echo "funclist = $funclist" # DEBUG
for func in ${funclist}; do
ucheck_fail "${sym_sftp}" "${sym_uchr}" "${func}"
done
}
failed()
{
echo >&2 "ERROR: Self test failed: $1. Try -U to disable."
exit 255
}
# Verify that all symboles will get hijacked. exit on failure.
# linux osx solaris
# sftp -Du -pu -Du
# .so -D|T -p|T -p|T
uchroot_check()
{
local VALID_CMD
local FAIL_CMD
# skip nm-style symbol check on cygwin
# (sftp-server does not like nm on cygwin?!)
if [[ x"$OSTYPE" != "xcygwin"* ]]; then
# NOT cygwin
uchroot_check_sym
fi
# Run a self test (sftp -D sftp-server)
command -v sftp >/dev/null 2>&1 || { failed "sftp not found"; }
mkdir -p "${ROOTDIR}/ok"
mkdir -p "${ROOTDIR}/denied"
# echo "ROOTDIR=${ROOTDIR}" # DEBUG
echo hello exist-allowed.txt >"${ROOTDIR}/ok/exist-allowed.txt"
echo hello exist-denied.txt >"${ROOTDIR}/denied/exist-denied.txt"
dd if=/dev/urandom bs=1k count=1 2>/dev/null >"${ROOTDIR}/ok/test1k.dat"
echo "\
#! /bin/bash
cd \"${ROOTDIR}\"/ok
${PRELOAD} ${SFTP_SERVER_BIN} ${SFTP_ARGS[*]}" >"${ROOTDIR}/sftp-server.sh"
chmod 755 "${ROOTDIR}/sftp-server.sh"
# Run GOOD commands that should work
VALID_CMD="
mkdir dir1
cd dir1
cd ..
cd dir1
cd ../
ls ${ROOTDIR}/ok
ls ${ROOTDIR}/ok/exist-allowed.txt
put test1k.dat dir1
mkdir ./dir2/
"
[[ $(cd "${ROOTDIR}/ok"; echo "$VALID_CMD" | sftp -D "${ROOTDIR}/sftp-server.sh" 2>&1 | grep -c "Permission denied") -eq 0 ]] || { failed "valid cmd 0"; }
[[ -d "${ROOTDIR}/ok/dir1" ]] || { failed "valid-cmd 1"; }
[[ -d "${ROOTDIR}/ok/dir2" ]] || { failed "valid-cmd 2"; }
[[ -f "${ROOTDIR}/ok/dir1/test1k.dat" ]] || { failed "valid-cmd 3"; }
FAIL_CMD="
rename exist-allowed.txt ../denied/0wned.txt
mkdir ./dir1/../../denied/0wned
cd dir1/../../denied
cd ./../denied
ls ${ROOTDIR}
cd ${ROOTDIR}
cd ${ROOTDIR}/denied
cd ${ROOTDIR}/ok/../denied
rm ./../denied/exist-denied.txt
put test1k.dat ../denied/0wned.dat
put test1k.dat ../denied/exist-denied.txt
rename exist-allowed.txt ../denied/0wned.txt
rename exist-allowed.txt /0wned.txt
"
[[ $(cd "${ROOTDIR}/ok"; echo "$FAIL_CMD" | sftp -D "${ROOTDIR}/sftp-server.sh" 2>&1 | grep -c "Permission denied") -eq 13 ]] || { failed "fail cmd (2)"; }
FAIL_CMD="
ls dir1/../../denied
ls ./../denied/exist-denied.txt"
[[ $(cd "${ROOTDIR}/ok"; echo "$FAIL_CMD" | sftp -D "${ROOTDIR}/sftp-server.sh" 2>&1 | grep -c "not found") -eq 2 ]] || { failed "fail cmd (3)"; }
rm -rf "${ROOTDIR}/ok" &>/dev/null
rm -rf "${ROOTDIR}/denied" &>/dev/null
rm -rf "${ROOTDIR}/sftp-server.sh" &>/dev/null
}
gs_find_so_single()
{
[[ -e "${1}/${2}" ]] && { echo "$(cd "${1}" || exit; pwd)""/${2}"; }
}
arrayContains()
{
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
# Search for the dynamic shared object file.
# 1. Try $basedir
# 2. Try ${basedir}/../lib
# 3. Try /usr/lib
# 4. Try /usr/local/lib
# Return absolute path to DSO.
gs_find_so()
{
local DL=("${BASEDIR}")
# Debian packaging requires libs in /usr/lib/x86_64-linux-gnu :/
if command -v dpkg-architecture &>/dev/null; then
DL+=("/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)")
fi
DL+=("${1}/lib") # This is either GS_PREFIX/lib or BASEDIR/../lib
arrayContains "/usr/lib" "${DL[@]}" || DL+=("/usr/lib")
arrayContains "/usr/local/lib" "${DL[@]}" || DL+=("/usr/local/lib")
for dir in "${DL[@]}"; do
res=$(gs_find_so_single "${dir}" "${2}")
[[ -z "$res" ]] || { echo "$res"; return; }
done
}
gs_init()
{
GS_NETCAT_BIN="gs-netcat"
BIN="${BASEDIR}/${GS_NETCAT_BIN}"
[[ -f "${BIN}" ]] && GS_NETCAT_BIN="${BIN}"
# shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally).
GS_SFTP_BIN="${BASEDIR}/gs-sftp"
EXE=""
if [[ "$OSTYPE" == "cygwin"* ]]; then
EXE=".exe"
fi
# To find sftp-server and DSO's in PREFIX/lib
PREFIX="$GS_PREFIX"
[[ -z "$PREFIX" ]] && PREFIX="$(cd "$(dirname "${0}")/../" || exit; pwd)"
# on OSX the dl-files are called .bundle (not .dylib) but it is generally
# accepted to call them .so. OSX keep those is /System/Library/gsocket
# but automake insists on ${PREFIX}/lib
UCHROOT_BIN=$(gs_find_so "$PREFIX" "gsocket_uchroot_dso.so.0${EXE}")
[[ -z "$UCHROOT_BIN" ]] && { echo >&2 "gsocket: gsocket_uchroot_dso.so.0${EXE} not found. Try 'apt install dpkg-dev'."; exit 5; }
# shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally).
GS_SO_BIN=$(gs_find_so "$PREFIX" "gsocket_dso.so.0${EXE}")
[[ -z "$GS_SO_BIN" ]] && { echo >&2 "gsocket: gsocket_dso.so.0${EXE} not found."; exit 5; }
# shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally).
BIN_NAME="$(basename "${0}")"
command -v "${GS_NETCAT_BIN}" >/dev/null 2>&1 || { echo >&2 "${GS_NETCAT_BIN} not found. Check PATH=?"; exit 1; }
}
usage()
{
echo "
-l Server Mode.
-R Server in read-only mode.
-s <secret> Secret (e.g. password).
-k <file> Read Secret from file.
Example:
$ ${1} -s MySecret -l # Server
$ ${1} -s MySecret # Client
See 'gs-netcat -h' for more options."
}
do_getopt()
{
OPTERR=0
FL_NEED_PASSWORD=1
IS_UCHROOT=1
# Check if -s or -k is already supplied in environment and dont ask again.
[[ "$GSOCKET_ARGS" =~ ^'-s' ]] && unset FL_NEED_PASSWORD
[[ "$GSOCKET_ARGS" =~ ' -s' ]] && unset FL_NEED_PASSWORD
[[ "$GSOCKET_ARGS" =~ ^'-k' ]] && unset FL_NEED_PASSWORD
[[ "$GSOCKET_ARGS" =~ ' -k' ]] && unset FL_NEED_PASSWORD
# shellcheck disable=SC2220 # Invalid flags are not handled. Add a *) case.
while getopts ":qhURgls:k:L:" opt; do
case ${opt} in
s )
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$OPTARG" # Add to end of array
unset FL_NEED_PASSWORD
;;
k )
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-k" # Add to end of array
KFILE=$(cd "$(dirname "$OPTARG")" && pwd)/$(basename "$OPTARG")
[[ -f "${KFILE}" ]] || { echo >&2 "File not found: ${KFILE}"; exit 255; }
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="${KFILE}" # Add to end of array
# KFILE=$(eval echo "$OPTARG") # Add to end of array
# GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]=$(eval echo "$OPTARG") # Add to end of array
unset FL_NEED_PASSWORD
;;
g )
"${GS_NETCAT_BIN}" -g
exit
;;
h )
my_usage
;;
q )
IS_QUIET=1
ARGS_NEW[${#ARGS_NEW[@]}]="-q"
;;
l )
# shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally).
IS_SERVER=1
ARGS_NEW[${#ARGS_NEW[@]}]="-l" # Add to end of array
;;
R )
# shellcheck disable=SC2034 # appears unused. Verify use (or export if used externally).
IS_READONLY=1
SFTP_ARGS[${#SFTP_ARGS[@]}]="-R"
;;
U )
unset IS_UCHROOT
;;
\? )
# UNKNOWN option. Handle before '*' (e.g. -l)
ARGS_NEW[${#ARGS_NEW[@]}]="-${OPTARG}" # Add to end of array
;;
* )
# Other (known opts from opstring) w parameters (e.g. -L <file>)
ARGS_NEW[${#ARGS_NEW[@]}]="-${opt}" # Add to end of array
ARGS_NEW[${#ARGS_NEW[@]}]="${OPTARG}" # Add to end of array
;;
esac
done
# Solaris 10 problems:
# - stock sftp-server does not allow -p <whitelist> -> Acceptable risk
# - LD_PRELOAD does not seem to work. Does anyone still use solaris10?
if [[ "$OSTYPE" == "solaris2.10"* ]]; then
echo -e >&2 "\033[1;31mWARNING\033[0m: uchroot not (yet) supported on solaris 10."
unset IS_UCHROOT
fi
}
env_arg_init()
{
# Prepare existing GSOCKET_ARGS to take more arguments if there are any
[[ -n "$GSOCKET_ARGS" ]] && GSOCKET_ARGS+=" "
if [[ -n "$FL_NEED_PASSWORD" ]]; then
password=$(read_password)
# shellcheck disable=SC2034 # GSOCKET_SECRET appears unused => It's used in 'gs'
GSOCKET_SECRET="${password}"
echo "${GS_PRFX}=Secret : ${password}"
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array
GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$password" # Add to end of array
fi
# Have to output it here because gs-netcat might be started from withing
# sshfs or sftpd where stderr is no longer available to gs-netcat
[[ -n "$IS_QUIET" ]] || echo >&2 "${GS_PRFX}=Encryption : SRP-AES-256-CBC-SHA-End2End (Prime: 4096 bits)"
ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}"
}
sftp_server_start()
{
# SERVER
if [[ "$OSTYPE" == "darwin"* ]]; then
# OSX does not allow LD_PRELOAD of binaries in /usr/. Copy to tmp...
ROOTDIR=$(mktemp -d -t thc-gs-sftp)
# FIXME: temp file only cleaned on reboot. Hmm...
cp /usr/libexec/sftp-server "${ROOTDIR}/sftp-server" &>/dev/null
SFTP_SERVER_BIN="${ROOTDIR}/sftp-server"
PRELOAD="DYLD_INSERT_LIBRARIES=${UCHROOT_BIN} DYLD_FORCE_FLAT_NAMESPACE=1"
else
if [[ -n "${IS_UCHROOT}" ]]; then
ROOTDIR=$(mktemp -d -t thc-gs-sftp-XXXXXXXXXXXXXXX)
fi
SFTP_SERVER_BIN=$(find_binary "sftp-server${EXE}" "${PREFIX}/lib" /opt/csw/libexec /usr/lib /usr/local/lib /usr/libexec /usr/libexec/openssh /usr/lib/ssh /usr/sbin)
PRELOAD="LD_PRELOAD=${UCHROOT_BIN}"
fi
[[ -z "${SFTP_SERVER_BIN}" ]] && { echo >&2 "sftp-server binary not found."; exit 1; }
# SFTP_ARGS[${#SFTP_ARGS[@]}]="-l"
# SFTP_ARGS[${#SFTP_ARGS[@]}]="DEBUG3" # tail /var/log/auth.log | grep 'Refusing non-whitelisted'
# Whitelist of commands sftp-server should allow (most are not needed
# by sftp but for sshfs)
# *** WARNING ***: If you add a string here you also must make sure that
# gsocket_uchroot_dso checks the command for uchroot-escape.
SFTP_ARGS[${#SFTP_ARGS[@]}]="-p"
SFTP_ARGS[${#SFTP_ARGS[@]}]="open,opendir,mkdir,remove,rmdir,symlink,hardlink,stat,posix-rename,statvfs,setstat,fsetstat,fstat,lstat,readdir,realpath,write,read,close"
ENV_ARGS="${GSOCKET_ARGS}${GSNC_ENV_ARGS[*]}"
if [[ -n "${IS_UCHROOT}" ]]; then
[[ -z "${ROOTDIR}" ]] && { failed "(mktemp)"; }
uchroot_check
# Try to delete temporary directory. OSX still has sftp-server bin in there and must be deleted
rmdir "${ROOTDIR}" &>/dev/null
else
echo -e >&2 "\033[1;31mWARNING\033[0m: uchroot disabled. Allowing access to *ALL* files on this host."
unset PRELOAD
fi
GSOCKET_NO_GREETINGS="1" GSOCKET_ARGS="${ENV_ARGS}" exec "${GS_NETCAT_BIN}" "${ARGS_NEW[@]}" -e "${PRELOAD} ${SFTP_SERVER_BIN} ${SFTP_ARGS[*]} 2>/dev/null"
}
+135
View File
@@ -0,0 +1,135 @@
#! /usr/bin/env bash
# Try to use the gs-netcat that's in the same directory as this executable.
BASEDIR="$(cd "$(dirname "${0}")" || exit; pwd)"
# shellcheck disable=SC1090 # Can't follow non-constant source. Use a directive to specify location.
# shellcheck disable=SC1091 # Not following: /etc/gsocket.conf was not specified as input (see shellcheck -x)
source "${BASEDIR}/gs_funcs" 2>/dev/null || source "${BASEDIR}/../share/gsocket/gs_funcs" 2>/dev/null || { { source /etc/gsocket.conf 2>/dev/null || source "${BASEDIR}/../etc/gsocket.conf" 2>/dev/null || { echo >&2 "gsocket: gsocket.conf not found."; exit 3; } } && { source "${GS_PREFIX}/share/gsocket/gs_funcs" 2>/dev/null; } } || { echo >&2 "gsocket: gs_funcs not found"; exit 3; }
my_usage()
{
echo "${BIN_NAME} [-k file] [-s password] <programm> <parameters>
-s <secret> Secret (e.g. password).
-k <file> Read Secret from file.
-p <ports> Range of listening ports to redirect [default=all]
-T Use TOR.
Example:
$ ${BIN_NAME} -s MySecret /usr/bin/sshd -d # Server
$ ${BIN_NAME} -s MySecret ssh root@gsocket # Client
See 'gs-netcat -h' for more options."
exit "$1"
}
my_getopt()
{
OPTERR=0
# shellcheck disable=SC2034 # FL_NEED_PASSWORD appears unused. => used i env_arg_init
FL_NEED_PASSWORD=1
# Check if -s or -k is already supplied in environment and dont ask again.
[[ "$GSOCKET_ARGS" =~ ^'-s' ]] && unset FL_NEED_PASSWORD
[[ "$GSOCKET_ARGS" =~ ' -s' ]] && unset FL_NEED_PASSWORD
[[ "$GSOCKET_ARGS" =~ ^'-k' ]] && unset FL_NEED_PASSWORD
[[ "$GSOCKET_ARGS" =~ ' -k' ]] && unset FL_NEED_PASSWORD
# shellcheck disable=SC2220 # Invalid flags are not handled. Add a *) case.
while getopts ":qhgTp:s:k:L:" opt; do
case ${opt} in
s )
# GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-s" # Add to end of array
# GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="$OPTARG" # Add to end of array
GSOCKET_SECRET="$OPTARG"
unset FL_NEED_PASSWORD
;;
k )
# GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="-k" # Add to end of array
KFILE=$(cd "$(dirname "$OPTARG")" && pwd)/$(basename "$OPTARG")
[[ -f "${KFILE}" ]] || { echo >&2 "File not found: ${KFILE}"; exit 255; }
GSOCKET_SECRET=$(<"${KFILE}")
# GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]="${KFILE}" # Add to end of array
# KFILE=$(eval echo "$OPTARG") # Add to end of array
# GSNC_ENV_ARGS[${#GSNC_ENV_ARGS[@]}]=$(eval echo "$OPTARG") # Add to end of array
unset FL_NEED_PASSWORD
;;
g )
"${GS_NETCAT_BIN}" -g
exit
;;
h )
my_usage 0
;;
p )
GS_HIJACK_PORTS="${OPTARG}"
;;
T )
[[ -z "${GSOCKET_SOCKS_IP}" ]] && GSOCKET_SOCKS_IP="127.0.0.1"
;;
q )
# shellcheck disable=SC2034 # IS_QUIET appears unused. => Used in env_arg_init
IS_QUIET=1
ARGS_NEW[${#ARGS_NEW[@]}]="-q"
;;
\? )
# UNKNOWN option. Handle before '*' (e.g. -l)
ARGS_NEW[${#ARGS_NEW[@]}]="-${OPTARG}" # Add to end of array
;;
* )
# Other (known opts from opstring) w parameters (e.g. -L <file>)
ARGS_NEW[${#ARGS_NEW[@]}]="-${opt}" # Add to end of array
ARGS_NEW[${#ARGS_NEW[@]}]="${OPTARG}" # Add to end of array
;;
esac
done
[[ -n "${GSOCKET_SECRET}" ]] && unset FL_NEED_PASSWORD
}
# default values
GS_HIJACK_PORTS="1-65535"
# shellcheck disable=SC2034 # GS_RFX appears unused. => Used in gs_funcs
GS_PRFX="gsocket: "
gs_init
my_getopt "$@"
shift $((OPTIND -1))
[[ ${#@} -le 0 ]] && { echo >&2 "ERROR: No program specified"; my_usage 255; }
command -v "$1" >/dev/null 2>&1 || { echo >&2 "gsocket: command not found: ${1}"; exit 1; }
if [[ "$OSTYPE" == "darwin"* ]]; then
# OSX does not allow LD_PRELOAD of binaries in /usr/. Copy to tmp...
ROOTDIR=$(mktemp -d -t thc-gsXXXXXX)
PROGBIN_FULLPATH=$(which "$1")
[[ -z "$PROGBIN_FULLPATH" ]] && { echo >&2 "gsocket: command not found: ${1}"; exit 1; }
# FIXME: temp file is only cleaned on reboot. Hmm...
cp "${PROGBIN_FULLPATH}" "${ROOTDIR}/" &>/dev/null
PROGBIN_NAME="$(basename "${1}")" # programm binary
PROGBIN="${ROOTDIR}/${PROGBIN_NAME}"
# System Integrity Protection makes dyld ignore
# DYLD_INSERT_LIBRARIES.
# There are two ways how MacOS determines if a binary is SIP protected:
# 1. The location of the binary (ls -alO /usr/bin/ssh)
# 2. If the binary contains 'entitlements' (regardless of its location on the fs).
# A hack around this is to remove the signature completed (which will also disable
# any entitlements).
IS_REMOVE_SIGN=1
command -v csrutil >/dev/null && [[ ! "$(csrutil status)" =~ enabled ]] && { unset IS_REMOVE_SIGN; }
[[ -n $IS_REMOVE_SIGN ]] && command -v codesign >/dev/null && [[ -n "$(codesign -d --entitlements - "${PROGBIN}" 2>/dev/null)" ]] && {
codesign --remove-signature "${PROGBIN}";
}
else
ROOTDIR=""
PROGBIN="${1}"
fi
env_arg_init
shift 1
if [[ "$OSTYPE" == "darwin"* ]]; then
GS_NETCAT_BIN=${GS_NETCAT_BIN} GS_HIJACK_PORTS="${GS_HIJACK_PORTS}" GSOCKET_SOCKS_IP="${GSOCKET_SOCKS_IP}" GSOCKET_ARGS="${ENV_ARGS} ${ARGS_NEW[*]}" GSOCKET_SECRET="${GSOCKET_SECRET}" DYLD_INSERT_LIBRARIES=${GS_SO_BIN} DYLD_FORCE_FLAT_NAMESPACE=1 exec "${PROGBIN}" "$@"
else
GS_NETCAT_BIN=${GS_NETCAT_BIN} GS_HIJACK_PORTS="${GS_HIJACK_PORTS}" GSOCKET_SOCKS_IP="${GSOCKET_SOCKS_IP}" GSOCKET_ARGS="${ENV_ARGS} ${ARGS_NEW[*]}" GSOCKET_SECRET="${GSOCKET_SECRET}" LD_PRELOAD=${GS_SO_BIN} exec "${PROGBIN}" "$@"
fi
Binary file not shown.
Binary file not shown.