1 00:00:02,940 --> 00:00:10,080 Hi there. All right, thanks very much. Welcome to the talk. I'm not very good at intros, 2 00:00:10,080 --> 00:00:15,320 and I always talk under different pseudonyms, so I'm just going to tell you some facts about 3 00:00:15,320 --> 00:00:19,860 myself to hopefully make you trust what I'm about to tell you. I've been mainly working 4 00:00:19,860 --> 00:00:25,100 in embedded systems slash enterprise perimeter for a few years, sometimes as a consultant, 5 00:00:25,100 --> 00:00:30,980 sometimes as a researcher, sometimes in education. I've published research into Microsoft, Cisco, 6 00:00:31,180 --> 00:00:36,860 Netgear stuff, all kinds of different software over the years. I spoke here a few years ago 7 00:00:36,860 --> 00:00:41,680 about cellular hotspots and things like that. My main interest is just reverse engineering, 8 00:00:41,880 --> 00:00:47,600 so we might go off on a bit of a tangent here on some of these. I'm going to have to speed 9 00:00:47,600 --> 00:00:51,800 through some of this because I've got a lot to talk about, and this is one of the bits 10 00:00:51,800 --> 00:00:53,060 I'm going to speed through. 11 00:00:55,100 --> 00:01:01,920 If you don't know what PBX is, a PBX is a private branch exchange, emphasis on the private. 12 00:01:02,560 --> 00:01:07,700 Before these private branch exchanges, everything went through public branch exchanges for 13 00:01:07,700 --> 00:01:12,980 telephone calls. The problem was when businesses wanted to make calls to each other internally, 14 00:01:13,240 --> 00:01:20,140 the calls had to go through a public exchange, so it cost them money, so they moved the branch 15 00:01:20,140 --> 00:01:25,080 exchanges indoors. These first early PBX systems were for cloud. They were for cloud. They were for 16 00:01:25,100 --> 00:01:32,300 classic phones, and then VoIP started becoming more and more cheaper and more popular, so digital 17 00:01:32,300 --> 00:01:38,940 PBX started popping up, starting off as hardware and then slowly over time becoming implemented 18 00:01:38,940 --> 00:01:48,240 purely in software. Then as time went on, communication styles started morphing again, so PBX 19 00:01:48,240 --> 00:01:54,400 started morphing into something that people start to call unified communication servers today, which is like video, 20 00:01:54,400 --> 00:02:02,120 text, and all kinds of other kinds of communication. So this is more like modern chat-based contemporary 21 00:02:02,120 --> 00:02:07,480 stuff, but I'll use the term PBX more here because the servers and the software that I'm talking 22 00:02:07,480 --> 00:02:14,300 about is more like PBX servers. They're not really unified communication servers, although they do 23 00:02:14,300 --> 00:02:23,320 function in the way that unified communication servers claim to as well. This kind of stuff shows up in 24 00:02:24,980 --> 00:02:30,400 enterprise environments where they like to do things on-prem. There's a lot of different stuff in the 25 00:02:30,400 --> 00:02:38,540 PBX slash UC space, so probably the most fundamental will be like the SIP switching telephony software. 26 00:02:39,860 --> 00:02:45,600 Something like asterisk or free switch, for example. This is like the bare-bones telephone exchange 27 00:02:46,220 --> 00:02:53,960 functionality. Then there's other products that show up which use these phone exchange cores, and then 28 00:02:53,960 --> 00:03:00,340 provide easier UI uh configuration so for for example FreePBX is basically just like a UI 29 00:03:00,340 --> 00:03:05,520 configuration wrapper for asterisk and sipxcom is basically a UI configuration wrapper for free 30 00:03:05,520 --> 00:03:12,940 switch. Um and then on top of that they'll uh bolt another a whole bunch of other stuff on like 31 00:03:12,940 --> 00:03:22,360 text and video chat sort of make it a bit more UC like. Okay. There's a few big like PBX 32 00:03:22,360 --> 00:03:28,120 systems. FreePBX and 3CX are probably the biggest uh and then there's sipxcom as well. Um 33 00:03:28,840 --> 00:03:34,760 there's about 10 to 19 thousand um FreePBX web interfaces I could see on showdown the other 34 00:03:34,760 --> 00:03:41,920 day. About 250,000 3CX ones. Um there's not so many sipxcom ones but it has been around for 35 00:03:41,920 --> 00:03:51,260 quite a long time so it's still worth looking into. Um Free uh PBX servers are due to the 36 00:03:51,260 --> 00:03:55,740 complexity and all the all the kinds of services that you find on them. They can have a 37 00:03:55,740 --> 00:04:01,420 really big attack surface as well so they'll have things like the sip like telephone exchange 38 00:04:01,420 --> 00:04:09,440 core. Uh they'll have proprietary um uh uh services like the inter asterisk exchange 39 00:04:09,440 --> 00:04:18,680 protocol which you find in asterisk. Uh there's things like MGCP, RTSP, XMPP, MySQL, DNS 40 00:04:18,680 --> 00:04:20,560 all kinds of stuff you'll find on these servers. 41 00:04:20,560 --> 00:04:30,300 So there's a lot to look into. Um there's also these like um web management interfaces which 42 00:04:30,300 --> 00:04:37,240 are which are the core of a lot of these things. So um as I said before FreePBX the the web is 43 00:04:37,240 --> 00:04:42,080 basically just a web UI that uh allows you to configure all of these extra services plus 44 00:04:42,080 --> 00:04:48,960 asterisk and things like that. Um all of these servers also uh require authentication user 45 00:04:48,960 --> 00:04:54,320 accounts so post authentication stuff is also on the table for this kind of research. So the 46 00:04:54,320 --> 00:05:00,520 attack surface is really really broad. Um I'm gonna talk about two different uh servers today. 47 00:05:01,100 --> 00:05:09,420 The first one will be uh SIPX com and the other one will be FreePBX. Um I there's a caveat to it 48 00:05:09,420 --> 00:05:15,260 which is that I found these bugs through sort of less structured research. So despite the massive 49 00:05:15,260 --> 00:05:18,940 attack surface I only managed to sort of really touch the service surface of what I found. So I'm 50 00:05:18,960 --> 00:05:22,740 not sure what actually is on these servers but what I found I think is quite interesting so. 51 00:05:24,460 --> 00:05:33,680 So the first bug is um an RCE chain in SIPX com. So SIPX com is mainly written in Java. Uh it's 52 00:05:33,680 --> 00:05:40,880 all open source, all on GitHub. It ships it ships with this um optional XMPP server called SIPX 53 00:05:40,880 --> 00:05:48,860 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 54 00:05:48,960 --> 00:05:55,300 complex, SIPX open fire is quite complex uh integration with other like SIPX components so it's not a 55 00:05:55,300 --> 00:06:04,400 totally stand alone XMPP server. Um it sort of integrates with the whole SIPX ecosystem. Within SIPX open 56 00:06:04,400 --> 00:06:10,740 fire there's a message interceptor uh called default message packet interceptor. And every message 57 00:06:10,740 --> 00:06:18,940 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 58 00:06:18,960 --> 00:06:25,880 directives internally. So these directives are at call, at conf, and at xfer. If the message starts 59 00:06:25,880 --> 00:06:30,780 with one of these directives, then that message is handed off to some other external SIPX 60 00:06:30,780 --> 00:06:37,980 component. So this is part of the whole integration. The issues sort of affect a couple of the 61 00:06:37,980 --> 00:06:43,740 directives, but I'm just going to follow the at call one just for the simplicity here. So every 62 00:06:43,740 --> 00:06:49,340 message is intercepted and then passed to a function called process chat message, where it's 63 00:06:49,340 --> 00:06:54,180 checked for directives. If it starts with at call, then the rest of the message is passed to the 64 00:06:54,180 --> 00:06:59,220 map arbitrary name to SIP endpoint function, and then the string that comes out of that is passed 65 00:06:59,220 --> 00:07:05,600 to build REST call command, and the result of that is passed to send REST request. So we can just 66 00:07:05,600 --> 00:07:10,500 follow this flow really quickly. Map arbitrary name to SIP endpoint just checks for usernames 67 00:07:10,500 --> 00:07:13,720 in the string and basically just returns back the string. So this is the end of the 68 00:07:13,740 --> 00:07:20,640 string wholesale as we want it, as we give it, without doing anything to it if it doesn't find a 69 00:07:20,640 --> 00:07:25,540 valid username. Build REST call command takes the whole string that we've passed in the 70 00:07:25,540 --> 00:07:30,520 message, concats it directly into a URL string and then returns it, and there's no check or 71 00:07:30,520 --> 00:07:36,060 filtering on it at all. And then that whole URL string is passed to send REST request, which 72 00:07:36,060 --> 00:07:41,400 just concats it directly into a curl command string. So, and this curl command string just 73 00:07:41,400 --> 00:07:43,400 gets passed directly to runtime. 74 00:07:45,580 --> 00:07:50,920 There's a to do note above this function suggesting that they know this isn't really the 75 00:07:50,920 --> 00:07:58,520 ideal way to implement this functionality, but it's been there since about 2010, according to the 76 00:07:59,220 --> 00:08:08,940 git history. So 13 years of not doing anything about it. The conventional wisdom of this would 77 00:08:08,940 --> 00:08:13,620 say that this is just arbitrary command execution, but that's not actually really true. Run 78 00:08:13,620 --> 00:08:20,540 time.exec doesn't quite work like that. There's an assumption that runtime.exec for some reason 79 00:08:20,540 --> 00:08:27,460 behaves like system or P open, which is not true at all. So all the kind of classic code 80 00:08:27,460 --> 00:08:35,000 execution payloads that we might want to use for this will always fail. So just to give a quick 81 00:08:35,000 --> 00:08:39,960 rundown of how runtime.exec works, we'll just follow the source. 82 00:08:43,620 --> 00:08:50,560 So if you pass just a normal string directly to runtime.exec, the first overload we hit is the one 83 00:08:50,560 --> 00:08:55,180 that just takes a single string. This passes it to another exec overload, which takes three 84 00:08:55,180 --> 00:09:00,740 arguments, the first of which is a string. That overload takes the string and passes it to a 85 00:09:00,740 --> 00:09:05,720 string tokenizer and then just pushes that into a string array, which passes it to another exec 86 00:09:05,720 --> 00:09:11,440 overload, which takes three arguments and an array as its first argument. And then this overload 87 00:09:11,440 --> 00:09:17,240 passes the string array to process builder and creates the process using .start. So we've got this 88 00:09:17,240 --> 00:09:22,620 array of strings being passed to process builder. Process builder takes the first element in the 89 00:09:22,620 --> 00:09:29,340 array and checks its executability and then the array gets passed to process impl.start, which 90 00:09:29,340 --> 00:09:35,080 just, in our case, because we're running on Linux, creates a Unix process. So the first element in 91 00:09:35,080 --> 00:09:40,100 the array is the executable argument to the Unix process. So regardless of what we actually 92 00:09:40,100 --> 00:09:41,420 inject into this component, we're just going to pass the string array to process builder. So 93 00:09:41,440 --> 00:09:44,560 we're going to use the command string. We're always going to be running curl, so there's no way 94 00:09:44,560 --> 00:09:53,760 around it. So it is, we don't have direct command execution, but we do, we can kind of use this to 95 00:09:53,760 --> 00:09:58,820 our advantage. So we can't control the executable. It's always going to be curl. But we can pass 96 00:09:58,820 --> 00:10:05,460 arbitrary arguments to curl. So the next question is what arguments can we pass to create a useful 97 00:10:05,460 --> 00:10:10,480 primitive there? Before we figure that out, we have to look at how the command string is actually 98 00:10:11,320 --> 00:10:16,140 laid out and what we control. So we can't control the arguments at the beginning because they're 99 00:10:16,140 --> 00:10:20,880 hard coded, but as long as we pass a string that contains spaces, we can put whatever arguments we 100 00:10:20,880 --> 00:10:26,780 want later into the command. So for example, we can download files within the same curl command by 101 00:10:26,780 --> 00:10:33,320 just adding an extra dash x get argument and specifying just a file to output to with the O flag. 102 00:10:33,560 --> 00:10:39,460 So it's a pretty useful primitive. We can force the server to download files from anywhere and save them 103 00:10:39,460 --> 00:10:47,040 or write them anywhere on the server. SIP X open file runs as the daemon user, so we can only really 104 00:10:47,040 --> 00:10:52,700 write where the daemon user can write. That's the only real limitation on it. We can also read files 105 00:10:52,700 --> 00:10:58,440 from the server. So we can use the D flag to read a file on the server then send it over to wherever 106 00:10:58,440 --> 00:11:08,800 we specify. So an injection like this one tells the first x dash x post request to output the result of the 107 00:11:08,800 --> 00:11:14,780 request to some temp file and then tells curl to read the password file using the D flag and then 108 00:11:14,780 --> 00:11:24,160 send it over to an IP address. So we can both read and write files using this curl argument 109 00:11:24,160 --> 00:11:30,300 injection. So they're quite interesting and good primitives, but it doesn't quite get us to code 110 00:11:30,300 --> 00:11:38,320 execution directly. But there is one more bug which is quite useful in this case. The open file 111 00:11:38,800 --> 00:11:44,980 file for SIP X open file is installed with daemon daemon privileges in the init.d directory, so 112 00:11:45,520 --> 00:11:50,320 with our write primitive we can overwrite this file, which will execute as root whenever the 113 00:11:50,320 --> 00:11:57,540 service is restarted. So we can chain those things together. We overwrite the open file in it 114 00:11:57,540 --> 00:12:03,840 file using the curl file download primitive and then replace it with an almost identical file 115 00:12:04,420 --> 00:12:08,780 with just a command exec payload in it. We wait for the service to read the file and then we can 116 00:12:08,780 --> 00:12:14,480 be restarted or force it to restart using the web interface and then we just get a root shell. So 117 00:12:14,480 --> 00:12:23,400 it's a fun bug chain just by sending XMPP messages from one user to another. You can overwrite 118 00:12:23,400 --> 00:12:33,780 files and then eventually get a root shell from this server. There's a full rundown of the 119 00:12:33,780 --> 00:12:38,760 exploit on setlist that I sent over in March that you can have a look at. I'm going to show you a 120 00:12:39,860 --> 00:12:40,720 little bit of what we've done there. So we're going to have a look at SIP X open file. SIP X 121 00:12:40,720 --> 00:12:46,000 open file is, sorry, SIP X com is maintained by a company called Cordial who just never 122 00:12:46,620 --> 00:12:53,060 responded to anything that I've said. So I sent them emails for a while. I first reported in 123 00:12:53,060 --> 00:12:59,720 November. They didn't reply. I kept on sending emails for a while. They didn't reply to any of 124 00:12:59,720 --> 00:13:05,480 them. I kept sending them tweets and they just kept on untagging themselves from tweets, so I 125 00:13:06,140 --> 00:13:08,760 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 126 00:13:08,760 --> 00:13:15,180 of uh active indifference and so these are just bugs that are still in the latest version of 127 00:13:15,180 --> 00:13:20,400 SIPXCOM and I guess we'll stay there for a while. It looks like SIPXCOM might be dead. I'm 128 00:13:20,400 --> 00:13:27,520 not entirely sure. Um so yeah Cordial gets half a star for their vendor response. Very bad 129 00:13:27,520 --> 00:13:37,620 experience. Don't work with them. Okay the next bugs are all in uh FreePBX. So FreePBX is 130 00:13:37,620 --> 00:13:43,620 maintained by Sangoma. Um it's based on Asterisk for the telephone side of things. There's a web 131 00:13:43,620 --> 00:13:50,200 interface um loads of free and paid modules that you can sort of strap onto it. Um and according 132 00:13:50,200 --> 00:13:55,200 to their website they run a bug bounty program. So they say they want to work with security 133 00:13:55,200 --> 00:14:00,760 researchers. That they want to fix everything within 60 days. Um so that all looks really nice 134 00:14:00,760 --> 00:14:05,480 and of course at this point I'm I'm really looking forward to the professional disclosure 135 00:14:05,480 --> 00:14:07,600 process with lots of care. 136 00:14:07,620 --> 00:14:12,580 Communication and very happy outcomes and for everyone involved. 137 00:14:16,880 --> 00:14:21,940 Um SIPXCOM is pretty straight forward. It's just straight forward open source Java. FreePBX is a 138 00:14:21,940 --> 00:14:29,780 bit more complicated. So it's mainly written in PHP which is nice. Um the core or a lot a lot of 139 00:14:29,780 --> 00:14:37,540 the core code is open source to some extent. Uh there's a FreePBX core bit that's free. Um 140 00:14:37,620 --> 00:14:43,640 and the code for that's all in the FreePBX bit bucket. Um there's a few free plugins which come 141 00:14:43,640 --> 00:14:48,760 bundled with FreePBX which you can't find the source for for some reason. And then Sangoma also 142 00:14:48,760 --> 00:14:53,000 sells licenses for some other plugins. And none of those plugins are open source either. So 143 00:14:53,560 --> 00:14:58,380 there's a lot of functionality where where the code sort of just isn't public. Um despite the 144 00:14:58,380 --> 00:15:07,600 fact that FreePBX is uh touted as as something like an open source PBX server. Um so the 145 00:15:07,620 --> 00:15:13,480 it's mainly written in PHP. So and it's shipped mainly as a Linux VM. So whoever has access to 146 00:15:13,480 --> 00:15:19,280 the VM could read the the PHP files. So obviously to avoid leaking code for the non open source 147 00:15:19,280 --> 00:15:27,660 components um they've used something called IonCube. Um so IonCube is a PHP source code of 148 00:15:27,660 --> 00:15:36,740 obfuscation solution. Um it uh the the IonCube compiler compiles down PHP to Zen byte code. 149 00:15:36,740 --> 00:15:44,800 Essentially and stores it in its proprietary um IonCube format. And then at runtime the PHP uh 150 00:15:45,340 --> 00:15:52,200 uh process loads the IonCube module which uh decompiles the PHP before running it. So it's a 151 00:15:52,200 --> 00:15:56,180 massive overs oversimplification of actually what IonCube's doing. But uh it's essentially what 152 00:15:56,180 --> 00:16:00,660 it does. It's a lot like things like Zengard and Source Guardian. There's some really nice um 153 00:16:00,660 --> 00:16:06,720 previous research into IonCube by um these guys that I've mentioned here. Um but it's through a 154 00:16:06,720 --> 00:16:10,440 quite a few years ago so. Some of the information's still relevant some of it's a little 155 00:16:10,440 --> 00:16:18,540 bit outdated. Um the point of IonCube is just to create as much hassle as possible for for 156 00:16:18,540 --> 00:16:24,320 people like us. So anyone who wants to have a look at the source code. Um it it will cause us 157 00:16:24,320 --> 00:16:30,240 cause cause us to spend a lot of time trying to uh get access to the source or maybe just give up 158 00:16:30,240 --> 00:16:36,640 entirely. And the point is also to make money. Like they sell a license for like 200 229 dollars. 159 00:16:36,720 --> 00:16:46,340 There's no free or open source deobfuscators available. Um I'm not entirely sure why. I 160 00:16:46,340 --> 00:16:52,640 assume it's because IonCube are litigious. Um I'm not entirely sure how legal it is or how 161 00:16:52,640 --> 00:16:58,340 legal it would be to offer a deobfuscator for free. But regardless because there's nothing free 162 00:16:58,340 --> 00:17:03,860 out there there's this grey market for deobfuscation tools that exists out there. Um so 163 00:17:03,860 --> 00:17:06,700 you can find these deobfuscations as a service. Um and and uh. So I'm not sure if there's any 164 00:17:06,700 --> 00:17:12,960 and people trying to sell things on Telegram and very dodgy looking YouTube videos that 165 00:17:12,960 --> 00:17:20,580 show nothing in particular happening with very big price tags. I spent a bit of time 166 00:17:20,580 --> 00:17:29,380 playing with these during the process of looking at the free PBS code. I did get some useful 167 00:17:29,380 --> 00:17:43,540 code out of some of them but it's a bit of a grey area. Regardless I spent quite a lot of time 168 00:17:43,540 --> 00:17:50,020 looking at the deobfuscation process so I'm going to share a little bit of that today as well. In 169 00:17:50,020 --> 00:17:59,140 the case of free PBS they're using the iron cube loader for PHP 7.4 which is version 10.4.5. The 170 00:17:59,380 --> 00:18:07,540 loader PHP module is an SO that's just under 1.4 megabytes. It's part of the free PBXVM image so 171 00:18:07,540 --> 00:18:12,620 you can just dump it straight out of there. It hooks Xen compile file and Xen execute X functions 172 00:18:13,440 --> 00:18:20,060 in the main PHP process. What it does very basically at the beginning is just check for magic 173 00:18:20,060 --> 00:18:26,520 bytes at the start of every PHP file that comes in. If it finds them it will try to deobfuscate 174 00:18:26,520 --> 00:18:29,360 it and run it. If it doesn't find it it just passes the files directly to the PHP module. So 175 00:18:29,380 --> 00:18:36,720 it's just directly back to the PHP Xen VM. If it does find the bytes then it will it goes on 176 00:18:36,720 --> 00:18:45,180 this sort of chaotic journey. So the whole loader is a complete chaotic mess. We have to really 177 00:18:45,180 --> 00:18:54,040 follow a lot of things going along. It doesn't just deobfuscate the Xen byte code and just pass 178 00:18:54,040 --> 00:18:59,360 it back to the main PHP Xen VM. It actually ships a whole modified Xen VM which is a 179 00:18:59,380 --> 00:19:04,320 standard Xen Xen code within itself and every op code is executed within the loader itself. 180 00:19:04,580 --> 00:19:10,440 Nothing ever goes back to the main PHP process. So the whole extension is really, really big and 181 00:19:10,440 --> 00:19:14,820 you can waste a lot of time in it. So I'm just going to share a few little bits and pieces that 182 00:19:14,820 --> 00:19:23,840 I noticed while I was working on it. The loader is kind of obfuscated. So all the strings or the 183 00:19:23,840 --> 00:19:29,360 useful strings within it XORed with this static XOR key. So obviously when you're trying to do a 184 00:19:29,360 --> 00:19:34,820 to reverse engineer it, being able to see the strings is very beneficial as part of the process. 185 00:19:36,500 --> 00:19:42,500 I wrote a GIDRA script which you can download here to help you do that. You do need to 186 00:19:46,040 --> 00:19:50,720 put the XOR key into it for the specific loader, although I think it might be static 187 00:19:51,800 --> 00:19:57,560 among different versions, but we'll have to see. Once all the strings are deobfuscated, 188 00:19:57,560 --> 00:20:01,920 it makes it very obvious, as you can maybe see in these little images here, where the 189 00:20:03,020 --> 00:20:07,080 Zend VM code is just copied and pasted. You just see the exact same strings from the Zend 190 00:20:07,080 --> 00:20:16,060 PHP Zend VM, except weirdly obfuscated within the loader itself. It makes it a bit easier to see 191 00:20:16,060 --> 00:20:21,160 which bits are just Zend VM and which bits are actually Ion Cube. There's also a bunch of other 192 00:20:21,160 --> 00:20:26,240 weird little stuff in there. There's something called Ion Cube 24, which is endpoint security 193 00:20:26,240 --> 00:20:27,540 for PHP or something. 194 00:20:27,560 --> 00:20:32,880 I'm not entirely sure what it does, but it just registers lots of IC24 underscore 195 00:20:33,680 --> 00:20:39,160 PHP functions in there. Knowing that there's something that isn't really relevant in there 196 00:20:39,160 --> 00:20:42,980 is useful as well. It means we can just sort of cut through the fat a little bit. 197 00:20:44,520 --> 00:20:51,000 It registers a bunch of underscore Ion Cube PHP functions as well, but it also registers these 198 00:20:51,000 --> 00:20:55,680 other strange functions with names like someone sort of mashed the keyboard. 199 00:20:57,580 --> 00:21:03,460 Each of these functions takes two arguments. One just is a pointer, and the other is a kind of 200 00:21:03,460 --> 00:21:12,780 checksum, which is just that same pointer XORed with this number. If you don't give it the right 201 00:21:12,780 --> 00:21:18,960 arguments, it will just send you some really sinister threats. It will say things like, 202 00:21:18,980 --> 00:21:25,500 a rat who gnaws at a cat's tail invites destruction, and do good, reap good, do evil, 203 00:21:25,580 --> 00:21:27,540 reap evil, and things like that, which isn't very... 204 00:21:27,960 --> 00:21:32,420 isn't very nice. But if you give it the right arguments, it will 205 00:21:33,000 --> 00:21:36,160 do something. I never actually figured out exactly what it was doing, but 206 00:21:37,380 --> 00:21:41,820 it seems like some kind of debug functionality in there. Maybe it'll be a fun thing to look at 207 00:21:41,820 --> 00:21:49,440 another day. So once all of this is sort of sifted through and we've cut through a lot of the fat, 208 00:21:51,060 --> 00:21:55,600 the way to start de-offuscating this stuff is to hook some strategic points in the unpacking 209 00:21:55,600 --> 00:21:57,540 process. And you can dump the... 210 00:21:57,560 --> 00:22:04,160 opcodes in this sort of proprietary way that they've stored them. You might be able to see 211 00:22:04,160 --> 00:22:12,160 here with these very strange-looking strings. But it stores the variable names, it stores the 212 00:22:12,160 --> 00:22:17,900 function names, like everything is retrievable from within the compiled 213 00:22:22,020 --> 00:22:26,860 IonCube format, whatever it is. Anyway, it's a whole hassle and it's a whole thing to talk about 214 00:22:26,860 --> 00:22:27,260 another day. 215 00:22:27,560 --> 00:22:31,520 But it's elaborate and complicated and you have to spend a lot of time in it. But 216 00:22:32,180 --> 00:22:37,440 I'll talk about it probably another day and maybe talk to legal professionals about 217 00:22:38,640 --> 00:22:41,620 why there isn't... why this kind of stuff isn't in public anyway at the moment. 218 00:22:44,300 --> 00:22:52,700 Anyway, we have de-offuscated code. Why does FreePBX use this de-offuscated code in the 219 00:22:52,700 --> 00:22:57,320 first place? I'm not entirely sure. I think it has something to do with the license 220 00:22:57,560 --> 00:23:02,960 model. So they've got all these paid modules and the paid modules check for licenses before they 221 00:23:02,960 --> 00:23:09,060 run. But since it's all PHP, if the code wasn't obfuscated somehow, then maybe people would 222 00:23:09,060 --> 00:23:14,520 modify the code and then bypass the license checks. But it does sort of serve a licensing 223 00:23:14,520 --> 00:23:20,380 purpose, maybe. The only problem with this logic is that once you've de-obfuscated this stuff, 224 00:23:20,620 --> 00:23:27,540 you can just replace those... these obfuscated files with the de-obfuscated ones and FreePBX won't make a lot of money. 225 00:23:27,540 --> 00:23:32,160 Notice. And you can comment out the code. It doesn't check for integrity or anything like that. 226 00:23:32,360 --> 00:23:36,900 It does check for integrity on other files that aren't obfuscated, which is also very strange. So 227 00:23:36,900 --> 00:23:42,540 they've decided to do obfuscation instead of integrity checking, which I don't really 228 00:23:42,540 --> 00:23:47,100 understand. Maybe you get a sense by now. I think obfuscation is really silly. Anyway. 229 00:23:48,720 --> 00:23:57,160 So let's look at some bugs. The first one is in the Defone API component. This is part of the core 230 00:23:57,540 --> 00:24:04,780 functionality of FreePBX, but the code is still obfuscated for some reason. There's a lot of 231 00:24:04,780 --> 00:24:09,580 functionality within this, but it does require authentication, which is handled by this function 232 00:24:09,580 --> 00:24:19,120 called doAuth. doAuth contains this subtle if condition, which checks if the password is just the 233 00:24:19,120 --> 00:24:26,000 word login. In the abstract, this seems like a weird decision, but I think it's because they've 234 00:24:26,000 --> 00:24:27,480 designed this API to be a... 235 00:24:27,540 --> 00:24:35,200 this component to be an API for the Digium or other Sangoma like VoIP phones. So these devices 236 00:24:35,200 --> 00:24:39,940 aren't expected to have their own credentials. So this is a kind of concession in the authentication 237 00:24:39,940 --> 00:24:47,160 process for these particular devices to be able to authenticate. But it does essentially mean 238 00:24:48,630 --> 00:24:57,260 that it's an authentication bypass. All you need to pass the logic of this authentication function 239 00:24:57,540 --> 00:24:57,820 into the 240 00:24:57,820 --> 00:25:00,560 bot. We are going to show you an example of this in just a second. Two of the things you need is the 241 00:25:00,560 --> 00:25:08,520 MAC address of a registered phone, VoIP device, and this hard-coded password login. 242 00:25:09,800 --> 00:25:16,460 There's also one more check, which is the user agent header. So you just have to modify the user 243 00:25:16,460 --> 00:25:21,280 agent header to look like you're coming from a Digium or Sangoma phone. So the whole auth 244 00:25:21,280 --> 00:25:25,580 bypass is just sending a packet that makes it look like you're a VoIP device. 245 00:25:26,000 --> 00:25:27,520 You basically modify it. You basically have to do something. If you're using a voice-over, you can 246 00:25:27,520 --> 00:25:34,740 basically authenticate with just a MAC address. And maybe I don't need to tell this audience but 247 00:25:34,740 --> 00:25:43,400 MAC addresses are not particularly unique. Digium MAC addresses also have this 24-bit prefix so 248 00:25:44,360 --> 00:25:49,260 you can find the MAC addresses just by sniffing on the network, you can find them printed on the 249 00:25:49,260 --> 00:25:54,940 back of the VoIP devices inside a building or if you're really desperate you could try to brute 250 00:25:54,940 --> 00:26:03,200 force the last 24 bits of the MAC address. Two to the power of 24 seconds is like 27 weeks so if 251 00:26:03,200 --> 00:26:09,260 you sent a request every second for 27 weeks you'd be able to figure out at least one of the 252 00:26:09,260 --> 00:26:16,460 Digium devices on the network. And so we have this kind of authentication bypass and we can 253 00:26:16,460 --> 00:26:24,400 chain it with this other bug that is also in the Defone API. The Defone API handles all these 254 00:26:24,400 --> 00:26:24,920 different... 255 00:26:24,940 --> 00:26:32,160 methods that are specified in this request method field in the JSON post request. And so the 256 00:26:32,160 --> 00:26:39,400 PBX.users.currentcalls.stoprecording method is one that's vulnerable here. So let's have a look. 257 00:26:42,200 --> 00:26:47,120 So the channel ID function, the channel ID value from the JSON request is passed directly just 258 00:26:47,120 --> 00:26:53,060 into a PHP exec function. There's no attempt at input filtering or checking anything. It's just a 259 00:26:53,060 --> 00:26:54,920 very pure classic command. 260 00:26:54,940 --> 00:26:55,080 There's no attempt at input filtering or checking anything. It's just a very pure classic command 261 00:26:55,080 --> 00:27:02,440 injection in PHP in this software in 2023. I'm sorry it's not more interesting than that. I'm sorry 262 00:27:02,440 --> 00:27:09,220 it's not more complex bug. It's just... I mean it's fun in the fact that it's just very, very 263 00:27:09,220 --> 00:27:17,420 classic and very, very simple command injection. So that's an authentication bypass to RCE chain in 264 00:27:20,220 --> 00:27:24,660 FreePBX. There's another few issues as well. This one's another authentication issue in FreePBX. 265 00:27:24,660 --> 00:27:32,880 Where they have this admin interface that I tried to avoid finding bugs in because if you 266 00:27:32,880 --> 00:27:38,860 actually have admin privileges you can just create a skeleton module and just install it yourself and 267 00:27:38,860 --> 00:27:43,680 then you're just running code. So it didn't seem like a proper boundary. But they do have this 268 00:27:43,680 --> 00:27:49,860 other functionality that allows normal users to authenticate the admin interface but they don't 269 00:27:49,860 --> 00:27:51,260 get administrative rights. 270 00:27:52,420 --> 00:27:54,640 I think this is maybe just a little bit more complicated than the other ones. But I think this is 271 00:27:54,660 --> 00:27:58,580 just for monitoring or creating these like lower privileged accounts with this limited 272 00:27:58,580 --> 00:28:04,980 functionality. They get to see some like module output when they log in and they can be granted 273 00:28:04,980 --> 00:28:10,240 access to specific modules and stuff but they're explicitly not given full administration rights. 274 00:28:11,040 --> 00:28:15,960 But actually it means nothing because anyone who can authenticate to the admin interface has full 275 00:28:15,960 --> 00:28:21,860 admin privileges on pretty much anything. Like it's only enforced in the UI. So there's no 276 00:28:21,860 --> 00:28:24,640 separation between these lower privileged and admin privileges. So that's a little bit more 277 00:28:24,660 --> 00:28:30,020 complicated than the admin roles in the admin web interface. And so we can use this to exploit 278 00:28:30,020 --> 00:28:36,240 another vulnerability which is in the API module which any of these non-admin users of the admin 279 00:28:36,240 --> 00:28:43,540 interface can access. This is part of the core free PBX. So this isn't actually obfuscated at all. 280 00:28:43,600 --> 00:28:49,120 This is just in the bit bucket, just in the open source core. If we send a request with the 281 00:28:49,120 --> 00:28:54,640 command generate docs, we hit this like generate documentation function. And then we get this 282 00:28:54,660 --> 00:29:00,200 value. It takes two arguments which we also specify in the request that we're sending it. The 283 00:29:00,200 --> 00:29:07,840 most obvious issue is that if you can see the code here, the host argument is just concatted into a 284 00:29:07,840 --> 00:29:12,340 string which is passed directly to a process. So again this is just a very, very bog standard 285 00:29:12,340 --> 00:29:19,380 command injection vulnerability. The only thing that actually needs to be taken into account when 286 00:29:19,380 --> 00:29:24,440 you're exploiting this is the host value needs to actually resolve somewhere. So the command 287 00:29:24,440 --> 00:29:31,580 injection payload has to start with a valid URL to an actual server that will actually respond. 288 00:29:31,940 --> 00:29:40,520 But we can just spin up a server and do that. So the host will point somewhere like attacker.com 289 00:29:40,520 --> 00:29:46,340 slash command injection and then return some valid access token and all the checks will be passed 290 00:29:46,340 --> 00:29:52,100 and the command will be run. But also because the access token itself that's retrieved is 291 00:29:52,100 --> 00:29:54,420 concatted into a string, we can also just spin up the access token itself and the command will be run. 292 00:29:54,440 --> 00:30:02,080 So we can just spin up a server that would just return command injections as access tokens and we 293 00:30:02,080 --> 00:30:05,860 just, we don't even have to send a command injection as part of the payload. We just send a host 294 00:30:05,860 --> 00:30:11,900 and we've got a server that's just returning command injection payloads as part of the, as access 295 00:30:11,900 --> 00:30:19,300 tokens. So this makes it also quite a fun, a fun way to exploit this bug. And then finally there's 296 00:30:21,160 --> 00:30:24,420 one more little dovetail. 297 00:30:24,440 --> 00:30:33,200 This is a DOS that I found reported to Sangoma. It's in another endpoint called UCP, which is the 298 00:30:34,040 --> 00:30:43,300 user control panel. This is accessible to like every user by default. It's just a UI for normal 299 00:30:43,660 --> 00:30:49,120 user functions. So making calls, managing phone books and extensions and stuff like that. It's 300 00:30:49,120 --> 00:30:54,420 meant to be for everybody. In the UCP PMS model, we've got a lot of things that we can do. So 301 00:30:54,420 --> 00:30:59,180 this is a DOS module. Any user can send a request with the command parameter woo and then some 302 00:30:59,180 --> 00:31:04,060 other value passed to woo del. And then this woo del value gets used to create a path, which is 303 00:31:04,060 --> 00:31:10,140 just passed directly to unlink. So we can pass a path traversal string and unlink anything that we 304 00:31:10,140 --> 00:31:16,640 want on the server. It runs with asterisk user privileges. So anything owned by asterisk, you 305 00:31:16,640 --> 00:31:24,020 can, you can delete on the server. So it's a kind of way for any, any user to, to delete files. Useful. 306 00:31:24,740 --> 00:31:31,180 Asterisk files off the server. The disclosure for the, the disclosure process with Sangoma was 307 00:31:31,180 --> 00:31:38,140 pretty, pretty bad as well. Um, the response was really lukewarm. I sent them a disclosure at the 308 00:31:38,140 --> 00:31:43,820 start of May and then they replied a few days later, sort of asking about the IonCube stuff. And 309 00:31:43,820 --> 00:31:49,300 then they never, um, then they, I, I sent a few updates and requests for information and they 310 00:31:49,300 --> 00:31:54,400 never replied. Um, and then I chased them with some tweets for a while. Um, and then they 311 00:31:54,420 --> 00:31:58,100 didn't reply at all. And I did eventually get a response saying that they have patched some 312 00:31:58,100 --> 00:32:06,960 stuff. Um, but without telling me or helping me to, um, with version numbers or anything like 313 00:32:06,960 --> 00:32:14,820 this. So, um, this was about a month ago. They, they, I replied to that, that email from them with a 314 00:32:14,820 --> 00:32:18,620 whole bunch of questions and tried to get some other information out of them and they just 315 00:32:18,620 --> 00:32:24,160 haven't replied at all. So again, nothing coming back from Sangoma. It was a really, really, 316 00:32:24,160 --> 00:32:29,720 really annoying situation, especially considering they have this big page saying that they 317 00:32:29,720 --> 00:32:33,140 really want to work with security researchers and they really want to try and fix 318 00:32:33,140 --> 00:32:38,380 vulnerabilities as quickly as possible. Um, and that's also why none of these issues have CVS 319 00:32:38,380 --> 00:32:42,300 related to them at all. And the one email they did send back to me, they said that they were going 320 00:32:42,300 --> 00:32:49,460 to apply for a CVE for the issues. So it might just be that they've decided to apply for one CVE 321 00:32:49,460 --> 00:32:54,920 and bundle all of these issues under one CVE, which is helpful and useful for all the defenders 322 00:32:54,920 --> 00:33:02,500 and customers out there. Um, so yeah, I sent them these emails. They never replied to me. Um, I 323 00:33:02,500 --> 00:33:11,500 did, um, have a look at the patch for the API, um, bug that I mentioned here. Um, and it looks 324 00:33:11,500 --> 00:33:15,700 like the patch is no good. So I would have also been very happy to tell them that if they'd 325 00:33:15,700 --> 00:33:19,440 email me back. Um, Sangoma gets two, two stars. So, um, so, um, so, um, so, um, so, um, so, um, so, 326 00:33:19,440 --> 00:33:23,500 how do we do this? Uh, there are two stars because they sent me two emails, um, for their vendor 327 00:33:23,500 --> 00:33:47,880 response. And so I am going to show, oh, oh, no. How do I do this? So this is yesterday. 328 00:33:53,100 --> 00:33:55,480 I'm not sure why, there we go. 329 00:33:55,940 --> 00:34:02,260 This is the most updated version of FreePBX, as you can see here. 330 00:34:02,500 --> 00:34:19,140 I've taken the session token from the low-privileged user, and I am sending the patch bypass for 331 00:34:19,140 --> 00:34:23,260 the API exploit here. 332 00:34:27,060 --> 00:34:28,520 And getting a shell back. 333 00:34:41,460 --> 00:34:46,580 So obviously, still issues in FreePBX today. 334 00:34:48,060 --> 00:34:48,440 Okay. 335 00:34:52,880 --> 00:34:56,120 I mean, I did write a kind of summary for this. 336 00:34:56,340 --> 00:34:59,900 The PBX systems are meant to be pretty robust, they're meant to handle all the communications 337 00:34:59,900 --> 00:35:02,220 in these on-prem situations. 338 00:35:02,780 --> 00:35:08,620 People use them because they want to do things on-prem, they want to trust what's happening 339 00:35:08,620 --> 00:35:12,860 with their data, but the threat model is quite complicated. 340 00:35:13,480 --> 00:35:15,600 These servers are... 341 00:35:16,760 --> 00:35:17,980 They give different permissions. 342 00:35:17,980 --> 00:35:21,780 There's all kinds of different users, there's all kinds of different objects trying to connect 343 00:35:21,780 --> 00:35:22,160 to them. 344 00:35:22,240 --> 00:35:26,500 There's such a massive threat model for them that it's... 345 00:35:26,500 --> 00:35:29,700 They're very, very difficult to secure. 346 00:35:33,480 --> 00:35:35,400 User accounts are often required as well. 347 00:35:35,620 --> 00:35:38,520 Many employees will have some kind of phone or chat access. 348 00:35:38,760 --> 00:35:40,200 Many devices need their own accounts. 349 00:35:40,580 --> 00:35:44,540 And the privilege models are also sort of all over the place as well. 350 00:35:45,820 --> 00:35:47,900 There's this extra functionality. 351 00:35:47,980 --> 00:35:52,560 They keep on adding to make it more, like, UC-like or voice chat and video chat and things 352 00:35:52,560 --> 00:35:55,480 like this, text chat and data transfers and stuff. 353 00:35:56,920 --> 00:36:00,400 It's probably an interesting place to start if anyone wants to start looking at these 354 00:36:00,400 --> 00:36:01,040 kinds of servers. 355 00:36:03,900 --> 00:36:13,800 And adding XMPP servers to internal enterprise environments in 2023 seems silly, but, I mean, 356 00:36:13,860 --> 00:36:14,420 maybe. 357 00:36:14,520 --> 00:36:16,020 Maybe there's situations where it's called for. 358 00:36:17,840 --> 00:36:23,820 Another takeaway is there's just command injection bugs in PBX servers in 2023. 359 00:36:25,320 --> 00:36:26,480 And loads of them. 360 00:36:27,080 --> 00:36:30,100 So have fun also trying to look for them. 361 00:36:31,040 --> 00:36:33,420 Also bugs in open source can just sit there for years. 362 00:36:33,680 --> 00:36:38,760 So the SIPX open file bug's been sitting there for 13 years and nobody's done anything 363 00:36:38,760 --> 00:36:39,200 about it. 364 00:36:39,800 --> 00:36:43,100 And also Sangoma, really, really disappointing to work with. 365 00:36:43,240 --> 00:36:45,020 They say they wanted to work with researchers. 366 00:36:45,020 --> 00:36:46,940 They said they had this whole bug bounty program. 367 00:36:47,340 --> 00:36:50,900 They said they made all these big claims and then they didn't reply to any of my emails. 368 00:36:51,180 --> 00:36:54,560 So don't trust offenders. 369 00:36:57,580 --> 00:36:59,960 And also code obfuscation is stupid. 370 00:37:01,020 --> 00:37:02,800 It's fun to try and break it. 371 00:37:02,960 --> 00:37:04,340 We should all try and break it more. 372 00:37:05,400 --> 00:37:09,380 This is exactly the kind of place where people should be trying to mess around with that 373 00:37:09,380 --> 00:37:09,760 kind of stuff. 374 00:37:10,400 --> 00:37:11,160 And yeah. 375 00:37:11,240 --> 00:37:11,720 Thank you. 376 00:37:12,080 --> 00:37:12,840 Twitter's going under. 377 00:37:12,900 --> 00:37:14,580 Here's my email address if you want to contact me. 378 00:37:15,740 --> 00:37:16,160 Yeah. 379 00:37:16,240 --> 00:37:16,560 Thanks.