EvilZone
Programming and Scripting => Scripting Languages => : Ragehottie July 08, 2012, 05:38:58 PM
-
I have written a botnet type thing in Python, and I am not sure how to start this, but here it goes:
When a client connects to my server it makes a new thread for said client. So if I have 100 bots I will have ~100 threads running. Is that, umm, good? Like can my computer handle that?
*I will post the code later, as I am not on my computer atm*
-
The less threads the better. You can minimize the amount of resources that your bot-net type project will use if you limit what needs to be stored at any given time(in a general sense). You don't necessarily need to keep a live session between every bot and the control server at all times. As for the software installed on your 'bot'; you could hard code it to just listen, or even better just check back with command and control every so often and then parse a list of instructions(queue style; this functionality will have to have been implemented before hand obviously) for the bot to perform when he checks back. That way you don't have to worry about firewalls.
Everything should be done as efficiently as possible. Sometimes it's about finding the balance between functionality, resource-usage and convenience. If I was going about your project, that's the way I would be thinking about it. There's no one-way approach and there's going to be trial and error; no way around it. That's the way to find what works best in regards to your intended implementation of this idea. As the creator, it's up to you.
-
^^This for the most part.
I think you may benefit from Twisted (http://twistedmatrix.com/trac/).
-
Thanks for the links. My brother told me to use cpickle to save the connection and just load it when I need it. Is that good?
-
Thanks for the links. My brother told me to use cpickle to save the connection and just load it when I need it. Is that good?
Regular pickle will be okay. There is no need of cpickle at this point. Maybe once you get more on tune with coding, but for now, saving data regular python pickle is just fine.
-
Not that I am a python coder but this is what I would do:
Store each connection/socket in an array/list and loop through it every so often. When looping through the socket list: Check if there is data availible or otherwise actions to be taken, if there is start a new thread to take care of the actions that needs to be taken care of for that client.
However, this type of client server system wont be able to hold a large ammount of clients..
A report system would be much better; Clients connecting with a regular interval to report back stuff and also receive commands.
-
I tried a report system long ago. I just did time.sleep(5) so every 5 seconds it would check. Only problem was that all the bots were out of sync. I waiuld have to do something better if I did that.
I was thinking this morning. When a client connects, save its connection in a pickle then add it to a list. Whenever I issued a command the server would load the list and send the command to each of the clients. This way the bots would instantly get the command.
-
I tried a report system long ago. I just did time.sleep(5) so every 5 seconds it would check. Only problem was that all the bots were out of sync. I waiuld have to do something better if I did that.
I was thinking this morning. When a client connects, save its connection in a pickle then add it to a list. Whenever I issued a command the server would load the list and send the command to each of the clients. This way the bots would instantly get the command.
It is not the server that should sleep. The server should take connections all the time and make new threads to handle the connections. However, the connections should timeout/close when they are done and the bot is to reconnect after x ammount of time.
And the pickle(?) idea of yours is the same as I described.
-
Honestly I don't see a need to pickle. Unless you wanted to save connection. data like a timestamp or something.
-
@ande
I was talking about the client
and your idea was to check every so often. Mine was instant
@techb
to save the connection so I can send the command instantly.
-
The connection object could be saved in a list, or a dict. Pickleing would be good if the server went down, but even then you would need to make a new connection.
But Twisted seems like a better idea though. It is event driven and has methods and functions to do what your. after.
@ande, pickle is pythons way of serializing objects
-
Ahhh, I was not aware that you could save objects to a list. Ill do that :P
-
Ill leave this here : http://nadiana.com/python-pickle-insecure (http://nadiana.com/python-pickle-insecure)
-
I will let this here : http://nadiana.com/python-pickle-insecure (http://nadiana.com/python-pickle-insecure)
Ill leave this here:
Ahhh, I was not aware that you could save objects to a list. Ill do that :P
-
Ill leave this here:
Ill leave this here:
Thnx