1 00:00:00,540 --> 00:00:07,620 In the first lecture of creating the Windows application, we will gather following information 2 00:00:07,620 --> 00:00:17,490 operating system and hostname, current user and privileges, network configuration, current directory, 3 00:00:17,490 --> 00:00:22,380 current process name, process id and the executable path of current process. 4 00:00:23,550 --> 00:00:28,800 All of those information are crucial in red teaming, penetration testing and hacking. 5 00:00:29,930 --> 00:00:37,610 We will send all of those information to our attacker server. As an additional idea, you can detect 6 00:00:37,620 --> 00:00:43,790 the antivirus software installed, but let's take it as Homework and do it by yourself. 7 00:00:45,410 --> 00:00:54,500 To do so, we will create a class called GeneralInfo or you can call it whatever you like, and 8 00:00:54,500 --> 00:01:01,310 inside the class we will define functions to gather specified information and assign them to corresponding 9 00:01:01,310 --> 00:01:05,000 variables of class so we can use them later on. 10 00:01:07,130 --> 00:01:13,700 In C Sharp, there are many predefined classes that exist to retrieve information from the system. 11 00:01:15,150 --> 00:01:22,010 For example, and Environment class for enumerating the environment, which contains username info, 12 00:01:22,740 --> 00:01:31,050 current directory info, operating system info, etc., and process class for determining process name, 13 00:01:31,050 --> 00:01:34,080 process id, executable path etc. 14 00:01:35,610 --> 00:01:41,670 If you are new to these concepts, I highly encourage you to learn more about them before continue. 15 00:01:43,170 --> 00:01:44,520 So let's start coding. 16 00:01:47,120 --> 00:01:48,650 Here is our dummy application. 17 00:01:49,790 --> 00:01:51,380 We will start coding by 18 00:01:53,020 --> 00:01:56,290 creating a new file, it will be our new class. 19 00:02:00,120 --> 00:02:08,550 I will name it as info.cs, but you can you can give any name you want and copy the contents 20 00:02:08,550 --> 00:02:12,930 of a program.cs file into the new file you have created. 21 00:02:17,040 --> 00:02:23,010 And change the class name, I will use generalinfo as my class name. 22 00:02:25,240 --> 00:02:30,250 And remove that trivial code, so your class is ready. 23 00:02:31,290 --> 00:02:32,150 What's next? 24 00:02:33,400 --> 00:02:38,060 For the next step, we will create variables for storing data. 25 00:02:39,520 --> 00:02:41,500 We will need a lot of variables. 26 00:02:45,080 --> 00:02:45,890 Here are them. 27 00:02:49,300 --> 00:02:56,410 A string variable for storing the operating system, another string variable for storing username. 28 00:02:57,380 --> 00:02:59,000 An integer variable for 29 00:03:00,250 --> 00:03:08,000 storing the process id, a boolean variable for the storing the privilege information to check if 30 00:03:08,000 --> 00:03:15,980 our user is administrator or not. For the next step, we will create a main function that will gather 31 00:03:16,030 --> 00:03:17,410 all of those information. 32 00:03:18,430 --> 00:03:25,600 It will be our constructor if you are new to this concept, constructor is a method that will be called 33 00:03:25,600 --> 00:03:27,980 whenever an object of class is created. 34 00:03:28,630 --> 00:03:34,030 So it's best option to perform initial operations. To create a constructor 35 00:03:36,010 --> 00:03:45,210 simply create a function and name it with the same name with the class general info. 36 00:03:46,660 --> 00:03:48,340 So this is our constructer. 37 00:03:52,660 --> 00:03:54,580 Let's start to gather information. 38 00:03:55,110 --> 00:03:56,080 We will start with 39 00:03:57,190 --> 00:03:58,240 operating system. 40 00:04:00,660 --> 00:04:09,000 To gather operating system version, we will use the OS version, the property 41 00:04:09,000 --> 00:04:10,470 of the environment class. 42 00:04:14,720 --> 00:04:22,760 It will return the operating system version, but its data type is not string, its type is 43 00:04:22,760 --> 00:04:26,460 system.operating system in order to convert it to String 44 00:04:27,530 --> 00:04:29,480 we will use ToString method. 45 00:04:34,020 --> 00:04:44,670 To gather username information, we will use the username property of the environment class, and for 46 00:04:44,670 --> 00:04:52,770 the current directory, we will use the current directory property of the environment class. 47 00:04:57,550 --> 00:05:03,960 And for proces name, we will use process class to do so, we need the name space. 48 00:05:04,510 --> 00:05:07,000 So let let's define it first. 49 00:05:10,550 --> 00:05:19,400 In order to use process class directly, we need to define a system that diagnostics namespace at the top 50 00:05:19,400 --> 00:05:30,350 of our file and then we would use the get current process method of the process class. 51 00:05:32,300 --> 00:05:35,400 The current process methods. 52 00:05:36,980 --> 00:05:44,630 This method will return the information about the process and people we will use to process name 53 00:05:47,900 --> 00:05:54,200 property of the Process class to retrieve process name information from the system. 54 00:05:57,260 --> 00:06:04,160 And for the Process id, we will use Process class again with the current process method 55 00:06:06,860 --> 00:06:09,320 and we will use the Id property. 56 00:06:12,800 --> 00:06:22,100 And for hostname, we will use DNS class, but in order to use it we need to define a 57 00:06:22,100 --> 00:06:23,090 System.Net namespace. 58 00:06:24,080 --> 00:06:29,190 Let's do it at the top of our file System.Net 59 00:06:33,130 --> 00:06:37,540 We will use get hostname method of the DNS class. 60 00:06:44,590 --> 00:06:55,650 So this method will return the current hostname and for the IP version for address, we will use the 61 00:06:55,660 --> 00:06:56,590 DNS class again. 62 00:06:57,340 --> 00:07:04,450 But this time we will use get lost by name methods, post by name. 63 00:07:04,460 --> 00:07:11,700 And this method returns the DNS information of given hostname. 64 00:07:12,100 --> 00:07:14,650 So we will use our hostname as argument. 65 00:07:18,310 --> 00:07:23,570 And we will get the first element of the address list property. 66 00:07:24,370 --> 00:07:32,590 Hopefully it will be the true one and we need to convert its data type to string. 67 00:07:34,270 --> 00:07:36,430 To do so, we will use the ToString method. 68 00:07:45,190 --> 00:07:54,220 And in order to check if our user has administrator privileges or not, we will use Windows Identity 69 00:07:54,220 --> 00:07:55,990 and Windows principal classes. 70 00:08:00,460 --> 00:08:02,910 Here is the sample code for it. 71 00:08:11,590 --> 00:08:12,580 In the first line. 72 00:08:15,340 --> 00:08:23,650 We are getting the windows are against the object of the current user and the second line, we are enabling 73 00:08:23,650 --> 00:08:27,390 all code to check if our user is in a user group or not. 74 00:08:27,850 --> 00:08:29,520 We are just enabling this feature. 75 00:08:30,340 --> 00:08:40,120 And the third line with the IsInRole method, we are deciding if our user has administrator privileges 76 00:08:40,120 --> 00:08:40,610 or not. 77 00:08:42,790 --> 00:08:52,180 So we have completed our task in order to check if everything are OK, switch back to your 78 00:08:52,180 --> 00:08:56,260 program.cs file and create an object of our class 79 00:08:58,740 --> 00:09:07,090 I will call it info object, but it doesn't matter, the names doesn't matter. 80 00:09:08,910 --> 00:09:11,070 It's new generalinfo. 81 00:09:14,850 --> 00:09:15,960 And let's check. 82 00:09:22,030 --> 00:09:29,890 If the IP version four address variable of the general info class 83 00:09:32,190 --> 00:09:41,760 will return our IP version four address, open up your terminal and type dotnet run. 84 00:09:46,750 --> 00:09:53,620 Ignore the warnings and look at the end of the output, as you can see, here is our IP version four 85 00:09:53,620 --> 00:10:03,160 address excellent. As an advice to not try to memorize all of the code, just take notes and use them 86 00:10:03,160 --> 00:10:04,030 whenever you need. 87 00:10:05,140 --> 00:10:06,310 That's it for this lecture. 88 00:10:06,670 --> 00:10:07,720 See you in the next one.