Hack Like a Pro: Linux Basics for the Aspiring Hacker, Part 21 (GRUB Bootloader) « Null Byte :: WonderHowTo

Welcome back, my aspiring hackers!Many of you have installedKali Linuxas a virtual machine (VM) using VMware or VirtualBox, while others have installed Kali (orBackTrack) in adual-boot system. The drawback to installing these hacking systems as a VM is that it then requires anexternal wireless adapter(your wireless adapter is piped through the VM as a wired device, eth0), but it makes for a great place to test your hacks while honing your skills.Using Kali in a dual-boot system doesn't require another wireless adapter and enables you to use the full resources of your physical system without having to go through a hypervisor. In this way, when you need your Windows, you boot into Windows, and when you need Kali, you boot into Kali.The BootloaderTo be able to run a dual-boot system, you must have a bootloader, and therein lies the issue. The bootloader enables us to choose which operating system we want to boot into. To be comfortable with this arrangement, we need to understand a bit about this thing called a bootloader.Historically,Linuxhas used two bootloaders, LILO and GRUB. You may find LILO on some older, legacy systems, but it has largely been replaced by GRUB. GRUB has two versions, the original GRUB and now the new improved GRUB2! Our Kali system comes with GRUB2 by default, so I will focus my attention on this newer version here.To help you better understand how GRUB works and to help you configure and troubleshoot GRUB, I dedicate these next two Linux tutorials, so stay tuned for Part 22 in myLinux Basicsseries.A Little Background on GRUBGRUB is an acronym for GRand Unified Bootloader. It largely replaces the legacy bootloader found on many older Linux version, LILO. GRUB works by intercepting control of the boot process when the BIOS transfers control to the Master Boot Record (MBR) in the first sector of the primary hard drive. Rather than the MBR then finding the first active partition, GRUB replaces the MBR with its own code that controls which partition is booted.Step 1: Exploring GRUBLet's take a look at GRUB2 as it is installed on Kali. GRUB2, unlike the original GRUB, has all its files installed into three main locations. These are:/boot/grub/grub.cfg- this is the main configuration file (replaces menu.lst)/etc/grub.d- this directory contains the scripts that build the grub.cfg/etc/default/grub- this file contains the GRUB menu settingsNow, let's begin by navigating and looking inside the GRUB directory.kali > cd /boot/grubkali >ls -lAs you can see, there are many files in this directory, but the one we want to focus on here is thegrub.cfg. This is the configuration file in the new GRUB2 that comes with Kali. It replaces the oldmenu.lstthat you will find on the original GRUB. Let's open it with themorecommand and examine it.Grub.cfgis basically a script for running and configuring GRUB2. It is generated by the scripts in/etc/grub.dand you generally should NOT try editing it directly (note the warning on the second line of the file).Step 2: The /Etc/grub.d DirectoryNext, let's look at the/etc/grub.ddirectory.kali > cd /etc/grub.dkali > ls -lAs you can see in the screenshot above, this directory has a number of scripts that are run to create thegrub.cfg file. Let's look at the key entries here.00_header- this script loads the settings from /etc/default/grub05_debian_theme- this script defines the colors, background, etc.10_linux- this script loads the menu entries20_memtest86- this script loads the memory tester30_os-prober- this script scans the hard drives for other operating systems40_custom- this is a template for manually adding other menu entriesStep 3: Exploring /Etc/Default/GrubNow, let's go to the/etc/defaultdirectory and look to see what is in this directory.kali > cd /etc/defaultkali > ls -lThis directory contains many files and scripts that configure various daemons or services in Linux. The only one we are interested here is thegrubfile that I highlighted in the screenshot above. Let's open that file with the more command.kali > more /etc/default/grubWhen we do so, we will see the following output.This file contains many of the customization parameters for GRUB such as the TIMEOUT and other parameters. If you change anything it this file, you must run "update-grub" for those changes to take effect as it then makes changes to thegrub.cfgfile.Step 4: How GRUB2 WorksBefore we go any further, I want to take a moment to detail how GRUB2 works. It's quite different than the original GRUB and you need to understand this before you attempt any edits or changes to GRUB2.The differences in configuring GRUB and GRUB2.Image viajErikoThe/etc/default/grubfile contains customization parameters.The/etc/grub.d/directory contains scripts for the GRUB menu information and the scripts to boot the various operating systems. When theupdate-grubcommand is run, it reads the contents of the grub file and thegrub.dscripts and creates the grub.cfg file.To change thegrub.cfgfile, you need to edit the grub file or the scripts undergrub.d.Stay Tuned for More on GRUB...In my next tutorial in myLinux Basicsseries, I will show how to edit your GRUB bootloader, so keep coming back, my aspiring hackers!Want to start making money as a white hat hacker?Jump-start your hacking career with our2020 Premium Ethical Hacking Certification Training Bundlefrom the newNull Byte Shopand get over 60 hours of training from cybersecurity professionals.Buy Now (90% off) >Other worthwhile deals to check out:97% off The Ultimate 2021 White Hat Hacker Certification Bundle99% off The 2021 All-in-One Data Scientist Mega Bundle98% off The 2021 Premium Learn To Code Certification Bundle62% off MindMaster Mind Mapping Software: Perpetual LicenseRelatedNews:How to Study for the White Hat Hacker Associate Certification (CWA)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 11 (Apache Web Servers)How To:The Essential Skills to Becoming a Master HackerHack Like a Pro:Linux Basics for the Aspiring Hacker, Part 6 (Networking Basics)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 1 (Getting Started)How To:The Hardware Hacker's Introduction to Microcontrollers, Part One: Anatomy of an ArduinoHow To:Install GRUB 2 and apply themes on Ubuntu LinuxHow to Hack Like a Pro:Getting Started with MetasploitHack Like a Pro:Linux Basics for the Aspiring Hacker, Part 25 (Inetd, the Super Daemon)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 12 (Loadable Kernel Modules)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 13 (Mounting Drives & Devices)How To:Linux Basics for the Aspiring Hacker: Using Start-Up ScriptsHack Like a Pro:Linux Basics for the Aspiring Hacker, Part 2 (Creating Directories & Files)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 9 (Managing Environmental Variables)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 5 (Installing New Software)Mac for Hackers:How to Install Kali Linux as a Virtual MachineSecure Your Computer, Part 2:Password-Protect the GRUB Bootloader on Dual-Booted PCsHow To:Give Your GRand Unified Bootloader a Custom ThemeGoodnight Byte:HackThisSite Walkthrough, Part 6 - Legal Hacker TrainingNews:Cannot find windows loader after Linux install?Community Byte:HackThisSite Walkthrough, Part 6 - Legal Hacker TrainingHow To:Change Grub Boot Loader BackgroundGoodnight Byte:HackThisSite Walkthrough, Part 8 - Legal Hacker TrainingCommunity Byte:HackThisSite Walkthrough, Part 1 - Legal Hacker TrainingHack Like a Pro:Hacking Samba on Ubuntu and Installing the MeterpreterCommunity Byte:HackThisSite Walkthrough, Part 2 - Legal Hacker TrainingGoodnight Byte:HackThisSite Walkthrough, Part 10 - Legal Hacker TrainingGoodnight Byte:HackThisSite Walkthrough, Part 9 - Legal Hacker TrainingNews:Let Me Introduce MyselfGoodnight Byte:HackThisSite Walkthrough, Part 4 - Legal Hacker TrainingHow To:How Hackers Take Your Encrypted Passwords & Crack Them