This is a tiny tryout to get Kali rolling a realtime kernel and more..
Downloaded : http://cdimage.kali.org/kali-images/kali-2021.1/kali-linux-2021.1-live-amd64.iso
Copy iso to usb :
sudo dd bs=4M if=kali-linux-2021.1-live-amd64.iso of=/dev/sdb conv=fdatasync status=progress
Copy the iso files (include hidden file ./disk) to /kali/original/ and to /kali/rebranded/.
We could do a debootstrap. But first let's explore the original Kali iso.
cd kali/rebranded/live/
unsquashfs filesystem.squashfs # This will produce the folder /squashfs-root
mount --bind /dev squashfs-root/dev
mount --bind /sys squashfs-root/sys
mount --bind /proc squashfs-root/proc
chroot squashfs-root
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export LC_ALL=C
dhclient
Okey now we are inside. It looks quite serious now. Lets see what resources they use.
cat /etc/apt/sources.list
Lets add the sid list.
echo "deb http://ftp.de.debian.org/debian sid main" >> /etc/apt/sources.list
apt-get update
Lets try to install a realtime kernel-image and the kernel headers.
apt-get install linux-image-5.10.0-5-rt-amd64 # https://packages.debian.org/sid/amd64/linux-image-5.10.0-5-rt-amd64/download
apt-get install linux-kbuild-5.10 # to solve a problem
apt-get install linux-headers-5.10.0-5-rt-amd64
apt-get remove linux-image-amd64
apt-get remove linux-image-5.10.0-kali3-amd64
update-initramfs -u
For our kali undercover c++ program we need Tor.
apt-get install tor # To my surprise Tor isn't on Kali by default.
Let's see what crontab -e has inside.
crontab -e # Is empty by default. Wtf.
Add this line :
@reboot /etc/init.d/./set-random-mac
# The script "set-random-mac" will be a c++ program that chooses a random mac for you at boot time.
The base command to set a mac adres is : ifconfig eth0 hw ether 00:00:00:00:00:00
Ok we need qt-creator to write our c++ code wich will set our mac adres to a random value at boot time. This is a compiled script, the source code is not visible if you don't forget to delete it !! The package will install qt-creator in the /opt/ dir and make a system menu launcner for us.
mkdir /home/software && cd /home/software/
wget https://github.com/grotius-cnc/debian_distro_live_build_post_tweaking/releases/download/1.0.2/qt-creator.deb
dpkg -i qt-creator.deb
rm -rfv /home/software/qt-creator.deb # Erase source.
Oke lets start the program ct-creator in chroot. But we need to set a display.
xhost +local:
echo $DISPLAY
export DISPLAY=:0
Start normal terminal on host pc :
xhost +local:
Go on in chroot terminal and start the qt-creator program by :
cd /opt/qt-creator/Tools/QtCreator/bin/
./qtcreator.sh
And wholla, we are inside the qt gui now in a chroot environment, wow :
Ok now create a new project, qt console application. I named it : "set-random-mac", I set the filepath to /home/software/
I see we need to set the version path. Like this is oke. You have to search in your chroot path.
Now select Desktop and Next.
And select Finish. Now we can code. Isn't this a beauty :
Ok lets copy our brand new code to the /etc/init.d/ dir.
cd home/software/build-set-random-mac-Desktop-Debug
cp set-random-mac /etc/init.d/
Ok for now lets leave the chroot environment :
umount /sys /proc /dev
exit
# extra control steps to umount :
mount
# i had to to this one just to be sure :
umount -l /home/user/kali/rebranded/live/squashfs-root/dev
Rename iso, edit /rebranded/.disk/info file
Debian-Kali-5.10.0-5-rt-amd64
Copy these files from /live/squashfs-root/boot to /live. Copy the files higher in hierarchy.
config-5.10.0-5-rt-amd64
initrd.img-5.10.0-5-rt-amd64
System.map-5.10.0-5-rt-amd64
vmlinuz-5.10.0-5-rt-amd64
Delete /rebranded/live/filesystem.squashfs
rm /rebranded/live/filesystem.squashfs
Resquash in /rebranded/live/
mksquashfs squashfs-root/ filesystem.squashfs -comp xz
Move the rebranded/live/squashfs-root dir outside the iso environment beforen we pack the new iso.
Create new iso in top level dir /rebranded/ :
xorriso -as mkisofs -V 'Debian-Kali-5.10.0-5-rt-amd64' \
-o Debian-Kali-5.10.0-5-rt-amd64.iso -J -J -joliet-long -cache-inodes \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat -boot-load-size 4 -boot-info-table -no-emul-boot -eltorito-alt-boot \
-e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -isohybrid-apm-hfsplus .
Iso filesize : 4.2Gb
Put iso on usb storage device :
sudo dd bs=4M if=Debian-Kali-5.10.0-5-rt-amd64.iso of=/dev/sdb conv=fdatasync status=progress
Runtest : Modified the ./set-random-mac main.cpp code a little bit to improve a random mac adres value :
#include <QCoreApplication>
#include <iostream>
#include <string>
#include <random>
#include <chrono>
//The base command to set a mac adres is : ifconfig eth0 hw ether 00:00:00:00:00:00
// $ ./set-random-mac
std::string OneDigit();
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string str0 = "ifconfig eth0 hw ether ";
std::string str1 = OneDigit()+OneDigit();
std::string str2 = OneDigit()+OneDigit();
std::string str3 = OneDigit()+OneDigit();
std::string str4 = OneDigit()+OneDigit();
std::string str5 = OneDigit()+OneDigit();
std::string str6 = OneDigit()+OneDigit();
std::string tot = str0+str1+":"+str2+":"+str3+":"+str4+":"+str5+":"+str6;
std::cout<<"your new mac is set to : " << tot.c_str()<<std::endl;
system("/etc/init.d/networking stop");
system(tot.c_str());
system("/etc/init.d/networking start");
return a.exec();
}
std::string OneDigit(){
auto start = std::chrono::high_resolution_clock::now();
// operation to be timed ...
auto finish = std::chrono::high_resolution_clock::now();
finish+=std::chrono::nanoseconds(rand());
std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(finish-start).count() << "ns\n";
int iSecret, number = 0;
number = std::chrono::duration_cast<std::chrono::nanoseconds>(finish-start).count();
/* generate secret number: */
iSecret = number % 9 + 1;
return std::to_string(iSecret);
}
The pc was booting ok with new kernel. I really like the kali desktop environment and the text predicion in the terminal.
At last i came to the conclusion there is already a "macchange" program installed in Kali. But above example is still usefull.