1 00:00:00,300 --> 00:00:02,370 Hello everybody and welcome back. 2 00:00:02,490 --> 00:00:09,240 And right now let us try to make our sending all messages infinite or basically we will send messages 3 00:00:09,240 --> 00:00:14,590 back and forth until someone terminates the connection and that someone will be the server. 4 00:00:14,700 --> 00:00:18,180 So let us open up our server in this terminal. 5 00:00:18,180 --> 00:00:20,600 We have the same code as from the previous video. 6 00:00:20,610 --> 00:00:24,030 So it is everything the same I did and change everything. 7 00:00:24,030 --> 00:00:24,480 Anything. 8 00:00:24,510 --> 00:00:32,550 So what we want to do first of all we have to create an infinite while loop in both of these programs. 9 00:00:32,550 --> 00:00:34,680 So let's start off with the server. 10 00:00:34,680 --> 00:00:37,610 First of all let us delete the things that we don't need. 11 00:00:37,800 --> 00:00:39,090 Here we have everything. 12 00:00:39,090 --> 00:00:42,840 So we will use all of this after the print Target connected. 13 00:00:42,840 --> 00:00:44,990 We want to open a while loop. 14 00:00:45,000 --> 00:00:49,710 So we want to make it basically infinite. 15 00:00:49,710 --> 00:00:58,040 So we will do while true which means that it will execute everything in the loop forever until the program 16 00:00:58,100 --> 00:00:59,030 is terminated. 17 00:00:59,510 --> 00:01:02,560 So we have to put everything right here in the while loop. 18 00:01:02,570 --> 00:01:04,910 So tab it just tap it right here. 19 00:01:04,940 --> 00:01:05,690 Target set. 20 00:01:05,700 --> 00:01:12,170 Message and Sir equals target not receive print answer and then sock it out close. 21 00:01:12,230 --> 00:01:17,140 Now socket that close you do not want to put in the while loop since every time at the end of the while 22 00:01:17,140 --> 00:01:18,680 loop it will close the connection. 23 00:01:18,680 --> 00:01:25,670 So socket that close or as it got closer or higher renamed it should stay outside of the while true 24 00:01:26,380 --> 00:01:27,490 of the. 25 00:01:27,890 --> 00:01:30,570 Yeah basically outside of the while loop. 26 00:01:30,620 --> 00:01:34,340 So here we also want to add something. 27 00:01:34,340 --> 00:01:41,540 So this should start off with the command or message in our case or input shall and then we pipe our 28 00:01:41,540 --> 00:01:45,740 string input of the IP address and the local port to it. 29 00:01:45,740 --> 00:01:49,310 Now this is something optional you can just type here anything you want. 30 00:01:49,310 --> 00:01:54,710 I just type this or it looks prettier and so we can see from where the connection is coming from then 31 00:01:54,800 --> 00:02:02,630 we send the message and what we want to do after that is actually have to have two different choices 32 00:02:03,410 --> 00:02:08,540 which is basically on two different outcomes which basically if the message is anything else we want 33 00:02:08,540 --> 00:02:12,160 to send it to the target and wait for the reply. 34 00:02:12,200 --> 00:02:18,020 If the message equals Q Just a simple letter Q We want to terminate the connection. 35 00:02:18,020 --> 00:02:22,970 If we do not have that statement to terminate the connection this file to look will on forever and we 36 00:02:22,970 --> 00:02:26,840 will have to close the program on the UN appropriate weight. 37 00:02:26,840 --> 00:02:34,850 So we want to actually exit it properly so after the center command we want to run and if our slope. 38 00:02:34,850 --> 00:02:44,320 So if message which is something that we type equals equals double quotes Q close double quotes and 39 00:02:44,320 --> 00:02:52,120 then two dots we want to actually break out of the loop as we can see right here we break out of the 40 00:02:52,120 --> 00:02:55,040 loop and then we can type your Ls 41 00:02:58,670 --> 00:03:03,650 answer equals target dot receive print answer. 42 00:03:03,820 --> 00:03:06,340 So let's see if this makes sense. 43 00:03:06,400 --> 00:03:12,610 We actually type the message itself we store it in this variable we send the message to the target if 44 00:03:12,610 --> 00:03:17,950 message equals Q This will close the program it will call it will break out of the loop then it will 45 00:03:18,190 --> 00:03:22,310 continue to the next execution which is as close if it is not clear. 46 00:03:22,450 --> 00:03:28,240 Q It will receive a target answer it will print the answer and it will go to the beginning of the loop 47 00:03:28,270 --> 00:03:35,380 which will prompt us with the input of another message and that will do forever until we specify Q As 48 00:03:35,380 --> 00:03:36,210 a message. 49 00:03:36,400 --> 00:03:38,980 So this should work for the server. 50 00:03:39,040 --> 00:03:44,150 Now let's see what we have to type for the client in order for this to actually work together. 51 00:03:44,170 --> 00:03:50,860 So for the client what we want to actually first delete is the answer or no. 52 00:03:50,870 --> 00:03:52,210 Let's actually make a chat program. 53 00:03:52,210 --> 00:03:55,200 So what we want to do is delete these two instructions. 54 00:03:55,300 --> 00:03:58,270 Here we have a message equals saga about receive. 55 00:03:58,900 --> 00:04:02,390 So we want to put both of those into while True loop. 56 00:04:02,410 --> 00:04:04,620 So let's see how this will do. 57 00:04:04,810 --> 00:04:12,370 While true we run the same thing then we tab these two message equals all not receive print message 58 00:04:12,460 --> 00:04:14,770 and then we leave this octet close below. 59 00:04:14,830 --> 00:04:20,440 We do not want to put that in the while loop for same reason that we didn't want to put it here so it 60 00:04:20,440 --> 00:04:23,380 doesn't terminate the connection in our while loop. 61 00:04:24,280 --> 00:04:28,480 So right now let's see what we have to code right here in order for this to work. 62 00:04:28,480 --> 00:04:35,530 So we send the message this will receive the message and it will print the message so good. 63 00:04:35,530 --> 00:04:39,280 Then afterwards we want to specify the message back. 64 00:04:39,280 --> 00:04:43,510 So this is something we can do right here. 65 00:04:43,760 --> 00:04:50,110 The message back let me just see if this will work the way it should work. 66 00:04:50,110 --> 00:04:58,060 So this is something that we want to do so if message that we received equals equals Q Same as in the 67 00:04:58,060 --> 00:05:01,330 previous we want to break the connection as well. 68 00:05:01,330 --> 00:05:05,530 Since if this server right here sent Q it already closed this program. 69 00:05:05,530 --> 00:05:09,620 So if we receive a Q command it means that the server has closed the connection. 70 00:05:09,640 --> 00:05:11,270 So we want to close it as well. 71 00:05:12,170 --> 00:05:16,350 Else we want to actually get an input. 72 00:05:16,370 --> 00:05:20,780 So we want to send message back or we'll call it like that. 73 00:05:20,780 --> 00:05:33,740 That is a variable and then raw input third type message to send to server which is a little bit long 74 00:05:33,770 --> 00:05:35,140 but it doesn't matter. 75 00:05:35,210 --> 00:05:36,650 So we get the message back. 76 00:05:36,650 --> 00:05:45,440 We get an input on our client to send a message back to server and then we basically just suck it up 77 00:05:45,440 --> 00:05:50,270 send the message back then after that it will go back. 78 00:05:50,290 --> 00:05:56,560 Right here it will receive another message that it will print the message and we can go on forever I 79 00:05:56,560 --> 00:05:56,910 believe. 80 00:05:56,920 --> 00:06:01,480 So let us save this control all their control acts to exit. 81 00:06:01,480 --> 00:06:02,230 Same as here. 82 00:06:02,230 --> 00:06:08,860 Control all control extra exit and then we run our server first policing for incoming connections then 83 00:06:08,860 --> 00:06:15,610 we run the reverse shall that be why we get him prompted with this shall command through and we will 84 00:06:15,610 --> 00:06:16,210 just type here. 85 00:06:16,210 --> 00:06:23,640 Hello and we can see that the client printed out our message and it prompts declined to type message 86 00:06:23,640 --> 00:06:29,620 to send to the server and we will type here Hello or Hi there. 87 00:06:29,830 --> 00:06:30,700 Let's just type here. 88 00:06:30,940 --> 00:06:31,710 Hi there. 89 00:06:32,380 --> 00:06:34,570 And we can see this works perfectly. 90 00:06:34,570 --> 00:06:43,930 We got the message back from the client which says hi there that we can say what are you doing. 91 00:06:44,530 --> 00:06:47,080 And the client will receive our question. 92 00:06:47,080 --> 00:06:51,460 They can answer nothing with the slash. 93 00:06:51,460 --> 00:06:52,480 That was a typo. 94 00:06:52,510 --> 00:06:56,900 So right now let's say we want to terminate this connection and we type your cue. 95 00:06:57,010 --> 00:06:59,710 They both terminate the connection. 96 00:06:59,710 --> 00:07:04,100 Just right here it also prints the answer which is not necessary but it doesn't really matter. 97 00:07:04,150 --> 00:07:06,910 They both successfully terminated the connection. 98 00:07:06,910 --> 00:07:09,850 So our simple chat program works. 99 00:07:09,850 --> 00:07:15,820 So this is a simple code that we wrote in order to make a chat program but you might be asking why are 100 00:07:15,820 --> 00:07:17,050 we making a chat program. 101 00:07:17,050 --> 00:07:22,020 Of course our reverse Shell will not be prompted anything for the target to type. 102 00:07:22,090 --> 00:07:27,900 We want to actually execute the commands and not exchange messages between each other. 103 00:07:27,940 --> 00:07:29,370 So this will be similar. 104 00:07:29,380 --> 00:07:33,220 We will not change much to this but this will have to change. 105 00:07:33,220 --> 00:07:38,230 So the user or the target doesn't get prompted with these type messages to send to the server. 106 00:07:38,320 --> 00:07:44,170 We just want to make the target actually execute the message and send the output of that message back 107 00:07:44,530 --> 00:07:45,190 in our case. 108 00:07:45,190 --> 00:07:47,770 Those will be terminal commands or command prompt comments. 109 00:07:48,310 --> 00:07:52,480 So we will do that in the next video and I hope I see you there by.