The Magic Enterprise Edition Version 8 is a multi-platform, flexible application that supports well-known web browsers, web servers, application servers, and databases. Magic v8 gives the developer the ability to create portable and scalable client-/server-based or web-based applications.
Magic is used by important eCommerce sites, payment systems, banks, big automobile companies and even on government servers.
Several security vulnerabilities in Magic range from buffer overflow to temporary file and permission mishandling.
Vulnerable systems:
Magic version 8.30-5 and prior
Magic version 9.x
(All platforms, including but limited to: Solaris, Linux, AIX, HP/UX, SCO, Digital Unix, AS/400, NT)
Several security holes in Magic Enterprise Edition Version 8 (Solaris) were discovered by Immutec while doing a penetration test for a customer. In depth, the analysis was done for the Linux version. Version 9 was not fully tested, but at least some issues were also verified for Version 9.
memory corruption: (remote)
The CGI executable 'mgrqcgi' is used as a kind of gateway to handle different tasks.
mgrqcgi reads different variables from the QUERY_STRING environment variable, which is set by the HTTP server.
The names of the variables:
+ APPNAME
+ PRGNAME
+ ARGUMENTS
+ PageID
+ mgaction
+ H_ShopID
+ H_SID
+ H_WID
+ H_INF
+ and much more
The variable data is copied into local variables using the non-bound checking library function strcpy(3). This can be easily verified by triggering the overflow using a standard web browser. Overwriting the memory for APPNAME byte wise results in overwriting PRGNAME input until an internal server error occurs.
[...]
Starting program: /usr/local/httpd/cgi-bin/mgrqcgi
(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...
(no debugging symbols found)...
Program received signal SIGSEGV, Segmentation fault.
0x0804b103 in strcpy ()
(gdb) info stack
#0 0x0804b103 in strcpy ()
#1 0x41414141 in ?? ()
#2 0x0804a440 in strcpy ()
#3 0x08049b18 in strcpy ()
#4 0x41414141 in ?? ()
[...]
Some characters cannot be used for overflowing the internal buffers, because they have other meanings in the CGI context or are filtered. Characters that cannot be used:
memory corruption: (local)
The Linux RPM comes with one setuid root application:
+ /usr/magicadm/servers/mgdispatch
There seem to be several buffer overflows in the code of mgdispatch. One example of missing bounds checking occurs very early in the program code while reading an environment variable called MGDISPATCH_LOG. The destination buffer is about 3000 bytes big, so an attacker has enough space for stuffing the shellcode in and executes arbitrary commands.
(gdb) r 78
Starting program: ./mgdispatch 78
(no debugging symbols found)...(no debugging symbols found)...
(no debugging symbols found)...(no debugging symbols found)...
Program received signal SIGSEGV, Segmentation fault.
0x4008d63b in getenv () from /lib/libc.so.6
(gdb) bt
#0 0x4008d63b in getenv () from /lib/libc.so.6
#1 0x0804dec8 in strcpy ()
#2 0x41414141 in ?? ()
[...]
Temporary file handling:
Some shell script files included in the Linux RPM (probably applies to other versions as well) do insecure temporary file handling, allowing symlink attacks, replacing information and execution of commands.
Insecure permissions:
The RPM file installs some files and directories group 'users' writeable. This includes the Magic Admin home directory /usr/magicadm (a magicadm account is created in /etc/passwd), the license directory, and various executables.
The list of group writeable executables:
+ /usr/magicadm/bin/magicrnt
+ /usr/magicadm/bin/mdinformix
+ /usr/magicadm/bin/mdmssql
+ /usr/magicadm/bin/mdoracle
+ /usr/magicadm/bin/mgcircvr
+ /usr/magicadm/bin/mgcisam
+ /usr/magicadm/bin/mginformix
+ /usr/magicadm/bin/mgmemory
+ /usr/magicadm/bin/mgoracle
+ /usr/magicadm/bin/mgtcp
+ /usr/magicadm/broker/mgrqcmdl
+ /usr/magicadm/broker/mgrqmrb
+ /usr/magicadm/cgibin/mgrqcgi
+ /usr/magicadm/servers/mgdatasrvr
This allows an attacker to replace these writeable executables to gain higher privileges and even any other file to exploit trusted information.
Miscellaneous:
The symbols that are exported by the executables and by the Magic-Request API library reveal, that there are even more insecure C-library functions like system(3), strcpy(3), strcat(3) and sprintf(3) and alike.
Vendor response:
Vendor contacted at 11.12.2001 according to 'Full Disclosure Policy 2.0', however no appropriate response was received.