how to make a botnet in python

Solutions on MaxInterview for how to make a botnet in python by the best coders in the world

showing results for - "how to make a botnet in python"
Luca
15 Oct 2018
1Task execution
2
3Tasks are initially parsed by the command program and then dispatched to workers via the command channel.
4The operator can specify any number of workers to set to work on a specific task. The syntax is straightforward:
5
6!execute (<number of workers>) <command> <arguments>
7
8Worker tasks are parsed by the worker bot and can accept any number of arbitrary arguments,
9which are extracted by an operator-defined regex. Here's an example of how the "run" command looks (which executes a command on the host machine):
10
11def get_task_patterns(self):
12    return (
13        ('run (?P<program>.*)', self.run),
14        # ... any other command patterns ...
15    )
16
17def run(self, program):
18    fh = os.popen(program)
19    return fh.read()
20Dead simple! Tasks can return any arbitrary text which is then parsed by the worker's task runner and sent back to the command program. At any time,
21the operator can request the data for a given task.
22
23A note on security
24The operator must authenticate with the command program to issue commands - the password is hardcoded in the BotnetBot. Likewise, workers will only accept commands from the command program.
25
26Example session
27Below is a sample session. First step is to authenticate with the bot:
28
29<cleifer> !auth password
30<boss1337> Success
31
32<cleifer> !status
33<boss1337> 2 workers available
34<boss1337> 0 tasks have been scheduled
35Execute a command on one of the workers:
36
37<cleifer> !execute 1 run vmstat
38<boss1337> Scheduled task: "run vmstat" with id 1 [1 workers]
39<boss1337> Task 1 completed by 1 workers
40Print the data returned by the last executed command:
41
42<cleifer> !print
43<boss1337> [workerbot:{alpha}] - run vmstat
44<boss1337> procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
45<boss1337> r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
46<boss1337> 0  0      0 352900 583696 1298868    0    0    16    31  133  172  4  2 94  0
47Find open ports on the workers hosts:
48
49<cleifer> !execute ports
50<boss1337> Scheduled task: "ports" with id 2 [2 workers]
51<boss1337> Task 2 completed by 2 workers
52<cleifer> !print
53<boss1337> [workerbot:{alpha}] - ports
54<boss1337> [22, 80, 631]
55<boss1337> [workerbot_346:{rho}] - ports
56<boss1337> [22, 80]
57
58Becoming a bot herder
59If you'd like to try this out yourself, feel free to grab a checkout of the source, available on GitHub. The worker is programmed with the following commands:
60
61run executes the given program
62download will download the file at the given url and save it to the host machine
63info returns information about the host machine's operating system
64ports does a quick port-scan of the system ports 20-1025
65send_file streams the file on the host computer to the given host:port
66status returns the size of the worker's task queue
67Adding your own commands is really easy, though -- just add them to the tuple returned by the get_task_patterns method, which looks like this:
68
69def get_task_patterns(self):
70    return (
71        ('download (?P<url>.*)', self.download),
72        ('info', self.info),
73        ('ports', self.ports),
74        ('run (?P<program>.*)', self.run),
75        ('send_file (?P<filename>[^\s]+) (?P<destination>[^\s]+)', self.send_file),
76        ('status', self.status_report),
77
78        # adding another command - this will return the system time and optionally
79        # take a format parameter
80        ('get_time(?: (?P<format>.+))?', self.get_time),
81    )
82Now define your callback, which will perform whatever task you like and optionally return a string. The returned data will be sent to the command program and made available to the operator.
83
84def get_time(self, format=None):
85    now = datetime.datetime.now() # remember to import datetime at the top of the module
86    if format:
87        return now.strftime(format)
88    return str(now)
89Here's how you might call that command:
90
91<cleifer> !execute get_time
92<boss1337> Scheduled task: "get_time" with id 1 [1 workers]
93<boss1337> Task 1 completed by 1 workers
94<cleifer> !print 1
95<boss1337> [workerbot:{alpha}] - get_time
96<boss1337> 2011-04-21 10:41:16.251871
97<cleifer> !execute get_time %H:%M
98<boss1337> Scheduled task: "get_time %H:%M" with id 2 [1 workers]
99<boss1337> Task 2 completed by 1 workers
100<cleifer> !print
101<boss1337> [workerbot:{alpha}] - get_time %H:%M
102<boss1337> 10:42
103The bots are extensible so you can write your own commands if you want to take up bot-herding -- this tool could be used to restart web nodes, update checkouts, report on status, anything really since it can be used to execute arbitrary commands.
104
105Happy hacking!