mirror of
https://github.com/Wojtek242/route0.git
synced 2024-12-21 23:24:39 +01:00
Port remaining files for the BGP hijack demo
This commit is contained in:
parent
ee4a4fe684
commit
8a2a15351a
11
route0.py
11
route0.py
@ -1,4 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
"""Route 0 is a suite for learning about and experimenting with routing
|
||||
protocols. It uses the [Free Range Routing (FRR)](https://frrouting.org/)
|
||||
protocol implementations running on top of a network setup locally using
|
||||
[Mininet](http://mininet.org/).
|
||||
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
@ -69,6 +74,10 @@ def run(experiment):
|
||||
node.cmd("sysctl -w net.ipv4.ip_forward=1")
|
||||
node.waitOutput()
|
||||
|
||||
# Run scenario script if one has been provided.
|
||||
if experiment.script is not None:
|
||||
experiment.script(net)
|
||||
|
||||
CLI(net)
|
||||
net.stop()
|
||||
if experiment.daemons:
|
||||
|
0
topology/line_03_and_rogue/scenario/__init__.py
Normal file
0
topology/line_03_and_rogue/scenario/__init__.py
Normal file
22
topology/line_03_and_rogue/scenario/bgp_hijack/scenario.py
Normal file
22
topology/line_03_and_rogue/scenario/bgp_hijack/scenario.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""Script to launch web servers for the BGP hijack demo."""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def script(net):
|
||||
"""The script."""
|
||||
|
||||
# Clean up after any previous experiment.
|
||||
os.system('pgrep -f webserver.py | xargs kill -9')
|
||||
|
||||
# Start honest server.
|
||||
net.getNodeByName("h3_1") \
|
||||
.popen("python"
|
||||
" topology/line_03_and_rogue/scenario/bgp_hijack/webserver.py"
|
||||
" --text 'Default web server'", shell=True)
|
||||
|
||||
# Start rogue server
|
||||
net.getNodeByName("h4_1") \
|
||||
.popen("python"
|
||||
" topology/line_03_and_rogue/scenario/bgp_hijack/webserver.py"
|
||||
" --text '*** Attacker web server ***'", shell=True)
|
13
topology/line_03_and_rogue/scenario/bgp_hijack/start_rogue.sh
Executable file
13
topology/line_03_and_rogue/scenario/bgp_hijack/start_rogue.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(readlink -f $0)
|
||||
DIRNAME=$(dirname $SCRIPT)
|
||||
|
||||
echo "Killing any existing rogue AS"
|
||||
$DIRNAME/stop_rogue.sh
|
||||
|
||||
echo "Starting rogue AS"
|
||||
sudo python $DIRNAME/../../../../attach.py --node R4 \
|
||||
--cmd "/usr/lib/frr/zebra -f $DIRNAME/../../zebra/R4.conf.rogue -d -i /tmp/R4-zebra.pid > /tmp/R4-zebra.out"
|
||||
sudo python $DIRNAME/../../../../attach.py --node R4 \
|
||||
--cmd "/usr/lib/frr/bgpd -f $DIRNAME/bgpd/R4.conf.rogue -d -i /tmp/R4-bgpd.pid > /tmp/R4-bgpd.out"
|
7
topology/line_03_and_rogue/scenario/bgp_hijack/stop_rogue.sh
Executable file
7
topology/line_03_and_rogue/scenario/bgp_hijack/stop_rogue.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(readlink -f $0)
|
||||
DIRNAME=$(dirname $SCRIPT)
|
||||
|
||||
sudo python $DIRNAME/../../../../attach.py --node R4 --cmd "pgrep -u frr -f R4-zebra | xargs -r kill -9"
|
||||
sudo python $DIRNAME/../../../../attach.py --node R4 --cmd "pgrep -u frr -f R4-bgpd | xargs -r kill -9"
|
24
topology/line_03_and_rogue/scenario/bgp_hijack/webserver.py
Normal file
24
topology/line_03_and_rogue/scenario/bgp_hijack/webserver.py
Normal file
@ -0,0 +1,24 @@
|
||||
import SimpleHTTPServer
|
||||
import SocketServer
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--text', default="Default web server")
|
||||
FLAGS = parser.parse_args()
|
||||
|
||||
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
# Disable logging DNS lookups
|
||||
def address_string(self):
|
||||
return str(self.client_address[0])
|
||||
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/html")
|
||||
self.end_headers()
|
||||
self.wfile.write("<h1>%s</h1>\n" % FLAGS.text)
|
||||
self.wfile.flush()
|
||||
|
||||
|
||||
PORT = 80
|
||||
httpd = SocketServer.TCPServer(("", PORT), Handler)
|
||||
httpd.serve_forever()
|
15
topology/line_03_and_rogue/scenario/bgp_hijack/website.sh
Executable file
15
topology/line_03_and_rogue/scenario/bgp_hijack/website.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
node=${1:-h1_1}
|
||||
bold=`tput bold`
|
||||
normal=`tput sgr0`
|
||||
|
||||
SCRIPT=$(readlink -f $0)
|
||||
DIRNAME=$(dirname $SCRIPT)
|
||||
|
||||
while true; do
|
||||
out=`sudo python $DIRNAME/../../../../attach.py --node $node --cmd "curl -s 13.0.1.1"`
|
||||
date=`date`
|
||||
echo $date -- $bold$out$normal
|
||||
sleep 1
|
||||
done
|
@ -1,11 +1,16 @@
|
||||
"""The experiment module is responsible for collecting topology and scenario
|
||||
settings.
|
||||
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
class Experiment(object):
|
||||
"""Class that describes a network experiment. An experiment is a particular
|
||||
combination of topology and scenario.
|
||||
class Experiment:
|
||||
"""Class that describes a network experiment. An experiment is a
|
||||
particular combination of topology and scenario.
|
||||
|
||||
A topology determines the nodes and their links in the network.
|
||||
|
||||
@ -37,6 +42,7 @@ class Experiment(object):
|
||||
# Check if the scenario directory exists. If it does work out which
|
||||
# daemons are to be used and on which nodes. If the scenario is
|
||||
# "basic" skip this step.
|
||||
self._scenario_script = None
|
||||
if scenario != "basic":
|
||||
scenario_dir = os.path.join(topo_dir,
|
||||
"scenario/{}".format(scenario))
|
||||
@ -48,6 +54,16 @@ class Experiment(object):
|
||||
for daemon in os.listdir(scenario_dir):
|
||||
self._get_daemon_nodes(scenario_dir, daemon)
|
||||
|
||||
# If there is a scenario.py in the directory import the script
|
||||
# function from it.
|
||||
if os.path.exists(os.path.join(scenario_dir, "scenario.py")):
|
||||
self._scenario_script = (
|
||||
importlib
|
||||
.import_module("topology.{}.scenario.{}.scenario"
|
||||
.format(topology, scenario))
|
||||
.script
|
||||
)
|
||||
|
||||
# Zebra and staticd daemons are special. If they don't have an
|
||||
# override in the scenario directory, take the defaults from the
|
||||
# topology directory.
|
||||
@ -80,3 +96,10 @@ class Experiment(object):
|
||||
|
||||
"""
|
||||
return self._topo
|
||||
|
||||
@property
|
||||
def script(self):
|
||||
"""The script to run after the daemons have been started.
|
||||
|
||||
"""
|
||||
return self._scenario_script
|
||||
|
Loading…
Reference in New Issue
Block a user