<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### **常見php命令注入函數** eval(),,assert(), system(),preg_replace(), create_function, call_user_func, call_user_func_array,array_map(),反引號,ob_start(),exec(),shell_exec(),passthru(),escapeshellcmd(),popen(),proc_open(),pcntl_exec() [https://www.freebuf.com/column/166385.html](https://www.freebuf.com/column/166385.html) **PHP 執行系統命令可以使用以下幾個函數** system、exec、passthru、·· 反引號、shell_exec、popen、proc_open、pcntl_exec **system:** 執行外部程序并顯示輸出 >[info]string system ( string $command [, int &$return_var ] ) ``` system ("/php7/php.exe test.php"); ``` **exec:** 執行一個外部命令 >[info]string exec ( string $command [, array &$output [, int &$return_var ]] ) ``` exec("/php7/php.exe test.php") ``` **passthru:** 執行外部程序并且顯示原始輸出 >[info]void passthru (string command, int &return_var) ``` passthru('echo $PATH'); ``` **shell_exec:**通過shell環境執行命令 ``` shell_exec('ls -lart') ``` >[info]string shell_exec (string command) `` 反引號:`反引號號里直接包含shell 命令` 會直接執行 ``` echo `ls -al`; $get="whoami"; echo `$get` ``` resource popen ( string $command , string $mode ) resource proc_open ( string $cmd , array $descriptorspec , array &$pipes [, string $cwd [, array $env [, array $other_options ]]] ) void pcntl_exec ( string $path [, array $args [, array $envs ]] ) 例子: ``` if( isset( $_POST[ 'Submit' ] ) ) { // Get input $target = $_REQUEST[ 'ip' ]; // Determine OS and execute the ping command. if( stristr( php_uname( 's' ), 'Windows NT' ) ) { // Windows $cmd = shell_exec( 'ping ' . $target ); } else { // *nix $cmd = shell_exec( 'ping -c 4 ' . $target ); } // Feedback for the end user echo "<pre>{$cmd}</pre>"; } 正常輸入: input框輸入 www.baidu.com或者輸入ip 命令注入: input輸入 0 | dir c:提交測試 常見的危險注入符號:%&|>等 ``` # **簡單防御:** php.ini禁用這些函數 ``` disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_get_status,proc_open,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server ``` # **防御函數** 當用戶提供的數據傳入此函數,使用 escapeshellarg() 或 escapeshellcmd() 來確保用戶欺騙 系統從而執行任意命令。 ## **escapeshellarg** ( string $arg ) 可以用到 php 的安全中,會過濾掉 arg 中存在的一些特殊字符。在輸入的參數中如果包含中 文傳遞給 escapeshellarg,會被過濾掉。 php.5.6.10之前存在任意命令注入的漏洞,php.5.6.10被修復 ~~~ $dir = "."; system('ls '.escapeshellarg($dir)); escapeshellcmd('ls $dir'); ~~~ ## **escapeshellcmd** ( string $command ) escapeshellcmd()函數會轉義命令中的所有 shell 元字符來完成工作。這些元字符包括:# & ; ` , | * ? ~ < > ^ ( ) [ ] { } $ \\ ``` 二者分工不同,前者為了防止用戶利用shell的一些技巧(如分號、反引號等),執行其他命令;后者是為了防止用戶的輸入逃逸出“參數值”的位置,變成一個“參數選項”(命令構成:命令 參數選項 參數值) 滲透測試:[http://www.52bug.cn/hkjs/4879.html](http://www.52bug.cn/hkjs/4879.html) localhost/test.php?cmd=echo "aaaaaaa" >>1.txt 注釋: 一、> 是定向輸出到文件,如果文件不存在,就創建文件;如果文件存在,就將其清空;在我的一篇清空linux歷史命令的文章中,就是這種方法,用echo > .bash_history,將文件內容清空(文件大小變成0字節)。 二、>> 這個是將輸出內容追加到目標文件中。如果文件不存在,就創建文件;如果文件存在,則將新的內容追加到那個文件的末尾,該文件中的原有內容不受影響。 ``` 防御例子: ``` if( isset( $_POST[ 'Submit' ] ) ) { // 檢查Anti-CSRF令牌 checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' ); // 獲取input信息 $target = $_REQUEST[ 'ip' ]; $target = stripslashes( $target ); // 把IP分成4個字節 $octet = explode( ".", $target ); //檢查每八位字節是否為整數 if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) { //如果所有的4個字節都是int,把IP放回去。 $target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3]; // 確定操作系統并執行ping命令。 if( stristr( php_uname( 's' ), 'Windows NT' ) ) { // Windows $cmd = shell_exec( 'ping ' . $target ); } else { // *nix $cmd = shell_exec( 'ping -c 4 ' . $target ); } // 為最終用戶提供結果 $html .= "<pre>{$cmd}</pre>"; } else { // 返回錯誤信息 $html .= '<pre>ERROR: You have entered an invalid IP.</pre>'; } } // 生成Anti-CSRF令牌 generateSessionToken(); ``` ``` // 檢查Token function checkToken( $user_token, $session_token, $returnURL ) { //檢查用戶表單傳過來的token是否等于當前的token 或者token不存在 if( $user_token !== $session_token || !isset( $session_token ) ) { if( !isset( $_SESSION[ 'dvwa' ] ) ) { $_SESSION[ 'dvwa' ] = array(); } $dvwaSession=$_SESSION[ 'dvwa' ]; if( !isset( $dvwaSession[ 'messages' ] ) ) { $dvwaSession[ 'messages' ] = array(); } $dvwaSession[ 'messages' ][] = 'CSRF token is incorrect'; session_commit(); header( "Location: {$returnURL}" ); exit; } } ``` ``` //生成token function generateSessionToken() { # Generate a brand new (CSRF) token if( isset( $_SESSION[ 'session_token' ] ) ) { unset( $_SESSION[ 'session_token' ] ); } $_SESSION[ 'session_token' ] = md5( uniqid() ); } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看