• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Error decrypting LUKS partition prior to capture/imaging

Scheduled Pinned Locked Moved Solved
FOG Problems
5
44
5.1k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H
    humoss233
    last edited by humoss233 Oct 22, 2019, 9:29 AM Oct 22, 2019, 3:21 PM

    @Sebastian-Roth clever hack! there was one more hurdle: blockdev --rereadpt in the runPartprobe function fails due to ioctl error on BLKRRPART: Device or resource busy because cryptsetup luksOpen appears to be locking the device. Luckily partprobe works fine, so I just replaced that part of the script. Here’s my final commands (the last line just shows that the line has been replaced successfully). After running fog, the decrypted partition/disk is successfully captured (with /dev/md126 as “Host Primary Disk”). 1 GB instead of 800 GB!

    dc2e2598-c531-4465-acec-8ec2046acf3e-image.png

    G 1 Reply Last reply Oct 22, 2019, 3:40 PM Reply Quote 1
    • G
      george1421 Moderator @humoss233
      last edited by george1421 Oct 22, 2019, 9:44 AM Oct 22, 2019, 3:40 PM

      @humoss233 I’m not sure this will work, since you are linking the /dev/md126p3_crypt to /dev/md126p3 then deleted it and then recreating it as itself. You are kind of looping back to itself. I can see a circular link here.

      I wonder if you can rename /dev/md126p3 right from the start to /dev/md126p3raw and then do your cryptsetup against the renamed raw device and linking.

      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

      1 Reply Last reply Reply Quote 1
      • H
        humoss233
        last edited by humoss233 Oct 22, 2019, 1:11 PM Oct 22, 2019, 6:43 PM

        @george1421 That’s a good point and your method is safer, but the one that I’m using (from @Sebastian-Roth) also works - I unzipped and mounted the resulting .img file to make sure it’s good. It’s beyond me but cryptsetup must work in a way that once the decrypted partition is mapped, it’s no longer dependent on the device file representation.

        Now I just need to think of a clever way of prompting for and transmitting the password over the network, as I’d rather not put the plaintext pass in the postinit script.

        Both of you, thanks very much for your help!!

        G 1 Reply Last reply Oct 22, 2019, 7:55 PM Reply Quote 0
        • G
          george1421 Moderator @humoss233
          last edited by Oct 22, 2019, 7:55 PM

          @humoss233 Hmm… pass-o-words…

          How about an encrypted password passed as a kernel parameter to FOS Linux bzImage, then in your postinit script decode the password using local seed (same one used to encrypt the password).

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

          H 1 Reply Last reply Oct 24, 2019, 4:42 PM Reply Quote 0
          • H
            humoss233 @george1421
            last edited by Oct 24, 2019, 4:42 PM

            @george1421 that’s a good idea - I’ve been researching it, but it looks like openssl is not available in FOS. Is there another way available to decrypt a given cipher?

            G 2 Replies Last reply Oct 24, 2019, 5:08 PM Reply Quote 0
            • G
              george1421 Moderator @humoss233
              last edited by george1421 Oct 24, 2019, 11:13 AM Oct 24, 2019, 5:08 PM

              @humoss233 I don’t know off the top of my head of base64 is part of fos linux or not. But that would be one option

              Update: Base64 is part of fos linux, but I don’t think that is the tool to use looking a bit deeper into it.

              Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

              1 Reply Last reply Reply Quote 0
              • G
                george1421 Moderator @humoss233
                last edited by george1421 Oct 24, 2019, 11:31 AM Oct 24, 2019, 5:30 PM

                @humoss233 I’m rebuilding the inits with openssl included. This is only half of the issue if the kernel doesn’t have openssl enabled. We’ll see one step at a time.

                Edit: Wait, I just remembered that we built a custom kernel for the LUKS bits, so I can add it if needed since you are already running a custom kernel.

                Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                T H 2 Replies Last reply Oct 24, 2019, 6:49 PM Reply Quote 0
                • T
                  Tom Elliott @george1421
                  last edited by Oct 24, 2019, 6:49 PM

                  @george1421 Open SSL is already built into the init’s, that’s how we can do SSH Sessions!

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                  G 1 Reply Last reply Oct 24, 2019, 6:59 PM Reply Quote 0
                  • G
                    george1421 Moderator @Tom Elliott
                    last edited by Oct 24, 2019, 6:59 PM

                    @Tom-Elliott Interesting the openssl application doesn’t seem to be in my usb boot. I think the ssl libraries have to be there for ssh. Let me search the inits. I may have just totally missed it when I checked.

                    Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                    1 Reply Last reply Reply Quote 0
                    • H
                      humoss233 @george1421
                      last edited by Oct 25, 2019, 12:38 AM

                      @george1421 thanks for looking into this!

                      By the way, here is a simple initial stab at a postinit script for folks using LUKS with FOG in the future. It tries to decrypt all partitions and then links the decrypted partitions in the cases of successful decryption. It currently uses a plaintext PASSWORD in the script, but hopefully we can switch this out for an encrypted password passed as a kernel parameter.

                      for i in {/dev/sd*,/dev/nvme*,/dev/md*}; do
                          echo -n PASSWORD | cryptsetup luksOpen $i $(basename $i)_crypt  -d -
                          if [ -e /dev/mapper/$(basename $i)_crypt ]; then
                              rm $i
                              ln -s /dev/mapper/$(basename $i)_crypt $i
                          fi
                      done
                      sed -i 's/blockdev --rereadpt/partprobe/g' /usr/share/fog/lib/funcs.sh
                      
                      G 1 Reply Last reply Oct 25, 2019, 1:11 AM Reply Quote 0
                      • G
                        george1421 Moderator @humoss233
                        last edited by Oct 25, 2019, 1:11 AM

                        @humoss233 Here are the inits that should have openssl application. For full disclosure I haven’t tested them myself yet, I ran out of time today. I’ll load it onto my usb stick in the morning USA time. But if you want to try to see if it works: https://drive.google.com/open?id=1OnVpqqGnFkVkS19B4OwNxP2FMoyustwT

                        You will just download them as initCrypt.xz and save it in /var/www/html/fog/service/ipxe directory. Then go into the host definition and add into the init field initCrypt.xz. As I said I don’t know if it will boot correctly (it should) but it also should have the openssl executable installed.

                        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                        H 1 Reply Last reply Oct 25, 2019, 4:16 AM Reply Quote 1
                        • H
                          humoss233 @george1421
                          last edited by Oct 25, 2019, 4:16 AM

                          @george1421 getting error message below

                          06a63034-9b10-496b-a7bd-a05670b54cee-image.png

                          G 1 Reply Last reply Oct 25, 2019, 9:24 AM Reply Quote 0
                          • G
                            george1421 Moderator @humoss233
                            last edited by Oct 25, 2019, 9:24 AM

                            @humoss233 It almost sounds like you are running an older version of FOG and your ram disk size is not 275000. What version of FOG are you using?

                            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                            H 1 Reply Last reply Oct 25, 2019, 10:41 AM Reply Quote 0
                            • H
                              humoss233 @george1421
                              last edited by humoss233 Oct 25, 2019, 5:19 AM Oct 25, 2019, 10:41 AM

                              @george1421 I run 1.5.5 because that’s the latest available as a docker container (https://github.com/Mudislander/fogproject).

                              I changed KERNEL RAMDISK SIZE to 275000 and it now works - thanks! I successfully decrypted and encrypted a sample file using the following commands.

                              openssl aes-256-cbc -a -salt -pass pass:PASSWORD -in sample.txt -out sample.txt.enc
                              openssl aes-256-cbc -d -a -pass pass:PASSWORD -in sample.txt.enc -out sample.txt.new

                              Is the best way for the postinit script to access kernel parameters to parse /proc/cmdline?

                              G 1 Reply Last reply Oct 25, 2019, 11:40 AM Reply Quote 0
                              • G
                                george1421 Moderator @humoss233
                                last edited by Oct 25, 2019, 11:40 AM

                                @humoss233 To access kernel parameters you can surely use the /proc/cmdline but also when the master FOG script starts to run it converts the kernel parameters into bash variables. So if you set a kernel parameter of foobar=XXXYTVBZ when the master FOG script starts it will create a variable called $foobar with the value set to XXXYTVBZ.

                                Version 1.5.5 may be close enough to 1.5.7 (init base I built against) so that there won’t be any problems. You might run into a problem because at 1.5.6 the name of the fog (linux) service account changed from fog to fogproject. You might need to create a linux user on the FOG server called fogproject and set the password to the password found in the hidden file /opt/fog/.fogsettings file. You will know there is an issue upon upload, once all of the files are uploaded you will see a ftp error and then another error about updating the database. But first things first, you need to get the password encrypted and then integrated into your code.

                                Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                                H 1 Reply Last reply Oct 26, 2019, 5:15 AM Reply Quote 0
                                • S
                                  Sebastian Roth Moderator
                                  last edited by Oct 25, 2019, 11:45 AM

                                  @humoss233 said in Error decrypting LUKS partition prior to capture/imaging:

                                  I run 1.5.5 because that’s the latest available as a docker container (https://github.com/Mudislander/fogproject).

                                  Do you know the person creating this? Would be interesting to know why 1.5.5 was used and not updated since.

                                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                                  T 1 Reply Last reply Oct 25, 2019, 11:59 AM Reply Quote 1
                                  • T
                                    Tom Elliott @Sebastian Roth
                                    last edited by Oct 25, 2019, 11:59 AM

                                    @Sebastian-Roth Too add on, 1.2.0 container to 1.5.7 container should still work too. The version the docker has may have 1.5.5, but I’m 99% sure that you can still upgrade it to 1.5.7.

                                    Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                                    Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                                    Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                                    1 Reply Last reply Reply Quote 0
                                    • H
                                      humoss233 @george1421
                                      last edited by humoss233 Oct 26, 2019, 4:06 AM Oct 26, 2019, 5:15 AM

                                      @george1421 mostly figured out the script, but having trouble getting it to run. I’m following your guide here (https://forums.fogproject.org/topic/9463/fog-postinit-scripts-before-the-magic-begins/) but getting this error:

                                      5773ac33-3323-420b-895c-c91eb3425478-image.png

                                      /images/dev/fog.postinit:

                                      #!/bin/bash
                                      
                                      . $postinitpath/fog.ACME.selector
                                      

                                      /images/dev/fog.ACME.selector contains the script from your post and exeutes the decryption script if the machine type matches

                                      Here’s the actual decryption script in a separate file:

                                      #!/bin/bash
                                      
                                      # only needed if using intel raid:
                                      mdadm /dev/md126
                                      
                                      pass_dec=`echo $pass_enc | openssl enc -base64 -d -aes-256-cbc -nosalt -pbkdf2 -pass pass:LOCALKEY`
                                      
                                      for i in {/dev/sd*,/dev/nvme*,/dev/md*}; do
                                          echo -n $pass_dec | cryptsetup luksOpen $i $(basename $i)_crypt  -d -
                                          if [ -e /dev/mapper/$(basename $i)_crypt ]; then
                                              rm $i
                                              ln -s /dev/mapper/$(basename $i)_crypt $i
                                          fi
                                      done
                                      
                                      sed -i 's/blockdev --rereadpt/partprobe/g' /usr/share/fog/lib/funcs.sh
                                      

                                      One would generate the encrypted key using echo 'MY_DECRYPTED_PASS' | openssl enc -base64 -e -aes-256-cbc -nosalt -pbkdf2 -pass pass:LOCALKEY and pass this in the “pass_enc” kernel parameter

                                      @Sebastian-Roth don’t know the docker creator but his github is https://github.com/Mudislander/fogproject

                                      1 Reply Last reply Reply Quote 0
                                      • S
                                        Sebastian Roth Moderator
                                        last edited by Oct 26, 2019, 9:21 AM

                                        @humoss233 The error in the picture you posted is most likely due to the file being created on Windows using \r\n line endings. Convert the file to Linux file endings \r and it shouldn’t throw that error again.

                                        Plus I see a difference in the paths: /imagesinit/... vs /images/...

                                        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                                        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                                        H 1 Reply Last reply Oct 26, 2019, 12:06 PM Reply Quote 0
                                        • H
                                          humoss233 @Sebastian Roth
                                          last edited by humoss233 Oct 26, 2019, 6:09 AM Oct 26, 2019, 12:06 PM

                                          @Sebastian-Roth thanks! changing the line endings fixed the error and the difference in paths doesn’t seem to be an issue

                                          I had to repad the base64 string as trailing ='s can’t be passed in the kernel parameter (they are ignored). Here’s the final result:

                                          #!/bin/bash
                                          
                                          # REF: https://gist.github.com/catwell/3046205
                                          function repad {
                                            _l=$((${#1} % 4))
                                            if [ $_l -eq 2 ]; then _s="$1"'=='
                                            elif [ $_l -eq 3 ]; then _s="$1"'='
                                            else _s="$1" ; fi
                                            echo -n $_s
                                          }
                                          
                                          pass_dec=`echo -n $(repad $pass) | base64 -d | openssl enc -d -aes-128-ecb -K 691CACE3402341778F3DBCFD74859E0C -nosalt`
                                          
                                          for i in {/dev/sd*,/dev/nvme*,/dev/md*}; do
                                              echo -n $pass_dec | cryptsetup luksOpen $i $(basename $i)_crypt  -d - 2> /dev/null
                                              if [ -e /dev/mapper/$(basename $i)_crypt ]; then
                                                  rm $i
                                                  ln -s /dev/mapper/$(basename $i)_crypt $i
                                                  echo Decrypted $i
                                              fi
                                          done
                                          sed -i 's/blockdev --rereadpt/partprobe/g' /usr/share/fog/lib/funcs.sh
                                          

                                          Generate the encrypted pass using echo -n 'MY_LUKS_PASSWORD' | openssl enc -base64 -aes-128-ecb -K 691CACE3402341778F3DBCFD74859E0C -nosalt and pass the result into a pass kernel parameter

                                          Thanks again @george1421 and @Sebastian-Roth for all your help in making this work

                                          G 1 Reply Last reply Oct 26, 2019, 1:14 PM Reply Quote 1
                                          • 1
                                          • 2
                                          • 3
                                          • 2 / 3
                                          2 / 3
                                          • First post
                                            27/44
                                            Last post

                                          216

                                          Online

                                          12.0k

                                          Users

                                          17.3k

                                          Topics

                                          155.2k

                                          Posts
                                          Copyright © 2012-2024 FOG Project