shell脚本 + patchelf方便切换libc

更便捷切换libc

目前自己的切换libc的方法是用patchelf --set-interpreter换ld文件 + LD_PRELOAD换libc
并且我的libc都在/glibc/目录下

于是感觉有点麻烦,遂写了个shell脚本,主要是省略了路径上的困难
思路就是case语句判断是哪个版本的,然后判断是32还是64位的,还要加上一个—help
思路有点死板,路径啥的被我写死了(x

目前没发现啥问题

脚本

#!/bin/zsh

if [[ $1 = "--help" ]] || [[ $1 = "-h" ]] || [[ $1 = "" ]]
then
echo "--------------------"
echo "arg1: libc版本"
echo "arg2: 32 or 64"
echo "arg3: binary path"
echo "such as: sl 2.23 64 ./pwn"
echo "--------------------"
exit 0
fi

message="请查看帮助 -h (--help)"

case $1 in
"2.23")
if [ $2="64" ]
then
ld="/glibc/2.23-0ubuntu11.3_amd64/ld-2.23.so"
libc="/glibc/2.23-0ubuntu11.3_amd64/libc-2.23.so"
elif [ $2="32" ]
then
ld="/glibc/2.23-0ubuntu11.3_i386/ld-2.23.so"
libc="/glibc/2.23-0ubuntu11.3_i386/libc-2.23.so"
else
echo $message
fi
;;
"2.27")
if [ $2="64" ]
then
ld="/glibc/2.27-3ubuntu1_amd64/ld-2.27.so"
libc="/glibc/2.27-3ubuntu1_amd64/libc-2.27.so"
elif [ $2="32" ]
then
ld="/glibc/2.27-3ubuntu1.2_i386/ld-2.27.so"
libc="/glibc/2.27-3ubuntu1.2_i386/libc-2.27.so"
else
echo $message
fi
;;
"2.29")
if [ $2="64" ]
then
ld="/glibc/2.29/64/lib/ld-2.29.so"
libc="/glibc/2.29/64/lib/libc-2.29.so"
elif [ $2="32" ]
then
ld="/glibc/2.29/32/lib/ld-2.29.so"
libc="/glibc/2.29/32/lib/libc-2.29.so"
else
echo $message
fi
;;
"2.31")
if [ $2="64" ]
then
ld="/glibc/2.31/64/lib/ld-2.31.so"
libc="/glibc/2.31/64/lib/libc-2.31.so"
elif [ $2="32" ]
then
ld="/glibc/2.31/32/lib/ld-2.31.so"
libc="/glibc/2.31/32/lib/libc-2.31.so"
else
echo $message
fi
;;
*)
echo $message
;;
esac

figlet -f small "Switch the libc"
echo -e "\033[1;32mld-path:$ld\033[0m"
echo -e "\033[1;32mlibc-path:$libc\033[0m"
figlet -f small "Switch the libc"

patchelf --set-interpreter $ld $3
LD_PRELOAD=$libc $3
exit 0
文章作者: Alex
文章链接: http://example.com/2021/07/23/switch-libc/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Alex's blog~