hey guys it's El back again with another antivirus bypass video we're going to talk about something called Trad injection and this injection techniques that makes your payload to be super invasive now it was originally brought to the World by ethical cares and the full link to the conference can be found on the top right corner I was so amazed by the techniques that I decided to create my own implementation in C so I can learn the language better and also contribute to the op Source world now let's get into details on how this works what
does it do and why it's so evasive in order to understand injection we need to address the windows architecture and the windows apis windows apis are rra method which are C when you create some kind of actions for instance if you create a file with notepad create file W function will get involved the problem is that a lot of the times windows apis are abused for malicious behaviors for instance sh Cod Runners as shown in my previous video uses Windows apis to allocate memory right our pay to that allocated memory then execute it with a
new threat this behavior is extremely suspicious for a and IND and what Trad injection do it the chains the first two step from the third one which means that using Trad injection we can allocate the memory write our pay to the memory but let the windows do the heavy lifting for us and execute the pay in ch this injection work by hooking a legitimate Windows function so that when it's executed it's going to actually execute our payad and then resume its normal working process okay but how do we know what function to hook thankfully we
have tools for that and one such tool is called API monitor this tool allows us to monitor a process in real time and see what the API code it's doing including it parameters as explained in the screenshot I have already downloaded API Monitor and let's demonstrate how it works when downloaded make sure to cck all this filter so you can get the most coverage out of the process now I need to start a new notepad process and keep in mind that I'm just testing with notepad in your environment you will choose a different process and
then just click here which is going to actually attach to the process and start to monitor it now we don't see any API codes because the notepad is Idle but if I go and poke it a little bit like that if I go back to Pro monitor we can see a lot a lot of API calls in real time now in your environment you want to choose a function that's called on time interval and that's because you don't want to rely on user interaction for instance in this demo you're going to see just now we
are hooking creative and W function which is involed as soon as someone save a f with notepad to avoid this Behavior choose a function which is called on time interval so you don't depend on users whatsoever I have loed my PC visual studio and now let's analyze how it works the key component are the following we have the shell Cod water which is designed to be a custom shell Cod which is going to redirect the execution flow then we have our Malicia Shell Code which is designed to give us access and then we have the
main method which requires four system arguments the first one is of course the function the program itself then we have the module we want to see the function from then we need the function we want to hook at and then thep do the remote process here we pass the arguments and here we pretty much ensure that the module is correctly wed after that we open the process and then we jump into a function called find memory hole this function gets the exported function address which is the exported function we specifying the system arguments get the
address to it and then it calculates a SL off set after it this softs set is then used to store our shell C waterer and then we need to allocate the memory to that offset address with the virtual ax API after that function is completed we jump into another function which is called generate hook the generate hook function restores the original native flow so it modifies the sh cut water variable to contain a CO instruction and that Co instruction to be equal to the original bytes that are from the original function so when that function
calls it's going to call the Shell CER which is now modified to call original function instructions when it finish executing after after that we have to craft one additional piece of custom shell Cod which is designed to perform the initial hook that initial Hook is going to get allocated and written to the exported function address and what's going to happen is that after we write this Shell Code there it's going to call Shell Code loer which is going to call our mous payad and then the sh coder is going to finish the execution of the
Native function then we need to craft our final pay and then we need to tweak the memory protection settings write the pay to the memory ho address twak the memory settings again and then just wait the windows do the heavy lifting for us to demonstrate how it works I have prepared the calculator Shell Code now this is just for demonstrational purposes and in the original PC you have the option of specifying the Shell Code from file this option is missing here because mainly for two reasons first reason is I want to make things as simple
as possible and the second one I am learning along along the way as well and it's easier for me just to specify C txz and see if it works now this is as I mentioned c.x so I'm going to compile that as relase NX 64 I'm going to Dos Thad inject minus cxz and here we have the syntax now let's specify kernel base. DL and create event W function because this is what we want to hook and pretty much create NW stays and lives inside kernel base. DL and then we need to specify the P
of the notepad process for this to happen I'm going to actually open a notepad process here and I'm going to open open also process hacker to and search for notepad now after I did that we can observe that the notepad process has the P ID of 1316 so so I need to provide that here 1316 so and run the application based on the output we can observe that the function is Success hooked now if I go back to the application and try to save any Demi file we can observe that the calculator. txe is right
off the B being spawned which means that our shell code is successfully executed now you may ask all right but how to weaponize that so let me show you how to weaponize the tter msf Venom and a custom shell code generated from it now for that to happen we need to First replace this variable here because this is as mentioned before our malicious shell Cod keep in mind that if you replace this variable is not going to work because this is pretty much our hook now let let me get back to my cover machine and
generate a simple sh code for you guys this windows x64 and stages reverse TP the ET Z will be the host and the port is 9443 I want the format to be Inc because just want to copy and paste the sh code just for demonstrational purposes so I can copy this big piece of code then go back replace it to here and rename it to be shell Cod now I can recompile that and then I need to spawn another notepad process I can do notpad take note of the P ID which is 16 8 to4
and then run the exact same command which is 18 uh 168 to4 and now let me get back to the same paint in there and then I can click run now before that I need to set up my listener so I can do NC mop 9443 then I can just simply run the exact exactly the same command go back to the Notepad application and try to save something when I do it we can see that the Notepad application works but if I go back we can get a shell thank you so much for watching guys
and I have to especially thank palang J and Al sorry if I pronounce your name wrong for your patreon support you have no idea how much that means to me how much I appreciate it and how much it makes me feel motivated to perform and do more content like this one I have to apologize that in the past month I was not that active on YouTube but a lot of stuff were going on for me and it was so hard for me to manage all this stuff in record the video but expect more for the
future happy New Year and see you in the new [Music] one [Music] [Music]