Tuesday, May 8, 2018

Building a Minimal Busybox based Linux distro

Introduction :- This post shall help us build a minimal linux distro from kernel upwards alongwith a root file system which can be mounted as a Ramdisk and also a startup process /init which will take us from the kernel space to user space after booting is complete. I have used a debian based virtualbox VM for the build process.

1.     Download and extract the latest linux kernel.
       
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.16.7.tar.xz
tar xvf linux-4.16.7.tar.xz
cd linux-4.16.7/
(one can download and extract kernel without using wget and tar commands using gui tools )
2.    Create a config file to be used for the kernel compilation

make allnoconfig

3.    Tweak the config file created above to add or remove functionalities into the linux kernel.

make menuconfig
Enable following options :-
General setup ---> Initial RAM filesystem and RAM disk (initramfs/initrd) support
Executable file formats / Emulations ---> Kernel support for ELF binaries 

Exit and make sure to save the configuration 

4.    Compile the kernel

make

5.    Get Busybox : Download and statically link Busybox. 

wget https://busybox.net/downloads/busybox-1.28.3.tar.bz2

6.    What is busybox ?
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc.

7.    Why we need it ?
It will provide us with the shell / command line utils like ls , cp , ifconfig, ifup, route, etc

8.   Configure and build the busybox 
(a)  Extract the busybox download
tar xjvf busybox-1.28.3.tar.bz2

(b) Now generate a minimal .config file
cd busybox-1.28.3/ make allnoconfig

(c)   Configure busybox build options 
make menuconfig

We need to enable:
Settings ---> Support files > 2 GB
Settings ---> Support Unicode
Settings ---> Build Options ---> Build static binary (no shared libs)

.....and add  support for some executables to it. You will get most of the options to enable utilities below the Settings menu option.

Exit by saving changes to the .config file in the busybox-1.28.3 directory

(d)  finally build and install the static linked busybox binary
make
make install

9.   Builiding a root filesystem.  After compiling busybox, in the same directory we have a directory called _install, which will be used for building a root filesystem by us.

(a)     Copy the _install folder as rootfs folder 
mv _install ../rootfs

(b)  Remove the linuxrc
cd ../rootfs
rm linuxrc

(c)  We create some dirs - dev, proc, sys, and tmp. 
mkdir dev proc sys tmp

(d)  We need at least one device, which is the console 
sudo mknod dev/console c 5 1

(e)       We need to create an init script , next which will provide us a shell after the booting is complete. We will use gedit to create a file init inside the directory rootfs :-
#!/bin/ash
mount -t proc none /proc
mount -t sysfs none /sys
/bin/ash

(f)        Change the file permission of /rootfs/init as under :-
chmod +x init

(g)  Finally, we archive the initramfs with cpio and compress it with gzip:

find . | cpio -H newc -o | gzip > ../rootfs.cpio.gz 

10.  Lastly, we will put our kernel image and the root filesystem alongwith busybox into a usb thumb drive, so that we can boot a bare metal machine with it.

(a)  Make a single partition on the usb and mount it on your debian system :-

mkfs.ext3 /dev/sdb1
mount /dev/sdb1 /mnt

(b)  Install grub on the usb 

grub-install --root-directory=/mnt /dev/sdb

(c)      Copy the kernel image bzImage file and the rootfilesystem (incl busybox static binary) rootfs.cpio.gz file to the root partition of the usb i.e /mnt 

(d)     Unmount your usb and plug it into another system, which has been configured to be boot up from a usb disk.

(e)     When  you get the grub prompt enter the following :-

set root=(hd0,msdos1)
linux  /bzImage
initrd /rootfs.cpio.gz
boot

Watch your minimal busybox based linux distro come to live.....! It will give a command prompt. Enter some commands and navigate through the directory to explore your minimal linux system.

Enjoy!

 

  
 

Saturday, May 28, 2016

RECOVERING DATA / WORKING FILES FROM A CRASHED WINDOWS VIRTUALBOX VM


Scenario : I had a windows 7 virtual box machine running as guest on my host ubuntu. One fine day, during software installation in win 7, my vm crashed and just wouldn't start.

Problem : I had some very important files on the win7 guest machine and needed them desperately. 

Solution : I have a remnux (linux) VM too. So I switched it off first. Next, I opened the settings -> storage, and added the win7 .vmdk file under the external:SATA section. It was now listed in addition to the existing remnux.vmdk

Next, I booted up my remnux machine and opened the file browser, I then located my mounted win7 hard disk. I simply browsed to the relevant folder and copied all the needed files to the remnux disk. I next used the shared folder to transfer these files to my host OS. 

I was back in business in no time!


Note :- If you donot have a shared folder in your host OS. First install guest additions and virtual box extension pack. Next add a shared folder inside your guest OS VM (Devices-> Shared Folder Settings OR Settings-> Shared folders -> Machine Folders -> Click on +/Add button). Browse to the folder in your host OS, which you would like to share with the guest OS, choose the settings as auto-mount and permanent. Click on OK. Next open a terminal inside you guest VM and execute the command - sudo adduser remnux vboxsf
(remember in remnux distro the user name is also remnux) . Finally, reboot your guest OS VM, the shared folder will always be mounted under /etc/media/

 Enjoy ;-) !!


Wednesday, October 22, 2014

Virtualbox Problem with netoworking : "No host only network adapter selected"

Scenario :-

While carrying out dynamic malware analysis, it is better to set up a host only network with the victim host (on which you are running the malware) and the remnux host (on which you will be running the analysis tools).

Problem :-

I had a problem with my virtualbox on ubuntu 12.04, I coudn't add a host only adapter, the message was "no host only network adapter selected" and neither I could select anything.

Solution :-

Actually, the virtual host-only network wasn't set up yet. Here's is how to fix this problem:

    From the main menu, select File > Preferences (Ctrl+G) - NOT the settings of
    any particular vm.

    Select Network in the list on the left.

    You should see an empty white box with "Host-only Networks" at the top. On
    the right, there are three buttons to manage them. Click the topmost one
   (with a green plus symbol).

   A new Host-only network will be created and added to the list.

You should now be good to go!
:-)






Monday, September 8, 2014

multiple distro's on usb

I have a usb with multiple distros on it. The entire usb has two partitions - both fat32, one for the data and another one for the live distros.
I then installed multisystem on my laptop (Ubuntu14.04) :-
          Add the following line to /etc/apt/sources.list file:-
       deb http://liveusb.info/multisystem/depot all main
         and update the repositories :-
      sudo apt-get update && apt-get install multisystem
Now fireup the multisystem and insert the formatted usb. Remember to be a non root user. Select your usb drive partition which should store the distros. Now choose the .iso image you wish to have on the usb and multisystem does the rest. You can have multiple distros and may even have persistence working for any one of them. 

 

Bye!

Monday, June 2, 2014

USING VLC AS A VIDEO/AUDIO CUTTER

hi everyone!
Here are the steps for using VLC media player, as  an audio/video cutter :-
1.     Load your video / audio file in VLC.
2.     Activate Advanced controls located under the View menu. You will now
        see four extra buttons above the normal play/pause button.
3.     Seek to the position you want to start your recording and play the audio /
        video stream. Now press the record  button (the first one) in the Advanced
        controls section.
4.     Press the Record button again, when you want to stop the recording.
5.     Basically, we have used the built-in VLC decoder to record the audio / video
        clip.

Credits : - http://www.guidingtech.com/8802/use-vlc-as-video-cuting-tool/

Ofcourse, if you have ffmpeg insalled, you may use the following command line from a terminal window :-
      ffmpeg -i in.mp4 -ss [start] -t [duration] -c:v copy 
            -c:a copy out.mp4
The various options are as under:-   
     -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds) 
     -t  specifies the duration of the clip (same format). 
     -c:v copy and -c:a copy copy the video and audio bitstreams without
        re-encoding them. This won't harm the quality and make the command run
        within seconds.
 
simple and pure joy of using open source software!
bye!

Friday, May 23, 2014

HOW TO CONVERT .MP4 VIDEOS TO PSP COMPATIBLE .MP4 FORMAT

Hi,
I have recently loaded the Arista Transcoder, using the Ubuntu Software Centre.
It is pretty simple to use, all you have to do is select the format for the conversion (from the drop-down box) and choose the video file to convert, it does the rest for you. Now upload the .mp4 file onto the VIDEO folder of your PSP and enjoy
:)

Tuesday, February 25, 2014

CREATING A VMDK FROM YOUR PHYSICAL WIN7 INSTLN

I have a dual boot system with Ubuntu12.04 and Windows 7. Presently, I am using Grub2 to choose the OS to boot into.

Since I mostly operate in Ubuntu, I decided to give up my Windows 7 installation entirely by moving it from physical installation to a VM. . After all when I need Windows and I donot need to reboot and I can freeze / unfreeze the system in a short time.

So essentially I installed Ubuntu12.04 as my base system and installed VirtualBox in it. Now I created a VM from my physical Win7 install and I use it in the Virtual Box. The steps to do it are as follows:-

(a)    Download and install VMware-converter-en-5.5.0-1362012.exe from the
internet, on the win7.

(b)    Create a vmdk image of the win7 system and save it in an external HDD.

(c)    Create  a VM inside the Virtual Box and choose to create it from - Use an
existing Virtual Hard Drive File.

There is yet another way to accomplish this task :-

(a)   Download and install  in the windows partition, Disk2vhd.exe from the sysinternals suite.

(b)   Create a .vhd image of your live system. But the important thing is the external HDD where you store this image must be NTFS partition , otherwise you will always get insufficient disk space error! which ofcourse is not a correct prompt for the error. There is yet another problem, the .vhd image will also carry your Grub installation, and inside the VM this will always give a grub rescue prompt. Just proceed to next step and remove the Grub installation from the .vhd file and reinstate the mbr using a Win7 System Restore disk.

(c)   Start VirtualBox and create a new VM. Reboot the virtual machine and Select CD/DVD as boot option. Boot from Recovery Disk, log in when prompted
Select command line as utility and execute the following commands:

       Bootrec.exe /FixMbr
    Bootrec.exe /FixBoot
    Bootrec.exe /RebuildBcd


(the intention here is to get rid of grub( which was in the dual boot original system) in the VM,  otherwise you'd be getting grub rescue at boot)

(d)  Reboot Virtual Machine and use it.

Thanks !