|
|
 |
escapeshellcmd (PHP 3, PHP 4, PHP 5) escapeshellcmd -- Escapar meta-caracteres del intérprete de
comandos Descripciónstring escapeshellcmd ( string comando )
escapeshellcmd() escapa cualquier caracter en
una cadena que pueda ser usado para engañar a un comando de
shell a que ejecute comandos arbitrarios. Esta función puede
ser usada para asegurarse de que cualquier dato viniendo de la
entrada del usuario sea escapado antes de que este dato sea pasado
a las funciones exec() o
system(), o al operador de comilla
invertida.
Los siguientes caracteres son precedidos por una barra invertida:
#&;`|*?~<>^()[]{}$\,
\x0A y
\xFF. ' y
" son escapados únicamente si no
están emparejados. En Windows, todos estos caracteres mas
% son reemplazados por un espacio en su lugar.
Lista de parámetros
- comando
El comando a ser escapado.
Valores retornados
La cadena escapada.
Ejemplos
Ejemplo 1. Ejemplo de escapeshellcmd() |
<?php
$e = escapeshellcmd($entrada_usuario);
system("echo $e");
$f = escapeshellcmd($nombre_archivo);
system("touch \"/tmp/$f\"; ls -l \"/tmp/$f\"");
?>
|
|
abennett at clarku dot edu
05-Jul-2006 11:59
I've got a php script that needs to pass a username and password via exec to a perl script. The problem is valid password characters were getting escaped...
Here's a little perl function I wrote to fix it.
sub unescape_string {
my $string = shift;
# all these interpolated regex's are slow, so if there's no
# backslash in the string don't bother with it
# index() is faster then a regex
if ( ! index($string,'\\\\') ) {
return $string;
}
my @characters = ('#', '&', ';', '`', '|', '*', '?', '~', '<', '>', '^', '(', ')',
'[', ']', '{', '}', '$', '\\', ',', ' ', '\x0A', '\xFF' );
my $character;
foreach $character (@characters) {
$character = quotemeta($character);
my $pattern = "\\\\(" . $character . ")";
$string =~ s/$pattern/$1/g;
}
return $string;
}
Hope this is useful.
ceejay at trashfactory dot de
15-Mar-2006 04:43
Well guys, i find it very hard that escapeshellarg and escapeshellcmd are forcely run when passing a command to exec, system or popen, when safe_mode is turned on.
Right now, i did not find any working solution to pass commands like this:
cmd -arg1 -arg2 "<BLA varname=\"varvalue\" varname1=\"varvalue1\" />"
it is just the case, that the parameter for arg2 which is a string that looks like an HTML-Tag with various attributes set, all attributes of the string in arg2 gets splitted by the whitespaces within. this wont happen with safe_mode turned off, so it must be one of the escapefunctions, that breaks functionality.
In order to circumvent this, i have made a temporary solution, which dynamically creates a skriptfile (by fopen), which just contains the whole command with arguments, and then execute that skriptfile. i dont like that solution, but in the other hand, safe_mode cannot be easily turned off on that server.
cast3r
13-Sep-2005 05:31
"normal any user on linux can view almost any directory so:
ls / -als will print a complete list of any file in the linux filesystem including its size, security and hidden files as well."
ls / -alsR is the whole filesystem.
docey
12-Apr-2005 05:56
the main reason for quoting a command is that it not multiple command can be joined. i don't know for sure if this is the right syntax but remeber that this can do some nice security breaks. here's one way of how to know exactly what your trying to break into for.
normal any user on linux can view almost any directory so:
ls / -als will print a complete list of any file in the linux filesystem including its size, security and hidden files as well.
now the output would only become known to php and never will the user be able to view this data unless the php script would actual start to print it out. like passtru does!! but a good php coder knows never to use passtru unless not otherwise possible.
but what would happen if you can direct the output from ls also from that same commandline to a file in the webroot most webserver still default their base-webroot to /var/www/ so storing it there in text file to download it later and you can simply take coffee while checking wich files can be read by php security mode and then simply use the cp command to copy those to the webroot and download them to your own hard-disk. without a list of the files you can only guess where to copy from! and thats harder then guessing the root password.
so if the first command was quoted it is not possible to attach another command because of a syntax error. think of all the thinks you can do once you got a complete list of every file on the filesystem. including mounted once via NFS and others. security starts at keeping the door hidden.
also another nice command for hanging the webserver can be "php <?php while(true){ exec('ls / -als'); }; ?>" this keeps creating a file list on the entire filesystem wich not only keeps the hard-disk(s) bussy but also memory and cpu wich must store the returned list. so keeping in mind not all command accepted from users can be used blind.
actualy never accept any command from external sources only proven built-in predefined commands should be executed.
trisk at earthling dot net
31-Jan-2005 10:19
This function does not work as shown in the php.net examples.
If you put your encoded filename into double-quotes as they suggest, then it will break on certain characters in filenames, such as ampersand.
For example if you have a filename called "foo & bar.jpg" and you use this function on it, your resulting filename when double-quoted will produce this and not be found:
"foo \& bar.jpg"
If you need to have a single argument where spaces are included then do not use this function with added double-quotes, use escapeshellarg() which encloses the whole string in single quotes.
I do not understand which purpose this particular function is intended for. I can't see any use for it, unless you pass it through another function and convert spaces " " to "\ ", which would allow you to use the string directly on the command line.
| |
| | Citas célebres | Un sentimental es un hombre que ve un absurdo valor en todo, y no conoce el precio fijo de nada. Oscar Wilde Escritor irlandés (1854-1900) | | Citas en tu mail | | ©Contenidos Gratis |
| Chiste de... Relaciones laborales | | Vagos | Un tío va a la oficina del paro y le dice al de la ventanilla:
- Uahhhhhhhhh! (esto es un bostezo) Uaaaaaaaa, Buenas (ahora uno se empieza a estirar como si se acabara de levantar) Uaaaaaaa taaaaaardes.
- ¿Y con esa actitud viene usted a buscar trabajo?
- No, si no es para mí, es para mi heeeeermano que esta acostado. | | Chistes en tu mail | | ©ContenidosGratis |
| Inicio | Acción | Estrategia | Palabras | Puzzles | Solitarios | Foro Trucos |  | Cake Mania Jugadores: 6835 Categoría del juego: Acción Objetivo del juego: Ayuda a Jill a recuperar la pastelería de su abuela llevando su propia pastelería; consigue clientes y gana dinero. |
|  | Rainbow Web Jugadores: 2199 Categoría del juego: Puzzles Objetivo del juego: Rompe un pegajoso hechizo y salva un reino de fantasía en Rainbow Web. Tendrás toneladas de diversión mientras juegas a este mágico desafío para la mente. |
|  | Mahjongg Fortuna Jugadores: 12462 Categoría del juego: Solitarios Objetivo del juego: Velocidad y habilidad mental son las armas más importantes en esta versión de un antiguo juego asiático. Despeja el tablero lo antes posible haciendo clic en las fichas iguales y gánate la fama eterna de la puntuación más alta. |
|  | Chainz 2 Jugadores: 6955 Categoría del juego: Puzzles Objetivo del juego: Entra en el mundo de las combinaciones con Chainz 2: Relinked, emocionante secuela del exitazo del año pasado, Chainz. Gira eslabones y crea combinaciones de 3 ó más. |
|  | Delicious Jugadores: 4405 Categoría del juego: Acción Objetivo del juego: ¿Eres un as de la multitarea? ¿Quieres que tus clientes estén contentos? ¡Pues Delicious es tu juego! Sacia el apetito de los clientes y tenlos contentos; ¡no te arriesgues! |
|  | Bookworm Jugadores: 4568 Categoría del juego: Palabras Objetivo del juego: Junta las letras para formar palabras. ¡Las palabras más largas valen más puntos! |
|  | Zuma Jugadores: 4976 Categoría del juego: Acción Objetivo del juego: Controla el ídolo de la rana de piedra de los antiguos Zuma en este intrigante enigma de acción. ¡Dispara bolas para formar conjuntos de tres, pero si dejas que lleguen a la calavera dorada morirás! |
|  | Jewel of Atlantis Jugadores: 3798 Categoría del juego: Puzzles Objetivo del juego: Descubre la ciudad hundida de la Atlántida y busca valiosos tesoros. Viaja más allá de las profundidades del mar y vive trepidantes aventuras en Jewel of Atlantis. |
|  | Jewel Quest Jugadores: 3727 Categoría del juego: Puzzles Objetivo del juego: Convierte la arena de la antigua selva en oro tan rápido como puedas juntando grupos de 3 elementos. ¡Los grupos más grandes valen más puntos! |
|  | Bejeweled 2 Jugadores: 3659 Categoría del juego: Puzzles Objetivo del juego: Con cuatro modos de juego únicos y fascinantes, nuevas piezas de juego explosivas e imponentes fondos planetarios, Bejeweled 2 es mucho más adictivo que nunca. |
|
|