This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:nbrimme1:portfolio:break-into-linux [2018/09/28 22:00] – [Method 1:] nbrimme1 | user:nbrimme1:portfolio:break-into-linux [2019/02/22 00:44] (current) – [Method 2: boot to single-user mode] nbrimme1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
=====Objectives===== | =====Objectives===== | ||
- | To explore the various methods of breaking into any Linux system | + | * To explore the various methods of breaking into any Linux system |
+ | * To examine the procedure of setting up FDE and other remediations to prevent this. | ||
=====Prerequisites===== | =====Prerequisites===== | ||
Line 9: | Line 10: | ||
=====Procedure===== | =====Procedure===== | ||
- | ====Method 1:==== | + | ====Method 1: Using /sbin/init to execute a shell==== |
+ | [[https:// | ||
- Power on/reboot the target machine | - Power on/reboot the target machine | ||
- Through a graphical login screen: for a clean reboot just use the shutdown/ | - Through a graphical login screen: for a clean reboot just use the shutdown/ | ||
Line 19: | Line 21: | ||
- Continue booting. | - Continue booting. | ||
- | DONE! THAT'S ALL FOLKS! | + | DONE! THAT'S ALL FOLKS!\\ |
After the target machine finishes booting, the kernel will detect the hardware and immediately drop you into a root shell. Since the system initialization script '/ | After the target machine finishes booting, the kernel will detect the hardware and immediately drop you into a root shell. Since the system initialization script '/ | ||
- | we need to remount the root file system | + | you need to remount the root file system to make the system more usable: |
- | - Mount the /proc file system: < | + | - Mount the /proc file system: < |
- Remount the root file system in read-write mode: < | - Remount the root file system in read-write mode: < | ||
- | - Depending on how the target' | + | - Depending on how the target' |
- Do whatever nefarious things you want: | - Do whatever nefarious things you want: | ||
- **Change the root account password:** < | - **Change the root account password:** < | ||
- | - **PROTIP:** I don't recommend doing this as the next time the real user logs into the system they will notice that their root password has been changed. We need to be super sneaky, secretive, and surreptitious so here's something a little less noticeable: | + | - **PROTIP:** I don't recommend doing this. The next time the real user logs into the system they will notice that the root password has been changed |
- Simply add another user without modifying the original root password: < | - Simply add another user without modifying the original root password: < | ||
passwd bad-user</ | passwd bad-user</ | ||
- | - Also add the newly created user to the sudoers file. This is also not as noticable as changing the actual root password: < | + | - Now add the newly created user to the sudoers file. This is also not as noticable as changing the actual root password: < |
bad-user ALL=(ALL) ALL</ | bad-user ALL=(ALL) ALL</ | ||
- | - Reboot the target machine to make the changes | + | - Reboot the target machine to make any changes to the file system persistent. |
- | - Once the file systems are all unmounted, you can reboot with either | + | - Flush any disk I/O to the hardware: < |
+ | - Unmount any mounted file systems in reverse order: < | ||
+ | - Reboot with either < | ||
+ | ====Method 2: boot to single-user mode==== | ||
+ | [[https:// | ||
+ | - Power on/ | ||
+ | - Through a graphical login screen: for a clean reboot just use the shutdown/ | ||
+ | - Through a Textual User Interface: switch to a text console with < | ||
+ | - If all else fails, press the Reset button or power cycle the target machine. | ||
+ | - Press/hold the < | ||
+ | - At the grub prompt, press ' | ||
+ | - Add a space and the letter ' | ||
+ | - Sometimes there may still be some mysterious failures in single-user mode, because of **Security-Enhanced Linux policy enforcement**. In that case, add another boot parameter before the ' | ||
+ | - Now press < | ||
+ | ====Method 3: Boot a LiveCD/USB Key/ | ||
+ | ===LiveCD=== | ||
+ | - Power off the target machine | ||
+ | - Through a graphical login screen: for a clean reboot | ||
+ | - Through a Textual User Interface: switch to a text console | ||
+ | - If all else fails, press the Reset button or power cycle the target machine. | ||
+ | - Press/hold the < | ||
+ | - Insert any live CD and boot the system. | ||
+ | - Once it boots, login to the LiveCD OS and get a terminal. Become root with < | ||
=====Remediation Methods===== | =====Remediation Methods===== | ||
- | ====Method 1==== | + | ====Method 1: BIOS Password==== |
+ | - Reboot the system and go into the BIOS. Disable booting from anything other than the main disk. | ||
+ | - Set a BIOS password. This prevents unauthorized changes to the BIOS settings without a password. | ||
+ | - Set a BIOS Power On password. Now the machine will require a password before powering on. | ||
+ | ====Method 2: GRUB Password==== | ||
+ | - In one terminal, run:< | ||
+ | - In another terminal, edit the GRUB configuration file inside the '/ | ||
+ | - Add a new line directly below the ' | ||
+ | # ... comments above ... | ||
+ | default=0 | ||
+ | timeout=5 | ||
+ | password --md5 5f3782baec534bae412c27fc0850fc6d | ||
+ | spashimage=(hd0, | ||
+ | hiddenmenu | ||
+ | ......</ | ||
+ | - Now Change the file permissions to prevent viewing and recovery of the GRUB password: | ||
+ | - Now if you needed to legitimately break into your own machine, you need to press P while inside GRUB to enter the password to edit the boot parameters. | ||
+ | ====Method 3: single-user mode sulogin==== | ||
+ | - Find where your system has its program sulogin with this command: | ||
+ | < | ||
+ | - This will force users to enter the root password to get a shell when booting into single-user mode. This is done by requiring sulogin to get into single-user mode. | ||
+ | - To have the system boot up to its default run state (with the login prompt) type < | ||
+ | - This remedy depends on what is running; traditional init, Upstart or systemd | ||
+ | - Look at your file a/ | ||
+ | - If that file contains a line similar to: < | ||
+ | - In this case, leave that line alone and add a new line:< | ||
+ | si:: | ||
+ | ss: | ||
+ | - If that file is mostly comments with just one line specifying initdefault or even missing, and you have a directory /etc/init, then you have Upstart for init. In this case: | ||
+ | - If / | ||
+ | - If there is no '/ | ||
+ | stop on runlevel [!S] | ||
+ | |||
+ | console owner | ||
+ | script | ||
+ | if [ -x / | ||
+ | exec / | ||
+ | else | ||
+ | exec / | ||
+ | fi | ||
+ | end script | ||
+ | |||
+ | [...]</ | ||
+ | =====Full Disk Encryption==== | ||
+ | ====Loop Device==== | ||
+ | A small file named **// | ||
+ | < | ||
+ | dd if=/ | ||
+ | # create device node | ||
+ | losetup /dev/loop0 /crypt | ||
+ | # setup LUKS header | ||
+ | cryptsetup -c aes-xts-plain64 --key-size 512 \ | ||
+ | --hash sha512 --iter-time 5000 \ | ||
+ | --use-urandom luksFormat / | ||
+ | # open file | ||
+ | cryptsetup open /dev/loop0 crypt | ||
+ | # create filesystem | ||
+ | mkfs.ext4 / | ||
+ | # create mountpoint | ||
+ | mkdir / | ||
+ | # mount file | ||
+ | mount -t ext4 / | ||
+ | |||
+ | ... | ||
+ | |||
+ | # unmount file | ||
+ | umount / | ||
+ | # delete mountpoint | ||
+ | rmdir / | ||
+ | # close file | ||
+ | cryptsetup close crypt | ||
+ | # delete device node | ||
+ | losetup -d / | ||
+ | ====Entire Partition==== | ||
+ | **Note:** /dev/sdb1 will be used as the test partition, ' | ||
+ | < | ||
+ | cryptsetup -c aes-xts-plain64 \ | ||
+ | --key-size 512 --hash sha512 \ | ||
+ | --iter-time 5000 --use-urandom /dev/sdb1 | ||
+ | # open volume onto device mapper | ||
+ | cryptsetup open /dev/sdb1 private | ||
+ | # create filesystem | ||
+ | mkfs.ext4 / | ||
+ | # open mapped device | ||
+ | cryptsetup --type luks open /dev/sdb1 private | ||
+ | # mount encrypted partition | ||
+ | mount -t ext4 / | ||
- | =====General Remediation Methods==== | + | ... |
- | * **Setting up Full Disk Encryption: | + | |
- | * **Other Remediations: | + | # unmount |
+ | umount /dev/sdb1 | ||
+ | # close mapped device | ||
+ | cryptsetup close private</ | ||
=====References===== | =====References===== |