<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nislab_</title>
    <description>The latest articles on DEV Community by Nislab_ (@asded_).</description>
    <link>https://dev.to/asded_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1090265%2F3f792ca3-bf3d-4b03-99fa-bfc47775f854.png</url>
      <title>DEV Community: Nislab_</title>
      <link>https://dev.to/asded_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/asded_"/>
    <language>en</language>
    <item>
      <title>Deploying your Kali-linux templates with Cloud-init, under Proxmox VE</title>
      <dc:creator>Nislab_</dc:creator>
      <pubDate>Fri, 26 May 2023 18:37:09 +0000</pubDate>
      <link>https://dev.to/asded_/deploying-your-kali-linux-templates-with-cloud-init-under-proxmox-ve-2ng7</link>
      <guid>https://dev.to/asded_/deploying-your-kali-linux-templates-with-cloud-init-under-proxmox-ve-2ng7</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/pe6eIPXI000"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Deploying your KVM virtual machines via Cloud-init, is a fast and flexible way to deploy your KVM virtual machines. With the Proxmox template system. &lt;/p&gt;

&lt;p&gt;But what if your distribution doesn't include Cloud-init in its prebuild (qcow2,raw,...) ?&lt;/p&gt;

&lt;p&gt;That's what this article is all about, so we'll take a look at how to make the famous Kali-linux pentesting and forensic distribution 'compatible' with Cloud-init.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the future Kali-linux template
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; qm create 103 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--name&lt;/span&gt; template-kalilinux &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--agent&lt;/span&gt; 1 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--memory&lt;/span&gt; 4096 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--bios&lt;/span&gt; seabios
    &lt;span class="nt"&gt;--sockets&lt;/span&gt; 1 &lt;span class="nt"&gt;--cores&lt;/span&gt; 4
    &lt;span class="nt"&gt;--cpu&lt;/span&gt; host
    &lt;span class="nt"&gt;--net0&lt;/span&gt; virtio,bridge&lt;span class="o"&gt;=&lt;/span&gt;vmbr0 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--scsihw&lt;/span&gt; virtio-scsi-single
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Retrieving the QEMU prebuild image from Kali linux
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget &lt;span class="nt"&gt;-P&lt;/span&gt; /mnt/pve/DS418/template/iso/ https://cdimage.kali.org/kali-2023.1/kali-linux-2023.1-qemu-amd64.7z
7z x /mnt/pve/DS418/template/iso/kali-linux-2023.1-qemu-amd64.7z
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Modification of the image for Cloud-init support
&lt;/h2&gt;

&lt;p&gt;Check necessary packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; libguestfs-tools p7zip-full
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cloud-init added to Kali image :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;virt-customize &lt;span class="nt"&gt;-a&lt;/span&gt; /mnt/pve/DS418/template/iso/kali-linux-2023.1-qemu-amd64.qcow2 &lt;span class="nt"&gt;--install&lt;/span&gt; cloud-init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll take this opportunity to install the QEMU agent, and enable SSH (the latter is not active by default under Kali):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;virt-customize &lt;span class="nt"&gt;-a&lt;/span&gt; /mnt/pve/DS418/template/iso/kali-linux-2023.1-qemu-amd64.qcow2 &lt;span class="nt"&gt;--install&lt;/span&gt; qemu-guest-agent
virt-customize &lt;span class="nt"&gt;-a&lt;/span&gt; /mnt/pve/DS418/template/iso/kali-linux-2023.1-qemu-amd64.qcow2 &lt;span class="nt"&gt;--run-command&lt;/span&gt; &lt;span class="s1"&gt;'systemctl enable ssh.service'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Import disk image
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm importdisk 103 /mnt/pve/DS418/template/iso/kali-linux-2023.1-qemu-amd64.qcow2 local-btrfs &lt;span class="nt"&gt;--format&lt;/span&gt; qcow2
&lt;span class="c"&gt;# All that's left is to attach the disk from the web interface.&lt;/span&gt;
&lt;span class="c"&gt;# A single command-line alternative for both import and attachment&lt;/span&gt;
qm &lt;span class="nb"&gt;set &lt;/span&gt;103 &lt;span class="nt"&gt;--scsi0&lt;/span&gt; local-btrfs:0,import-from&lt;span class="o"&gt;=&lt;/span&gt;/mnt/pve/DS418/template/iso/kali-linux-2023.1-qemu-amd64.qcow2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Cloud-init configuration
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Add Cloud-init disk
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm &lt;span class="nb"&gt;set &lt;/span&gt;103 &lt;span class="nt"&gt;--ide0&lt;/span&gt; local-btrfs:cloudinit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Define boot order
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm &lt;span class="nb"&gt;set &lt;/span&gt;103 &lt;span class="nt"&gt;--boot&lt;/span&gt; c &lt;span class="nt"&gt;--bootdisk&lt;/span&gt; scsi0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add VGA interface for console access
&lt;/h3&gt;

&lt;p&gt;The documentation recommends configuring the interface in serial, as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm &lt;span class="nb"&gt;set &lt;/span&gt;103 &lt;span class="nt"&gt;--serial0&lt;/span&gt; socket &lt;span class="nt"&gt;--vga&lt;/span&gt; serial0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But we're going to use an alternative method (to make Kali accessible from NoVNC):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm &lt;span class="nb"&gt;set &lt;/span&gt;103 &lt;span class="nt"&gt;--vga&lt;/span&gt; std
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Convert VM to template
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm template 103
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting Cloud-init parameters
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm &lt;span class="nb"&gt;set &lt;/span&gt;103 &lt;span class="nt"&gt;--ciuser&lt;/span&gt; USER &lt;span class="nt"&gt;--cipassword&lt;/span&gt; PASSWORD 
qm &lt;span class="nb"&gt;set &lt;/span&gt;103 &lt;span class="nt"&gt;--sshkey&lt;/span&gt; /PATH/TO/YOUR/key.pub
qm &lt;span class="nb"&gt;set &lt;/span&gt;103 &lt;span class="nt"&gt;--ipconfig0&lt;/span&gt; &lt;span class="nv"&gt;ip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;192.168.2.12/24,gw&lt;span class="o"&gt;=&lt;/span&gt;192.168.2.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploying from template
&lt;/h2&gt;

&lt;p&gt;All that's left to do is clone your Kali-linux template over and over again.&lt;br&gt;
if you modify the Configuration of the template or one of your clones, don't forget to regenerate the Cloud-init image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;qm clone 103 104 &lt;span class="nt"&gt;--name&lt;/span&gt; kali-104
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Resources :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pve.proxmox.com/pve-docs/qm.1.html" rel="noopener noreferrer"&gt;https://pve.proxmox.com/pve-docs/qm.1.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pve.proxmox.com/wiki/Cloud-Init_Support" rel="noopener noreferrer"&gt;https://pve.proxmox.com/wiki/Cloud-Init_Support&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pve.proxmox.com/wiki/VM_Templates_and_Clones" rel="noopener noreferrer"&gt;https://pve.proxmox.com/wiki/VM_Templates_and_Clones&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://wiki.debian.org/ThomasChung/CloudImage" rel="noopener noreferrer"&gt;https://wiki.debian.org/ThomasChung/CloudImage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.openstack.org/image-guide/obtain-images.html" rel="noopener noreferrer"&gt;https://docs.openstack.org/image-guide/obtain-images.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>proxmox</category>
      <category>kali</category>
      <category>cloudinit</category>
    </item>
  </channel>
</rss>
