Last day I was riddling with Evilginx, a phishing attack tool. It needs to be hosted online somewhere in the cloud to get it working. I will write a blog on how to use it and how to to phishing attacks on several web application such as Facebook and Gmail. This time I am talking about configuring SSH access with a Google cloud instance. I acquainted with Amazon AWS while setting up my own blog and I never worked with Google Cloud. So to setup Evilginx I decided to go for Google cloud so that I can get good hands on with compute engine as well. I was able to setup a new project and create a virtual machine pretty quick. The toughest part for me was setting up SSH access to the instance. I didn’t like the web SSH client since I wanted to transfer several contents from my local machine. I had to do a little research because I couldnt easily find one single blog post which deals with the scenario. And so I decided to write a blog post on how to setup SSH with Google cloud compute engine.
How to SSH from command-line to Google Cloud instance
In order to enable third party client SSH you first need to install Google Cloud SDK. To install gcloud-sdk on your Linux machine, type
$curl https://sdk.cloud.google.com | bash
This will install smoothly if you have configured python2 environment in your machine properly. Here’s a video tutorial if in case you find it difficult to do that.
Sometimes the installation may throw the below error if you haven’t configured Python 2.7 environment properly.
Welcome to the Google Cloud SDK! Traceback (most recent call last): File "/home/pratos/google-cloud-sdk/lib/third_party/enum/__init__.py", line 364, in __getattr__ return cls._member_map_[name] KeyError: '_convert'
No need to panic, just create a python2.7 environment
$ conda create --name gcloud python=2.7
It would install the python2 environment in the system at /home/username/miniconda/envs/gcloud/bin/python2.7.
Add the path for CLOUDSDK_PYTHON
$ nano ~/.profile
Edit the file to add
Then source it
$ source ~/.profile
Run the cURL command again
$ curl https://sdk.cloud.google.com | bash
Now SSH using Gcloud:
$ gcloud compute ssh [INTERNAL_INSTANCE_NAME] --internal-ip
Enabling SSH without GCloud tools
Some people like me doesn’t like the idea of using gcloud to simply SSH into my remote machine. I like using the traditional SSH. In order to do this you need to first import your SSH public key to the remote server. Check if you already have a set of public SSH keys:
$ cat ~/.ssh/id_rsa.pub
This will print out your public key if you have already set the SSH keys. If you haven’t created a key in the past, you can do it now. Here is a tutorial to do that.
Next step is to import these keys to your remote Google cloud instance. Enable OS login first using the gcloud command
$ gcloud compute project-info add-metadata --metadata enable-oslogin=TRUE
Now lets move the SSH public keys to our instance.
$ gcloud compute os-login ssh-keys add \ --key-file [KEY_FILE_PATH] \ --ttl [EXPIRE_TIME]
Expiration time can be set if you want your keys to be expired after a certain time interval. I don’t want the key to expire,so I will go for 0.
$gcloud compute os-login ssh-keys add \ > --key-file ~/.ssh/id_rsa.pub \ > --ttl 0
This will show a message which contains your ssh username. That’s it. Let’s Go ahead and SSH to our instance.
$ ssh -i [PATH_TO_PRIVATE_KEY] [USERNAME]@[EXTERNAL_IP_ADDRESS]
The path to private key is ~/.ssh/id_rsa. Provide the password you have set while creating the SSH keys. And there you are, logged into your Google cloud instance!