Anonymous avatar Anonymous committed cbdce1f

add ManualExperiment , it can read oconfigure file from net_setting.py

Comments (0)

Files changed (18)

core/ns3/Topology.py

 
 # from Topology import TopologyReaderHelper
 from ns.nix_vector_routing import Ipv4NixVectorHelper
-from ns.network import NetDeviceContainer
+# from ns.network import NetDeviceContainer
 from ns.point_to_point import PointToPointHelper
 from ns.network import Ipv4Address, Ipv4Mask
 from ns.network import NodeContainer
-from ns.internet import Ipv4InterfaceContainer, Ipv4InterfaceAddress
-from ns.core import ofstream
+# from ns.internet import Ipv4InterfaceContainer, Ipv4InterfaceAddress
 import ns3
 import sys
 class TopologyNet():
+    """Load Topology File and Contruct the Network Accordingly"""
     def __init__(self, _input, _format, NodeCreator, *args, **kwargs):
         self._input = _input
         self._format = _format
         ns3.Ipv4GlobalRoutingHelper.PopulateRoutingTables()
 
     def load_file(self):
+        """Load Topology File"""
         self.inFile, self.nodes = self._load_file(self._input, self._format, self.NodeCreator)
 
     def install_stack(self):
+        """Install Internet Stack"""
         self._install_stack(self.nodes)
 
     def init_link(self):
+        """Construct Point to Point Link in the Network"""
         self.linksC = self._init_link(self.inFile)
 
     def init_net_device(self, *args, **kwargs):
+        """Initial the ip address and network devices"""
         self.ndc, self.ipic = self._init_net_device(self.inFile, self.linksC, *args, **kwargs)
 
+    def set_pcap_trace():
+        pass
+
     @staticmethod
     def _load_file(_input, _format, NodeCreator):
         topoHelp = TopologyReaderHelper()
         staticRouting = ns.internet.Ipv4StaticRoutingHelper()
         # olsr = ns3.OlsrHelper()
 
-
         listRH = ns.internet.Ipv4ListRoutingHelper()
         listRH.Add(staticRouting, 0)
         listRH.Add(nixRouting, 10)
                 # base=Ipv4Address(ipv4AddrBase)
                 # base=Ipv4Address('0.0.0.1')
                 )
-        # print ipv4NetworkBase
-        # print ipv4Mask
-        # print ipv4AddrBase
 
         ipic = [] #ip interface container
         for i in xrange(totlinks):
             ipic.append( address.Assign(ndc[i]) )
             address.NewNetwork()
 
+        # from ns.core import ofstream
         # _ascii = ofstream("wifi-ap.tr")
         # p2p.EnableAsciiAll("test")
 
         return ndc, ipic
 
+
+def get_net(ipaddress, netmask):
+    ip = ipaddress.split(".")
+    netm = netmask.split(".")
+    network = str(int(ip[0])&int(netm[0]))+"."+str(int(ip[1])&int(netm[1]))+"."+str(int(ip[2])&int(netm[2]))+"."+str(int(ip[3])&int(netm[3]))
+    return network
+
+def get_net_addr(ipaddress, netmask):
+    ip = ipaddress.split(".")
+    netm = netmask.split(".")
+    addr = str(int(ip[0])&(~int(netm[0])))+"."+str(int(ip[1])&(~int(netm[1])))+"."+str(int(ip[2])& (~int(netm[2])))+"."+str(int(ip[3])&(~int(netm[3])))
+    print 'addr, ', addr
+    return addr
+
+
+from util import len2mask
+# import ns3
+class ManualTopologyNet(TopologyNet):
+    """Topology network with manual ip settings"""
+    @staticmethod
+    def CIDR_to_subnet_mask(s_addr):
+        addr, prefix_len = s_addr.rsplit('/')
+        mask = len2mask(int(prefix_len))
+        net = get_net(addr, mask)
+        print 'addr, ', addr, 'mask, ', mask, 'net, ', net
+        return addr, net, mask
+
+    def get_link_name(self, i):
+        link = self.inFile.m_linksList[i]
+        link_name = (int(link.GetFromNodeName()), int(link.GetToNodeName()) )
+        return link_name
+
+    def get_link_attr(self, i):
+        default = self.net_settings.link_attr_default
+        return self.net_settings.link_attr.get(self.get_link_name(i), default)
+
+    def init_net_device(self, net_settings, *args, **kwargs):
+        """Initial the ip address and network devices"""
+        self.net_settings = net_settings
+        totlinks = self.inFile.LinksSize()
+        p2p = ns3.PointToPointHelper()
+        ndc = [] # Net Device Container
+        for i in xrange(totlinks):
+            Delay, DataRate = self.get_link_attr(i)
+            p2p.SetChannelAttribute("Delay", ns.core.StringValue(Delay))
+            p2p.SetDeviceAttribute("DataRate", ns.core.StringValue(DataRate))
+            ndc.append( p2p.Install( self.linksC[i]) )
+
+        # Create little subnets, one for each couple of nodes
+        defaultAddressHelper = ns3.Ipv4AddressHelper()
+        defaultAddr, defaultNetBase, defaultMask = self.CIDR_to_subnet_mask(net_settings.ipv4_net_addr_base)
+        netAddr = get_net_addr(defaultAddr, defaultMask)
+        defaultAddressHelper.SetBase(
+                network=ns3.Ipv4Address(defaultNetBase),
+                mask = ns3.Ipv4Mask(defaultMask),
+                base = ns3.Ipv4Address(netAddr),
+                )
+
+        addressHelper = ns3.Ipv4AddressHelper()
+        ipic = [] #ip interface container
+        for i in xrange(totlinks):
+            ips = self.net_settings.link_to_ip_map.get(self.get_link_name(i), None)
+            if not ips:
+                ipic.append( defaultAddressHelper.Assign(ndc[i]) )
+                addressHelper.NewNetwork()
+                continue
+
+            addr, netBase, mask = self.CIDR_to_subnet_mask(ips[0])
+            net_addr = get_net_addr(addr, mask)
+            print 'net_addr, ', net_addr
+            addressHelper.SetBase(
+                    network=ns3.Ipv4Address(netBase),
+                    mask = ns3.Ipv4Mask(mask),
+                    base = ns3.Ipv4Address(net_addr),
+                    )
+            ip1 = addressHelper.Assign(ns3.NetDeviceContainer(ndc[i].Get(0)))
+
+            addr, netBase, mask = self.CIDR_to_subnet_mask(ips[1])
+            net_addr = get_net_addr(addr, mask)
+            addressHelper.SetBase(
+                    network=ns3.Ipv4Address(netBase),
+                    mask = ns3.Ipv4Mask(mask),
+                    base = ns3.Ipv4Address(net_addr)
+                    )
+            ip2 = addressHelper.Assign(ns3.NetDeviceContainer(ndc[i].Get(1)))
+            ipic.append((ip1, ip2))
+
+        self.p2p = p2p
+
+        # from ns.core import ofstream
+        # _ascii = ofstream("wifi-ap.tr")
+        # p2p.EnableAsciiAll("test")
+
+        return ndc, ipic
+
+
 def main():
     topoHelper = TopologyReaderHelper()
     topoHelper.SetFileType('Inet')
Add a comment to this file

doc/build/html/.doctrees/environment.pickle

Binary file modified.

Add a comment to this file

doc/build/html/.doctrees/index.doctree

Binary file modified.

Add a comment to this file

doc/build/html/_images/client_fsm.png

Added
New image
Add a comment to this file

doc/build/html/_images/genearal-structure9.png

Added
New image
Add a comment to this file

doc/build/html/_images/imalse-abstract9.png

Added
New image

doc/build/html/_sources/index.txt

 The basic botnet mechanism can be described as **F**\ inite **S**\ tate **M**\
 achine. The **FSM** for the **ClientCMD** is as follows:
 
-.. image:: ./figure/client_fsm.svg
+.. image:: ./figure/client_fsm.png
     :align: center 
     :height: 400px
 

doc/build/html/index.html

 <li><strong>hybrid approach</strong>: of pure ns3 mode and netns3 mode</li>
 </ul>
 </div></blockquote>
-<img alt="_images/imalse-abstract8.png" class="align-center" src="_images/imalse-abstract8.png" />
+<img alt="_images/imalse-abstract9.png" class="align-center" src="_images/imalse-abstract9.png" />
 <div class="section" id="typical-use-case">
 <h3>Typical Use Case<a class="headerlink" href="#typical-use-case" title="Permalink to this headline">¶</a></h3>
 <p>Suppose Conan is a Ph.D student who has proposed a novel anomaly
 <p>To support the variety of modes noted above, Imalse design in a way that to
 seperate the botnet mechanism and the network.</p>
 <p>The general structure of Imalse is shown in the following figure:</p>
-<img alt="_images/genearal-structure8.png" class="align-center" src="_images/genearal-structure8.png" />
+<img alt="_images/genearal-structure9.png" class="align-center" src="_images/genearal-structure9.png" />
 <p><strong>Node</strong> and <strong>C</strong>ommand <strong>M</strong>eta <strong>D</strong>escription are the two key concepts in the design.
 <strong>Node</strong> is the abstraction of a real computer. A node should support:</p>
 <blockquote>
 botnet by subclassing <strong>ServerCMD</strong>, <strong>ClientCMD</strong> and <strong>BotmasterCMD</strong>, each
 flavor is called a new <strong>scenario</strong>.</p>
 <p>The basic botnet mechanism can be described as <strong>F</strong>inite <strong>S</strong>tate <strong>M</strong>achine. The <strong>FSM</strong> for the <strong>ClientCMD</strong> is as follows:</p>
-<div align="center" class="align-center"><object data="_images/client_fsm8.svg" height="400px" type="image/svg+xml"><embed height="400px" src="_images/client_fsm8.svg" type="image/svg+xml" /></object>
-</div>
+<img alt="_images/client_fsm.png" class="align-center" src="_images/client_fsm.png" style="height: 400px;" />
 </div>
 <div class="section" id="scenario">
 <h3>Scenario:<a class="headerlink" href="#scenario" title="Permalink to this headline">¶</a></h3>

doc/build/html/objects.inv

 # Project: imalse
 # Version: 0.0
 # The remainder of this file is compressed using zlib.
-xڭVKo�0
-�ы����Բ�_�(��QaO+�`�B��{yo#Mu��\���[�c��6Q��Zl�ŵ�]\��*���F
-V^6��
+xڭUMo�0��W 5�E�z˭M+eY���[�=
+�2Me1�w��ِ��ƀ(݂��PBs��ꐸ�T�}yNCU6�j��J.%3X0	U�( ����9<�����O��,�{�
+

doc/build/html/searchindex.js

-Search.setIndex({objects:{core:{CMD:[1,2,1]},"core.Server":{ServerCMD:[1,2,1]},"core.Client.ClientCMD":{recv_disconn_req:[1,1,1],request_connect:[1,1,1],recv_ack:[1,1,1],echo:[1,1,1],request_time_out:[1,1,1],connection_refused:[1,1,1]},"core.ns3.Experiment.ImalsePureSimExperiment":{event:[1,3,1]},"core.ns3":{Topology:[1,0,1]},"core.ns3.Topology":{TopologyReaderHelper:[1,2,1],TopologyNet:[1,2,1],TopologyReader:[1,2,1],InetTopologyReader:[1,2,1]},"core.CMD":{start:[1,1,1],dispatcher:[1,1,1],install:[1,1,1]},"core.BaseNode.BaseNode":{close_socks:[1,1,1]},"core.ns3.Experiment":{ImalseExperiment:[1,2,1],ImalsePureSimExperiment:[1,2,1],ImalseNetnsExperiment:[1,2,1]},"core.BaseNode":{BaseNode:[1,2,1]},"core.Server.ServerCMD":{initialize:[1,1,1],echo_bots:[1,1,1],recv_request_conn:[1,1,1],dispatcher:[1,1,1],verify_master:[1,1,1]},"core.ns3.Node":{ImalseNetnsNode:[1,2,1],ImalseNetnsSimNode:[1,2,1],PhyNode:[1,2,1]},"core.Client":{ClientCMD:[1,2,1]},"core.ns3.Node.ImalseNetnsSimNode":{add_msg_deprec:[1,3,1],after:[1,1,1],get_msg:[1,3,1],get_msg_deprec:[1,3,1],connect:[1,1,1],add_msg:[1,3,1],dispatcher:[1,1,1]},"core.ns3.Experiment.ImalseExperiment":{print_srv_addr:[1,1,1],node_run:[1,1,1],get_node:[1,1,1],start_nodes:[1,1,1]},"core.ns3.Node.PhyNode":{close_socks:[1,1,1]},"core.ns3.Experiment.ImalseNetnsExperiment":{get_node:[1,1,1]}},terms:{all:[0,1],concept:0,botmastercmd:0,consum:0,tapbridg:0,code:0,sleep:0,edu:1,follow:0,topoexperi:0,request_timeout:1,decid:0,depend:[0,1],send:[0,1],init:0,under:0,introduc:0,"_type":1,sourc:[0,1],string:1,far:1,phynod:1,reader:1,imalsenetnsnod:1,util:0,novel:0,mechan:0,veri:0,strang:0,level:[0,1],cmd:[0,1],upload:0,escript:0,emul:[0,1],small:0,pleas:0,fortun:0,request_connect:1,seper:0,past:0,second:[0,1],design:0,pass:0,download:0,even:1,index:[0,1],what:0,botmast:0,section:[0,1],overload:0,access:0,version:0,"new":0,method:[0,1],gener:[0,1],behaviour:0,connection_refus:1,exper_fnam:0,pygoocanva:0,sinc:0,wait:1,search:[0,1],addr_port:1,behav:0,implement:[0,1],socks_seq_set:1,modul:[0,1],apt:0,ask:0,api:[0,1],instal:[0,1],select:0,plot:0,from:[0,1],describ:0,commun:0,two:[0,1],few:0,music:0,recommend:0,msg:1,type:[0,1],inet:[0,1],more:[0,1],diamond:0,peopl:0,umich:1,pylint:0,accept:1,ommand:0,compani:0,ware:0,must:0,none:1,join:0,work:0,dev:0,netsecur:0,can:[0,1],root:0,def:0,control:0,claim:1,tarbar:0,process:0,sudo:0,indic:[0,1],want:0,hbhzwj:0,cours:0,thing:0,ping:0,write:0,how:0,machinc:0,instead:0,sim:[0,1],confid:0,map:0,clone:0,after:[0,1],usabl:1,befor:0,attent:0,mai:[0,1],data:[0,1],mal:0,physic:1,clientcmd:[0,1],bind:[0,1],file_exfiltr:0,issu:0,inform:0,maintain:1,combin:0,secnario:0,netn:1,least:0,help:0,ith:1,echo_bot:1,itd:0,imul:0,paper:0,through:0,still:0,dynam:0,paramet:0,setacceptcallback:1,video:0,disconnect:1,onc:0,nodecr:1,unknowneventexcept:1,"return":[0,1],pure:[0,1],thei:0,handl:1,dai:0,initi:[0,1],framework:0,botnet:[0,1],verifi:1,now:0,introduct:0,name:[0,1],realist:0,good:0,mode:[0,1],each:[0,1],found:0,higher:0,netns3:[0,1],navi:0,approari:1,meta:1,"static":1,connect:[0,1],verify_mast:1,event:[0,1],out:[0,1],ftp:0,shown:0,network:[0,1],dsr:0,research:0,content:1,adapt:1,internet:0,print:1,srv_port:1,forth:0,factori:0,integr:0,clarifi:0,manipul:0,reason:0,base:[0,1],achin:0,org:0,recv:1,bash:0,care:0,client_sock:1,launch:0,imalsenetnsexperi:[0,1],put:0,refus:1,turn:0,propos:0,think:0,first:0,softwar:0,reimplement:1,staticrouteexperi:0,independ:0,echo:1,request_time_out:1,alreadi:0,done:0,messag:[0,1],open:0,topologyreaderhelp:1,differ:0,start_nod:1,tate:0,system:0,construct:[0,1],mercuri:0,checker:0,master:1,allinon:0,scheme:0,includ:0,malwar:0,namespac:[0,1],tool:0,copi:0,specifi:1,part:0,pars:1,recv_ack:1,mode_map:0,exactli:0,than:0,serv:0,enjoi:0,recv_disconn_req:1,provid:[0,1],structur:0,project:0,toposimexperi:0,comput:0,ani:0,correspond:0,packag:0,have:0,tabl:[0,1],need:0,close_sock:1,mil:0,callback:1,self:1,client:[0,1],note:0,pybindgen:1,take:0,which:0,techniqu:0,though:0,who:0,most:0,attack:0,deploi:0,pygraphviz:0,"class":[0,1],don:0,flow:0,schedu:1,declar:0,pacetk:1,"_path":0,baseclass:0,"94d1ff15736f":0,syntax:0,hack:1,current:0,onli:0,"_input":1,"_format":1,configur:0,solut:0,forev:0,should:[0,1],won:0,suppos:0,analyz:0,rich:0,folder:0,local:0,get:[0,1],becaus:0,cannot:1,mulat:0,requir:[0,1],add_msg_deprec:1,topolog:[0,1],whether:0,common:0,contain:[0,1],set:[0,1],servercmd:[0,1],packet:[0,1],result:0,arg:1,close:1,detect:0,kei:[0,1],pattern:0,pacekt:1,figur:0,enclosur:1,"import":0,experi:[0,1],approach:0,demostr:0,xvf:0,accord:0,extend:0,get_msg:1,extens:0,lazi:0,succeed:1,imals:[0,1],recv_request_conn:1,satisfi:0,last:0,vitur:0,eta:0,whole:0,comment:0,simpli:1,kwd:1,point:0,schedul:[0,1],ns3_path:0,address:[0,1],dispatch:1,littl:0,linux:[0,1],imalsepuresimexperi:[0,1],quit:0,xzvf:0,anomali:0,three:0,been:[0,1],json:1,much:[0,1],interest:0,basic:[0,1],dure:0,defind:0,execfil:0,func:1,input:0,node_run:1,"case":0,ident:1,defin:[0,1],outcom:0,abov:0,intranet:0,tar:0,ddos_ping_flood:0,demo:0,convinc:0,worri:0,kwarg:1,incom:0,revis:0,pygccxml:0,sever:0,welcom:0,saml:0,receiv:1,make:0,transpar:0,start_act:1,same:0,member:0,python:[0,1],html:0,pai:0,document:[0,1],complet:0,finish:0,http:[0,1],imalseexperi:1,experiemtn:1,rais:1,user:0,student:0,whenver:0,typic:0,recent:0,scenario:0,ntegrat:0,exampl:[0,1],command:[0,1],bot:[0,1],thi:[0,1],model:0,rout:0,ubuntu:0,usual:0,load:0,just:[0,1],less:0,print_srv_addr:1,shape:0,topologynet:1,flavor:0,characterist:0,had:0,compromis:0,add:[0,1],sock_seq_set:1,experimetn:0,botmster:0,transit:1,build:0,real:[0,1],applic:[0,1],topologyread:1,format:1,read:[0,1],avali:0,testb:0,traffic:0,know:0,bit:0,password:[0,1],add_msg:1,inettopologyread:1,desc:1,like:0,specif:[0,1],filenam:1,imalsenetnssimnod:1,manual:0,server:[0,1],collect:0,specifii:0,page:[0,1],eec:1,www:0,deal:0,srv_addr:1,some:0,back:1,certain:0,sampl:0,successfulli:0,deploy:0,definit:0,subclass:0,when:[0,1],ddo:0,refer:0,machin:[0,1],core:[0,1],previou:0,run:[0,1],host:0,execu:0,wget:0,get_nod:1,src:[],about:0,actual:0,socket:[0,1],ack:1,send_p:0,simul:[0,1],bz2:0,experiment_factori:0,disabl:0,block:1,own:0,ddos_ping_attack:0,encod:1,automat:0,save:0,chang:0,wai:[0,1],support:[0,1],lastest:0,question:0,pyflak:0,start:1,techiniqu:0,lot:[0,1],call:[0,1],"function":[0,1],enough:0,link:0,translat:0,line:0,ns3:[0,1],bug:0,gccxml:0,perform:0,consist:0,"default":0,basenod:[0,1],record:0,otherwis:1,creat:0,classic:0,request:[0,1],"abstract":[0,1],doesn:[0,1],conan:0,file:[0,1],exist:0,check:0,probabl:0,nrl:0,hybrid:0,detail:0,virtual:[0,1],flood:0,other:0,get_msg_deprec:1,varieti:0,test:0,you:0,node:[0,1],matur:[0,1],sequenc:1,why:0,bitbucket:0,sock:1,directori:0,descript:[0,1],fsm:0,ignor:0,potenti:0,time:[0,1],prototyp:0},objtypes:{"0":"py:module","1":"py:method","2":"py:class","3":"py:staticmethod"},titles:["Welcome to IMALSE&#8217;s documentation!","API Documentation"],objnames:{"0":"Python module","1":"Python method","2":"Python class","3":"Python static method"},filenames:["index","API"]})
+Search.setIndex({objects:{core:{CMD:[1,2,1]},"core.ns3.Experiment.ImalseNetnsExperiment":{get_node:[1,1,1]},"core.Client.ClientCMD":{recv_disconn_req:[1,1,1],request_connect:[1,1,1],recv_ack:[1,1,1],echo:[1,1,1],request_time_out:[1,1,1],connection_refused:[1,1,1]},"core.ns3.Experiment.ImalsePureSimExperiment":{event:[1,3,1]},"core.ns3":{Topology:[1,0,1]},"core.ns3.Topology":{TopologyReaderHelper:[1,2,1],TopologyNet:[1,2,1],TopologyReader:[1,2,1],InetTopologyReader:[1,2,1]},"core.CMD":{start:[1,1,1],dispatcher:[1,1,1],install:[1,1,1]},"core.BaseNode.BaseNode":{close_socks:[1,1,1]},"core.ns3.Experiment":{ImalseExperiment:[1,2,1],ImalsePureSimExperiment:[1,2,1],ImalseNetnsExperiment:[1,2,1]},"core.BaseNode":{BaseNode:[1,2,1]},"core.Server.ServerCMD":{initialize:[1,1,1],echo_bots:[1,1,1],recv_request_conn:[1,1,1],dispatcher:[1,1,1],verify_master:[1,1,1]},"core.ns3.Node":{ImalseNetnsNode:[1,2,1],ImalseNetnsSimNode:[1,2,1],PhyNode:[1,2,1]},"core.Client":{ClientCMD:[1,2,1]},"core.ns3.Node.ImalseNetnsSimNode":{add_msg_deprec:[1,3,1],after:[1,1,1],get_msg:[1,3,1],get_msg_deprec:[1,3,1],connect:[1,1,1],add_msg:[1,3,1],dispatcher:[1,1,1]},"core.ns3.Experiment.ImalseExperiment":{print_srv_addr:[1,1,1],node_run:[1,1,1],get_node:[1,1,1],start_nodes:[1,1,1]},"core.ns3.Node.PhyNode":{close_socks:[1,1,1]},"core.Server":{ServerCMD:[1,2,1]}},terms:{demo:0,all:[0,1],concept:0,botmastercmd:0,consum:0,tapbridg:0,code:0,sleep:0,edu:1,follow:0,topoexperi:0,request_timeout:1,decid:0,depend:[0,1],descript:[0,1],send:[0,1],init:0,under:0,introduc:0,sourc:[0,1],string:1,far:1,phynod:1,reader:1,imalsenetnsnod:1,util:0,ident:1,mechan:0,veri:0,strang:0,level:[0,1],cmd:[0,1],upload:0,escript:0,emul:[0,1],small:0,pleas:0,fortun:0,request_connect:1,seper:0,request:[0,1],past:0,second:[0,1],design:0,pass:0,download:0,even:1,index:[0,1],what:0,botmast:0,section:[0,1],overload:0,access:0,version:0,"new":0,method:[0,1],gener:[0,1],behaviour:0,connection_refus:1,exper_fnam:0,pygoocanva:0,sinc:0,wait:1,search:[0,1],addr_port:1,behav:0,implement:[0,1],socks_seq_set:1,modul:[0,1],apt:0,achin:0,api:[0,1],instal:[0,1],select:0,plot:0,from:[0,1],describ:0,commun:0,two:[0,1],few:0,music:0,recommend:0,msg:1,type:[0,1],inet:[0,1],more:[0,1],diamond:0,peopl:0,umich:1,pylint:0,accept:1,ommand:0,compani:0,ware:0,must:0,none:1,join:0,work:0,dev:0,netsecur:0,kwarg:1,can:[0,1],root:0,def:0,control:0,claim:1,tarbar:0,process:0,sudo:0,indic:[0,1],want:0,hbhzwj:0,cours:0,turn:0,ping:0,write:0,how:0,pure:[0,1],verifi:1,sim:[0,1],confid:0,map:0,clone:0,after:[0,1],usabl:1,befor:0,attent:0,mai:[0,1],data:[0,1],mal:0,physic:1,welcom:0,clientcmd:[0,1],bind:[0,1],correspond:0,issu:0,callback:1,maintain:1,combin:0,secnario:0,netn:1,least:0,help:0,ith:1,echo_bot:1,itd:0,imul:0,paper:0,through:0,still:0,dynam:0,paramet:0,setacceptcallback:1,video:0,disconnect:1,onc:0,nodecr:1,unknowneventexcept:1,"return":[0,1],machinc:0,thei:0,handl:1,dai:0,initi:[0,1],framework:0,botnet:[0,1],instead:0,now:0,introduct:0,document:[0,1],name:[0,1],realist:0,mode:[0,1],each:[0,1],found:0,complet:0,netns3:[0,1],navi:0,approari:1,meta:1,"static":1,connect:[0,1],verify_mast:1,event:[0,1],out:[0,1],ftp:0,shown:0,network:[0,1],dsr:0,research:0,content:1,adapt:1,internet:0,print:1,srv_port:1,forth:0,factori:0,integr:0,clarifi:0,manipul:0,reason:0,base:[0,1],ask:0,org:0,recv:1,bash:0,care:0,client_sock:1,launch:0,imalsenetnsexperi:[0,1],put:0,refus:1,thing:0,propos:0,think:0,first:0,softwar:0,reimplement:1,staticrouteexperi:0,independ:0,echo:1,request_time_out:1,alreadi:0,done:0,messag:[0,1],open:0,topologyreaderhelp:1,differ:0,start_nod:1,tate:0,system:0,construct:[0,1],mercuri:0,checker:0,master:1,allinon:0,scheme:0,techiniqu:0,malwar:0,namespac:[0,1],tool:0,copi:0,specifi:1,part:0,pars:1,recv_ack:1,mode_map:0,exactli:0,than:0,serv:0,enjoi:0,recv_disconn_req:1,provid:[0,1],structur:0,exampl:[0,1],project:0,imals:[0,1],comput:0,ani:0,file_exfiltr:0,packag:0,have:0,tabl:[0,1],need:0,close_sock:1,mil:0,inform:0,self:1,note:0,pybindgen:1,take:0,which:0,though:0,who:0,most:0,deploi:0,pygraphviz:0,"class":[0,1],don:0,flow:0,schedu:1,declar:0,"_path":0,baseclass:0,"94d1ff15736f":0,syntax:0,hack:1,current:0,onli:0,"_input":1,"_format":1,configur:0,solut:0,forev:0,should:[0,1],won:0,suppos:0,analyz:0,rich:0,folder:0,local:0,get:[0,1],becaus:0,cannot:1,mulat:0,requir:[0,1],add_msg_deprec:1,topolog:[0,1],"default":0,common:0,contain:[0,1],set:[0,1],servercmd:[0,1],packet:[0,1],result:0,arg:1,close:1,detect:0,kei:[0,1],pattern:0,hybrid:0,pacekt:1,figur:0,enclosur:1,"import":0,experi:[0,1],approach:0,xvf:0,accord:0,extend:0,get_msg:1,extens:0,lazi:0,succeed:1,recent:0,toposimexperi:0,recv_request_conn:1,satisfi:0,last:0,vitur:0,comment:0,eta:0,whole:0,load:0,simpli:1,kwd:1,point:0,schedul:[0,1],ns3_path:0,address:[0,1],dispatch:1,linux:[0,1],imalsepuresimexperi:[0,1],quit:0,xzvf:0,anomali:0,three:0,been:[0,1],json:1,much:[0,1],interest:0,basic:[0,1],"abstract":[0,1],defind:0,execfil:0,func:1,sock_seq_set:1,node_run:1,"case":0,novel:0,defin:[0,1],outcom:0,abov:0,intranet:0,tar:0,ddos_ping_flood:0,pacetk:1,convinc:0,worri:0,good:0,incom:0,revis:0,pygccxml:0,sever:0,demostr:0,saml:0,receiv:1,make:0,format:1,start_act:1,same:0,member:0,python:[0,1],html:0,pai:0,attack:0,higher:0,finish:0,http:[0,1],imalseexperi:1,experiemtn:1,rais:1,user:0,student:0,whenver:0,typic:0,techniqu:0,scenario:0,ntegrat:0,client:[0,1],command:[0,1],bot:[0,1],thi:[0,1],model:0,rout:0,ubuntu:0,usual:0,compromis:0,just:[0,1],less:0,print_srv_addr:1,shape:0,topologynet:1,flavor:0,password:[0,1],had:0,littl:0,add:[0,1],input:0,experimetn:0,botmster:0,transit:1,build:0,real:[0,1],applic:[0,1],topologyread:1,transpar:0,read:[0,1],avali:0,testb:0,traffic:0,know:0,bit:0,characterist:0,inettopologyread:1,desc:1,like:0,specif:[0,1],filenam:1,imalsenetnssimnod:1,manual:0,server:[0,1],collect:0,specifii:0,page:[0,1],eec:1,www:0,deal:0,srv_addr:1,some:0,back:1,sampl:0,successfulli:0,deploy:0,definit:0,subclass:0,ddo:0,refer:0,machin:[0,1],core:[0,1],previou:0,run:[0,1],host:0,execu:0,wget:0,get_nod:1,src:[],about:0,actual:0,socket:[0,1],ack:1,send_p:0,simul:[0,1],bz2:0,experiment_factori:0,disabl:0,block:1,matur:[0,1],own:0,ddos_ping_attack:0,encod:1,automat:0,chang:0,wai:[0,1],support:[0,1],lastest:0,question:0,pyflak:0,start:1,includ:0,lot:[0,1],call:[0,1],"function":[0,1],enough:0,link:0,translat:0,line:0,ns3:[0,1],bug:0,gccxml:0,perform:0,consist:0,whether:0,basenod:[0,1],record:0,otherwis:1,creat:0,classic:0,certain:0,dure:0,doesn:[0,1],fsm:0,conan:0,file:[0,1],exist:0,check:0,probabl:0,nrl:0,when:[0,1],detail:0,virtual:[0,1],flood:0,other:0,get_msg_deprec:1,varieti:0,test:0,you:0,node:[0,1],"_type":1,sequenc:1,why:0,bitbucket:0,sock:1,directori:0,add_msg:1,save:0,ignor:0,potenti:0,time:[0,1],prototyp:0},objtypes:{"0":"py:module","1":"py:method","2":"py:class","3":"py:staticmethod"},titles:["Welcome to IMALSE&#8217;s documentation!","API Documentation"],objnames:{"0":"Python module","1":"Python method","2":"Python class","3":"Python static method"},filenames:["index","API"]})
Add a comment to this file

doc/source/figure/client_fsm.png

Added
New image

doc/source/index.rst

 The basic botnet mechanism can be described as **F**\ inite **S**\ tate **M**\
 achine. The **FSM** for the **ClientCMD** is as follows:
 
-.. image:: ./figure/client_fsm.svg
+.. image:: ./figure/client_fsm.png
     :align: center 
     :height: 400px
 

experiments/API.py

 from core.ns3 import ImalseNetnsExperiment, ImalsePureSimExperiment
 
+class Basic(object):
+    def initparser(self, parser): pass
+    def _install_cmds(srv_addr): pass
+
 mode_map = {
         'netns3':ImalseNetnsExperiment,
         'sim':ImalsePureSimExperiment,
+        'basic':Basic,
         }
 
 import settings
 
 def experiment_factory(experiment, mode):
-    BaseClass = mode_map[mode]
+    if isinstance(mode, str):
+        BaseClass = mode_map[mode]
+    else:
+        BaseClass = mode
     exper_fname = settings.ROOT + '/experiments/' + experiment + '.py'
     execfile(exper_fname, locals())
     return locals()[experiment]

experiments/ManualTopoExperiment.py

+"""
+It demos the process of loading a predefined topology file.
+"""
+import settings
+from core.ns3.Topology import ManualTopologyNet
+from experiments import experiment_factory
+import os
+
+SERVER_ADDR = "10.0.1.1"
+
+TopoExperiment = experiment_factory('TopoExperiment', BaseClass)
+from util import Namespace
+
+class ManualTopoExperiment(TopoExperiment):
+    """In Manual Topo Experiment,  You can specify and ip address for each indexing"""
+    def initparser(self, parser):
+        TopoExperiment.initparser(self, parser)
+
+        parser.set_defaults(net_settings=settings.ROOT+"/net_config/net_settings.py",
+                )
+        parser.add_option('--net_settings', dest="net_settings",
+                help='net settings file',
+                )
+
+    def load_net_settings(self):
+        s = {}
+        execfile(self.options.net_settings, s)
+        return Namespace(s)
+
+    def setup(self):
+        BaseClass.setup(self)
+        self.net = ManualTopologyNet(
+                os.path.abspath(self.options.topology_file),
+                self.options.topology_type,
+                self.NodeCreator,
+                self.load_net_settings(),
+                )
+
+        self._install_cmds(srv_addr = SERVER_ADDR)
+        self.print_srv_addr()
+        self._set_server_info()
+        self.start_nodes()
+

net_config/net_settings.py

+ipv4_net_addr_base = '10.7.0.1/24'
+# link_to_interface_map
+link_to_ip_map = {
+        (0, 1):['10.0.1.1/24', '10.0.1.2/24'],
+    }
+
+link_attr_default = ['2ms','5Mbps']
+link_attr = {
+        (0, 1):['2ms','5Mbps'],
+        }

util/Namespace.py

+"""namespace module"""
+
+__all__ = ("Namespace", "as_namespace")
+
+from collections import Mapping, Sequence
+
+class _Dummy: pass
+CLASS_ATTRS = dir(_Dummy)
+del _Dummy
+
+
+class Namespace(dict):
+    """A dict subclass that exposes its items as attributes.
+
+    Warning: Namespace instances do not have direct access to the
+    dict methods.
+
+    """
+
+    def __init__(self, obj={}):
+        # super().__init__(obj)
+        super(Namespace, self).__init__(obj)
+
+    def __dir__(self):
+        return tuple(self)
+
+    def __repr__(self):
+        # return "%s(%s)" % (type(self).__name__, super().__repr__())
+        return "%s(%s)" % (type(self).__name__, super(Namespace, self).__repr__())
+
+    def __getattribute__(self, name):
+        try:
+            return self[name]
+        except KeyError:
+            msg = "'%s' object has no attribute '%s'"
+            raise AttributeError(msg % (type(self).__name__, name))
+
+    def __setattr__(self, name, value):
+        self[name] = value
+
+    def __delattr__(self, name):
+        del self[name]
+
+    #------------------------
+    # "copy constructors"
+
+    @classmethod
+    def from_object(cls, obj, names=None):
+        if names is None:
+            names = dir(obj)
+        ns = {name:getattr(obj, name) for name in names}
+        return cls(ns)
+
+    @classmethod
+    def from_mapping(cls, ns, names=None):
+        if names:
+            ns = {name:ns[name] for name in names}
+        return cls(ns)
+
+    @classmethod
+    def from_sequence(cls, seq, names=None):
+        if names:
+            seq = {name:val for name, val in seq if name in names}
+        return cls(seq)
+
+    #------------------------
+    # static methods
+
+    @staticmethod
+    def hasattr(ns, name):
+        try:
+            object.__getattribute__(ns, name)
+        except AttributeError:
+            return False
+        return True
+
+    @staticmethod
+    def getattr(ns, name):
+        return object.__getattribute__(ns, name)
+
+    @staticmethod
+    def setattr(ns, name, value):
+        return object.__setattr__(ns, name, value)
+
+    @staticmethod
+    def delattr(ns, name):
+        return object.__delattr__(ns, name)
+
+
+def as_namespace(obj, names=None):
+
+    # functions
+    if isinstance(obj, type(as_namespace)):
+        obj = obj()
+
+    # special cases
+    if isinstance(obj, type):
+        names = (name for name in dir(obj) if name not in CLASS_ATTRS)
+        return Namespace.from_object(obj, names)
+    if isinstance(obj, Mapping):
+        return Namespace.from_mapping(obj, names)
+    if isinstance(obj, Sequence):
+        return Namespace.from_sequence(obj, names)
+
+    # default
+    return Namespace.from_object(obj, names)
 from util import *
+from Namespace import Namespace
 
     for vl in v:
         print vl[0]
 
-# if __name__ == "__main__":
-    # sys.path.insert(0, '..')
-    # res = get_experiment_option()
-    # print res
 
+# CIDR to Netmask conversion
+# (c) 2010 Peter Bittner, http://linux.bittner.it/blog
+#
+# Tip for an excellent background read: "IP subnetting made easy"
+# http://articles.techrepublic.com.com/5100-10878_11-6089187.html
 
+def len2mask(len):
+    """Convert a bit length to a dotted netmask (aka. CIDR to netmask)"""
+    mask = ''
+    if not isinstance(len, int) or len < 0 or len > 32:
+        print "Illegal subnet length: %s (which is a %s)" % (str(len), type(len).__name__)
+        return None
+
+    for t in range(4):
+        if len > 7:
+            mask += '255.'
+        else:
+            dec = 255 - (2**(8 - len) - 1)
+            mask += str(dec) + '.'
+        len -= 8
+        if len < 0:
+            len = 0
+
+    return mask[:-1]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.