Thursday, August 18, 2016

Hacking Cloud VM to use User password to Login(2)


Hacking Cloud VM to use User password to Login(2)

Based on my previous blog that talk about how to hack cloud image and we then can login to VM by using use and password directly.

Thanks for this blog that describe the detailed process to hack vm.

The following the the process cmd based on the above blog, and it works greatly.

  qemu-img convert -c -O qcow2 trusty-server-cloudimg-amd64-disk1.img trusty-server-cloudimg-amd64-disk1_30GB.qcow2
  qemu-img resize trusty-server-cloudimg-amd64-disk1_30GB.qcow2 30G
  sudo modprobe nbd
  sudo qemu-nbd -c /dev/nbd0 `pwd`/trusty-server-cloudimg-amd64-disk1_30GB.qcow2
  ls image || mkdir image
  sudo mount /dev/nbd0p1 image
  sudo sed -ri 's|(/boot/vmlinuz-3.13.0-24-generic\s*root=LABEL=cloudimg-rootfs.*)$|\1 ds=nocloud|' image/boot/grub/grub.cfg
  sudo sed -ri 's|^(GRUB_CMDLINE_LINUX_DEFAULT=).*$|\1" ds=nocloud"|' image/etc/default/grub
  sudo sed -ri 's|^#(GRUB_TERMINAL=console)$|\1|' image/etc/default/grub
  sudo mkdir -p image/var/lib/cloud/seed/nocloud
  sudo tee image/var/lib/cloud/seed/nocloud/meta-data <<EOF
instance-id: ubuntu
local-hostname: ubuntu

  sudo tee image/var/lib/cloud/seed/nocloud/user-data <<EOF
password: ubuntu
chpasswd: { expire: False }
ssh_pwauth: True

  sudo sed -ri "s|^(\s*localhost)$|\1\n127.0.0.1 `cat image/etc/hostname`|" image/etc/hosts
  sudo sync
  sudo umount image
  sudo qemu-nbd -d /dev/nbd0
  sudo modprobe -r nbd

No comments:

Post a Comment