what is google colab? & Using it as a free RDP

A.R Maheer
5 min readDec 27, 2021

--

What is colab?

Answer will be more meaningful if you ask what is google colab , colab is the short form for Colaboratory , its a product from google , colab’s main motive was to create a environment where many developer can collaborate in a single project , mainly it was created for practicing and creating project based on machine learning / data analysis using python3. Its similar to jupyter notebook. Jupyter notebook is an opensource notebook where you can run code live and run every code block separately if you want. It gives to an advantage to write clean code and see what are the output of the code

So lets See what advantage google colab offer us for free it offer us single 12GB NVIDIA Tesla K80 GPU that can be used up to 12 hours continuously.So lets take that advantage and use this colab as rdp for free. Lets check some of google colab functions.

  • +Code will create a block where you can write your code.
  • +Text will create a block where you can write text like instruction or any disclaimer.

After Creating a new code block you can run os command by only adding (!) before the os command.

Play button will run your written code . You can also write markdown before the code to write what is the code for , to write markdown on a code block you just have to add (#@markdown) and after that you can start writing markdown. It will live render the markdown.

You also can take user input graphically on your python variable just using and build in function of colab param . just add a simple variable and add (#@param {type:”string”}). Example :

var = "Default value" #@param {type:"string"} // can change type 

Now We are gonna use the functions and ability to create a rdp using google colab.

Open This gist on your colab , if you are familiar with python this script explains itself. We are gonna use google remote desktop to connect to our desktop environment.Our work is not that hard now we just have to do four thing

copy debian linux command from https://remotedesktop.google.com/headless page and paste it on this form.

now just click the run button after 1–2 minute it will show google drive access prompt , remember we are using google drive to store our os data so it doesn’t get lost after the instance is killed. and go to https://remotedesktop.google.com/access and wait for incoming connection, if you never used google remote desktop your remote desktop access will be empty like the image below.

after 2–3 minute you will get the connection.

now click on this device , it will ask for a pin enter your pin you configured on colab note.

here we go our rdp is connected .

but we have a problem after 10 minutes of inactive tab the colab will suspend this machine , don’t worry we have a solution for that , we are gonna create a javascript to automatically click a connect button after every 1 minute . first we have to find the button id to click the connect button.when we go to inspect element we can see some some id with id inside .

now lets create a function , inside the function we will select #top-toolbar it contains all toolbar. then the colab-connect-button which is the connect button and then the #connect id located inside shadowRoot after that will will use click() function to click this button.

function ClickConnect() {
document
.querySelector('#top-toolbar > colab-connect-button')
.shadowRoot.querySelector('#connect')
.click()
}

if you call this function it will click the connect button single time but we want to click the button after every one minute we can use a javascript built in setInterval() to call it after every one minute. now the code will look like.

function ClickConnect() {
console.log('Clicked')
document
.querySelector('#top-toolbar > colab-connect-button')
.shadowRoot.querySelector('#connect')
.click()
}

setInterval(ClickConnect, 60000)//milliseconds

I have added a console log with text clicked in it to show it after its been clicked. now we have to paste it on the console of google colab page.

now it will press click button after every one minute until you close the tab.

Thanks For Reading.

--

--

A.R Maheer
A.R Maheer

Written by A.R Maheer

Security Researcher | Penetration Tester

Responses (1)