bug61367-read.phpt 1.6 KB

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