1 00:00:00,870 --> 00:00:01,710 ‫Instructor: Hi. 2 00:00:01,710 --> 00:00:03,030 ‫Within this section, 3 00:00:03,030 --> 00:00:07,050 ‫we're going to take a look at Android reverse engineering 4 00:00:07,050 --> 00:00:10,530 ‫and Android app manipulation. 5 00:00:10,530 --> 00:00:15,330 ‫So this is one of the hardest subjects on our course, 6 00:00:15,330 --> 00:00:18,420 ‫and also this is one of the most interesting 7 00:00:18,420 --> 00:00:22,860 ‫and most fun funnest part of our course as well. 8 00:00:22,860 --> 00:00:26,190 ‫So if you master reverse engineering, 9 00:00:26,190 --> 00:00:28,860 ‫you will have the chance to see the vulnerabilities, 10 00:00:28,860 --> 00:00:31,740 ‫you will have the chance to manipulate the apps 11 00:00:31,740 --> 00:00:33,450 ‫in a way that you want. 12 00:00:33,450 --> 00:00:36,150 ‫So this is very important. 13 00:00:36,150 --> 00:00:38,670 ‫But in order to master reverse engineering, 14 00:00:38,670 --> 00:00:42,180 ‫first we have to understand how an Android app 15 00:00:42,180 --> 00:00:47,100 ‫is actually created on background, on theory, okay? 16 00:00:47,100 --> 00:00:50,910 ‫Then we will learn how to reach source codes 17 00:00:50,910 --> 00:00:55,910 ‫or bytecodes from the latest product, final product. 18 00:00:56,220 --> 00:00:59,910 ‫So let me tell you all about this theory. 19 00:00:59,910 --> 00:01:03,090 ‫So I found a simple diagram on internet, 20 00:01:03,090 --> 00:01:04,500 ‫so you don't have to do that, 21 00:01:04,500 --> 00:01:06,930 ‫you can just follow along with me. 22 00:01:06,930 --> 00:01:11,460 ‫So this is Java source code to Java final product, 23 00:01:11,460 --> 00:01:16,460 ‫and this is Java source code to final Android product. 24 00:01:17,370 --> 00:01:20,100 ‫So it doesn't matter if you're writing in Java 25 00:01:20,100 --> 00:01:22,140 ‫or if you're writing in Kotlin. 26 00:01:22,140 --> 00:01:23,220 ‫Okay? 27 00:01:23,220 --> 00:01:25,890 ‫If you are creating an Android app, 28 00:01:25,890 --> 00:01:28,380 ‫then you're following a different path 29 00:01:28,380 --> 00:01:31,830 ‫than a simple Java application. 30 00:01:31,830 --> 00:01:33,870 ‫So why is that? 31 00:01:33,870 --> 00:01:37,290 ‫So if you can look at the chart on the right-hand side, 32 00:01:37,290 --> 00:01:40,590 ‫you will see it starts with source code, of course. 33 00:01:40,590 --> 00:01:45,150 ‫Because we're gonna write some code in Java or Kotlin. 34 00:01:45,150 --> 00:01:48,360 ‫Anyhow, but then it transforms 35 00:01:48,360 --> 00:01:50,580 ‫to something called Java bytecode, 36 00:01:50,580 --> 00:01:53,310 ‫and this is just byte version of Java code 37 00:01:53,310 --> 00:01:56,010 ‫and it's actually similar 38 00:01:56,010 --> 00:02:00,540 ‫to the process of Java final products as well. 39 00:02:00,540 --> 00:02:04,230 ‫But then it transforms to something called 40 00:02:04,230 --> 00:02:06,090 ‫Dalvik bytecode. 41 00:02:06,090 --> 00:02:10,290 ‫And this is where it gets actually interesting. 42 00:02:10,290 --> 00:02:12,630 ‫Why do we use Dalvik bytecode, 43 00:02:12,630 --> 00:02:14,220 ‫and what is that? 44 00:02:14,220 --> 00:02:18,030 ‫So Android operating system actually run something 45 00:02:18,030 --> 00:02:20,880 ‫called Dalvik virtual machine, okay? 46 00:02:20,880 --> 00:02:23,370 ‫And in order to run this app 47 00:02:23,370 --> 00:02:26,430 ‫that you have written in Java or Kotlin, 48 00:02:26,430 --> 00:02:29,700 ‫it uses Dalvik virtual machine, 49 00:02:29,700 --> 00:02:34,700 ‫and in order to run some APKs final products 50 00:02:35,220 --> 00:02:37,882 ‫on this Dalvik virtual machine, 51 00:02:37,882 --> 00:02:41,430 ‫it has to be transformed into Dalvik bytecode. 52 00:02:41,430 --> 00:02:43,770 ‫So by reverse engineering, 53 00:02:43,770 --> 00:02:47,400 ‫we mean getting Dalvik bytecodes 54 00:02:47,400 --> 00:02:49,260 ‫out of the final APK, 55 00:02:49,260 --> 00:02:53,043 ‫or getting Java source codes out of the final APK. 56 00:02:53,910 --> 00:02:57,090 ‫Actually, we have different products, different tools 57 00:02:57,090 --> 00:03:00,900 ‫for this both of this process, 58 00:03:00,900 --> 00:03:03,450 ‫and we're gonna see how to do that. 59 00:03:03,450 --> 00:03:06,510 ‫And Dalvik bytecode isn't actually 60 00:03:06,510 --> 00:03:08,700 ‫very easy language to learn, 61 00:03:08,700 --> 00:03:11,700 ‫or very easy language to master. 62 00:03:11,700 --> 00:03:16,560 ‫And on the contrary, of course, Java is easy to learn. 63 00:03:16,560 --> 00:03:20,010 ‫We write applications already in Java, 64 00:03:20,010 --> 00:03:24,120 ‫but sometimes we cannot get to the Java source codes. 65 00:03:24,120 --> 00:03:27,150 ‫Then we will have to stick with Dalvik bytecodes. 66 00:03:27,150 --> 00:03:29,580 ‫We're gonna see all of these things. 67 00:03:29,580 --> 00:03:31,590 ‫First, let me tell you about the tools 68 00:03:31,590 --> 00:03:34,920 ‫that we are going to see in this course. 69 00:03:34,920 --> 00:03:38,280 ‫We will mainly work on two tools, 70 00:03:38,280 --> 00:03:40,320 ‫first of which is Apktool, 71 00:03:40,320 --> 00:03:43,980 ‫it's spelled like this, Apktool, okay? 72 00:03:43,980 --> 00:03:46,202 ‫And if you search for Google 73 00:03:46,202 --> 00:03:48,630 ‫you will see the Apktool website, 74 00:03:48,630 --> 00:03:50,640 ‫which is a GitHub website. 75 00:03:50,640 --> 00:03:51,473 ‫Okay? 76 00:03:51,473 --> 00:03:52,650 ‫And as you can see, this is 77 00:03:52,650 --> 00:03:56,250 ‫for reverse engineering third-party closed apps. 78 00:03:56,250 --> 00:03:58,290 ‫So if you click on this, 79 00:03:58,290 --> 00:04:01,680 ‫you can see the Apktool requirements, 80 00:04:01,680 --> 00:04:04,593 ‫installation procedures, and everything. 81 00:04:05,820 --> 00:04:08,370 ‫So aside from Apktool, 82 00:04:08,370 --> 00:04:11,497 ‫we're going to use something called jadx. 83 00:04:11,497 --> 00:04:12,330 ‫Okay? 84 00:04:12,330 --> 00:04:17,040 ‫And this is spelled like jadx, like this. 85 00:04:17,040 --> 00:04:19,320 ‫So if you run this on Google, 86 00:04:19,320 --> 00:04:20,490 ‫if your search is on Google, 87 00:04:20,490 --> 00:04:24,000 ‫you can find the GitHub page, one more time, 88 00:04:24,000 --> 00:04:25,860 ‫for jadx as well. 89 00:04:25,860 --> 00:04:29,100 ‫And as you can see, it's dex to Java compiler. 90 00:04:29,100 --> 00:04:31,980 ‫Decompiler actually, not compiler. 91 00:04:31,980 --> 00:04:36,980 ‫So jadx actually gives us the source code, Java source code, 92 00:04:38,160 --> 00:04:39,870 ‫from Dalvik to Java. 93 00:04:39,870 --> 00:04:44,870 ‫And Apktool actually gives us the Dalvik bytecodes. 94 00:04:45,090 --> 00:04:47,310 ‫So we're gonna need both of those 95 00:04:47,310 --> 00:04:51,180 ‫in order to have a complete reverse engineering procedure. 96 00:04:51,180 --> 00:04:56,180 ‫So we're going to work with Apktool and jadx as well. 97 00:04:56,460 --> 00:04:59,730 ‫So if you go to GitHub page of jadx, 98 00:04:59,730 --> 00:05:01,710 ‫you can see the features 99 00:05:01,710 --> 00:05:05,040 ‫and download instructions, installation procedures, 100 00:05:05,040 --> 00:05:06,540 ‫and everything. 101 00:05:06,540 --> 00:05:08,730 ‫So the thing about jadx, 102 00:05:08,730 --> 00:05:11,910 ‫unfortunately it doesn't work with Windows. 103 00:05:11,910 --> 00:05:12,743 ‫Okay? 104 00:05:12,743 --> 00:05:17,313 ‫So you either will have to work on Linux or macOS. 105 00:05:18,480 --> 00:05:22,620 ‫In Apktool, actually you can work within Windows, 106 00:05:22,620 --> 00:05:25,470 ‫and work within Mac, work within Linux, 107 00:05:25,470 --> 00:05:27,240 ‫wherever you want. 108 00:05:27,240 --> 00:05:30,300 ‫But it only gives us Dalvik bytecodes. 109 00:05:30,300 --> 00:05:33,750 ‫So most of the time you might want to check 110 00:05:33,750 --> 00:05:36,870 ‫if you can reach the Java source codes first, 111 00:05:36,870 --> 00:05:39,690 ‫and then you go for bytecodes. 112 00:05:39,690 --> 00:05:44,160 ‫So we're gonna need to utilize both of them. 113 00:05:44,160 --> 00:05:45,097 ‫If you're thinking that, 114 00:05:45,097 --> 00:05:48,660 ‫"Yeah, I don't have macOS, what I'm gonna do?" 115 00:05:48,660 --> 00:05:50,040 ‫It's very easy actually, 116 00:05:50,040 --> 00:05:54,390 ‫since we have Kali Linux installed on your computers, 117 00:05:54,390 --> 00:05:56,790 ‫it will be an easy task. 118 00:05:56,790 --> 00:05:58,857 ‫We're gonna work with Kali Linux, 119 00:05:58,857 --> 00:06:02,760 ‫and we're going to actually start 120 00:06:02,760 --> 00:06:07,760 ‫we're going to install jadx and Apktool on Kali Linux. 121 00:06:07,860 --> 00:06:12,860 ‫We're going to do our procedures on Kali Linux as well. 122 00:06:13,080 --> 00:06:15,870 ‫And then finally, maybe 123 00:06:15,870 --> 00:06:19,140 ‫after you complete your reverse engineering 124 00:06:19,140 --> 00:06:20,370 ‫for the final product, 125 00:06:20,370 --> 00:06:24,390 ‫you may want to go from Kali Linux to your host machine, 126 00:06:24,390 --> 00:06:26,280 ‫from your host machine to Kali Linux. 127 00:06:26,280 --> 00:06:29,850 ‫So it may be a little bit hard for you, 128 00:06:29,850 --> 00:06:31,620 ‫but it will work. 129 00:06:31,620 --> 00:06:36,620 ‫And by hard, I mean just sending an email from Kali Linux 130 00:06:37,920 --> 00:06:41,430 ‫to your host machine, like sending the APK file 131 00:06:41,430 --> 00:06:44,790 ‫from your Windows to Kali Linux, or vice versa. 132 00:06:44,790 --> 00:06:46,020 ‫So it's not very hard, 133 00:06:46,020 --> 00:06:48,240 ‫but it's kind of time consuming. 134 00:06:48,240 --> 00:06:51,510 ‫Of course, if you have Linux running 135 00:06:51,510 --> 00:06:54,390 ‫on your main operating system, 136 00:06:54,390 --> 00:06:56,520 ‫running as your main operating system, 137 00:06:56,520 --> 00:07:00,300 ‫or if you have Mac running as your main operating system, 138 00:07:00,300 --> 00:07:03,540 ‫your job would be much more easier in this section. 139 00:07:03,540 --> 00:07:05,040 ‫But if you have Windows, 140 00:07:05,040 --> 00:07:07,740 ‫don't worry, again, you can actually 141 00:07:07,740 --> 00:07:10,980 ‫install Apktool and jadx on Kali Linux. 142 00:07:10,980 --> 00:07:14,100 ‫Just decompile the APK email, 143 00:07:14,100 --> 00:07:17,160 ‫the APK from Kali Linux 144 00:07:17,160 --> 00:07:20,370 ‫to the host machine, and vice versa. 145 00:07:20,370 --> 00:07:23,310 ‫So you're gonna have to spend a little bit time 146 00:07:23,310 --> 00:07:27,000 ‫compared to me in this lecture, in this section, 147 00:07:27,000 --> 00:07:28,860 ‫but again, it will work for you. 148 00:07:28,860 --> 00:07:30,000 ‫Okay? 149 00:07:30,000 --> 00:07:34,950 ‫So what we're gonna do, we're going to install jadx. 150 00:07:34,950 --> 00:07:37,710 ‫We're going to install Apktool first. 151 00:07:37,710 --> 00:07:40,170 ‫We're going to set our lab up, 152 00:07:40,170 --> 00:07:42,720 ‫and then we will create our first application 153 00:07:42,720 --> 00:07:45,690 ‫and try to reverse engineer it. 154 00:07:45,690 --> 00:07:47,430 ‫And then we're going to work 155 00:07:47,430 --> 00:07:51,600 ‫with pre-made, pre-built applications, 156 00:07:51,600 --> 00:07:55,860 ‫of course, the ones that I have written for this course. 157 00:07:55,860 --> 00:07:59,010 ‫And then we will actually manipulate. 158 00:07:59,010 --> 00:08:01,800 ‫For example, we will hack into a game 159 00:08:01,800 --> 00:08:04,800 ‫and we will actually change the game 160 00:08:04,800 --> 00:08:08,070 ‫in a way that we want using all of these tools 161 00:08:08,070 --> 00:08:11,940 ‫that we're going to master within this section. 162 00:08:11,940 --> 00:08:16,020 ‫So make sure you open these GitHub pages. 163 00:08:16,020 --> 00:08:17,100 ‫Okay? 164 00:08:17,100 --> 00:08:19,260 ‫For Apktool and jadx, 165 00:08:19,260 --> 00:08:21,393 ‫and meet me in the next lecture.