Hướng Dẫn Cách Quét Shell Trên Host

Thảo luận trong 'Bảo mật Joomla' bắt đầu bởi VJL, 25/8/12.

  1. VJL

    VJL Be like no others ... Staff Member

    Bài viết:
    501
    Likes :
    303
    Bạn thường thấy trên mạng có share nhiều code đẹp và bạn tải về nghiên cứu, hoặc sử dụng. Nếu bạn sử dụng bạn băn khoăn không biết trong code đc share kia có Shell không? vậy làm sao để tìm ra nó trong 1 rừng file như vậy.
    Bình thường những file chứa Shell thường được mã hóa dạng: base64, có thể qua mặt được những Antivirut
    tut này mình sẽ hướng dẫn các bạn tut tìm kiếm Shell trên host. Tut này khá đơn giản áp dụng cho tất cả code chạy php không riêng gì Joomla. Có thể Scan trên live hosting hay ở localhost đều được, miễn hỗ trợ chạy php.
    Đầu tiên là tải file đính kèm về giải nén và Up ngang hàng với file index.php.
    Hình 1
    Foder: điền thư mục cần tìm, để mặc định nếu tìm kiếm hết root
    Keywork: Để nguyên nếu tìm Shell, hoặc điền key khác nếu muốn tìm chữ nào đó mà ko biết ở file nào
    [​IMG]
    Hình 2
    Kết quả sau khi Scan, những file nào chứa key: base64 sẽ đc liệt kê màu đỏ
    Chúng ta nên kiểm tra từng file 1 bằng cách gõ trên trình duyệt.
    Ở đây như hình sau khi Scan tôi thấy file sukien/components/com_myblog/libraries/cgbin.php
    Tôi mở trình duyệt http://localhost/sukien/components/com_myblog/libraries/cgbin.php


    [​IMG]

    Hình 3
    Sau khi chạy file : http://localhost/sukien/components/com_myblog/libraries/cgbin.php
    ồ hóa ra nó đây, tìm và xóa đi

    [​IMG]
    Các bạn nên check từng file đc liệt kê màu đỏ cho yên tâm, ko phải file nào đc liệt kê cũng là shell.
    Ngoài ra còn 1 số chức năng khác ở file này các bạn tự kiểm tra nhé.
    Chúc các bạn thành công
    Download
     
    Last edited by a moderator: 5/6/14
  2. khacbinh171501

    khacbinh171501 Rất tích cực

    Bài viết:
    65
    Likes :
    5
    Em up vào web root ở localhost rồi gõ link mà sao nó không chạy nhỉ?
     
  3. joomla

    joomla OMG Staff Member

    Bài viết:
    1,068
    Likes :
    2,262
    Đã test trên localhost và host đều chạy rất tốt
     
    all4wildcat thích bài này.
  4. Mafia_13

    Mafia_13 Rất tích cực

    Bài viết:
    41
    Likes :
    5
    Mình cũng vậy. Ai demo cái link lên xem nào?
     
  5. nguyentheanh7777

    nguyentheanh7777 Mới tham gia

    Bài viết:
    2
    Likes :
    0
    Thanks bạn ! Bài viết rất hay
     
  6. flameseo

    flameseo Mới tham gia

    Bài viết:
    14
    Likes :
    1
    oh em đang cần hướng dẫn này đây, bực mình nó cứ chèn text link site em hoài
     
  7. Sausage

    Sausage Rất tích cực

    Bài viết:
    96
    Likes :
    17
    Thông báo lỗi: Parse error: syntax error, unexpected $end in D:\xxx\scan.php on line 188
     
  8. joomla

    joomla OMG Staff Member

    Bài viết:
    1,068
    Likes :
    2,262
    Mình không biết các bạn lỗi ntn, mình đã test = cách up lên host --> chạy tốt.
    Cài appserv 2.5.10 làm localhost test code --> test trên cái này chạy tốt.
    Trong 1 số trường hợp thì server, localhost của các bạn bật chế độ báo lỗi (Trong Joomla khuyên tắt)
    Bạn có thể coppy code phía dưới mình đã fix để các bạn chạy trên những server khó tính, Nhớ lưu lại dưới dạng tenfil.php nhé (Dùng notepad ++ hoặc EditPlust cho nó không có lỗi nhé)
    PHP:
    <?php
     
    /*********************************************************
    - Tool Scan shell vesion 1.0
    - Code by KID
    - Edit by : www.joomlaviet.vn
    **********************************************************/
    error_reporting (E_ALL);    // Mở báo lỗi
    ini_set("memory_limit","2000M");
    ini_set("safe_mode","off");
    $safe_mode = @ini_get('safe_mode');
    if (!
    $safe_mode)
    set_time_limit(0);
    if (@!isset(
    $_POST['key']))
    {
    ?>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Scan Shell v1.1</title>
    <style>
    body {
    font-family:arial;
    }
    </style>
    </head>
    <body bgcolor=black text=blue size=2><center>
    <form method='post' action=''>
    <div style="border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px">
    <h1>Scan Shell - v1.1</h1>
                      <div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Folder: <input type='text' size=70 name='folder' value='<?echo $_SERVER['DOCUMENT_ROOT']?>/'/></div>                   
                      &nbsp;<div>&nbsp; KeyWord:&nbsp; <input type='text' size=70 name='key' value='base64_decode'/></div> 
                      <p><input type='submit' name='submit' value='Tìm kiếm' /></p>  </div>
                      <div align=left><br>Step 1: Nhập đường dẫn thư mục cần scan</div>
                      <div align=left>Step 2: Nhập từ khóa cần tìm</div>
                </form>
     
    <br><br>
    ---------------------------------------------------------------------------------
    <br><br><i>Power By <a href="http://joomlaviet.vn"><font color=red>Joomla Việt</font></a><br>Copyright 2012<a href="http://diendan.joomlaviet.vn"><font color=yellow>Diễn Đàn Joomla Việt</font></a><br/>
    <br>---------------------------------------------------------------------------------
    </center>
     
    </body>
    </html>
      <?
    }
    else
    {
    if (
    $_POST['folder']) $folder $_POST['folder']; else $folder $_SERVER['DOCUMENT_ROOT'];
    define('Keyword',$_POST['key']);                                    // Tìm kiếm từ khóa
    define('TAB',"&nbsp;&nbsp;&nbsp;&nbsp;");                       
    define('IGNORE_EXTENSIONS',"jpg pdf zip psd doc gif swf xls gz txt");    // Không tìm những file
    define("MAX_SIZE",1024*1024*1024);                                    // Size tối đa
    define("IGNORE_BEFORE"strtotime('2009-08-01') );                // Tìm File trước ngày
    $shell $_SERVER["PHP_SELF"];
     
    function 
    findexts($filename)
    {
        
    $filename strtolower($filename) ;
        
    $exts split("[/\\.]"$filename) ;
        
    $n count($exts)-1;
        
    $exts $exts[$n];
        return 
    strtolower($exts);
    }
     
    function 
    check_dir($directory,$level) {
        global 
    $virus_detected$all$detect_errors_only$detected_Keyword_in_test_script;
     
        
    $indent='';
        for (
    $count=0;$count<$level;$count++) {
            
    $indent.=TAB;
        }
        
    $level++;
        
    $read_dir=opendir($directory);    // Mở thư mục hiện tại
        
    while ($file=readdir($read_dir)) {
            
    $filepath=$directory.'/'.$file;
            if (
    $detect_errors_only && $virus_detected) {
                exit;
            }
            if (
    is_dir($filepath)) {
                
    // Thư mục
                
    if ( ($file<>'.') && ($file<>'..') ) {
                    
    check_dir($filepath,$level);
                }
            }
            else {
                if (
    is_file($filepath)) {
                    
    // Tập
                    
    if ( (is_readable($filepath) )  &&  (!stristr(IGNORE_EXTENSIONSfindexts($file)))  ) {
                        if ((
    filesize($filepath)< MAX_SIZE) && (filemtime($filepath)>IGNORE_BEFORE) ){
                            
    $fileentry=$directory.'/'.$file.' - '.date('j F Y H:i',filemtime($filepath));
                            
    $filestring=file_get_contents($filepath);
                            
    $found=stripos($filestring,Keyword); // PHP 5 ONLY
                            
    $found=stristr($filestring,Keyword);flush();
                            if (
    $found==false) {
                                if ( (!
    $detect_errors_only) && (!$all) ) {
                                echo(
    $filepath.'  <font color=#FFFFFF>OK</font><br/>');
                                }
                            }
                            else {
                                if (
    $file=='scan_file.php'){
                                    
    $detected_Keyword_in_test_script=true;
                                }
                                else {
                                    
    $virus_detected=true;
                                    if (
    $detect_errors_only) {
                                        echo(
    '<b style="color:#F00">Tập tin đề nghị phát hiện</b><br/>');
                                    }
                                    else {
                                        echo(
    TAB.'<b style="color:#F00">'.$fileentry.'</b> - <b style="color:#FFFFF0">Phát hiện</b><br/>');
                                    }
                                }
                            }
                            
    $found='';
                        }
                        else {
                            if ( (!
    $detect_errors_only) && (!$all) ) {
                                echo(
    $filepath.'  <b style="color:yellow">NOT CHECKED - File quá lớn</b><br/>');
                            }
                        }
                    }
                    else {
                        if ( (!
    $detect_errors_only) && (!$all) ) {
                            echo(
    $filepath.'  <b style="color:yellow">NOT CHECKED - Không thuộc kiểu tìm kiếm</b><br/>');
                        }
                    }
                }
                else {
                }
            }
        }   
        
    closedir($read_dir);
    }
     
    $virus_detected=false;
    $all=true;
    $detect_errors_only=false;
    $detected_Keyword_in_test_script=false;
    if (isset(
    $_GET['all'])) {
        
    $all=false;
    }
    if (isset(
    $_GET['detect_errors_only'])) {
        
    $detect_errors_only=true;
    }
     
    echo<<<END1
    <html>
    <head>
    <title>Scan Shell v1.1</title>
    <style>
    body {
    font-family:arial;
    }
    </style>
    </head>
    <body bgcolor=black text=blue size=2>
    END1;
    ?>
    <div style="border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px">
    <h1>Truy xuất từ khóa "<?echo Keyword?>" trong hệ thống !</h1>
    Bỏ qua lỗi file : <font color=yellow><?echo IGNORE_EXTENSIONS?>.</font><br/>
    Bỏ qua file vượt quá : <font color=yellow><?echo MAX_SIZE?> bytes.</font><br/>
    Tìm kiếm file trước ngày :<font color=yellow> <?echo date('j F Y',IGNORE_BEFORE)?>.</font><br/><br></div>
    <br/><br>[<a href="<?echo $shell?>?all">Hiển thị tất cả?</a>]
    <br/><br/>&nbsp;<br/>
    <?
     
    if ($all) {
        echo(
    '<font color=yellow>List File</font><br/>');
    }
    check_dir($folder,0);
     
     
     
    if (
    $virus_detected) {
        echo(
    '<br/><b style="color:#f00">Tìm kiếm thành công!</b><br>&nbsp;<br/>');
    }
    else {
    echo(
    '<br/><b style="color:#f00">Không có file chứa Key Word!</b><br>&nbsp;<br/>');
    }
     
    ?>
    </body>
    </html>
    <?
    }
    ?>
     
  9. Sausage

    Sausage Rất tích cực

    Bài viết:
    96
    Likes :
    17
    Tại sao vẫn không được nhỉ? Trong file download thì dòng 188 là: ?><?
    Mình đã sửa lại thành ?> giống như code bạn vừa up lại.
    Vẫn lỗi Parse error: syntax error, unexpected $end in D:\xxx\scan.php on line 188
     
  10. joomla

    joomla OMG Staff Member

    Bài viết:
    1,068
    Likes :
    2,262
    Tốt nhất bạn tắt báo lỗi của host bạn scan đi
     
  11. Sausage

    Sausage Rất tích cực

    Bài viết:
    96
    Likes :
    17
    Bạn có thể nói rõ hơn tắt như thế nào không? File scan này chạy trên host thì ok nhưng chạy trên localhost nó báo lỗi
     
  12. kenli520

    kenli520 Mới tham gia

    Bài viết:
    5
    Likes :
    0
    cái này theo mình nghĩ cái server bạn đang sài ko hiểu được <?, bạn thử sửa các <? thành <?php xem sao nha
     
  13. Sausage

    Sausage Rất tích cực

    Bài viết:
    96
    Likes :
    17
    OK. Để tối nay về nhà thử lại. Sẽ báo kết quả sau.
     
  14. tuananhk43

    tuananhk43 Mới tham gia

    Bài viết:
    1
    Likes :
    1
    Mình cũng bị lỗi trên
    Bạn thay
    PHP:
    <?
    bằng
    Mã:
    <?php
    là OK
     
    chiplegends thích bài này.
  15. babong

    babong Mới tham gia

    Bài viết:
    17
    Likes :
    0
    Sau khi quet phát hiện: C:\\AppServ\\www\\cobang\\templates\\zt_opis25/html/com_k2/templates/zootemplate/item.php - 4 February 2012 15:00 - Phát hiện
    mở file lên thấy đoạn này khong biết phải không: 2012-10-29_205059.
     
  16. babong

    babong Mới tham gia

    Bài viết:
    17
    Likes :
    0
    Ah! cho mình hỏi: nó phát hiện file nào xóa file đó liệu có sao ko ?
     
  17. joomla

    joomla OMG Staff Member

    Bài viết:
    1,068
    Likes :
    2,262
    Các bạn nên check từng file đc liệt kê màu đỏ cho yên tâm, ko phải file nào đc liệt kê cũng là shell.
    Nếu trong file có đoạn code mã hóa, bạn hãy thử bỏ đoạn mã hóa và chạy thử xem có vấn đề gì không, nhớ coppy 1 file gốc ra phòng trường hợp bị sao đó còn add lại
     
  18. Sausage

    Sausage Rất tích cực

    Bài viết:
    96
    Likes :
    17
    Vẫn lỗi như trên. Chạy trên hosting thì OK, localhost thì error. Chắc do cái localhost cùi bắp :)
     
  19. avetlulu

    avetlulu Mới tham gia

    Bài viết:
    11
    Likes :
    0
    down về giai nén ra thì đc 1 file scan.php, mình up lên host trong folder public_html ngang hàng với file index.php rồi làm sao nữa các bạn?

    tks
     
  20. nhokkhoa

    nhokkhoa Rất tích cực

    Bài viết:
    51
    Likes :
    1
    lúc tìm xong mình copy link và vào thì lại báo:
    "Direct Accessssssssssss to this location is not allowed." có file thì là "Restricted access" là sao nhỉ?
     
    thitluocday thích bài này.
comments powered by Disqus
: scan, shell, tut

Chia sẻ trang này