前言

最近准备学渗透测试(其实是想学怎么黑垃圾网站),看了许多教程都是用的Kali Linux,所以准备先装个环境先。想起DigitalOcean还有多余的额度,已经吃灰好久的服务器终于派上用场了。

官方也有教程,看这两个足矣:

  1. 在DigitalOcean上使用自定义镜像:https://docs.digitalocean.com/products/images/custom-images/
  2. 在DigitalOcean上使用kali:https://www.kali.org/docs/cloud/digitalocean/#install-required-packages

其实直接上传官方的VM文件然后安装也可以,但kali官方也说了:

By default, the Kali Linux ISOs on the download page have a desktop environment installed, and while we could use it to build a virtual machine, we want to minimize the amount of data we have to upload to DigitalOcean for reasons we will talk about later. Having a GUI running on a headless system is also a waste of resources so while we could uninstall it or disable it, we’ll install the virtual machine using a netboot ISO. If you are comfortable with a text installation, grab the mini.iso in this directory. If not, head to the gtk/ directory and grab the mini.iso in there, which will start a graphical installer.

意思是我们大可不必安装桌面环境,可以用它提供的netboot镜像安装更简约的系统。但这个坑爹的地方是,DigitalOcean不支持iso安装,需要我们新建一个虚拟机,安装好之后,把虚拟机上传成自定义镜像。因为VMware是收费的,我也不想使用盗版,所以干脆使用VirtualBox了。

VirtualBox下载地址:https://www.virtualbox.org/wiki/Downloads

安装过程

1 新建虚拟机(本地)

在官方下载netboot镜像(mini.iso):http://http.kali.org/kali/dists/kali-rolling/main/installer-amd64/current/images/netboot/

在VirtualBox中新建虚拟机

镜像选择我们下载的mini.iso,Debian系统要改成64位的,我这个上面忘了修改了。

接下来的过程跟着屏幕提示就行,我建议不要安装中文操作系统,避免不必要的麻烦。

这一步没必要安装桌面环境了,可以节省一点资源。

附言:

  1. 如果实在需要一步一步跟着走的话,可以参考这个:https://blog.csdn.net/qq_33336310/article/details/105456266
  2. 如果网速是在太慢,也可以下载离线安装包:https://www.kali.org/get-kali/#kali-installer-images,但是这个安装出的包不够精简,倒不如直接下载虚拟机算了。

2 配置虚拟机

重启后登录虚拟机,接下来的过程我完全跟着官方:

升级系统

sudo apt update
sudo apt full-upgrade -y

安装依赖包

sudo apt install -y cloud-init
echo 'datasource_list: [ ConfigDrive, DigitalOcean, NoCloud, None ]' > /etc/cloud/cloud.cfg.d/99_digitalocean.cfg 
sudo systemctl enable cloud-init --now

安装并启用ssh

sudo apt install -y openssh-server
sudo systemctl enable ssh.service --now

删除root用户的密码(因为自定义镜像只支持ssh key登录)

passwd -d root

新建一个.ssh文件夹

mkdir -p /root/.ssh/

清理文件

apt autoremove
apt autoclean
rm -rf /var/log/*
history -c

关机

poweroff

3 上传虚拟机

定位到虚拟机所在的文件夹,然后使用bzip2压缩

在DigitalOcean的后台(https://cloud.digitalocean.com/images/custom_images)上传这个压缩文件

然后用这个镜像新建一个droplet即可。