Hi there. All right, thanks very much. Welcome to the talk. I'm not very good at intros, and I always talk under different pseudonyms, so I'm just going to tell you some facts about myself to hopefully make you trust what I'm about to tell you. I've been mainly working in embedded systems slash enterprise perimeter for a few years, sometimes as a consultant, sometimes as a researcher, sometimes in education. I've published research into Microsoft, Cisco, Netgear stuff, all kinds of different software over the years. I spoke here a few years ago about cellular hotspots and things like that. My main interest is just reverse engineering, so we might go off on a bit of a tangent here on some of these. I'm going to have to speed through some of this because I've got a lot to talk about, and this is one of the bits I'm going to speed through. If you don't know what PBX is, a PBX is a private branch exchange, emphasis on the private. Before these private branch exchanges, everything went through public branch exchanges for telephone calls. The problem was when businesses wanted to make calls to each other internally, the calls had to go through a public exchange, so it cost them money, so they moved the branch exchanges indoors. These first early PBX systems were for cloud. They were for cloud. They were for classic phones, and then VoIP started becoming more and more cheaper and more popular, so digital PBX started popping up, starting off as hardware and then slowly over time becoming implemented purely in software. Then as time went on, communication styles started morphing again, so PBX started morphing into something that people start to call unified communication servers today, which is like video, text, and all kinds of other kinds of communication. So this is more like modern chat-based contemporary stuff, but I'll use the term PBX more here because the servers and the software that I'm talking about is more like PBX servers. They're not really unified communication servers, although they do function in the way that unified communication servers claim to as well. This kind of stuff shows up in enterprise environments where they like to do things on-prem. There's a lot of different stuff in the PBX slash UC space, so probably the most fundamental will be like the SIP switching telephony software. Something like asterisk or free switch, for example. This is like the bare-bones telephone exchange functionality. Then there's other products that show up which use these phone exchange cores, and then provide easier UI uh configuration so for for example FreePBX is basically just like a UI configuration wrapper for asterisk and sipxcom is basically a UI configuration wrapper for free switch. Um and then on top of that they'll uh bolt another a whole bunch of other stuff on like text and video chat sort of make it a bit more UC like. Okay. There's a few big like PBX systems. FreePBX and 3CX are probably the biggest uh and then there's sipxcom as well. Um there's about 10 to 19 thousand um FreePBX web interfaces I could see on showdown the other day. About 250,000 3CX ones. Um there's not so many sipxcom ones but it has been around for quite a long time so it's still worth looking into. Um Free uh PBX servers are due to the complexity and all the all the kinds of services that you find on them. They can have a really big attack surface as well so they'll have things like the sip like telephone exchange core. Uh they'll have proprietary um uh uh services like the inter asterisk exchange protocol which you find in asterisk. Uh there's things like MGCP, RTSP, XMPP, MySQL, DNS all kinds of stuff you'll find on these servers. So there's a lot to look into. Um there's also these like um web management interfaces which are which are the core of a lot of these things. So um as I said before FreePBX the the web is basically just a web UI that uh allows you to configure all of these extra services plus asterisk and things like that. Um all of these servers also uh require authentication user accounts so post authentication stuff is also on the table for this kind of research. So the attack surface is really really broad. Um I'm gonna talk about two different uh servers today. The first one will be uh SIPX com and the other one will be FreePBX. Um I there's a caveat to it which is that I found these bugs through sort of less structured research. So despite the massive attack surface I only managed to sort of really touch the service surface of what I found. So I'm not sure what actually is on these servers but what I found I think is quite interesting so. So the first bug is um an RCE chain in SIPX com. So SIPX com is mainly written in Java. Uh it's all open source, all on GitHub. It ships it ships with this um optional XMPP server called SIPX open fire. Um the name is based on ignite open fire but the bugs don't actually affect ignite open fire. It's a quite complex, SIPX open fire is quite complex uh integration with other like SIPX components so it's not a totally stand alone XMPP server. Um it sort of integrates with the whole SIPX ecosystem. Within SIPX open fire there's a message interceptor uh called default message packet interceptor. And every message that's sent through the XMPP uh server is is checked by this interceptor to see if it starts with a a string that they call don't directives internally. So these directives are at call, at conf, and at xfer. If the message starts with one of these directives, then that message is handed off to some other external SIPX component. So this is part of the whole integration. The issues sort of affect a couple of the directives, but I'm just going to follow the at call one just for the simplicity here. So every message is intercepted and then passed to a function called process chat message, where it's checked for directives. If it starts with at call, then the rest of the message is passed to the map arbitrary name to SIP endpoint function, and then the string that comes out of that is passed to build REST call command, and the result of that is passed to send REST request. So we can just follow this flow really quickly. Map arbitrary name to SIP endpoint just checks for usernames in the string and basically just returns back the string. So this is the end of the string wholesale as we want it, as we give it, without doing anything to it if it doesn't find a valid username. Build REST call command takes the whole string that we've passed in the message, concats it directly into a URL string and then returns it, and there's no check or filtering on it at all. And then that whole URL string is passed to send REST request, which just concats it directly into a curl command string. So, and this curl command string just gets passed directly to runtime. There's a to do note above this function suggesting that they know this isn't really the ideal way to implement this functionality, but it's been there since about 2010, according to the git history. So 13 years of not doing anything about it. The conventional wisdom of this would say that this is just arbitrary command execution, but that's not actually really true. Run time.exec doesn't quite work like that. There's an assumption that runtime.exec for some reason behaves like system or P open, which is not true at all. So all the kind of classic code execution payloads that we might want to use for this will always fail. So just to give a quick rundown of how runtime.exec works, we'll just follow the source. So if you pass just a normal string directly to runtime.exec, the first overload we hit is the one that just takes a single string. This passes it to another exec overload, which takes three arguments, the first of which is a string. That overload takes the string and passes it to a string tokenizer and then just pushes that into a string array, which passes it to another exec overload, which takes three arguments and an array as its first argument. And then this overload passes the string array to process builder and creates the process using .start. So we've got this array of strings being passed to process builder. Process builder takes the first element in the array and checks its executability and then the array gets passed to process impl.start, which just, in our case, because we're running on Linux, creates a Unix process. So the first element in the array is the executable argument to the Unix process. So regardless of what we actually inject into this component, we're just going to pass the string array to process builder. So we're going to use the command string. We're always going to be running curl, so there's no way around it. So it is, we don't have direct command execution, but we do, we can kind of use this to our advantage. So we can't control the executable. It's always going to be curl. But we can pass arbitrary arguments to curl. So the next question is what arguments can we pass to create a useful primitive there? Before we figure that out, we have to look at how the command string is actually laid out and what we control. So we can't control the arguments at the beginning because they're hard coded, but as long as we pass a string that contains spaces, we can put whatever arguments we want later into the command. So for example, we can download files within the same curl command by just adding an extra dash x get argument and specifying just a file to output to with the O flag. So it's a pretty useful primitive. We can force the server to download files from anywhere and save them or write them anywhere on the server. SIP X open file runs as the daemon user, so we can only really write where the daemon user can write. That's the only real limitation on it. We can also read files from the server. So we can use the D flag to read a file on the server then send it over to wherever we specify. So an injection like this one tells the first x dash x post request to output the result of the request to some temp file and then tells curl to read the password file using the D flag and then send it over to an IP address. So we can both read and write files using this curl argument injection. So they're quite interesting and good primitives, but it doesn't quite get us to code execution directly. But there is one more bug which is quite useful in this case. The open file file for SIP X open file is installed with daemon daemon privileges in the init.d directory, so with our write primitive we can overwrite this file, which will execute as root whenever the service is restarted. So we can chain those things together. We overwrite the open file in it file using the curl file download primitive and then replace it with an almost identical file with just a command exec payload in it. We wait for the service to read the file and then we can be restarted or force it to restart using the web interface and then we just get a root shell. So it's a fun bug chain just by sending XMPP messages from one user to another. You can overwrite files and then eventually get a root shell from this server. There's a full rundown of the exploit on setlist that I sent over in March that you can have a look at. I'm going to show you a little bit of what we've done there. So we're going to have a look at SIP X open file. SIP X open file is, sorry, SIP X com is maintained by a company called Cordial who just never responded to anything that I've said. So I sent them emails for a while. I first reported in November. They didn't reply. I kept on sending emails for a while. They didn't reply to any of them. I kept sending them tweets and they just kept on untagging themselves from tweets, so I consider that a kind of vendor response. So we're just going to have a look at the results. So there's a few more things we can find out in the description. We've of uh active indifference and so these are just bugs that are still in the latest version of SIPXCOM and I guess we'll stay there for a while. It looks like SIPXCOM might be dead. I'm not entirely sure. Um so yeah Cordial gets half a star for their vendor response. Very bad experience. Don't work with them. Okay the next bugs are all in uh FreePBX. So FreePBX is maintained by Sangoma. Um it's based on Asterisk for the telephone side of things. There's a web interface um loads of free and paid modules that you can sort of strap onto it. Um and according to their website they run a bug bounty program. So they say they want to work with security researchers. That they want to fix everything within 60 days. Um so that all looks really nice and of course at this point I'm I'm really looking forward to the professional disclosure process with lots of care. Communication and very happy outcomes and for everyone involved. Um SIPXCOM is pretty straight forward. It's just straight forward open source Java. FreePBX is a bit more complicated. So it's mainly written in PHP which is nice. Um the core or a lot a lot of the core code is open source to some extent. Uh there's a FreePBX core bit that's free. Um and the code for that's all in the FreePBX bit bucket. Um there's a few free plugins which come bundled with FreePBX which you can't find the source for for some reason. And then Sangoma also sells licenses for some other plugins. And none of those plugins are open source either. So there's a lot of functionality where where the code sort of just isn't public. Um despite the fact that FreePBX is uh touted as as something like an open source PBX server. Um so the it's mainly written in PHP. So and it's shipped mainly as a Linux VM. So whoever has access to the VM could read the the PHP files. So obviously to avoid leaking code for the non open source components um they've used something called IonCube. Um so IonCube is a PHP source code of obfuscation solution. Um it uh the the IonCube compiler compiles down PHP to Zen byte code. Essentially and stores it in its proprietary um IonCube format. And then at runtime the PHP uh uh process loads the IonCube module which uh decompiles the PHP before running it. So it's a massive overs oversimplification of actually what IonCube's doing. But uh it's essentially what it does. It's a lot like things like Zengard and Source Guardian. There's some really nice um previous research into IonCube by um these guys that I've mentioned here. Um but it's through a quite a few years ago so. Some of the information's still relevant some of it's a little bit outdated. Um the point of IonCube is just to create as much hassle as possible for for people like us. So anyone who wants to have a look at the source code. Um it it will cause us cause cause us to spend a lot of time trying to uh get access to the source or maybe just give up entirely. And the point is also to make money. Like they sell a license for like 200 229 dollars. There's no free or open source deobfuscators available. Um I'm not entirely sure why. I assume it's because IonCube are litigious. Um I'm not entirely sure how legal it is or how legal it would be to offer a deobfuscator for free. But regardless because there's nothing free out there there's this grey market for deobfuscation tools that exists out there. Um so you can find these deobfuscations as a service. Um and and uh. So I'm not sure if there's any and people trying to sell things on Telegram and very dodgy looking YouTube videos that show nothing in particular happening with very big price tags. I spent a bit of time playing with these during the process of looking at the free PBS code. I did get some useful code out of some of them but it's a bit of a grey area. Regardless I spent quite a lot of time looking at the deobfuscation process so I'm going to share a little bit of that today as well. In the case of free PBS they're using the iron cube loader for PHP 7.4 which is version 10.4.5. The loader PHP module is an SO that's just under 1.4 megabytes. It's part of the free PBXVM image so you can just dump it straight out of there. It hooks Xen compile file and Xen execute X functions in the main PHP process. What it does very basically at the beginning is just check for magic bytes at the start of every PHP file that comes in. If it finds them it will try to deobfuscate it and run it. If it doesn't find it it just passes the files directly to the PHP module. So it's just directly back to the PHP Xen VM. If it does find the bytes then it will it goes on this sort of chaotic journey. So the whole loader is a complete chaotic mess. We have to really follow a lot of things going along. It doesn't just deobfuscate the Xen byte code and just pass it back to the main PHP Xen VM. It actually ships a whole modified Xen VM which is a standard Xen Xen code within itself and every op code is executed within the loader itself. Nothing ever goes back to the main PHP process. So the whole extension is really, really big and you can waste a lot of time in it. So I'm just going to share a few little bits and pieces that I noticed while I was working on it. The loader is kind of obfuscated. So all the strings or the useful strings within it XORed with this static XOR key. So obviously when you're trying to do a to reverse engineer it, being able to see the strings is very beneficial as part of the process. I wrote a GIDRA script which you can download here to help you do that. You do need to put the XOR key into it for the specific loader, although I think it might be static among different versions, but we'll have to see. Once all the strings are deobfuscated, it makes it very obvious, as you can maybe see in these little images here, where the Zend VM code is just copied and pasted. You just see the exact same strings from the Zend PHP Zend VM, except weirdly obfuscated within the loader itself. It makes it a bit easier to see which bits are just Zend VM and which bits are actually Ion Cube. There's also a bunch of other weird little stuff in there. There's something called Ion Cube 24, which is endpoint security for PHP or something. I'm not entirely sure what it does, but it just registers lots of IC24 underscore PHP functions in there. Knowing that there's something that isn't really relevant in there is useful as well. It means we can just sort of cut through the fat a little bit. It registers a bunch of underscore Ion Cube PHP functions as well, but it also registers these other strange functions with names like someone sort of mashed the keyboard. Each of these functions takes two arguments. One just is a pointer, and the other is a kind of checksum, which is just that same pointer XORed with this number. If you don't give it the right arguments, it will just send you some really sinister threats. It will say things like, a rat who gnaws at a cat's tail invites destruction, and do good, reap good, do evil, reap evil, and things like that, which isn't very... isn't very nice. But if you give it the right arguments, it will do something. I never actually figured out exactly what it was doing, but it seems like some kind of debug functionality in there. Maybe it'll be a fun thing to look at another day. So once all of this is sort of sifted through and we've cut through a lot of the fat, the way to start de-offuscating this stuff is to hook some strategic points in the unpacking process. And you can dump the... opcodes in this sort of proprietary way that they've stored them. You might be able to see here with these very strange-looking strings. But it stores the variable names, it stores the function names, like everything is retrievable from within the compiled IonCube format, whatever it is. Anyway, it's a whole hassle and it's a whole thing to talk about another day. But it's elaborate and complicated and you have to spend a lot of time in it. But I'll talk about it probably another day and maybe talk to legal professionals about why there isn't... why this kind of stuff isn't in public anyway at the moment. Anyway, we have de-offuscated code. Why does FreePBX use this de-offuscated code in the first place? I'm not entirely sure. I think it has something to do with the license model. So they've got all these paid modules and the paid modules check for licenses before they run. But since it's all PHP, if the code wasn't obfuscated somehow, then maybe people would modify the code and then bypass the license checks. But it does sort of serve a licensing purpose, maybe. The only problem with this logic is that once you've de-obfuscated this stuff, you can just replace those... these obfuscated files with the de-obfuscated ones and FreePBX won't make a lot of money. Notice. And you can comment out the code. It doesn't check for integrity or anything like that. It does check for integrity on other files that aren't obfuscated, which is also very strange. So they've decided to do obfuscation instead of integrity checking, which I don't really understand. Maybe you get a sense by now. I think obfuscation is really silly. Anyway. So let's look at some bugs. The first one is in the Defone API component. This is part of the core functionality of FreePBX, but the code is still obfuscated for some reason. There's a lot of functionality within this, but it does require authentication, which is handled by this function called doAuth. doAuth contains this subtle if condition, which checks if the password is just the word login. In the abstract, this seems like a weird decision, but I think it's because they've designed this API to be a... this component to be an API for the Digium or other Sangoma like VoIP phones. So these devices aren't expected to have their own credentials. So this is a kind of concession in the authentication process for these particular devices to be able to authenticate. But it does essentially mean that it's an authentication bypass. All you need to pass the logic of this authentication function into the bot. We are going to show you an example of this in just a second. Two of the things you need is the MAC address of a registered phone, VoIP device, and this hard-coded password login. There's also one more check, which is the user agent header. So you just have to modify the user agent header to look like you're coming from a Digium or Sangoma phone. So the whole auth bypass is just sending a packet that makes it look like you're a VoIP device. You basically modify it. You basically have to do something. If you're using a voice-over, you can basically authenticate with just a MAC address. And maybe I don't need to tell this audience but MAC addresses are not particularly unique. Digium MAC addresses also have this 24-bit prefix so you can find the MAC addresses just by sniffing on the network, you can find them printed on the back of the VoIP devices inside a building or if you're really desperate you could try to brute force the last 24 bits of the MAC address. Two to the power of 24 seconds is like 27 weeks so if you sent a request every second for 27 weeks you'd be able to figure out at least one of the Digium devices on the network. And so we have this kind of authentication bypass and we can chain it with this other bug that is also in the Defone API. The Defone API handles all these different... methods that are specified in this request method field in the JSON post request. And so the PBX.users.currentcalls.stoprecording method is one that's vulnerable here. So let's have a look. So the channel ID function, the channel ID value from the JSON request is passed directly just into a PHP exec function. There's no attempt at input filtering or checking anything. It's just a very pure classic command. There's no attempt at input filtering or checking anything. It's just a very pure classic command injection in PHP in this software in 2023. I'm sorry it's not more interesting than that. I'm sorry it's not more complex bug. It's just... I mean it's fun in the fact that it's just very, very classic and very, very simple command injection. So that's an authentication bypass to RCE chain in FreePBX. There's another few issues as well. This one's another authentication issue in FreePBX. Where they have this admin interface that I tried to avoid finding bugs in because if you actually have admin privileges you can just create a skeleton module and just install it yourself and then you're just running code. So it didn't seem like a proper boundary. But they do have this other functionality that allows normal users to authenticate the admin interface but they don't get administrative rights. I think this is maybe just a little bit more complicated than the other ones. But I think this is just for monitoring or creating these like lower privileged accounts with this limited functionality. They get to see some like module output when they log in and they can be granted access to specific modules and stuff but they're explicitly not given full administration rights. But actually it means nothing because anyone who can authenticate to the admin interface has full admin privileges on pretty much anything. Like it's only enforced in the UI. So there's no separation between these lower privileged and admin privileges. So that's a little bit more complicated than the admin roles in the admin web interface. And so we can use this to exploit another vulnerability which is in the API module which any of these non-admin users of the admin interface can access. This is part of the core free PBX. So this isn't actually obfuscated at all. This is just in the bit bucket, just in the open source core. If we send a request with the command generate docs, we hit this like generate documentation function. And then we get this value. It takes two arguments which we also specify in the request that we're sending it. The most obvious issue is that if you can see the code here, the host argument is just concatted into a string which is passed directly to a process. So again this is just a very, very bog standard command injection vulnerability. The only thing that actually needs to be taken into account when you're exploiting this is the host value needs to actually resolve somewhere. So the command injection payload has to start with a valid URL to an actual server that will actually respond. But we can just spin up a server and do that. So the host will point somewhere like attacker.com slash command injection and then return some valid access token and all the checks will be passed and the command will be run. But also because the access token itself that's retrieved is concatted into a string, we can also just spin up the access token itself and the command will be run. So we can just spin up a server that would just return command injections as access tokens and we just, we don't even have to send a command injection as part of the payload. We just send a host and we've got a server that's just returning command injection payloads as part of the, as access tokens. So this makes it also quite a fun, a fun way to exploit this bug. And then finally there's one more little dovetail. This is a DOS that I found reported to Sangoma. It's in another endpoint called UCP, which is the user control panel. This is accessible to like every user by default. It's just a UI for normal user functions. So making calls, managing phone books and extensions and stuff like that. It's meant to be for everybody. In the UCP PMS model, we've got a lot of things that we can do. So this is a DOS module. Any user can send a request with the command parameter woo and then some other value passed to woo del. And then this woo del value gets used to create a path, which is just passed directly to unlink. So we can pass a path traversal string and unlink anything that we want on the server. It runs with asterisk user privileges. So anything owned by asterisk, you can, you can delete on the server. So it's a kind of way for any, any user to, to delete files. Useful. Asterisk files off the server. The disclosure for the, the disclosure process with Sangoma was pretty, pretty bad as well. Um, the response was really lukewarm. I sent them a disclosure at the start of May and then they replied a few days later, sort of asking about the IonCube stuff. And then they never, um, then they, I, I sent a few updates and requests for information and they never replied. Um, and then I chased them with some tweets for a while. Um, and then they didn't reply at all. And I did eventually get a response saying that they have patched some stuff. Um, but without telling me or helping me to, um, with version numbers or anything like this. So, um, this was about a month ago. They, they, I replied to that, that email from them with a whole bunch of questions and tried to get some other information out of them and they just haven't replied at all. So again, nothing coming back from Sangoma. It was a really, really, really annoying situation, especially considering they have this big page saying that they really want to work with security researchers and they really want to try and fix vulnerabilities as quickly as possible. Um, and that's also why none of these issues have CVS related to them at all. And the one email they did send back to me, they said that they were going to apply for a CVE for the issues. So it might just be that they've decided to apply for one CVE and bundle all of these issues under one CVE, which is helpful and useful for all the defenders and customers out there. Um, so yeah, I sent them these emails. They never replied to me. Um, I did, um, have a look at the patch for the API, um, bug that I mentioned here. Um, and it looks like the patch is no good. So I would have also been very happy to tell them that if they'd email me back. Um, Sangoma gets two, two stars. So, um, so, um, so, um, so, um, so, um, so, um, so, how do we do this? Uh, there are two stars because they sent me two emails, um, for their vendor response. And so I am going to show, oh, oh, no. How do I do this? So this is yesterday. I'm not sure why, there we go. This is the most updated version of FreePBX, as you can see here. I've taken the session token from the low-privileged user, and I am sending the patch bypass for the API exploit here. And getting a shell back. So obviously, still issues in FreePBX today. Okay. I mean, I did write a kind of summary for this. The PBX systems are meant to be pretty robust, they're meant to handle all the communications in these on-prem situations. People use them because they want to do things on-prem, they want to trust what's happening with their data, but the threat model is quite complicated. These servers are... They give different permissions. There's all kinds of different users, there's all kinds of different objects trying to connect to them. There's such a massive threat model for them that it's... They're very, very difficult to secure. User accounts are often required as well. Many employees will have some kind of phone or chat access. Many devices need their own accounts. And the privilege models are also sort of all over the place as well. There's this extra functionality. They keep on adding to make it more, like, UC-like or voice chat and video chat and things like this, text chat and data transfers and stuff. It's probably an interesting place to start if anyone wants to start looking at these kinds of servers. And adding XMPP servers to internal enterprise environments in 2023 seems silly, but, I mean, maybe. Maybe there's situations where it's called for. Another takeaway is there's just command injection bugs in PBX servers in 2023. And loads of them. So have fun also trying to look for them. Also bugs in open source can just sit there for years. So the SIPX open file bug's been sitting there for 13 years and nobody's done anything about it. And also Sangoma, really, really disappointing to work with. They say they wanted to work with researchers. They said they had this whole bug bounty program. They said they made all these big claims and then they didn't reply to any of my emails. So don't trust offenders. And also code obfuscation is stupid. It's fun to try and break it. We should all try and break it more. This is exactly the kind of place where people should be trying to mess around with that kind of stuff. And yeah. Thank you. Twitter's going under. Here's my email address if you want to contact me. Yeah. Thanks.