diff options
Diffstat (limited to 'php_suhosin7.h')
| -rw-r--r-- | php_suhosin7.h | 200 |
1 files changed, 195 insertions, 5 deletions
diff --git a/php_suhosin7.h b/php_suhosin7.h index 805701e..b12e49c 100644 --- a/php_suhosin7.h +++ b/php_suhosin7.h | |||
| @@ -24,7 +24,11 @@ | |||
| 24 | extern zend_module_entry suhosin7_module_entry; | 24 | extern zend_module_entry suhosin7_module_entry; |
| 25 | #define phpext_suhosin7_ptr &suhosin7_module_entry | 25 | #define phpext_suhosin7_ptr &suhosin7_module_entry |
| 26 | 26 | ||
| 27 | #define SUHOSIN7_EXT_VERSION "0.10.0" | 27 | #define SUHOSIN7_EXT_VERSION "0.10.0dev" |
| 28 | |||
| 29 | #if PHP_VERSION_ID < 70000 | PHP_VERSION_ID >= 70100 | ||
| 30 | #error Suhosin7 works with PHP 7.0 only! Looking for Suhosin for PHP 5.x? Take a look at https://www.suhosin.org/ | ||
| 31 | #endif | ||
| 28 | 32 | ||
| 29 | #ifdef PHP_WIN32 | 33 | #ifdef PHP_WIN32 |
| 30 | # define PHP_SUHOSIN7_API __declspec(dllexport) | 34 | # define PHP_SUHOSIN7_API __declspec(dllexport) |
| @@ -38,17 +42,115 @@ extern zend_module_entry suhosin7_module_entry; | |||
| 38 | #include "TSRM.h" | 42 | #include "TSRM.h" |
| 39 | #endif | 43 | #endif |
| 40 | 44 | ||
| 45 | /* -------------- */ | ||
| 46 | |||
| 47 | #define SUHOSIN_LOG "/tmp/suhosin_log.txt" | ||
| 48 | |||
| 49 | #ifdef PHP_WIN32 | ||
| 50 | #define SDEBUG | ||
| 51 | #else | ||
| 52 | |||
| 53 | #ifdef SUHOSIN_DEBUG | ||
| 54 | #define SDEBUG(msg...) \ | ||
| 55 | {FILE *f;f=fopen(SUHOSIN_LOG, "a+");if(f){fprintf(f,"[%u] ",getpid());fprintf(f, msg);fprintf(f,"\n");fclose(f);}} | ||
| 56 | #else | ||
| 57 | #define SDEBUG(msg...) | ||
| 58 | #endif | ||
| 59 | #endif | ||
| 60 | |||
| 61 | /* -------------- */ | ||
| 62 | |||
| 41 | #define BYTE unsigned char /* 8 bits */ | 63 | #define BYTE unsigned char /* 8 bits */ |
| 42 | #define WORD unsigned int /* 32 bits */ | 64 | #define WORD unsigned int /* 32 bits */ |
| 43 | 65 | ||
| 66 | // PHP_MINIT_FUNCTION(suhosin); | ||
| 67 | // PHP_MSHUTDOWN_FUNCTION(suhosin); | ||
| 68 | // PHP_RINIT_FUNCTION(suhosin); | ||
| 69 | // PHP_RSHUTDOWN_FUNCTION(suhosin); | ||
| 70 | // PHP_MINFO_FUNCTION(suhosin); | ||
| 71 | |||
| 72 | #include "ext/standard/basic_functions.h" | ||
| 73 | |||
| 74 | static inline int suhosin_is_protected_varname(char *var, int var_len) | ||
| 75 | { | ||
| 76 | switch (var_len) { | ||
| 77 | case 18: | ||
| 78 | if (memcmp(var, "HTTP_RAW_POST_DATA", 18)==0) goto protected_varname; | ||
| 79 | break; | ||
| 80 | case 17: | ||
| 81 | if (memcmp(var, "HTTP_SESSION_VARS", 17)==0) goto protected_varname; | ||
| 82 | break; | ||
| 83 | case 16: | ||
| 84 | if (memcmp(var, "HTTP_SERVER_VARS", 16)==0) goto protected_varname; | ||
| 85 | if (memcmp(var, "HTTP_COOKIE_VARS", 16)==0) goto protected_varname; | ||
| 86 | break; | ||
| 87 | case 15: | ||
| 88 | if (memcmp(var, "HTTP_POST_FILES", 15)==0) goto protected_varname; | ||
| 89 | break; | ||
| 90 | case 14: | ||
| 91 | if (memcmp(var, "HTTP_POST_VARS", 14)==0) goto protected_varname; | ||
| 92 | break; | ||
| 93 | case 13: | ||
| 94 | if (memcmp(var, "HTTP_GET_VARS", 13)==0) goto protected_varname; | ||
| 95 | if (memcmp(var, "HTTP_ENV_VARS", 13)==0) goto protected_varname; | ||
| 96 | break; | ||
| 97 | case 8: | ||
| 98 | if (memcmp(var, "_SESSION", 8)==0) goto protected_varname; | ||
| 99 | if (memcmp(var, "_REQUEST", 8)==0) goto protected_varname; | ||
| 100 | break; | ||
| 101 | case 7: | ||
| 102 | if (memcmp(var, "GLOBALS", 7)==0) goto protected_varname; | ||
| 103 | if (memcmp(var, "_COOKIE", 7)==0) goto protected_varname; | ||
| 104 | if (memcmp(var, "_SERVER", 7)==0) goto protected_varname; | ||
| 105 | break; | ||
| 106 | case 6: | ||
| 107 | if (memcmp(var, "_FILES", 6)==0) goto protected_varname; | ||
| 108 | break; | ||
| 109 | case 5: | ||
| 110 | if (memcmp(var, "_POST", 5)==0) goto protected_varname; | ||
| 111 | break; | ||
| 112 | case 4: | ||
| 113 | if (memcmp(var, "_ENV", 4)==0) goto protected_varname; | ||
| 114 | if (memcmp(var, "_GET", 4)==0) goto protected_varname; | ||
| 115 | break; | ||
| 116 | } | ||
| 117 | |||
| 118 | return 0; | ||
| 119 | protected_varname: | ||
| 120 | return 1; | ||
| 121 | } | ||
| 122 | |||
| 123 | |||
| 124 | |||
| 44 | ZEND_BEGIN_MODULE_GLOBALS(suhosin7) | 125 | ZEND_BEGIN_MODULE_GLOBALS(suhosin7) |
| 45 | zend_long global_value; | 126 | zend_long global_value; |
| 46 | char *global_string; | 127 | char *global_string; |
| 47 | zend_bool protectkey; | 128 | zend_bool protectkey; |
| 48 | 129 | ||
| 49 | zend_bool simulation; | 130 | zend_bool simulation; |
| 131 | zend_bool stealth; | ||
| 50 | zend_bool already_scanned; | 132 | zend_bool already_scanned; |
| 51 | zend_bool abort_request; | 133 | zend_bool abort_request; |
| 134 | char *filter_action; | ||
| 135 | |||
| 136 | |||
| 137 | zend_bool executor_allow_symlink; | ||
| 138 | long max_execution_depth; | ||
| 139 | long executor_include_max_traversal; | ||
| 140 | zend_bool executor_include_allow_writable_files; | ||
| 141 | |||
| 142 | |||
| 143 | HashTable *include_whitelist; | ||
| 144 | HashTable *include_blacklist; | ||
| 145 | |||
| 146 | HashTable *func_whitelist; | ||
| 147 | HashTable *func_blacklist; | ||
| 148 | HashTable *eval_whitelist; | ||
| 149 | HashTable *eval_blacklist; | ||
| 150 | |||
| 151 | zend_bool executor_disable_eval; | ||
| 152 | zend_bool executor_disable_emod; | ||
| 153 | |||
| 52 | 154 | ||
| 53 | /* request variables */ | 155 | /* request variables */ |
| 54 | zend_long max_request_variables; | 156 | zend_long max_request_variables; |
| @@ -108,7 +210,7 @@ ZEND_BEGIN_MODULE_GLOBALS(suhosin7) | |||
| 108 | zend_bool upload_allow_utf8; | 210 | zend_bool upload_allow_utf8; |
| 109 | #endif | 211 | #endif |
| 110 | char *upload_verification_script; | 212 | char *upload_verification_script; |
| 111 | 213 | ||
| 112 | zend_bool no_more_variables; | 214 | zend_bool no_more_variables; |
| 113 | zend_bool no_more_get_variables; | 215 | zend_bool no_more_get_variables; |
| 114 | zend_bool no_more_post_variables; | 216 | zend_bool no_more_post_variables; |
| @@ -119,9 +221,14 @@ ZEND_BEGIN_MODULE_GLOBALS(suhosin7) | |||
| 119 | WORD fkey[120]; | 221 | WORD fkey[120]; |
| 120 | WORD rkey[120]; | 222 | WORD rkey[120]; |
| 121 | 223 | ||
| 122 | /* memory_limit */ | 224 | zend_bool session_encrypt; |
| 123 | zend_long memory_limit; | 225 | char* session_cryptkey; |
| 124 | zend_long hard_memory_limit; | 226 | zend_bool session_cryptua; |
| 227 | zend_bool session_cryptdocroot; | ||
| 228 | long session_cryptraddr; | ||
| 229 | long session_checkraddr; | ||
| 230 | |||
| 231 | long session_max_id_length; | ||
| 125 | 232 | ||
| 126 | char* decrypted_cookie; | 233 | char* decrypted_cookie; |
| 127 | char* raw_cookie; | 234 | char* raw_cookie; |
| @@ -133,6 +240,85 @@ ZEND_BEGIN_MODULE_GLOBALS(suhosin7) | |||
| 133 | long cookie_checkraddr; | 240 | long cookie_checkraddr; |
| 134 | HashTable *cookie_plainlist; | 241 | HashTable *cookie_plainlist; |
| 135 | HashTable *cookie_cryptlist; | 242 | HashTable *cookie_cryptlist; |
| 243 | |||
| 244 | zend_bool coredump; | ||
| 245 | zend_bool apc_bug_workaround; | ||
| 246 | zend_bool do_not_scan; | ||
| 247 | |||
| 248 | zend_bool server_encode; | ||
| 249 | zend_bool server_strip; | ||
| 250 | |||
| 251 | zend_bool disable_display_errors; | ||
| 252 | |||
| 253 | php_uint32 r_state[625]; | ||
| 254 | php_uint32 *r_next; | ||
| 255 | int r_left; | ||
| 256 | zend_bool srand_ignore; | ||
| 257 | zend_bool mt_srand_ignore; | ||
| 258 | php_uint32 mt_state[625]; | ||
| 259 | php_uint32 *mt_next; | ||
| 260 | int mt_left; | ||
| 261 | |||
| 262 | char *seedingkey; | ||
| 263 | zend_bool reseed_every_request; | ||
| 264 | |||
| 265 | zend_bool r_is_seeded; | ||
| 266 | zend_bool mt_is_seeded; | ||
| 267 | |||
| 268 | |||
| 269 | /* memory_limit */ | ||
| 270 | zend_long memory_limit; | ||
| 271 | zend_long hard_memory_limit; | ||
| 272 | |||
| 273 | |||
| 274 | |||
| 275 | |||
| 276 | /* PERDIR Handling */ | ||
| 277 | char *perdir; | ||
| 278 | zend_bool log_perdir; | ||
| 279 | zend_bool exec_perdir; | ||
| 280 | zend_bool get_perdir; | ||
| 281 | zend_bool post_perdir; | ||
| 282 | zend_bool cookie_perdir; | ||
| 283 | zend_bool request_perdir; | ||
| 284 | zend_bool upload_perdir; | ||
| 285 | zend_bool sql_perdir; | ||
| 286 | zend_bool misc_perdir; | ||
| 287 | |||
| 288 | /* log */ | ||
| 289 | zend_bool log_use_x_forwarded_for; | ||
| 290 | long log_syslog; | ||
| 291 | long log_syslog_facility; | ||
| 292 | long log_syslog_priority; | ||
| 293 | long log_script; | ||
| 294 | long log_sapi; | ||
| 295 | long log_stdout; | ||
| 296 | char *log_scriptname; | ||
| 297 | long log_phpscript; | ||
| 298 | char *log_phpscriptname; | ||
| 299 | zend_bool log_phpscript_is_safe; | ||
| 300 | long log_file; | ||
| 301 | char *log_filename; | ||
| 302 | zend_bool log_file_time; | ||
| 303 | |||
| 304 | /* header handler */ | ||
| 305 | zend_bool allow_multiheader; | ||
| 306 | |||
| 307 | /* mailprotect */ | ||
| 308 | long mailprotect; | ||
| 309 | |||
| 310 | /* sqlprotect */ | ||
| 311 | zend_bool sql_bailout_on_error; | ||
| 312 | char *sql_user_prefix; | ||
| 313 | char *sql_user_postfix; | ||
| 314 | char *sql_user_match; | ||
| 315 | long sql_comment; | ||
| 316 | long sql_opencomment; | ||
| 317 | long sql_union; | ||
| 318 | long sql_mselect; | ||
| 319 | |||
| 320 | int (*old_php_body_write)(const char *str, unsigned int str_length TSRMLS_DC); | ||
| 321 | |||
| 136 | ZEND_END_MODULE_GLOBALS(suhosin7) | 322 | ZEND_END_MODULE_GLOBALS(suhosin7) |
| 137 | 323 | ||
| 138 | /* Always refer to the globals in your function as SUHOSIN7_G(variable). | 324 | /* Always refer to the globals in your function as SUHOSIN7_G(variable). |
| @@ -141,6 +327,10 @@ ZEND_END_MODULE_GLOBALS(suhosin7) | |||
| 141 | */ | 327 | */ |
| 142 | #define SUHOSIN7_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(suhosin7, v) | 328 | #define SUHOSIN7_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(suhosin7, v) |
| 143 | 329 | ||
| 330 | #ifdef SUHOSIN_DEBUG | ||
| 331 | #define SUHOSIN_G(v) SUHOSIN7_G(v) | ||
| 332 | #endif | ||
| 333 | |||
| 144 | #if defined(ZTS) && defined(COMPILE_DL_SUHOSIN7) | 334 | #if defined(ZTS) && defined(COMPILE_DL_SUHOSIN7) |
| 145 | ZEND_TSRMLS_CACHE_EXTERN(); | 335 | ZEND_TSRMLS_CACHE_EXTERN(); |
| 146 | #endif | 336 | #endif |
