1 00:00:00,570 --> 00:00:03,750 Hello, everyone, welcome to a new video of our Python. 2 00:00:05,490 --> 00:00:10,650 Last time we talked about multi threading in Python and how to receive data from multiple clients at 3 00:00:10,650 --> 00:00:11,370 the same time. 4 00:00:12,870 --> 00:00:16,950 Now, in a back door scenario, we need to interact with a specific target. 5 00:00:17,340 --> 00:00:18,390 But how do we do that? 6 00:00:19,890 --> 00:00:26,400 Remember that we had our socketed object when we accept the connection in a variable rate, but how 7 00:00:26,400 --> 00:00:28,440 do we identify a socket object? 8 00:00:29,880 --> 00:00:34,470 What if we assign a number to each socket object and create a dictionary or a list? 9 00:00:35,670 --> 00:00:36,480 Let's do that. 10 00:00:38,130 --> 00:00:41,700 We will create a variable and assign it an initial value of zero. 11 00:00:42,360 --> 00:00:46,440 Now, every time we accept a socket object, we will increment this variable by one. 12 00:01:14,570 --> 00:01:20,330 Since we don't want to make things complicated, we can create a list of dictionaries, each dictionary 13 00:01:20,330 --> 00:01:23,120 holds the socket object and its corresponding number. 14 00:01:23,990 --> 00:01:26,390 Let's go to the top and create our list. 15 00:01:58,750 --> 00:02:04,270 Now, let's create another list of dictionaries to hold our IP and port and its corresponding socket 16 00:02:04,270 --> 00:02:05,070 number as well. 17 00:03:06,260 --> 00:03:12,860 Very good, but hold on for a second from before, the only thing we did was to reply to our client 18 00:03:13,040 --> 00:03:14,770 with whatever data we received. 19 00:03:15,620 --> 00:03:20,490 But how do we send commands to a specific client when we are inside a while already? 20 00:03:22,190 --> 00:03:29,690 Well, we can open a raw input to to get some commands from the user, but in another thread and leave 21 00:03:29,690 --> 00:03:32,390 our while loop to receive data in the background. 22 00:03:33,260 --> 00:03:34,070 Let's try that. 23 00:03:35,690 --> 00:03:40,790 Let's create another function just to get input from the user and we need it to be in a while loop as 24 00:03:40,790 --> 00:03:43,630 well to keep receiving commands over and over. 25 00:04:07,750 --> 00:04:12,070 We also need our love to do nothing in case the user didn't provide any input. 26 00:04:19,960 --> 00:04:25,000 Now let's run it on a different thread, but we need to do that right before our Lou. 27 00:04:43,280 --> 00:04:44,210 Now let's ride. 28 00:04:58,420 --> 00:05:05,560 Nice see, now our server is still listening in the background and we can still give it some comments, 29 00:05:07,660 --> 00:05:13,570 so far we know that our sockets from the clients are stored in our socket, underscore object lists. 30 00:05:14,080 --> 00:05:19,060 So let's create a function to print a list of the connected clients that are stored in our list. 31 00:06:49,280 --> 00:06:49,730 Very good. 32 00:06:49,880 --> 00:06:55,940 Now, we will call this function if the user type sessions from the C and D function, let's add that 33 00:06:55,940 --> 00:06:56,300 to it. 34 00:07:00,500 --> 00:07:00,800 But. 35 00:07:17,810 --> 00:07:18,640 Now, let's run it. 36 00:07:38,270 --> 00:07:41,840 Very good, what next? 37 00:07:42,740 --> 00:07:48,380 We can now use our commands function to send actual commands to our clients based on their number we 38 00:07:48,380 --> 00:07:49,330 got from our list. 39 00:07:50,120 --> 00:07:54,220 But before we do that, we need another function to send our command to the client. 40 00:07:55,070 --> 00:08:00,770 Let's try the function and call it we will call it send underscore to underscore client. 41 00:08:24,360 --> 00:08:29,100 This function will receive two arguments, the first argument is the client number that we want to send 42 00:08:29,100 --> 00:08:29,820 our data to. 43 00:08:30,270 --> 00:08:33,120 The second argument is the data itself that we want to send. 44 00:09:06,340 --> 00:09:12,580 Next, we need to to look for the dashi and the command we provide and take the third argument, which 45 00:09:12,580 --> 00:09:15,000 should be the session no, we want to interact with. 46 00:09:16,690 --> 00:09:18,340 Let's go to our esteemed function. 47 00:10:33,720 --> 00:10:34,350 Very good. 48 00:10:34,440 --> 00:10:36,510 Now let's check our sessions. 49 00:10:39,610 --> 00:10:45,670 As same way we have two decisions to interact with the first session, which is this client of the top 50 00:10:45,670 --> 00:10:58,750 right corner, that's my session, number one and low point one, I guess we were seated here. 51 00:10:59,810 --> 00:11:06,260 Let's do the same thing with the client who sessions just to make sure, OK. 52 00:11:06,580 --> 00:11:10,060 Sessions, I too. 53 00:11:12,460 --> 00:11:13,090 Hello. 54 00:11:14,050 --> 00:11:16,340 To receive it here. 55 00:11:16,470 --> 00:11:16,880 Very good. 56 00:11:16,970 --> 00:11:20,080 Now we can send and receive data to multiple clients. 57 00:11:23,260 --> 00:11:26,050 Now let's actually look at the client itself. 58 00:11:32,330 --> 00:11:37,940 As you can see, I'm only standing hello from client before the wild and in the while loop, I wait 59 00:11:37,940 --> 00:11:47,370 to receive data here from the server then I printed if I want to, of course you have to. 60 00:11:47,630 --> 00:11:49,700 And finally, I send the word done. 61 00:11:53,060 --> 00:11:57,460 Well, that was all I think we're done with this lesson, thank you and see you in the next one.