mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 10:47:18 +00:00 
			
		
		
		
	Merged revisions 314620 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r314620 | mnicholson | 2011-04-21 13:22:19 -0500 (Thu, 21 Apr 2011) | 20 lines Merged revisions 314607 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r314607 | mnicholson | 2011-04-21 13:19:21 -0500 (Thu, 21 Apr 2011) | 14 lines Added limits to the number of unauthenticated sessions TCP based protocols are allowed to have open simultaneously. Also added timeouts for unauthenticated sessions where it made sense to do so. Unrelated, the manager interface now properly checks if the user has the "system" privilege before executing shell commands via the Originate action. AST-2011-005 AST-2011-006 (closes issue #18787) Reported by: kobaz (related to issue #18996) Reported by: tzafrir ........ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@314628 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		
							
								
								
									
										22
									
								
								main/http.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								main/http.c
									
									
									
									
									
								
							| @@ -55,12 +55,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | ||||
| #include "asterisk/astobj2.h" | ||||
|  | ||||
| #define MAX_PREFIX 80 | ||||
| #define DEFAULT_SESSION_LIMIT 100 | ||||
|  | ||||
| /* See http.h for more information about the SSL implementation */ | ||||
| #if defined(HAVE_OPENSSL) && (defined(HAVE_FUNOPEN) || defined(HAVE_FOPENCOOKIE)) | ||||
| #define	DO_SSL	/* comment in/out if you want to support ssl */ | ||||
| #endif | ||||
|  | ||||
| static int session_limit = DEFAULT_SESSION_LIMIT; | ||||
| static int session_count = 0; | ||||
|  | ||||
| static struct ast_tls_config http_tls_cfg; | ||||
|  | ||||
| static void *httpd_helper_thread(void *arg); | ||||
| @@ -845,6 +849,10 @@ static void *httpd_helper_thread(void *data) | ||||
| 	char *uri, *method; | ||||
| 	enum ast_http_method http_method = AST_HTTP_UNKNOWN; | ||||
|  | ||||
| 	if (ast_atomic_fetchadd_int(&session_count, +1) >= session_limit) { | ||||
| 		goto done; | ||||
| 	} | ||||
|  | ||||
| 	if (!fgets(buf, sizeof(buf), ser->f)) { | ||||
| 		goto done; | ||||
| 	} | ||||
| @@ -910,17 +918,19 @@ static void *httpd_helper_thread(void *data) | ||||
|  | ||||
| 	if (!*uri) { | ||||
| 		ast_http_error(ser, 400, "Bad Request", "Invalid Request"); | ||||
| 		return NULL; | ||||
| 		goto done; | ||||
| 	} | ||||
|  | ||||
| 	handle_uri(ser, uri, http_method, headers); | ||||
|  | ||||
| 	/* Clean up all the header information pulled as well */ | ||||
| done: | ||||
| 	ast_atomic_fetchadd_int(&session_count, -1); | ||||
|  | ||||
| 	/* clean up all the header information */ | ||||
| 	if (headers) { | ||||
| 		ast_variables_destroy(headers); | ||||
| 	} | ||||
|  | ||||
| done: | ||||
| 	if (ser->f) { | ||||
| 		fclose(ser->f); | ||||
| 	} | ||||
| @@ -1072,6 +1082,12 @@ static int __ast_http_load(int reload) | ||||
| 				} | ||||
| 			} else if (!strcasecmp(v->name, "redirect")) { | ||||
| 				add_redirect(v->value); | ||||
| 			} else if (!strcasecmp(v->name, "sessionlimit")) { | ||||
| 				if (ast_parse_arg(v->value, PARSE_INT32|PARSE_DEFAULT|PARSE_IN_RANGE, | ||||
| 							&session_limit, DEFAULT_SESSION_LIMIT, 1, INT_MAX)) { | ||||
| 					ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of http.conf\n", | ||||
| 							v->name, v->value, v->lineno); | ||||
| 				} | ||||
| 			} else { | ||||
| 				ast_log(LOG_WARNING, "Ignoring unknown option '%s' in http.conf\n", v->name); | ||||
| 			} | ||||
|   | ||||
| @@ -3888,6 +3888,24 @@ static int action_originate(struct mansession *s, const struct message *m) | ||||
| 		format = 0; | ||||
| 		ast_parse_allow_disallow(NULL, &format, codecs, 1); | ||||
| 	} | ||||
| 	if (!ast_strlen_zero(app)) { | ||||
| 		/* To run the System application (or anything else that goes to | ||||
| 		 * shell), you must have the additional System privilege */ | ||||
| 		if (!(s->session->writeperm & EVENT_FLAG_SYSTEM) | ||||
| 			&& ( | ||||
| 				strcasestr(app, "system") ||      /* System(rm -rf /) | ||||
| 				                                     TrySystem(rm -rf /)       */ | ||||
| 				strcasestr(app, "exec") ||        /* Exec(System(rm -rf /)) | ||||
| 				                                     TryExec(System(rm -rf /)) */ | ||||
| 				strcasestr(app, "agi") ||         /* AGI(/bin/rm,-rf /) | ||||
| 				                                     EAGI(/bin/rm,-rf /)       */ | ||||
| 				strstr(appdata, "SHELL") ||       /* NoOp(${SHELL(rm -rf /)})  */ | ||||
| 				strstr(appdata, "EVAL")           /* NoOp(${EVAL(${some_var_containing_SHELL})}) */ | ||||
| 				)) { | ||||
| 			astman_send_error(s, m, "Originate with certain 'Application' arguments requires the additional System privilege, which you do not have."); | ||||
| 			return 0; | ||||
| 		} | ||||
| 	} | ||||
| 	/* Allocate requested channel variables */ | ||||
| 	vars = astman_get_variables(m); | ||||
|  | ||||
| @@ -3923,21 +3941,6 @@ static int action_originate(struct mansession *s, const struct message *m) | ||||
| 			} | ||||
| 		} | ||||
| 	} else if (!ast_strlen_zero(app)) { | ||||
| 		/* To run the System application (or anything else that goes to shell), you must have the additional System privilege */ | ||||
| 		if (!(s->session->writeperm & EVENT_FLAG_SYSTEM) | ||||
| 			&& ( | ||||
| 				strcasestr(app, "system") ||      /* System(rm -rf /) | ||||
| 				                                     TrySystem(rm -rf /)       */ | ||||
| 				strcasestr(app, "exec") ||        /* Exec(System(rm -rf /)) | ||||
| 				                                     TryExec(System(rm -rf /)) */ | ||||
| 				strcasestr(app, "agi") ||         /* AGI(/bin/rm,-rf /) | ||||
| 				                                     EAGI(/bin/rm,-rf /)       */ | ||||
| 				strstr(appdata, "SHELL") ||       /* NoOp(${SHELL(rm -rf /)})  */ | ||||
| 				strstr(appdata, "EVAL")           /* NoOp(${EVAL(${some_var_containing_SHELL})}) */ | ||||
| 				)) { | ||||
| 			astman_send_error(s, m, "Originate with certain 'Application' arguments requires the additional System privilege, which you do not have."); | ||||
| 			return 0; | ||||
| 		} | ||||
| 		res = ast_pbx_outgoing_app(tech, format, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL); | ||||
| 	} else { | ||||
| 		if (exten && context && pi) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user