Author Topic: [Python] New thread for each client  (Read 3472 times)

0 Members and 10 Guests are viewing this topic.

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
[Python] New thread for each client
« on: 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*
« Last Edit: July 08, 2012, 05:39:20 pm by Ragehottie »
Blog: rexmckinnon.tumblr.com

Offline frog

  • Knight
  • **
  • Posts: 232
  • Cookies: 16
    • View Profile
Re: [Python] New thread for each client
« Reply #1 on: July 23, 2012, 02:08:31 am »
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.

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [Python] New thread for each client
« Reply #2 on: July 23, 2012, 04:14:21 am »
^^This for the most part.


I think you may benefit from Twisted.
>>>import this
-----------------------------

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
Re: [Python] New thread for each client
« Reply #3 on: July 23, 2012, 05:07:57 am »
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?
Blog: rexmckinnon.tumblr.com

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [Python] New thread for each client
« Reply #4 on: July 23, 2012, 05:35:48 am »
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.
>>>import this
-----------------------------

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: [Python] New thread for each client
« Reply #5 on: July 23, 2012, 06:03:42 pm »
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.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
Re: [Python] New thread for each client
« Reply #6 on: July 23, 2012, 06:27:45 pm »
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.
Blog: rexmckinnon.tumblr.com

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: [Python] New thread for each client
« Reply #7 on: July 23, 2012, 07:27:31 pm »
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.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [Python] New thread for each client
« Reply #8 on: July 23, 2012, 07:32:38 pm »
Honestly I don't see a need to pickle. Unless you wanted to save connection. data like a timestamp or something.
>>>import this
-----------------------------

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
Re: [Python] New thread for each client
« Reply #9 on: July 23, 2012, 07:36:26 pm »
@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.
Blog: rexmckinnon.tumblr.com

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [Python] New thread for each client
« Reply #10 on: July 23, 2012, 07:57:47 pm »
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
>>>import this
-----------------------------

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
Re: [Python] New thread for each client
« Reply #11 on: July 23, 2012, 08:07:09 pm »
Ahhh, I was not aware that you could save objects to a list. Ill do that :P
Blog: rexmckinnon.tumblr.com

Offline LeXeL

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 1
    • View Profile
Re: [Python] New thread for each client
« Reply #12 on: July 25, 2012, 12:23:58 am »
« Last Edit: July 25, 2012, 03:53:02 am by LeXeL »

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
Re: [Python] New thread for each client
« Reply #13 on: July 25, 2012, 01:20:42 am »
I will let this here :  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
Blog: rexmckinnon.tumblr.com

Offline LeXeL

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 1
    • View Profile