1
00:00:00,450 --> 00:00:01,410
Welcome back everyone.

2
00:00:01,410 --> 00:00:05,970
And right now we are ready to start coding our at Sage connect function.

3
00:00:05,970 --> 00:00:08,580
In the previous video recorded all of this.

4
00:00:08,580 --> 00:00:13,470
So this is just the base part of the program where we ask for some important information.

5
00:00:13,470 --> 00:00:15,740
Then we check whether that information is correct.

6
00:00:15,780 --> 00:00:19,160
And then we continue with the actual brute forcing.

7
00:00:19,230 --> 00:00:23,960
Right now we're going to code the assets connect function and let's do it at the beginning of the program.

8
00:00:23,960 --> 00:00:30,540
We're going to define it first defined as say to underscore connect and this function will actually

9
00:00:30,540 --> 00:00:36,420
take two parameters one of them is going to be the password which is specified right here and the other

10
00:00:36,420 --> 00:00:41,640
one we're going to actually declare right here in the brackets and we're going to call it code to be

11
00:00:41,670 --> 00:00:43,220
equal to zero.

12
00:00:43,230 --> 00:00:48,510
What this means when you simply specify code to be equal to zero is in case we don't really specify

13
00:00:48,540 --> 00:00:50,300
anything as a second parameter.

14
00:00:50,310 --> 00:00:55,470
Right here in this line that means that this code parameter will automatically be set to zero.

15
00:00:55,470 --> 00:00:56,140
All right.

16
00:00:56,190 --> 00:00:57,760
And we want it like that.

17
00:00:57,810 --> 00:01:03,060
So let's add two dots right here and start coding the part of the function first of all we need to create

18
00:01:03,120 --> 00:01:09,990
a variable which is going to be called as a stage and that variable will be equal to practical dot as

19
00:01:09,990 --> 00:01:11,660
sage client.

20
00:01:11,730 --> 00:01:16,830
So we're going to use this as sage client function in order to declare this variable and then we're

21
00:01:16,860 --> 00:01:22,080
going to use this variable to set missing course key policy.

22
00:01:22,110 --> 00:01:26,910
So this is a long function as you can see if you can simply just tab it all to complete it once the

23
00:01:26,960 --> 00:01:29,880
PI charm outputs it as a possible function to use.

24
00:01:29,880 --> 00:01:36,570
So we're going to type a stage set missing course key policy and right here we need to specify radical

25
00:01:37,350 --> 00:01:41,920
dot out or add policy.

26
00:01:42,150 --> 00:01:44,190
And this is also a function.

27
00:01:44,190 --> 00:01:50,840
So this is just some basic two lines that we need to set before we try to connect to the stage client.

28
00:01:51,030 --> 00:01:57,900
And right after it comes to connect part which we will try we did try and accept a statement

29
00:02:00,570 --> 00:02:02,580
similar thing that we did with our port scanner.

30
00:02:02,590 --> 00:02:07,560
We're going to do right here and we're going to try to connect inside this try statement and in the

31
00:02:07,560 --> 00:02:11,610
accept statement we're going to print that the password was incorrect.

32
00:02:11,610 --> 00:02:12,300
All right.

33
00:02:12,360 --> 00:02:20,060
So right here in the statement we're going to type as a search dot connect we're going to connect on

34
00:02:20,100 --> 00:02:21,180
to the host.

35
00:02:21,390 --> 00:02:26,250
And keep in mind that the host is this variable right here which stores the IP address that the user

36
00:02:26,250 --> 00:02:27,620
specifies.

37
00:02:27,870 --> 00:02:35,150
We want to connect over the port twenty two because the port 22 is a regular port for DSH.

38
00:02:35,370 --> 00:02:42,160
We want to set the user name to be equal to user name which once again is this variable right here.

39
00:02:42,750 --> 00:02:49,110
And we want to set the last thing which is going to be the password to be equal to password which we

40
00:02:49,110 --> 00:02:52,490
pasted right here as a parameter.

41
00:02:52,560 --> 00:02:56,130
So it is going to get stored from here to here.

42
00:02:56,570 --> 00:02:57,300
All right.

43
00:02:57,330 --> 00:03:04,080
So this connect function that comes with the parameter code library has four parameters the IP address

44
00:03:04,140 --> 00:03:07,680
the port number the user name and password.

45
00:03:07,680 --> 00:03:12,130
And this is all that we are going to do right here in the tri statement in the accept statement.

46
00:03:12,130 --> 00:03:19,980
We're going to check for an error which is going to be called tyrannical authentication exception which

47
00:03:19,980 --> 00:03:23,530
simply just stands for if the password design was incorrect.

48
00:03:23,530 --> 00:03:25,720
We're going to perform this part of the code.

49
00:03:25,770 --> 00:03:31,410
So if that indication didn't manage to go through that means we specified the incorrect password and

50
00:03:31,470 --> 00:03:36,570
therefore we're going to set the code parameter which remember is the second parameter to our function

51
00:03:36,840 --> 00:03:44,120
to be equal to one and in the last case which is going to be another accept statement.

52
00:03:44,120 --> 00:03:57,080
We're going to set right here except circuit error as e we're going to set the code to be equal to and

53
00:03:57,090 --> 00:04:02,430
before I explain this try and accept once again let me just type here as sage up close once we finish

54
00:04:02,430 --> 00:04:09,540
everything and we want to return the code from this function so let's go through it once again we declared

55
00:04:09,550 --> 00:04:12,860
the asset client we add the auto add policy.

56
00:04:12,930 --> 00:04:15,550
These are two standard lines before we try to connect.

57
00:04:15,570 --> 00:04:17,410
Then we try to connect with the target.

58
00:04:17,490 --> 00:04:23,050
If we managed to connect with the password then the second parameter which is code will remain zero.

59
00:04:23,100 --> 00:04:26,880
If we specify wrong password the code will be changed to 1.

60
00:04:27,180 --> 00:04:31,890
And if there is any error during the connection for example we cannot connect to the target because

61
00:04:31,890 --> 00:04:32,910
it is offline.

62
00:04:32,970 --> 00:04:35,430
Then the code will be too.

63
00:04:36,270 --> 00:04:42,360
Therefore once we return the code and we check it then we will know which password is correct and which

64
00:04:42,360 --> 00:04:43,930
password is incorrect.

65
00:04:43,980 --> 00:04:50,010
All right so we're going to finish that in the next tutorial for now and we got our function ready.

66
00:04:50,010 --> 00:04:56,340
And before I finish off this lecture I will just add right here that the response is going to be equal

67
00:04:56,730 --> 00:04:57,480
to as such.

68
00:04:57,480 --> 00:04:59,670
Connect with the password.

69
00:04:59,730 --> 00:05:05,010
The reason for that is since we are returning the code from our function we want to store the result

70
00:05:05,040 --> 00:05:06,810
inside of our response variable.

71
00:05:06,810 --> 00:05:14,060
Therefore this response variable will contain the value of the code whether it is 0 1 or 2.

72
00:05:14,110 --> 00:05:14,620
All right.

73
00:05:14,640 --> 00:05:20,130
So simple as that and let's continue in the next material corpus you there and take care by.
