and this is the last log4j talk you'll ever need. So a bit about who I am and what do I do. I code, I teach, I hack. In other words I spend most of my days on work and off bashing my head against the keyboard in the AppSec space either to get code to work or to break other people's code and in that concussive stupor I also try to stand behind a podium, stage, whatever and give insights on my experiences to everyone else. I do I must add the disclaimer although I do have an employer currently I do not speak for the corporate hive mind. I am just one of its many cogs. So moving on to what are we talking about. On a your left you see one of the most popular logging libraries in Java and on the right you see your ticket to shelves and it's all about a pocket gaining a pocket full of shelves and do take note of the CVE don't get it confused with any of the other ones like for example CVE 45046 or any of the others they're nice they're good their ways of exploiting systems but the problem is they require effort and that's not what we come here for for log4shell. Log4shell isn't about effort and insight it's about getting arbitrary remote code execution anywhere and everywhere and so if you want to see the magical payload of what it takes actually exploit log4shell here it is it is just the JNDI LDAP the location via the IP of the port and the path to the exploit and let's just take a deep dive and look into it unlike most acronyms in IT LDAP and JNDI are actually useful for explaining what they are so LDAP you'll see tutorials classes seminars everywhere about that the long and short of it is LDAP a lightweight directory access protocol is just file operations over TCP IP that's just using internet web requests and you can see that it's a little bit more complicated than what you would expect how do you move files delete files create and edit files so your basic file operations that you find in the desktop how do you do it do the same thing online and JNDI is just the Java name directory interface and so what why do you need to use JNDI why would anyone use JNDI in the first place is because of code reusability is the number one so in each new project you don't want to define basic things like shared libraries or database connections configurations templates or for example setting where which logging server which logging server you want to use you kind of want to have that code easily be reused throughout multiple projects and the combination of these two both LDAP and JNDI helps facilitate that functionality and so just to dive deeper into the weeds LDAP is the number one provider for the NG NDI SPI which is just so you've got your Java application globally and then the JNDI API and the naming manager and one of the best ways to explain the use case of JNDI is DNS so remember in DNS you don't memorize series of octets and just route to them manually through your browser what you do instead is you use human friendly identifier like hostname so it's Deftconnexion or something like that and you're not going to still have dot org google.com etc and then the service of DNS routes the human friendly identify human friendly name to the machine readable identifier and it's the same thing with JNDI you don't always know the exact path of classes and objects within the code base so JNDI is really useful for designating designating that class path and if you go through Java Oracle documentation for Java 7 Java 8 the LDAP is just the number one provider here and so it's one of the most basic and most common use cases for doing something like that reusing the same code and libraries throughout the project now we go on to the kill chain so log for in this is for log for shell specifically you either spin up your own local LDAP server or if you take over someone else's then you do anything within the context of the app what will cause it to log this could include this can include just modifying the body of a post request but most often what you'll see in the wild is just modifying the header a header that most all that almost always gets logged is the user agent and so when log4j went out most like if you wanted to walk around the internet and get random shells everywhere from everywhere all you had to do was just change the user agent to a local LDAP server or one hosted remotely that you own and bam you would get our arbitrary connections so the lack the rest of the kill chain is the app flu that are that just by including the payload because the LDAP because the L dev server is automatically trusted the app will reach out to that server and the server will send you an jndi response including the class and then within that class you can inject into the process and get remote code execution from there yeah kill chain um so to facilitate this and make this a lot easier uh setup a home lab in minecraft uh so it is built on vagrant using ubuntu and because you bugged to and of course one of the most popular java applications out there there is a number of benefits on why this particular architecture than others namely i don't have to code java getting things to compile spent like days and weeks of my life trying to get things to compile with maven and gradle and i don't want to do that i promise you i promise you i'm a developer it's just for this particular project i'm just going to use ruby and by ruby i mean just enough ruby to get some bash scripts in there a few works cited this all of these exploit kits are available at github so the one these exploit that kit we're going to use the feihan-cs jnd exploit that actually was taken down by who knows who but we but one of the benefits of that is that you can find this sketchy exploit kit through the way back to the sheet then use it within our dm there are other exploit kits for there are plenty of exploit kits for the log for shell vulnerability most of these are just hey they'll automate and streamline the process of standing up your own jnd jndi compatible ldap server uh shout out to da667 on twitter uh guys mainly for the minecraft version and the java version which is very important java for this project i'm using open jdk 1.8.0 and making sure that the patch level is before 1.8.0 and making sure that the patch level is before one twenty two and one twenty one because act from then onward arbitrary class loading is disabled by default so yet now we have to have a vulnerable version application you have to have the vulnerable Java runtime vulnerable log for J and for this particular project and for this particular project a vulnerable version of Minecraft because as Mojang has discovered these things it's gotten to the point where the basic date time formatting that you normally were able to do in the chat which is dollar sign curly bracket date time it's gotten to the point where players are no longer to execute basic things like that so moving on of course with every sketchy exploit to use at your own risk that's why we're doing it in the VM and without and without further ado let's get into the demo all right so hopping into the first command you don't really need vagrant destroy destroy attack f at the beginning really all of this is was really necessary is just the vagrant up and the vagrant reload the vagrant up is to start the VM and the provisioners and get that started the vagrant reload is just to you know reboot the VM and get the virtual machine working vagrant destroy f is only needed if you need to blow it up and start again as I had to do many many times so right now we've got the vagrant up just loading up the GUI and all of this of course is because it's a vagrant box it's listed in the vagrant file and all the provisioners are included within that GitHub repo as well the first part is what the head lit the GUI which is just the virtual box provider popping up the when you do it at home or yourself just don't try to mess with it or do anything the first thing that will start is the tty I wanted to make this demo as simple as possible as possible so I avoided purposely made it simple enough to have the GUI start up before you do anything because there's no sense in giving you a VM to just have to wrestle and fight with I wasn't too I wasn't ultimately successful we'll see an error message that I'm still working out at the end you you you you ticks the next part of that is this just recording the wall downloading the mind graphics assets and the exploit kit as I was talking about before the particular script that I was using written down was from was the feyong-cs jndi exploit um and of course a lot of there's an elegant solution involving you know cloning everything and all that but since the repo was taken down just curling the way back archive was the best bet here it does seem the vm does appear to just you know stall and do nothing for a little while the reason for that is because i just am tired of blowing up the terminal with arbitrary output like the app get and installs are already bad enough so what i so what i did is just made this part quiet and silent if you have some networking issues of course this all crashes and fades away but um for the most part miss is just getting all of the assets installing not only the exploit kit but java making sure all the environment variables are set and these things are batched into stages for each of the revisioners on word you you you you and then shortly after all of the minecraft assets and the exploit kits are downloaded What we'll do is we'll just wait for the rest of it to install then do a full reboot one of the main provisioners that we'll always run is the serve.sh bash script all it does is set up two screens one will have the malicious LDAP server set up and the other one is going to have the minecraft server set up so there is going to be a big error and spent days days on this and for some reason just graphics and drivers issues just would not would got in the way of this build but the server started up everything else is fine the EULA acceptance script is pretty easy to get around and you can dive all the details to when you see it in the repo for right now we're just booting up the VM and then now that we've got a GUI just log in with the vagrant default credentials and getting started how you're going to do this how you're going to do this we're gonna have to find out you you you you you you you you you you you you you you you you you you you you you you you another part of the setup is just uh now that uh migration happens have to have a minecraft account explicitly set aside for this um yeah just jump cut to avoid throwing the password out there uh let's go and of course just so many so many loading screens the the java version which has not showed is uh openjdk 1.8.0 with patch level with a patch level before one two one and for this particular job installation of minecraft i really want to target 1.12.2 it's very popular obvious it's obviously legacy and one of the reasons is because of the modding community so you're just going to set play and agree now the one error that just was a complete showstopper i don't know why um because i'm thinking it's the distro or whatever and we can get to the other is just an array index out of bounds which i included in the repo um yeah i promise you it got this working in a previous youtube video and we'll just pull up the screenshots for those and discuss that instead but yeah after this loads up it's just array index out of bounds error for some reason it just cannot find it cannot find the primary display so uh graphics issue graphics and display driver issues is just par for the course for pretty much any linux distribution so yeah it's just graphics drivers issues and i by the time i got this recording in i did not have this issue resolved i am hoping by the time uh present this in person that the issue is resolved um yeah par for linux driver issues graphics driver issues so alternative solutions would probably um run this on jamie64 instead of bionic which is what i did in youtube and if you hold up a second the error message should pop up ever so slightly it's no pointer exception and for some reason it's um you can't this particular install and configuration can't find open gl for some reason even though like my display and everything works fine i've covered up the but that quick pop-up for a second was a null pointer exception and the stat full stack trace of course was available in github the first screenshot is the actual payload within in the context of minecraft um this is taken obviously from the youtube video that i did for or the project when i recorded in december and the ape and the ip address is just you know the network configuration for this particular virtual machine the base 64 encoded payload is just l is the ls command and you see on the right is the stack trace within the game and this is not the stack trace the server logs and you see like that class name foo and that that's the jndi output of uploading the class name you can look into the exploit kit and you can use it for reverse shell other commands base64 encoded and otherwise and that's it so let's talk about the impact here i mean after all minecraft is isn't really a good scenario for simulating the enterprise impact of log for shell after all it is an application based on a popular cross platform framework hosted publicly with legacy dependencies a user base of hundreds if not thousands of users at one time and actually is and is resistant to updates and changes because it has a consistent revenue stream so yeah minecraft is not is of course never in a good example uh so so what about remediation so how about fixing this it's easy to say just patch your systems that's the number one key thing use uh better you if the logging version of log4j is configurable go into the configuration settings and do the patch otherwise most of the apache projects have already updated it's no longer considered a patch for me so i'm going to go ahead and patch that so if you're going to be using it in the future and you're using your apache services it's probably going to be considered a zero day however some arbitrary application that's built on apache services may not be patched in which case this is one of those things like arbitrary remote code execution being exploited in the wild this is where you this is where as security practitioners professionals you could say nah just trap no just try to use it for the rest of the time change your technology stack and that is that is the best answer the best way we can go forward with that so there have been other patches other ways of trying to remediate using regex and all that just really so seriously patch to one dots later past one dot two dot one eight for log4j and move on so the reason why this talk is called the last log4j talk rather than the last log4j shell is because it's really easy when a huge vulnerability comes from a particular library that the library itself has no functionality utility it's all about the number one global vulnerability that's sort of part of the risk with free and open and free and open source software however this is just yet one of those cases where a simple like one simple the library forms the backbone of digital infrastructure globally and worldwide and you may think like as if you're doing penetration tests and offensive security you'll find things like lack like for example jQuery and others where it seems like instantaneous it blows up these libraries of vulnerable it blows up your scan logs and servers because there's always a patch coming only the security patch coming that's not necessarily a vulnerability that it is actually part of the feature and so part of is not just part of a mediation process part of what makes what makes good application security work in the world is just having a community development that's in line and coupled with the security community so that when something comes up the patch security patches are rolled into the rolled into the release pipeline and the blog4j developers actually did their best before it was before it was just like disabling and all of that but as the entire world had scrutiny on this one library for a period of a few weeks removing the function out it eventually got the pushback to remove the the JNDI arbitrary JNDI lookup functionality altogether which is probably which is I know it seems obvious it seems insane why would you trust arbitrary lookups remember no one ever it was a feature of the library pretty much November so part of going forward part of the lessons learned is for every free and open source for every library package find it find part of it is not only just its feature set but also looking into the community does it release patches security patches often is it well maintain and well-funded? Is this something that you want to be able to integrate within your own technology stack? And of course, these links, I'm active pretty much in way too many places, it's free OSINT, so feel free to harass me on any of these platforms. And my favorite part of the talk, the um-actually portion, so if you have questions about setup, what I did, and also mistakes that I made, feel free to...