OPSEC / Anonymity How to put a password on GRand Unified Bootloader (Rough)

0xOmar

New member
Joined
Apr 7, 2022
Messages
20
Hellcoins
♆770
Without a password for the bootloader, any user can enter the kernel editing mode and make their own settings in the bootloader, in order to exclude the possibility of changing the bootloader configuration outside the booted system, we need to put our own password on it.
Of course, this will hardly save you from online attacks on the machine, but from third-party physical ill-wishers, it will completely do, (although the axis on the flash drive will come to the rescue here too)

So, when we talk about grub password protection, the main things we need to know:

Firstly , there are 2 types of users: normal user and superuser (root)
  • Superuser - create bootloader entries.
  • Normal user - use bootloader entries.
Secondly, these are the types of passwords:
  • normal password - which is stored in plaintext in the configuration file.
  • Encrypted password - stored encrypted using the PBKDF2 caching algorithm.
Let's look at the structure of the entries that define users and superusers, you can define them in the files:
00_header and 40_custom inside the /etc/grub.d/

directory For now, we are considering clear passwords in plain text. The user is always defined with the password
keyword , followed by the username, then the password: The user can be promoted to superuser, for this we specify: This makes the user privileged and has the right to edit records. Open the file 00_header , go down to the very bottom, define the file segment " cat <<EOF EOF

password user1 gfhjkm1



set superusers="user1"



and make changes:

QUOTE:
cat <<EOF
set superusers="user1"
password user1 passwd_1
EOF

And to complete everything, after specifying all the parameters, we need to update the grub.cfg file for this we enter:

$ sudo grub-mkconfig -o /boot/grub/grub.cfg

============================

Of course, it is not safe to store passwords in files in clear text, for this you can use encryption, the grub-mkpasswd-pbkdf2 utility is responsible for this, in the terminal we enter:

QUOTE:
$ grub-mkpasswd-pbkdf2
Введите пароль : Повторно введите пароль
: Хэш PBKDF2 вашего пароля
: grub.pbkdf2.sha512.10000.AEBDB73556619C1667319465D2E3E1899AB7
B6F6FDEFF1D00D4701CC84CAA934AFDBBEA47E1EC31AAECA0D9E159C2B
077B8B30D7A41D366FA952CB102D976563.373C1E4EFDBE1AD3641BA08
B0CBC377D8D5BE2451CBE3C9D2450C6BBB321F58789B8441849D4034BA
D86BD0C92C7D695C01D3FA8DF35CADC42D64962C30530C1

Then in the configuration file 00_header we specify everything the same, only add the hashing algorithm _pbkdf2 to the password through the underscore :

QUOTE:
cat <<EOF
set superusers="user1"
password_pbkdf2 user1 grub.pbkdf2.sha512.10000.AEBDB73556619C1667319465D2E3E1899AB7
B6F6FDEFF1D00D4701CC84CAA934AFDBBEA47E1EC31AAECA0D9E159C2B
077B8B30D7A41D366FA952CB102D976563.373C1E4EFDBE1AD3641BA08
B0CBC377D8D5BE2451CBE3C9D2450C6BBB321F58789B8441849D4034BA
D86BD0C92C7D695C01D3FA8DF35CADC42D64962C30530C1

EOF

And also after specifying all the parameters, we need to update the grub.cfg file:

$ sudo grub-mkconfig -o /boot/grub/grub.cfg

================================= =============== I

’ll superficially tell you about the 40_custom file, since I don’t see the point in editing it at home (unless there are 10 other people using the machine besides you) The 40_custom
file is located in / etc/grub.d/ file, unlike 00_header this file allows us to fix the entries and the number of these entries and clearly control which user is responsible for what:

QUOTE:
set superusers="user1"
password user1 passwd_1
password user2 passswd_2
menuentry 'ОS_#1'{
...
}
menuentry 'ОS_#2' --users user2{
...
}

Here, user1 can upload and edit any entry, all users have the right to upload OS_#1 and only user2 has the right to upload OS_#2
In this example, users with an open password are shown, but as in the case of 00_header , you can write encrypted PBKDF2 passwords.
It can also be written directly in grub.cfg , but in order not to clutter it up, it simply contains the path to 40_custom in its original form.


This is just one of the ways to password protect the bootloader, you can get by with "less bloodshed" and make all changes only in the grub.cfg file itself.
You can also go the other way and create a passwd file and write it to grub.cfg , there are many solutions and they are as multifaceted as Linux itself.
 
Top