1 00:00:00,440 --> 00:00:03,390 We'll come to another video of our offensive cyber operations. 2 00:00:03,420 --> 00:00:09,780 Listen, we've been talking about Python before and starting from this lesson, we will try to build 3 00:00:09,780 --> 00:00:11,360 our own backdoor in Python. 4 00:00:12,300 --> 00:00:15,180 But first, we need to know how python socket works. 5 00:00:16,740 --> 00:00:17,780 Let's get started. 6 00:00:20,770 --> 00:00:27,280 A socket in general is one in point of a two way communication link, typically between client and server, 7 00:00:27,730 --> 00:00:34,570 where we can just say two devices in a network in order for us to build a socket, we need to be able 8 00:00:34,570 --> 00:00:37,960 to connect, send, receive and close the connection. 9 00:00:39,370 --> 00:00:44,980 In this lesson, we are going to talk about two types of sockets, TCP and UDP socket. 10 00:00:45,970 --> 00:00:48,760 Let's start with building UDP sockets first. 11 00:00:52,040 --> 00:00:58,040 To build a UDP socket, we start by creating a variable that will hold the socket object, then the 12 00:00:58,040 --> 00:01:05,240 syntax for the socket, as you can see in the slide socket, that socket, then open parenthesis, then 13 00:01:05,240 --> 00:01:07,510 we have two arguments inside the socket. 14 00:01:08,570 --> 00:01:09,290 First one. 15 00:01:12,800 --> 00:01:21,830 Is soccer dad, if underscore inet, which is used for IPV for the second one, is the protocol we're 16 00:01:21,830 --> 00:01:24,320 using and in this case we're using UDP. 17 00:01:25,070 --> 00:01:28,710 So we type socketed that Sorkh underscore the ground. 18 00:01:29,030 --> 00:01:30,670 A node is the acronym is UDP. 19 00:01:31,970 --> 00:01:34,160 Now that's where we build a socket. 20 00:01:34,550 --> 00:01:37,490 Let's look at how we listen on a port at the server side. 21 00:01:40,960 --> 00:01:45,440 We listen to a report using the brain function, so the name of the baby. 22 00:01:45,460 --> 00:01:54,580 We created the blind then inside to print these, we pass two arguments, the IP you want to listen 23 00:01:54,580 --> 00:01:58,690 on and a court notice that the IP is a string. 24 00:01:59,140 --> 00:02:01,300 So it has to be inside double quotes. 25 00:02:03,340 --> 00:02:06,450 After that, we started receiving packets from the sender. 26 00:02:07,000 --> 00:02:13,390 We do that using the socket that's received from and above her or how much bias you want to receive 27 00:02:13,390 --> 00:02:17,920 every time in this case we used one thousand twenty four bytes. 28 00:02:19,390 --> 00:02:23,340 We can also save what we receive in a variable so we can use it later. 29 00:02:24,340 --> 00:02:25,660 Let's see that in action. 30 00:02:37,080 --> 00:02:42,960 Let's import our Soviet module first, using the word import, followed by the name of the module, 31 00:02:42,960 --> 00:02:44,250 which is socket. 32 00:02:46,410 --> 00:02:47,820 Then we build the socket. 33 00:02:49,710 --> 00:02:52,410 Now we bind on an IP import. 34 00:02:52,620 --> 00:02:59,370 But this time we will use 0.01 zero, that zero to listen on all interfaces so we can receive traffic 35 00:02:59,370 --> 00:03:01,260 from other devices in our network. 36 00:03:04,320 --> 00:03:12,900 Let's receive some data now, but we need to save them in a variable called data and then print it. 37 00:03:15,690 --> 00:03:20,610 Now let's run this server and connect to it from another terminal using Ngarkat. 38 00:03:44,660 --> 00:03:49,950 As you noticed, when we print our data available, we get the message that was received along with 39 00:03:49,950 --> 00:03:51,590 the IP and Port of the Sender. 40 00:03:55,590 --> 00:04:02,730 Now, how do we separate the data from the sender information like IP and Port, since we know it's 41 00:04:02,730 --> 00:04:09,840 a couple of elements of two elements, we can assign each one to a different variable on the same line. 42 00:04:11,640 --> 00:04:17,640 If we add a comma and the name of another variable, then we can store IP and port information of the 43 00:04:17,640 --> 00:04:19,200 sender into that variable. 44 00:04:20,340 --> 00:04:22,290 Let's call it can see in an. 45 00:04:33,060 --> 00:04:39,750 And since we know that this information is stored as a list and the IP of the sender is the first element, 46 00:04:40,380 --> 00:04:45,300 then it should be element number zero and the port is element number one. 47 00:05:08,780 --> 00:05:09,610 Let's ride in. 48 00:05:24,840 --> 00:05:31,620 Nice, but we have a problem here, the socket only receives one packet and and then it closes. 49 00:05:32,490 --> 00:05:35,570 If we want to keep it running, we need to put it in a while loop. 50 00:05:36,140 --> 00:05:36,900 Let's do that. 51 00:06:23,640 --> 00:06:32,970 Our UDP server looks good now let's build our UDP client, the UDP client is kind of the same, but 52 00:06:32,970 --> 00:06:34,810 we don't need to bind on any port. 53 00:06:34,950 --> 00:06:38,220 We simply send the data using the Senate to function. 54 00:06:50,370 --> 00:06:52,590 Now, let's try again using the UDP client. 55 00:07:10,190 --> 00:07:16,150 We received the message nice, we have reached the end of this lesson, thank you. 56 00:07:16,160 --> 00:07:17,210 And soon the next one.