Created
December 27, 2021 11:26
-
-
Save JoyGhoshs/2952df40c3f589af1a276537a06ab9fa to your computer and use it in GitHub Desktop.
colab-rdp.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "colab-rdp.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyM4hVVDAhg67QpLRudltiTZ", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/JoyGhoshs/2952df40c3f589af1a276537a06ab9fa/colab-rdp.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"id": "4R7OEbwoAVpf" | |
}, | |
"outputs": [], | |
"source": [ | |
"#@title <center>**RDP SETUP** [Regular User]</center>\n", | |
"#@markdown </br>\n", | |
"#@markdown <br/>\n", | |
"#@markdown <br/>\n", | |
"#@markdown <center>Enter Username and Password For linux</center>\n", | |
"\n", | |
"import os\n", | |
"import subprocess\n", | |
"from google.colab import drive\n", | |
"\n", | |
"username = \"joy\" #@param {type:\"string\"}\n", | |
"password = \"joy123\" #@param {type:\"string\"}\n", | |
"\n", | |
"print(\"[+] Creating User and Setting it up\")\n", | |
"\n", | |
"# Creation of user\n", | |
"os.system(f\"useradd -m {username}\")\n", | |
"\n", | |
"# Add user to sudo group\n", | |
"os.system(f\"adduser {username} sudo\")\n", | |
" \n", | |
"# Set password of user to 'root'\n", | |
"os.system(f\"echo '{username}:{password}' | sudo chpasswd\")\n", | |
"\n", | |
"# Change default shell from sh to bash\n", | |
"os.system(\"sed -i 's/\\/bin\\/sh/\\/bin\\/bash/g' /etc/passwd\")\n", | |
"\n", | |
"print(\"[+] User Created and Configured\")\n", | |
"#@markdown <br/>\n", | |
"\n", | |
"#@markdown <center>Configure Google Remote Desktop</center>\n", | |
"#@markdown <center> Pin Should be 6 digit minimum\n", | |
"\n", | |
"Command = \"DISPLAY= /opt/google/chrome-remote-desktop/start-host --code=\\\"4/0AX4XfWhKPzW5JOvHjP0-WBBQkGM9XE8dWuONVOux8t041U1q8fZY1XtVeTIzuiXpsFjuQg\\\" --redirect-url=\\\"https://remotedesktop.google.com/_/oauthredirect\\\" --name=$(hostname)\" #@param {type:\"string\"}\n", | |
"Pin = 123456 #@param {type: \"integer\"}\n", | |
"\n", | |
"\n", | |
"class CRD:\n", | |
" def __init__(self):\n", | |
" os.system(\"apt update\")\n", | |
" self.installCRD()\n", | |
" self.installDesktopEnvironment()\n", | |
" self.installGoogleChorme()\n", | |
" self.finish()\n", | |
"\n", | |
" @staticmethod\n", | |
" def installCRD():\n", | |
" print(\"Installing Chrome Remote Desktop\")\n", | |
" subprocess.run(['wget', 'https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb'], stdout=subprocess.PIPE)\n", | |
" subprocess.run(['dpkg', '--install', 'chrome-remote-desktop_current_amd64.deb'], stdout=subprocess.PIPE)\n", | |
" subprocess.run(['apt', 'install', '--assume-yes', '--fix-broken'], stdout=subprocess.PIPE)\n", | |
"\n", | |
" @staticmethod\n", | |
" def installDesktopEnvironment():\n", | |
" print(\"Installing Desktop Environment\")\n", | |
" os.system(\"export DEBIAN_FRONTEND=noninteractive\")\n", | |
" os.system(\"apt install --assume-yes xfce4 desktop-base xfce4-terminal\")\n", | |
" os.system(\"bash -c 'echo \\\"exec /etc/X11/Xsession /usr/bin/xfce4-session\\\" > /etc/chrome-remote-desktop-session'\")\n", | |
" os.system(\"apt remove --assume-yes gnome-terminal\")\n", | |
" os.system(\"apt install --assume-yes xscreensaver\")\n", | |
" os.system(\"systemctl disable lightdm.service\")\n", | |
"\n", | |
" @staticmethod\n", | |
" def installGoogleChorme():\n", | |
" print(\"Installing Google Chrome\")\n", | |
" subprocess.run([\"wget\", \"https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb\"], stdout=subprocess.PIPE)\n", | |
" subprocess.run([\"dpkg\", \"--install\", \"google-chrome-stable_current_amd64.deb\"], stdout=subprocess.PIPE)\n", | |
" subprocess.run(['apt', 'install', '--assume-yes', '--fix-broken'], stdout=subprocess.PIPE)\n", | |
"\n", | |
" @staticmethod\n", | |
" def finish():\n", | |
" print(\"Finalizing\")\n", | |
" os.system(f\"adduser {username} chrome-remote-desktop\")\n", | |
" command = f\"{Command} --pin={Pin}\"\n", | |
" os.system(f\"su - {username} -c '{command}'\")\n", | |
" os.system(\"service chrome-remote-desktop start\")\n", | |
" print(\"[+] Finished Succesfully\")\n", | |
"\n", | |
"\n", | |
"try:\n", | |
" if username:\n", | |
" if Command == \"\":\n", | |
" print(\"Please enter authcode from the given link\")\n", | |
" elif len(str(Pin)) < 6:\n", | |
" print(\"Enter a pin more or equal to 6 digits\")\n", | |
" else:\n", | |
" CRD()\n", | |
"except NameError as e:\n", | |
" print(\"username variable not found\")\n", | |
" print(\"Create a User First\")\n", | |
"\n", | |
"print('[+] Mounting Google Drive')\n", | |
"drive.mount('/content/drive')" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment