1 00:00:00,270 --> 00:00:02,480 Hello everybody and welcome back. 2 00:00:02,520 --> 00:00:06,410 And in the previous two videos we actually created a simple server and reversal. 3 00:00:06,420 --> 00:00:12,390 And right now we want to be able to send some messages back and forth between these two programs. 4 00:00:12,390 --> 00:00:15,730 So we want to make a connection a little bit longer. 5 00:00:15,750 --> 00:00:21,570 We want to actually send some information from one program to another program and see if that will work. 6 00:00:21,570 --> 00:00:23,910 So let's start off with the server. 7 00:00:23,910 --> 00:00:30,420 So let us open server not be white as we can see we opened everything right here. 8 00:00:30,500 --> 00:00:36,810 Let's see any other video or let's actually open in the first video server and then the second video 9 00:00:36,810 --> 00:00:39,120 we will openly reverse shall not be white. 10 00:00:39,600 --> 00:00:49,440 So what we want to do right now is basically first of all we want to delete the as close for now so 11 00:00:49,590 --> 00:00:50,500 delete this. 12 00:00:50,520 --> 00:00:53,880 We want to delete that in the next one as well. 13 00:00:54,180 --> 00:00:57,510 We will perform the closing of connections at the end. 14 00:00:57,510 --> 00:01:03,870 And right now let us try to actually send something with the send and receive comments as we can see 15 00:01:03,870 --> 00:01:07,560 right here they send and receive is something that we didn't code yet. 16 00:01:07,620 --> 00:01:12,240 So these two comments both of these are both server and client have to have them. 17 00:01:12,270 --> 00:01:13,930 So one can receive and some. 18 00:01:14,070 --> 00:01:20,570 So both of them can both receive and send the information or the commands in our case. 19 00:01:21,060 --> 00:01:24,300 So let's see how we can actually implement that. 20 00:01:24,330 --> 00:01:28,220 Let us start off by implementing it in the server. 21 00:01:28,320 --> 00:01:32,640 So what we want to do is use the command call dot. 22 00:01:32,830 --> 00:01:37,730 Use the function in the socket library called sent it as simple as that. 23 00:01:37,740 --> 00:01:44,050 So what we want to do right here after the target has connected let us see what we can do. 24 00:01:44,070 --> 00:01:52,570 We want to actually get an output from which IP address the target is coming. 25 00:01:52,570 --> 00:02:01,450 So let us see how we can actually give us our command line tool that will be able to give a user that 26 00:02:01,450 --> 00:02:02,630 is using the server. 27 00:02:02,840 --> 00:02:08,230 Our command line that will where they specify a command and it sends that command to deliver shell which 28 00:02:08,230 --> 00:02:11,980 will execute it in Iran on the target machine. 29 00:02:11,980 --> 00:02:21,450 So let us actually make a variable called command so simple as that command is something that we will 30 00:02:21,450 --> 00:02:26,450 send and we want to get the user input for the command so raw input. 31 00:02:26,710 --> 00:02:27,820 We covered all of this. 32 00:02:27,820 --> 00:02:29,170 We know what your input is. 33 00:02:29,170 --> 00:02:32,440 It basically prompts user for an input. 34 00:02:32,440 --> 00:02:38,470 In our case a string input and we want to specify what the user will see. 35 00:02:38,470 --> 00:02:40,580 So double quotes. 36 00:02:40,780 --> 00:02:42,220 Let's start with something like this. 37 00:02:42,220 --> 00:02:48,230 So Star shell and then let's try to create some something simple as our routed terminal shell. 38 00:02:48,230 --> 00:02:54,300 So hash tag I believe something like that and this sign right here then the. 39 00:02:54,310 --> 00:03:02,230 Percent as the percent S is actually the part of the string of the IP that we will attach to the string. 40 00:03:02,230 --> 00:03:04,840 We covered all of this in the python basics. 41 00:03:04,840 --> 00:03:09,490 This is just before this this shell and then hash tag is basically something that you can specify anything 42 00:03:09,490 --> 00:03:09,840 you want. 43 00:03:09,840 --> 00:03:10,750 It doesn't really matter. 44 00:03:11,620 --> 00:03:15,820 I decided to specify that and then we closed this as a string. 45 00:03:15,940 --> 00:03:25,930 After that we need to do to attach loops the string of IP and we can see first of all close the double 46 00:03:25,930 --> 00:03:31,490 parentheses and we can see that the IP is something that we got with these as Dot accept command. 47 00:03:31,570 --> 00:03:39,670 So we will get prompted this string right here just instead of the percent s we will get have written 48 00:03:40,450 --> 00:03:42,620 the IP address of our target machine. 49 00:03:43,300 --> 00:03:49,920 So that would be that for the command then we type any command that we want to run on the target system 50 00:03:50,320 --> 00:03:53,440 and then the target system should execute that command. 51 00:03:53,440 --> 00:03:58,650 So for now on we want to send that command right after we receive it. 52 00:03:58,650 --> 00:04:07,110 So we will do since we specified here we will do socket dot send I believe or not socket since we specify 53 00:04:07,110 --> 00:04:09,950 the target to connect we want to send to the target. 54 00:04:09,990 --> 00:04:17,170 So we want to specify here target dot sent and then the command. 55 00:04:17,220 --> 00:04:21,780 I believe this is the syntax we'll have to check it out but it should be this. 56 00:04:21,810 --> 00:04:30,030 So this is something that for this is a function that will send the input for this command to the target 57 00:04:30,030 --> 00:04:30,750 server. 58 00:04:30,750 --> 00:04:38,940 So let us see if we can actually receive something from the target server after we want to after we 59 00:04:38,940 --> 00:04:40,910 specify the send command option. 60 00:04:40,920 --> 00:04:48,250 We want to actually receive a received data from the target system and how we do that. 61 00:04:48,540 --> 00:04:51,470 We do that with the DOT receive function. 62 00:04:51,600 --> 00:04:53,340 So we will do something like this. 63 00:04:53,370 --> 00:05:01,080 So after that terror target not receive and indeed parentheses in target dot receive we need to specify 64 00:05:01,080 --> 00:05:02,100 the number of bytes. 65 00:05:02,100 --> 00:05:04,980 It will allow us to receive back. 66 00:05:05,010 --> 00:05:12,190 So here will specify thousand and twenty four since we will not really be needing much more than that. 67 00:05:12,420 --> 00:05:14,820 And that would be it for the server. 68 00:05:14,820 --> 00:05:19,020 Now this is a code for only executing a simple command and one command. 69 00:05:19,050 --> 00:05:22,320 So we will send the command that target will execute it. 70 00:05:22,320 --> 00:05:24,820 It will send back the output of that command. 71 00:05:24,870 --> 00:05:28,550 We will print the output of that command and we will close the connection. 72 00:05:28,560 --> 00:05:35,230 So what we want to type right here is basically put this in. 73 00:05:35,380 --> 00:05:44,940 First of all we need to put this in r in a variable so let's call it let's call it result equals target 74 00:05:44,970 --> 00:05:45,970 that receive. 75 00:05:46,630 --> 00:05:49,810 And then after that we want to print the result. 76 00:05:50,890 --> 00:05:57,490 So this parenthesis right here is something from Python 3 so in python 2 you can use the print function 77 00:05:57,490 --> 00:06:01,870 both with or without the parentheses I will use it with in my case. 78 00:06:01,870 --> 00:06:05,250 And after that what I want to do is close the connection. 79 00:06:05,260 --> 00:06:09,380 So this should be it for the servers or server part of code. 80 00:06:09,520 --> 00:06:10,930 So let's double check. 81 00:06:11,050 --> 00:06:16,870 We got target connected we got prompted to input the command we send the command we receive the results 82 00:06:16,870 --> 00:06:19,810 of the command we print the results and we close the connection. 83 00:06:19,810 --> 00:06:26,960 So let us code the part of the client command all of the reverse shall computer code. 84 00:06:26,980 --> 00:06:28,720 So let us do that. 85 00:06:28,810 --> 00:06:33,750 It should be rather simple and similar to the server. 86 00:06:33,880 --> 00:06:43,060 But right now we first want to receive the command and then execute it now to execute the command. 87 00:06:43,060 --> 00:06:46,390 We need to use another library. 88 00:06:46,390 --> 00:06:54,290 So for now on we will not execute command we will just try to send a simple string message. 89 00:06:54,410 --> 00:06:59,770 And later on I will show you how you can send a command and make target executed for now on let's just 90 00:06:59,970 --> 00:07:02,860 say exchange some simple messages. 91 00:07:02,860 --> 00:07:03,970 So how we do that. 92 00:07:03,980 --> 00:07:10,860 Well basically right here we will or Let's for now and so you don't get confused rename this to message. 93 00:07:10,930 --> 00:07:11,960 So it's not a command. 94 00:07:11,980 --> 00:07:14,040 It's just a message simple message for now. 95 00:07:14,040 --> 00:07:16,380 So we have to rename it everywhere. 96 00:07:16,630 --> 00:07:19,880 Message and that should be about it. 97 00:07:20,050 --> 00:07:24,020 And the result we will rename to the answer. 98 00:07:24,550 --> 00:07:27,470 Print answer. 99 00:07:27,470 --> 00:07:30,520 And here we want to first receive the message. 100 00:07:30,550 --> 00:07:38,850 So the message right here will equal the SOC dot receive. 101 00:07:39,010 --> 00:07:43,150 Here we receive the input message of our server. 102 00:07:43,150 --> 00:07:49,450 So we want to receive 1024 bytes and we want to actually 103 00:07:53,280 --> 00:07:57,140 what we want to do is actually send the answer so SOC dot send. 104 00:07:57,480 --> 00:07:58,820 And we want to send. 105 00:07:58,860 --> 00:08:02,730 Well let's actually put it in a variable so answer equals 106 00:08:05,320 --> 00:08:06,220 shallow back 107 00:08:09,040 --> 00:08:14,450 so this is something that the client will send back to the server and we will print it in the answer 108 00:08:14,510 --> 00:08:15,620 as we can see right here. 109 00:08:16,280 --> 00:08:22,670 So now we want to in our client we want to send this answer so we do that we talked not send and we 110 00:08:22,670 --> 00:08:24,570 sent answer. 111 00:08:24,680 --> 00:08:27,550 And after that what we want to do is close the connection. 112 00:08:27,560 --> 00:08:31,420 So SOC that close and I believe this should work. 113 00:08:31,430 --> 00:08:33,670 Let us check it out so let us double check. 114 00:08:33,680 --> 00:08:36,050 We get the command we send the command. 115 00:08:36,170 --> 00:08:39,770 The target receives the command. 116 00:08:39,770 --> 00:08:49,610 It should print the command as well so print message then it they then the target answer will be hello 117 00:08:49,610 --> 00:08:50,630 back. 118 00:08:50,630 --> 00:08:56,380 And then we set the target sends the answer we receive it and put it in an answer variable. 119 00:08:56,390 --> 00:09:00,980 Then we print the answer then recall the connection then the target is what closes the connection. 120 00:09:00,980 --> 00:09:03,020 So in I believe this should work. 121 00:09:03,020 --> 00:09:09,710 So let the safe control all control acts to exit and then control and then control access to exit. 122 00:09:09,710 --> 00:09:13,600 We first run the server listening for incoming connections. 123 00:09:13,610 --> 00:09:14,440 Good. 124 00:09:14,480 --> 00:09:21,530 Then we run the reverse shell connection established the server and we can see that our string input 125 00:09:21,620 --> 00:09:22,660 actually works. 126 00:09:22,670 --> 00:09:30,560 So we get the connection from 127 to 0 0 1 1 port for 4 5 2 0 6. 127 00:09:30,560 --> 00:09:32,040 Here we will send. 128 00:09:33,230 --> 00:09:37,200 Let me just move this a little bit so we can see it. 129 00:09:37,220 --> 00:09:39,110 Oh good. 130 00:09:39,110 --> 00:09:40,160 Just a little bit more. 131 00:09:40,670 --> 00:09:41,210 OK good. 132 00:09:41,390 --> 00:09:46,760 And here we send hello and we can see everything worked perfectly. 133 00:09:46,790 --> 00:09:53,780 The shell the our server got an input of a message where we typed hello we sent that message to the 134 00:09:53,780 --> 00:09:58,100 client which printed that message in its terminal and we can see it does match. 135 00:09:58,100 --> 00:10:04,100 So it is the same message then send the answer back which recorded in the reverse shell which was hello 136 00:10:04,100 --> 00:10:11,300 back and we'd send it send that to our server which printed the answer in our terminal and then they 137 00:10:11,300 --> 00:10:16,370 both terminated the connection afterwards so we got yellow back printed and here we go. 138 00:10:16,400 --> 00:10:17,680 Hello printed. 139 00:10:17,750 --> 00:10:23,710 So that would be about it for the story all we managed to send a simple message. 140 00:10:23,840 --> 00:10:30,740 We will try to make a code which will send infinite messages are not infinite but basically we can send 141 00:10:30,740 --> 00:10:35,960 messages back and forth as long as we want and then we will implement it to be commands that can be 142 00:10:36,050 --> 00:10:40,460 executed on target server or pardon me on target machine. 143 00:10:40,670 --> 00:10:45,880 So that voted for this story well I hope you enjoyed it and I hope I see you in the next one. 144 00:10:46,160 --> 00:10:46,430 Bye.