bug61367-read.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. --TEST--
  2. Bug #61367: open_basedir bypass in libxml RSHUTDOWN: read test
  3. --EXTENSIONS--
  4. dom
  5. --SKIPIF--
  6. <?php
  7. if (LIBXML_VERSION >= 20912) die('skip For libxml2 < 2.9.12 only');
  8. ?>
  9. --INI--
  10. open_basedir=.
  11. --FILE--
  12. <?php
  13. /*
  14. * Note: Using error_reporting=E_ALL & ~E_NOTICE to suppress "Trying to get property of non-object" notices.
  15. */
  16. class StreamExploiter {
  17. public function stream_close ( ) {
  18. $doc = new DOMDocument;
  19. $doc->resolveExternals = true;
  20. $doc->substituteEntities = true;
  21. $dir = htmlspecialchars(dirname(getcwd()));
  22. $dir = str_replace('\\', '/', $dir); // fix for windows
  23. $doc->loadXML( <<<XML
  24. <!DOCTYPE doc [
  25. <!ENTITY file SYSTEM "file:///$dir/bad">
  26. ]>
  27. <doc>&file;</doc>
  28. XML
  29. );
  30. print $doc->documentElement->firstChild->nodeValue;
  31. }
  32. public function stream_open ( $path , $mode , $options , &$opened_path ) {
  33. return true;
  34. }
  35. }
  36. var_dump(mkdir('test_bug_61367-read'));
  37. var_dump(mkdir('test_bug_61367-read/base'));
  38. var_dump(file_put_contents('test_bug_61367-read/bad', 'blah'));
  39. var_dump(chdir('test_bug_61367-read/base'));
  40. stream_wrapper_register( 'exploit', 'StreamExploiter' );
  41. $s = fopen( 'exploit://', 'r' );
  42. ?>
  43. --CLEAN--
  44. <?php
  45. unlink('test_bug_61367-read/bad');
  46. rmdir('test_bug_61367-read/base');
  47. rmdir('test_bug_61367-read');
  48. ?>
  49. --EXPECTF--
  50. bool(true)
  51. bool(true)
  52. int(4)
  53. bool(true)
  54. Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "file:///%s/test_bug_61367-read/bad" in %s on line %d
  55. Warning: DOMDocument::loadXML(): Failure to process entity file in Entity, line: 4 in %s on line %d
  56. Warning: DOMDocument::loadXML(): Entity 'file' not defined in Entity, line: 4 in %s on line %d
  57. Warning: Attempt to read property "firstChild" on null in %s on line %d
  58. Warning: Attempt to read property "nodeValue" on null in %s on line %d