CentOS 7 root 密碼破解 及 grub 加密

CentOS 7 root 密碼破解 及 grub 加密

一、root 密碼破解

1、開機按光標上下鍵停止啓動,在菜單處按<e>進入編輯模式

blob.png

2、在 linux16 行,按<End>鍵定位到這行末尾,添加 rd.break console=tty0

blob.png

3、按<Ctrl-x>繼續啓動,然後輸入下面命令行

# mount -o remount,rw /sysroot
# chroot /sysroot/
# passwd root # 或者  echo redhat123 | passwd --stdin root
# touch /.autorelabel
# sync
# exit  #  兩次 或者  ctrl + d

blob.png

注:passwd 這行小方塊是中文編碼問題,不用管它。

4、重新啓動後,使用指定的密碼登錄系統,從而驗證密碼是否正確。

二、grub 加密

幾乎能接觸到物理機的人都能用上面的方法去修改 root 密碼,安全性還是有點問題,我們可以通過 grub 菜單加密,進入 grub 時必須輸入密碼,這樣就能避免上述情況發生。

1、 7.0 和 7.1方法如下

1)、執行生成加密密碼的命令"grub2-mkpasswd-pbkdf2",兩次輸入相同密碼,PBKDF2 hash of your password is 之後的部分就是加密後的密碼

[root@CentOS-04 ~]# grub2-mkpasswd-pbkdf2
輸入口令:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.497F246861691979B9B7A6E3758A865929ED27D121E913DB7CE825BA8051A6F12C8AFA6A1A497BA87AC2AEEF2FDDC293523114CAC53603B78B6BD790EEE802A7.3E1A2876C499CD9F12A8A634C7D4A18B84F8F0AF69BDB4D9C1E859A1861BB01EA5E34BBF65388CED8F4435C50051C61FBB460E489F1D1E4DA41A5B5984E43F1C

2)、編輯 /etc/grub.d/40_custom 文件,添加內容如下,密碼爲上面加密之後的密碼

set superusers = "root"
password_pbkdf2 root grub.pbkdf2.sha512.10000.497F246861691979B9B7A6E3758A865929ED27D121E913DB7CE825BA8051A6F12C8AFA6A1A497BA87AC2AEEF2FDDC293523114CAC53603B78B6BD790EEE802A7.3E1A2876C499CD9F12A8A634C7D4A18B84F8F0AF69BDB4D9C1E859A1861BB01EA5E34BBF65388CED8F4435C50051C61FBB460E489F1D1E4DA41A5B5984E43F1C

文件內容如下

# cat /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
set superusers = "root"
password_pbkdf2 root  grub.pbkdf2.sha512.10000.497F246861691979B9B7A6E3758A865929ED27D121E913DB7CE825BA8051A6F12C8AFA6A1A497BA87AC2AEEF2FDDC293523114CAC53603B78B6BD790EEE802A7.3E1A2876C499CD9F12A8A634C7D4A18B84F8F0AF69BDB4D9C1E859A1861BB01EA5E34BBF65388CED8F4435C50051C61FBB460E489F1D1E4DA41A5B5984E43F1C

3)、然後執行命令"grub2-mkconfig -o /boot/grub2/grub.cfg"重新生成配置文件。

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-5cd1608ab306482b8813c487489ccd84
Found initrd image: /boot/initramfs-0-rescue-5cd1608ab306482b8813c487489ccd84.img
done

4)、reboot 重啓,進行驗證

2、7.2 + 方法如下

從7.2開始,上述用於保護Grub的方法不起作用。在7.2中引入了新的實用程序“ grub2-setpassword ”

1) 執行 grub2-setpassword 命令

# grub2-setpassword
Enter password:
Confirm password:

2)如果現在重新啓動系統並嘗試修改引導條目,系統將要求提供憑據,但是可以在沒有憑據的情況下修改引導條目。爲了阻止未經授權的修改和未經授權的啓動,我們需要對 /boot/grub2/grub.cfg 文件進行更改

打開文件並使用密碼搜索需要保護的啓動條目,它以menuentry開頭。找到條目後,從中刪除 --unrestricted 參數

blob.png

3) reboot 重啓驗證,只有當輸入正確的用戶名和密碼時,才能進入 grub 菜單或者修改引導條目。

blob.png

注:輸入密碼時無回顯,Linux 特徵

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章