OffensiveCon2018 - The Return of Robin Hood Vs Cisco ASA
OffensiveCon2018 - The Return of Robin Hood Vs Cisco ASA
https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-20180129-asa1
The bug is not in IKEv1
new
Disclosure timeline (3)
• XX
new
new
https://web.archive.org/web/20180202110047/https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-20180129-asa1
https://web.archive.org/web/20180206165532/https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-20180129-asa1
SSL VPN
• WebVPN: client-less (browser)
• AnyConnect: client on Windows, OS X, Linux,
Android, iPhone OS
SSL
SSL
IKE VPN
• A.k.a. IPSec
• Typically static point-to-point VPNs
IKEv1 or IKEv2
Source: https://www.cisco.com/c/en/us/support/docs/security-vpn/webvpn-ssl-vpn/119208-config-asa-00.html#anc17
Previous work
• 2014
• Various WebVPN ASA version leaks (Alec Stuart-Muirk)
• 2016
• CVE-2016-1287: heap overflow in IKE Cisco fragmentation (Exodus Intel)
• CVE-2016-6366: SNMP OID stack overflow (Shadow Brokers)
• 2017
• Cisco ASA series on NCC blog in 8-parts (so far )
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/september/cisco-asa-series-part-one-intro-to-the-cisco-asa/
asatools
• All tools in one repo [1]
• asafw: unpack/repack firmware
• asadbg: debug ASA (hardware + qemu)
• libdlmalloc/libptmalloc: heap allocators (version dependent [2])
• libmempool: Cisco ASA specific heap header
• ret-sync: synchronise IDA and gdb (thanks Alex Gazet )
• idahunt: automate IDA cmdline, hunting for symbols
• Tutorial: configure a Cisco ASA test environment from ground zero [3]
[1] https://github.com/nccgroup/asatools
[2] https://github.com/nccgroup/asafw/blob/master/README.md#mitigation-summary
[3] https://github.com/nccgroup/asatools/blob/master/tutorial.md
asadbg - demo
Cisco ASA releases
END OF LIFE STILL PATCHED RECOMMENDED
Only NX if >= 9.3.3.9 or >= 9.4.3
7.x < 1/2/2016 Only ASLR if >= 9.5.1
ASLR & NX
8.x 8.7.1.18 < 1/5/2016 ptmalloc if >= 9.3.2 if >= 9.5.3
9.0 9.0.4.38 9.0.4.40 < 1/2/2017
XML parser
IKE heap overflow patch SNMP stack overflow patch double-free patch Hypothetical 0-day
(CVE-2016-1287) (CVE-2016-6366) (CVE-2018-0101) vulnerability
10/2/2016 17/8/2016 31/1/2018
9.9.1.2 4/12/2017 - *
XML parser
double-free patch Hypothetical 0-day
(CVE-2018-0101) vulnerability
31/1/2018
WebVPN/AnyConnect
SSL to trigger
the bug
The bigger the worse?
• What license to buy?
50 IKE sessions
250 IKE sessions
• An IKE session limits the quantity of data sent as IKE fragments to 0x8000 bytes
• More sessions more feng shui
• Exploit is more reliable against expensive Cisco hardware and license
• Possible to rob from the rich and give to the poor
• So I named my vulnerabilityexploit: Robin Hood
Source: https://www.cisco.com/c/en/us/td/docs/security/asa/asa97/configuration/vpn/asa-97-vpn-config/vpn-ike.html#ID-2441-00000058
Finding a bug
Sniffing SSL AnyConnect
Reverse engineering
https://github.com/aoh/radamsa
Connect GDB
Fire testcase
continue
• Interesting functions
• *auth_process_client*
• *FreeParser*
2 days reversing later…
• aggregateAuthParseBuf
• Receive the XML / initialize the libexpat parser
• Cisco-specific callbacks registered
• aggregateAuthStartHandler: called when XML tag opened
• aggregateAuthDataHandler: called when XML data parsed
• aggregateAuthEndHandler: called when XML tag closed
Data handler
Data handler
XML 1
Data handler
XML 1
Allocated chunk
Data handler
1
Data handler
Chunk is freed
1
Data handler
1
Data handler
1
Data handler
XML 2
1
Data handler
1 2
Data handler
1 2
Data handler
1 2
Data handler
• First packet with <host-scan-reply> tag
• Allocate heap buffer for data, copy data, free it (but dangling pointer)
• Second packet with <host-scan-reply> tag
• No reallocation, copy data, free it
• Tags’ data copied and appended in the same chunk
double-free vulnerability on 0x2040-byte chunk
assert() due to invalid metadata
• Inline metadata/header for heap chunks
Hchunk H chunk H Free chunk Hchunk
prev_foot = 0x8180d4d0
head = 0x1d0 (CINUSE|PINUSE)
mh_magic = 0xa11c0123 Allocated
mh_len = 0x1a4 chunk header
mh_refcount = 0x0
mh_unused = 0x0
mh_fd_link = 0xacb85b30
mh_bk_link = 0xa8800604
allocator_pc = 0x86816b3
free_pc = 0x868161d
Same offset
prev_foot = 0x8180d4d0
head = 0x30 (PINUSE)
fd = 0xac825ab8
bk = 0xa880005c
mh_refcount = 0xf3ee0123 Free chunk
mh_unused = 0x0
mh_fd_link = 0x0 header
mh_bk_link = 0x0
allocator_pc = 0x0
free_pc = 0x0
LastFrag=1
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/november/cisco-asa-series-part-eight-exploiting-the-cve-2016-1287-heap-
overflow-over-ikev1/
Leverage IKE reassembly
Reassembled packet length: n
Seqno=1
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/november/cisco-asa-series-part-eight-exploiting-the-cve-2016-1287-heap-
overflow-over-ikev1/
Leverage IKE reassembly
Reassembled packet length: n+n
Seqno=1 Seqno=2
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/november/cisco-asa-series-part-eight-exploiting-the-cve-2016-1287-heap-
overflow-over-ikev1/
Leverage IKE reassembly
Reassembled packet length: n+n+p
LastFrag=1
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/november/cisco-asa-series-part-eight-exploiting-the-cve-2016-1287-heap-
overflow-over-ikev1/
Leverage IKE reassembly
Reassembled packet length: n+n+p
LastFrag=1
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/november/cisco-asa-series-part-eight-exploiting-the-cve-2016-1287-heap-
overflow-over-ikev1/
Leverage IKE reassembly
Reassembled packet length: n+n+p
LastFrag=1
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/november/cisco-asa-series-part-eight-exploiting-the-cve-2016-1287-heap-
overflow-over-ikev1/
Leverage IKE reassembly
Reassembled packet length: n+n+p
LastFrag=1
1
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/november/cisco-asa-series-part-eight-exploiting-the-cve-2016-1287-heap-
overflow-over-ikev1/
Leverage IKE reassembly
Reassembled packet length: n+n+p
LastFrag=1
1 2
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/november/cisco-asa-series-part-eight-exploiting-the-cve-2016-1287-heap-
overflow-over-ikev1/
Leverage IKE reassembly
Reassembled packet length: n+n+p
LastFrag=1
1 2 3
https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2017/november/cisco-asa-series-part-eight-exploiting-the-cve-2016-1287-heap-
overflow-over-ikev1/
Leverage IKE reassembly
Reassembled packet length: n+n+p
LastFrag=1
1 2 3
overlapping
0x810 0x810 0x48f0 0x810 0x810
Primitive 1 - Hole creation with IKEv1
• Session 1 (feng): fill holes
• Session 2: only two fragments
• Frag 1: future hole
• Frag 2: trigger reassembly, hence creating hole
Primitive 1 - Hole creation with IKEv1
• Session 1 (feng): fill holes
• Session 2: only two fragments
• Frag 1: future hole
• Frag 2: trigger reassembly, hence creating hole
feng
Primitive 1 - Hole creation with IKEv1
• Session 1 (feng): fill holes
• Session 2: only two fragments
• Frag 1: future hole
• Frag 2: trigger reassembly, hence creating hole
feng feng
Primitive 1 - Hole creation with IKEv1
• Session 1 (feng): fill holes
• Session 2: only two fragments
• Frag 1: future hole
• Frag 2: trigger reassembly, hence creating hole
SeqNo=1
SeqNo=1
SeqNo=1
SeqNo=1
SeqNo=2
reass
SeqNo=1
SeqNo=2
SeqNo=1
reass
sess2
SeqNo=2
SeqNo=1 SeqNo=2
reass
sess2 sess2
LastFrag=1
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Small holes creation
• We want some adjacency
frag frag frag
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
0x70
sess1
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Small holes creation
• We want some adjacency
frag frag frag
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
0x70 0x70
sess1 sess2
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Small holes creation
• We want some adjacency
frag frag frag
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
0x70 0x70 0x70
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Small holes creation
• We want some adjacency
frag frag frag
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
0x70 0x70 0x70 0x70
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Small holes creation
• We want some adjacency
frag frag frag
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
0x70 0x70 0x70 0x70 0x70
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Small holes creation
• We want some adjacency
frag frag frag
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
0x70 0x70 0x70 0x70 0x70 0x70
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Small holes creation
• We want some adjacency
frag frag frag
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
0x70 0x70 0x70 0x70 0x70 0x70 0x70
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Small holes creation
• We want some adjacency
frag frag frag
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
0x70 0x70 0x70 0x70 0x70 0x70 0x70
sess2
sess1 sess2 sess1 sess2 sess1 sess2 sess1
LastFrag=1
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Small holes creation
• We want some adjacency
frag frag frag
• But small structures allocated will mess up with our feng shui
• When frags received, structures < 0x70 to track frags
frag frag frag
• Solution: send small fragments in two IKEv1 sessions and reassemble one of them
• Create 0x70-byte
0x70 0x70 0x70 0x70 0x70 0x70 0x70
• Similarly, when WebVPN packet received, structures < 0x400 so create 0x400 holes
Working with 0x800-byte chunks will give us some adjacency
Primitive 2 – Repeatable free with XML
• This is a really good primitive
• XML data allocated for first packet, then freed
• Allocate IKEv1 fragment in same hole
• Free IKEv1 fragment using the repeatable free primitive
• Allocate another IKEv1 fragment in same hole
Interesting confusion state
XML tag
feng feng data feng feng
Primitive 2 – Repeatable free with XML
• This is a really good primitive
• XML data allocated for first packet, then freed
• Allocate IKEv1 fragment in same hole
• Free IKEv1 fragment using the repeatable free primitive
• Allocate another IKEv1 fragment in same hole
Interesting confusion state
XML tag data
dangling
pointer
XML
feng feng S1 F feng feng packet 2
Primitive 2 – Repeatable free with XML
• This is a really good primitive
• XML data allocated for first packet, then freed
• Allocate IKEv1 fragment in same hole
• Free IKEv1 fragment using the repeatable free primitive
• Allocate another IKEv1 fragment in same hole
Interesting confusion state
XML tag data
dangling session frag
pointer
LastFrag=1
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n
Seqno=1
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n +p
Seqno=1 Seqno=3
LastFrag=1
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n +p
+18
Seqno=1 Seqno=3
LastFrag=1
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n+n+p
+18
LastFrag=1
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n+n+p
+18
LastFrag=1
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n+n+p
+18 N
LastFrag=1
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n+n+p
+18 N
LastFrag=1
1
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n+n+p
+18 N
LastFrag=1
1 2
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n+n+p
+18 N
LastFrag=1
1 2 3
Primitive 4 - Overflow with IKEv1
• Use a trick similar to CVE-2016-1287
• Abuse increased size of confused fragment created by previous primitive
• Allows overflow of adjacent memory
Reassembled packet length: n+n+p
+18 N
Heap overflow
Seqno=1 Seqno=2 Seqno=3 Reassembled packet
LastFrag=1
1 2 3
N+18
Limited overflow (18-byte on 32-bit)
[1]
[2]
[3]
[4]
[5]
Exploit in a (coco)nut shell
Robin Hood uses IKEv1 sessions
I I J J J J I K K K K K L M N O P I Somewhere
else on the heap
Exploit in a (coco)nut shell
malloc: 0xacd809a0 realsz 0x1f60, reqsz 0x1f34 - reassembled packet
(gdb) dlchunk 0xacd78090 -c 14 -p 0x44 Robin Hood uses IKEv1 sessions
0xacd78090 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0001 II
0xacd788a0 F sz:0x02040 fl:-P free_pc:0x0868d28d,- 0x4a4a JJ
• Blue: separators
0xacd7a8e0 M sz:0x00810 fl:C- alloc_pc:0x0869460d,- 0x0002 II • Green: hole creation
0xacd7b0f0 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0001 hex(0000)
0xacd7b900 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0002 hex(0000)
• Orange: targets for mirror writes
0xacd7c110 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0003 hex(0000)
0xacd7c920 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0004 hex(0000)
0xacd7d130 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0005 hex(0000)
0xacd7d940 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 LL
0xacd7e150 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 MM
0xacd7e960 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 NN
0xacd7f170 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 OO
0xacd7f980 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x5050 PP
0xacd80190 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0003 II
XML
Adjacent on the heap
packet 1
0x810 0x810 0x2040 0x810 0x810 0x810 0x810 0x810 0x810 0x810 0x810 0x810 0x810 0x810 0x810
…
I I I K K K K K L M N O P I Somewhere
else on the heap
Exploit in a (coco)nut shell
previous xml_tags[13].alloc = NULL
0xacd78090 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0001 II Robin Hood uses IKEv1 sessions
0xacd788a0 M sz:0x02030 fl:CP alloc_pc:0x0807f8c4,- xml_tags[13].alloc
0xacd7a8d0 F sz:0x00010 fl:-P
• Blue: separators
0xacd7a8e0 M sz:0x00810 fl:C- alloc_pc:0x0869460d,- 0x0002 II • Green: hole creation
0xacd7b0f0 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0001 hex(0000)
0xacd7b900 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0002 hex(0000)
• Orange: targets for mirror writes
0xacd7c110 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0003 hex(0000)
0xacd7c920 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0004 hex(0000)
0xacd7d130 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0005 hex(0000)
0xacd7d940 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 LL
0xacd7e150 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 MM
0xacd7e960 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 NN
0xacd7f170 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 OO
0xacd7f980 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x5050 PP
0xacd80190 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0003 II
I I S1 I K K K K K L M N O P I Somewhere
else on the heap
Exploit in a (coco)nut shell
(gdb) dlchunk 0xacd78090 -c 20 -p 0x44
0xacd78090 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0001 II Robin Hood uses IKEv1 sessions
0xacd788a0 M sz:0x02040 fl:CP alloc_pc:0x0869460d,- 0x6666 ff
0xacd7a8e0 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0002 II
• Blue: separators
0xacd7b0f0 F sz:0x02850 fl:-P free_pc:0x0868d28d, • Green: hole creation
0xacd7d940 M sz:0x00810 fl:C- alloc_pc:0x0869460d,- 0x0000 LL
0xacd7e150 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 MM
• Orange: targets for mirror writes
0xacd7e960 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 NN • Pink: confused session reassembled
0xacd7f170 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 OO
0xacd7f980 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x5050 PP
• Purple: replacement frag
0xacd80190 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0003 II
I I S1 I L M N O P I Somewhere
else on the heap
Exploit in a (coco)nut shell
malloc: 0xacd7b0f0 realsz 0x2820, reqsz 0x27f4 - reassembled packet
0xacd78090 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0001 II Robin Hood uses IKEv1 sessions
0xacd788a0 M sz:0x02040 fl:CP alloc_pc:0x0869460d,- 0x6666 ff
0xacd7a8e0 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0002 II
• Blue: separators
0xacd7b0f0 M sz:0x02820 fl:CP alloc_pc:0x0868d323,- • Green: hole creation
0xacd7d910 F sz:0x00030 fl:-P free_pc:0x00000000,-
0xacd7d940 M sz:0x00810 fl:C- alloc_pc:0x0869460d,- 0x0000 LL
• Orange: targets for mirror writes
0xacd7e150 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 MM • Pink: confused session reassembled
0xacd7e960 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 NN
0xacd7f170 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0000 OO
• Purple: replacement frag
0xacd7f980 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x5050 PP
0xacd80190 M sz:0x00810 fl:CP alloc_pc:0x0869460d,- 0x0003 II
I I I Overlapping L M N O P I Somewhere
0x48f0 else on the heap
Exploit in a (coco)nut shell
.bss:0xb2b7480 ch_is_validating = non-zero (Checkheaps disabled)
Robin Hood uses IKEv1 sessions
struct malloc_chunk @ 0xacd7f980 {
prev_foot = 0x8180d4d0 • Blue: separators
size = 0x810 (CINUSE|PINUSE) • Green: hole creation
struct mp_header @ 0xacd7f988 {
mh_magic = 0xa11c0123 • Orange: targets for mirror writes
mh_len = 0x7e4 • Pink: confused session reassembled
mh_refcount = 0x0
mh_unused = 0x0 • Purple: replacement frag
mh_fd_link = 0xc2e00000 (-) • Grey: overlapping packet
mh_bk_link = 0xb2b7470 (-)
alloc_pc = 0x4443 (-)
free_pc = 0x4241c448 (-)
I I I Overlapping L M N O I Somewhere
0x48f0 else on the heap
Exploit in a (coco)nut shell
Robin Hood uses IKEv1 sessions
• Blue: separators
• Green: hole creation
• Orange: targets for mirror writes
• Pink: confused session reassembled
• Purple: replacement frag
• Grey: overlapping packet
I I I Overlapping L M N I Somewhere
0x48f0 else on the heap
Exploit in a (coco)nut shell
Robin Hood uses IKEv1 sessions
• Blue: separators
• Green: hole creation
• Orange: targets for mirror writes
• Pink: confused session reassembled
• Purple: replacement frag
• Grey: overlapping packet
I I I Overlapping L M I Somewhere
0x48f0 else on the heap
Exploit in a (coco)nut shell
(gdb) x /3wx 0xc2831200
0xc2831200: 0xc2831204 0xc283128b 0xc2e2ff6a Robin Hood uses IKEv1 sessions
(gdb) x /3i 0xc2831204 • Blue: separators
0xc2831204: mov edx,DWORD PTR [edx]
0xc2831206: add edx,0x6a • Green: hole creation
0xc2831209: jmp edx • Orange: targets for mirror writes
struct malloc_chunk @ 0xacd7e150 { • Pink: confused session reassembled
prev_foot = 0x8180d4d0
size = 0x810 (CINUSE|PINUSE) • Purple: replacement frag
struct mp_header @ 0xacd7e158 { • Grey: overlapping packet
mh_magic = 0xa11c0123
mh_len = 0x7e4
mh_refcount = 0x0
mh_unused = 0x0
mh_fd_link = 0xc2831204 (-)
mh_bk_link = 0xc28311f0 (-)
alloc_pc = 0x4443 (-)
free_pc = 0x4241c448 (-)
XML tag data “confused”
dangling pointer session frag replacement frag
Adjacent on the heap
0x810 0x810 0x2040 0x810 0x2850 0x810 0x810 0x810 0x810 0x810 0x810 …
I I I Overlapping L I Somewhere
0x48f0 else on the heap
Exploit in a (coco)nut shell
Robin Hood uses IKEv1 sessions
• Blue: separators
• Green: hole creation
• Orange: targets for mirror writes
• Pink: confused session reassembled
• Purple: replacement frag
• Grey: overlapping packet
I I I Overlapping L I Somewhere
0x48f0 else on the heap
Exploit in a (coco)nut shell
.data:0xa46d330 IKEMM_BuildMainModeMsg2_ptr trampoline
Robin Hood uses IKEv1 sessions
struct malloc_chunk @ 0xacd7d940 {
prev_foot = 0x8180d4d0 • Blue: separators
size = 0x810 (CINUSE|PINUSE) • Green: hole creation
struct mp_header @ 0xacd7d948 {
mh_magic = 0xa11c0123 • Orange: targets for mirror writes
mh_len = 0x7e4 • Pink: confused session reassembled
mh_refcount = 0x0
mh_unused = 0x0 • Purple: replacement frag
mh_fd_link = 0xc2831200 (-) • Grey: overlapping packet
mh_bk_link = 0xa46d320 (-)
alloc_pc = 0x4443 (-)
free_pc = 0x4241c448 (-)
[1] https://github.com/nccgroup/asatools
Conclusions
Lessons learnt
• Fuzzing just the tags list is enough to find the bug
• Radamsa was useless in our case
• Working exploit on 32-bit (no ASLR/NX)
• Note: some old 64-bit don’t have ASLR either [1]
• 7-year old bug? – AnyConnect Host Scan available since 2011
• Cisco-specific handlers, not libexpat
• IKEv1 frag primitive to overflow memory / create mirror writes
• Confusion state: one chunk used for two different IKEv1 packets
• IKEv1 feng shui useful for any heap-based bug
[1] https://github.com/nccgroup/asafw/blob/master/README.md#mitigation-summary
Next steps
• WebVPN/AnyConnect exploit only (not relying on IKEv1)?
• Exploiting other attack vectors (e.g. IKEv2)?
• Turn a repeatable free into a memory revelation primitive?
• Bypass ASLR on recent 64-bit?
• Something like BENIGNCERTAIN on Cisco IOS [1]?
• XML grammar-based fuzzer to find new 0-day?
• Support for tags, attributes, etc.
[1] https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-20160916-ikev1
Protect against 0-day vulnerabilities?
Questions
• Special thanks to
• My colleague Aaron Adams (@FidgetingBits) for developing asatools with
me and for the help on exploiting this
• Cisco PSIRT for handling this
• Many people from REcon for their feedbacks
• Contact
• @saidelike
• cedric(dot)halbronn(at)nccgroup(dot)trust