Skip to content

Commit

Permalink
reorganized the code
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-w-du committed Aug 8, 2021
1 parent 1cdea60 commit 1b94925
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions examples/B05-botnet/botnet-basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# encoding: utf-8

import random
from seedemu.core import Emulator, Binding, Filter, Action
from seedemu.services import BotnetService, BotnetClientService
from seedemu.compiler import Docker
Expand All @@ -18,36 +19,46 @@
botClient = BotnetClientService()

# Create a virtual node for bot controller,
# and add a file to this node
f = open("./ddos.py", "r")
bot.install('bot_controller').addFile(f.read(), "/tmp/ddos.py")
# and customize its display name
bot.install('bot-controller')
emu.getVirtualNode('bot-controller').setDisplayName('Bot-Controller')

# Bind the virtual node to a physical node (create a new one)
emu.addBinding(Binding('bot_controller',
filter = Filter(ip='10.150.0.66'), action=Action.NEW))
# Install a file to this node
f = open("./ddos.py", "r")
emu.getVirtualNode('bot-controller').setFile(content=f.read(), path="/tmp/ddos.py")

for asn in [151, 152, 153, 154]:
vname = 'bot{}'.format(asn)
# Create 6 bot nodes
for counter in range(6):
vname = 'bot-node-%.3d'%(counter)

# Create a virtual node for each bot client,
# bind the virtual node to a physical node (new)
botClient.install(vname).setServer('bot_controller')
emu.addBinding(Binding(vname, filter = Filter(asn=asn), action=Action.NEW))
# tell them which node is the controller node,
# and customize its display name.
botClient.install(vname).setServer('bot-controller')
emu.getVirtualNode(vname).setDisplayName('Bot-%.3d'%(counter))


###############################################################################
# Bind the virtual nodes to physical nodes

emu.addLayer(bot)
emu.addLayer(botClient)
emu.render()
# Bind the controller node
emu.addBinding(Binding('bot-controller',
filter = Filter(ip='10.150.0.66'), action=Action.NEW))

###############################################################################
# Customize the display names of the controller and bots.
as_list = [150, 151, 152, 153, 154, 160, 161, 162, 163, 164, 170, 171]
for counter in range(6):
vname = 'bot-node-%.3d'%(counter)

# Pick an autonomous system randomly from the list,
# and create a new host for each bot.
asn = random.choice(as_list)
emu.addBinding(Binding(vname, filter=Filter(asn=asn), action=Action.NEW))

emu.getBindingFor('bot_controller').setDisplayName('Bot-Controller')
for asn in [151, 152, 153, 154]:
vname = 'bot{}'.format(asn)
emu.getBindingFor(vname).setDisplayName('Bot-{}'.format(asn))

###############################################################################

emu.addLayer(bot)
emu.addLayer(botClient)

emu.render()
emu.compile(Docker(), './output')

0 comments on commit 1b94925

Please sign in to comment.