1 00:00:00,640 --> 00:00:01,370 Welcome back. 2 00:00:01,630 --> 00:00:07,840 Now that we covered our shell and targeted communication functions, it is time we employed the reliable 3 00:00:08,290 --> 00:00:10,710 and reliable receive functions. 4 00:00:11,380 --> 00:00:17,980 So if I go to my server code right here, you will notice that we did code a part of the targeted communication 5 00:00:17,980 --> 00:00:18,430 function. 6 00:00:18,430 --> 00:00:20,660 But this is not really working. 7 00:00:21,160 --> 00:00:23,440 These functions do not exist. 8 00:00:23,620 --> 00:00:28,480 We must create them first in order to be able to successfully send and receive data. 9 00:00:28,930 --> 00:00:31,990 Let's start with the reliable function first. 10 00:00:32,380 --> 00:00:35,770 Since that one is easier, we just need to send the data. 11 00:00:36,100 --> 00:00:42,320 And for this we're going to use the JSON library in order to more easily pass the data. 12 00:00:43,060 --> 00:00:49,930 So down here, I'm going to define reliable, underscore and reliable and will take one parameter. 13 00:00:50,110 --> 00:00:53,870 As we can see right here, it has to be the data that we are going to send. 14 00:00:54,070 --> 00:00:56,880 So we're just going to name that parameter data. 15 00:00:57,250 --> 00:00:58,480 Then let's add two dots. 16 00:00:58,900 --> 00:01:04,690 And inside of the function, we're going to define something called Jason Data. 17 00:01:04,690 --> 00:01:12,340 And this is going to be a variable that is going to store the output of the dumps method from the Jason 18 00:01:12,340 --> 00:01:15,100 Library onto our data. 19 00:01:15,460 --> 00:01:21,610 Now, keep in mind that this data is the actual command in our case, since inside of the targeted communication 20 00:01:21,610 --> 00:01:27,760 function, once we call the reliable send, it passes the command inside of the brackets so you can 21 00:01:27,760 --> 00:01:30,750 just change those command to be this data right here. 22 00:01:31,150 --> 00:01:36,880 Then we perform the Jason dumps onto that command and we store it inside of JSON data. 23 00:01:37,120 --> 00:01:45,220 And finally, we can use the same function from the socket library onto our target to send the actual 24 00:01:45,370 --> 00:01:48,070 data so we can type JSON data. 25 00:01:48,310 --> 00:01:55,810 And just to remind you, this target is the actual target socket object that we get once we accept the 26 00:01:55,810 --> 00:02:02,290 connection, we're just using our sockets and function onto this target object once we're sending the 27 00:02:02,290 --> 00:02:02,710 data. 28 00:02:03,100 --> 00:02:09,430 But one more thing before we finish with the reliable function is that in Python three, once we are 29 00:02:09,430 --> 00:02:18,010 sending the data over sockets, we need to encode that data so we can do that by simply specifying inside 30 00:02:18,010 --> 00:02:22,180 of the brackets our data and then encode function onto it. 31 00:02:22,600 --> 00:02:28,480 Then it will first encode the data and then it will send it with this end function. 32 00:02:28,960 --> 00:02:34,770 Simple as that, not the same thing we need to do with our reliable receive. 33 00:02:34,780 --> 00:02:38,020 So I'm going to code it right here for reliable receive. 34 00:02:38,020 --> 00:02:42,850 And we know that the reliable receive doesn't take any parameters inside of the brackets. 35 00:02:43,660 --> 00:02:49,990 And what we're going to do to receive the data is we're first going to define a variable to be an empty 36 00:02:49,990 --> 00:02:50,560 string. 37 00:02:50,590 --> 00:02:52,450 We're just going to call it data. 38 00:02:53,330 --> 00:03:00,380 And we're going to then enter inside of the infinite while troop inside of that loop, what we are going 39 00:03:00,380 --> 00:03:10,520 to try is we are going to try to get the data by typing data equals data, plus target dot receive. 40 00:03:10,530 --> 00:03:15,080 And just to remind you, the receive function is the function from the socket library. 41 00:03:15,090 --> 00:03:18,680 So we're just using it once again on to our target connection. 42 00:03:18,900 --> 00:03:22,220 And this receive function takes one parameters. 43 00:03:22,440 --> 00:03:24,770 That is the amount of bytes that we want to receive. 44 00:03:24,950 --> 00:03:29,080 In our case, we are just going to specify a thousand and twenty four bytes. 45 00:03:29,480 --> 00:03:31,330 But this is not everything that we must do. 46 00:03:31,820 --> 00:03:38,060 Remember that once we are sending the data, we actually encode the data well in order for us to get 47 00:03:38,060 --> 00:03:45,970 the data as it was before it got encoded, we must then decode the data once we receive it right. 48 00:03:45,980 --> 00:03:50,840 And at the end we are going to add a strip function onto all of this. 49 00:03:51,650 --> 00:03:52,730 OK, great. 50 00:03:53,210 --> 00:04:01,120 After that, once we receive the data, we can return from this function digits on dot loads of our 51 00:04:01,280 --> 00:04:01,700 data. 52 00:04:01,970 --> 00:04:07,310 And this is just the format that we're going to output it since remember, we must return from this 53 00:04:07,310 --> 00:04:10,760 function as it does get stored inside of a variable. 54 00:04:11,000 --> 00:04:13,790 Our result will be our data. 55 00:04:14,330 --> 00:04:19,180 And in the accept statement, of course, we must not forget that. 56 00:04:20,000 --> 00:04:26,940 So I'm going to go down here and add, accept and what we're going to accept is the value error. 57 00:04:28,160 --> 00:04:33,110 So in case we get the value error, we're simply going to continue with the execution. 58 00:04:34,310 --> 00:04:37,010 So once again, what is this function doing? 59 00:04:37,280 --> 00:04:45,920 Well, it initiates a data variable to be empty string, then we try to get 20, 24 bytes from our target. 60 00:04:45,950 --> 00:04:48,350 We add it to the previous data that we received. 61 00:04:48,620 --> 00:04:54,770 Then we decode that data, of course, before adding it, and then we strip it from any additional characters. 62 00:04:55,280 --> 00:05:02,180 We then return the Jason loads of that data and that will be stored inside of the results variable that 63 00:05:02,180 --> 00:05:04,280 we then print to our screen. 64 00:05:05,590 --> 00:05:12,400 So all we need to do right now is we need to add these two functions to our backdoor code as well. 65 00:05:12,490 --> 00:05:19,240 So Capitán, save the server code and then no Back-Door, go up here. 66 00:05:20,480 --> 00:05:22,550 And based the functions. 67 00:05:23,940 --> 00:05:29,850 However, there is one thing that we must change, and that is this target that sent right here, since 68 00:05:29,850 --> 00:05:32,560 we are not sending to the target from our backdoor. 69 00:05:32,580 --> 00:05:37,160 We are sending to the server and we initiated the socket object to be s. 70 00:05:37,560 --> 00:05:44,070 So this is our only socket object and we are going to use that to send our data the same thing we want 71 00:05:44,070 --> 00:05:46,540 to do inside of the reliable receive function. 72 00:05:46,890 --> 00:05:54,270 We are not receiving from the target using the socket object since if we left here, target target is 73 00:05:54,270 --> 00:05:56,370 undefined inside of our backdoor code. 74 00:05:56,370 --> 00:05:58,550 Therefore it will throw us an error. 75 00:05:59,010 --> 00:06:00,860 Everything else can stay the same. 76 00:06:01,870 --> 00:06:07,030 And now that we got these two functions ready in the next video, we're going to right the part of the 77 00:06:07,030 --> 00:06:09,060 code that will execute the command. 78 00:06:09,250 --> 00:06:12,340 It is once again stored in this statement right here. 79 00:06:12,670 --> 00:06:17,560 We for now and just put the comment and in the next video, we're going to use the subprocess library 80 00:06:17,800 --> 00:06:20,660 to perform the action of executing the command. 81 00:06:21,100 --> 00:06:22,030 See you in the next video.