Shell Study

$ pushd $openssh_source_dir > /dev/null
命令 说明
command > file 将输出重定向到 file。
command < file 将输入重定向到 file。
command >> file 将输出以追加的方式重定向到 file。
n > file 将文件描述符为 n 的文件重定向到 file。
n >> file 将文件描述符为 n 的文件以追加的方式重定向到 file。
n >& m 将输出文件 m 和 n 合并。
n <& m 将输入文件 m 和 n 合并。
<< tag 将开始标记 tag 和结束标记 tag 之间的内容作为输入。

> /dev/null 如果希望执行某个命令,但又不希望在屏幕上显示输出结果,那么可以将输出重定向到 /dev/null, /dev/null 是一个特殊的文件,写入到它的内容都会被丢弃;如果尝试从该文件读取内容,那么什么也读不到。但是 /dev/null 文件非常有用,将命令的输出重定向到它,会起到”禁止输出”的效果。

如果希望屏蔽 stdoutstderr,可以这样写:

$ command > /dev/null 2>&1

pushd = PUSH Directory:

kali@kali:~$ pushd ~/test
~/test ~
kali@kali:~/test$ pushd ~/Documents/
~/Documents ~/test ~
kali@kali:~/Documents$ pushd
~/test ~/Documents ~
kali@kali:~/test$ pushd
~/Documents ~/test ~
kali@kali:~/Documents$ pushd
~/test ~/Documents ~
kali@kali:~/test$ pushd
~/Documents ~/test ~
kali@kali:~/Documents$ pushd
~/test ~/Documents ~
kali@kali:~/test$ pushd
~/Documents ~/test ~
kali@kali:~/Documents$ popd
~/test ~
kali@kali:~/test$ popd
~
kali@kali:~$ pushd
bash: pushd: no other directory
kali@kali:~$ popd
bash: popd: directory stack empty
kali@kali:~$
patch -p1 < ../$your_patch

https://www.runoob.com/linux/linux-comm-patch.html

Linux patch命令用于修补文件。

patch指令让用户利用设置修补文件的方式,修改,更新原始文件。倘若一次仅修改一个文件,可直接在指令列中下达指令依序执行。如果配合修补文件的方式则能一次修补大批文件,这也是Linux系统核心的升级方法之一。

[-p <剥离层级>] 设置欲剥离几层路径名称。

pushd $openssh_source_dir > /dev/null  # 进入到目录 $openssh_source_dir 
patch -p1 < ../$mitm_patch # 用 $mitm_patch 给 $openssh_source_dir 打补丁

Linux 里判断是否存在用户 ssh-mitm 如果跟了 --force 则删除用户:

# Check if the ssh-mitm user exists.
id ssh-mitm > /dev/null 2> /dev/null
if [[ $? == 0 ]]; then

# The user exists. If this script was run with the "--force" argument,
# then we will delete the user.
if [[ $1 == '--force' ]]; then
userdel -f -r ssh-mitm 2> /dev/null

# There could be saved sessions from an old version of SSH MITM that
# we shouldn't destroy automatically.
else
echo "It appears that the ssh-mitm user already exists. Make backups of any saved sessions in /home/ssh-mitm/, then re-run this script with the \"--force\" argument (this will cause the user account to be deleted and re-created)."
exit -1
fi
fi

下载 OpenSSH 并验证是否正品:

# Downloads OpenSSH and verifies its sources.
function get_openssh {
local openssh_sig='openssh-7.5p1.tar.gz.asc'
local release_key_fingerprint_expected='59C2 118E D206 D927 E667 EBE3 D3E5 F56B 6D92 0D30'
local openssh_checksum_expected='9846e3c5fab9f0547400b4d2c017992f914222b3fd1f8eee6c7dc6bc5e59f9f0'

echo -e "\nGetting OpenSSH release key...\n"
wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/RELEASE_KEY.asc

echo -e "\nGetting OpenSSH sources...\n"
wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/$openssh_sources

echo -e "\nGetting OpenSSH signature...\n"
wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/$openssh_sig

echo -e "\nImporting OpenSSH release key...\n"
gpg --import RELEASE_KEY.asc

local release_key_fingerprint_actual=`gpg --fingerprint 6D920D30`
if [[ $release_key_fingerprint_actual != *"$release_key_fingerprint_expected"* ]]; then
echo -e "\nError: OpenSSH release key fingerprint does not match expected value!\n\tExpected: $release_key_fingerprint_expected\n\tActual: $release_key_fingerprint_actual\n\nTerminating."
exit -1
fi
echo -e "\n\nOpenSSH release key matches expected value.\n"

local gpg_verify=`gpg --verify $openssh_sig $openssh_sources 2>&1`
if [[ $gpg_verify != *"Good signature from \"Damien Miller <djm@mindrot.org>\""* ]]; then
echo -e "\n\nError: OpenSSH signature invalid!\n$gpg_verify\n\nTerminating."
rm -f $openssh_sources
exit -1
fi

# Check GPG's return value. 0 denotes a valid signature, and 1 is returned
# on invalid signatures.
if [[ $? != 0 ]]; then
echo -e "\n\nError: OpenSSH signature invalid! Verification returned code: $?\n\nTerminating."
rm -f $openssh_sources
exit -1
fi

echo -e "Signature on OpenSSH sources verified.\n"

local openssh_checksum_actual=`sha256sum $openssh_sources`
if [[ $openssh_checksum_actual != "$openssh_checksum_expected"* ]]; then
echo -e "Error: OpenSSH checksum is invalid! Terminating."
exit -1
fi

return 1
}
0%