From e28f8d4d9a7357981e3b906de915ba2f52b6b506 Mon Sep 17 00:00:00 2001 From: Gijs Molenaar Date: Sun, 7 Oct 2018 15:01:45 +0200 Subject: [PATCH] add notebooks --- notebooks/os.detection.ipynb | 67 +++++++++++++++++++++++++ notebooks/requirements.txt | 1 + notebooks/secure_dns_spoofing.ipynb | 77 +++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 notebooks/os.detection.ipynb create mode 100644 notebooks/requirements.txt create mode 100644 notebooks/secure_dns_spoofing.ipynb diff --git a/notebooks/os.detection.ipynb b/notebooks/os.detection.ipynb new file mode 100644 index 00000000..39bfd26e --- /dev/null +++ b/notebooks/os.detection.ipynb @@ -0,0 +1,67 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "def detect_distro():\n", + " params = {}\n", + " with open('/etc/os-release', 'r') as f:\n", + " for line in f.readlines():\n", + " key, value = line.strip().split('=')\n", + " params[key] = value.strip('\"\"')\n", + " return params['ID'], params['VERSION_ID']" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('ubuntu', '18.04')" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "detect_distro()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/requirements.txt b/notebooks/requirements.txt new file mode 100644 index 00000000..886e8262 --- /dev/null +++ b/notebooks/requirements.txt @@ -0,0 +1 @@ +notebook diff --git a/notebooks/secure_dns_spoofing.ipynb b/notebooks/secure_dns_spoofing.ipynb new file mode 100644 index 00000000..c8c53105 --- /dev/null +++ b/notebooks/secure_dns_spoofing.ipynb @@ -0,0 +1,77 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import eduvpn.other_nm as NetworkManager\n", + "import dbus\n", + "import subprocess" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "type_tun = 16 # NM_DEVICE_TYPE_TUN\n", + "state_acticated = 100 # NM_DEVICE_STATE_ACTIVATED\n", + "devices = NetworkManager.NetworkManager.GetDevices() \n", + "interfaces = [x.Interface for x in devices if x.State == state_acticated and x.DeviceType == type_tun]\n", + "assert(len(interfaces) == 1)\n", + "interface = interfaces[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "link = int(subprocess.check_output(['/sbin/ip', 'link', 'show', 'dev', interface]).decode('ascii').split()[0][:-1])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "bus = dbus.SystemBus()\n", + "\n", + "node = \"/org/freedesktop/resolve1\"\n", + "bus_name = 'org.freedesktop.resolve1'\n", + "interface = \"org.freedesktop.resolve1.Manager\"\n", + "\n", + "resolve_proxy = bus.get_object(bus_name=bus_name, object_path=node)\n", + "resolve_iface = dbus.Interface(object=resolve_proxy, dbus_interface=interface)\n", + "\n", + "resolve_iface.SetLinkDomains(link, ((\".\", True),))" + ] + } + ], + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}