J2TEAM Security: A must-have extension for Chrome users. Install now!

Tutorial: Fix bug SQL Injection Music Gift for vBB

Tutorial: Fix bug SQL Injection Music Gift for vBB | Juno_okyo's Blog
6 min read
Vào AdminCP > Plugins & Products > Plugin Manager, sau đó kéo xuống và tìm đến Plugin của mod Music Gift.


Sửa plugin có hook là ajax_start, thêm vào đoạn đầu phần Plugin PHP Code hàm sau (hàm này có tác dụng lọc input của câu lệnh SQL):

function anti_sql($sql) {
$sql = str_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|*|--|\)/"),"",$sql);
return trim(strip_tags(addslashes($sql))); #strtolower()
}



Tiếp theo bạn nhấn Ctrl+F và nhập từ khóa:

if($_POST['do'] == 'check_name')

Chúng ta sẽ lọc input tại đây, tốt nhất nên copy toàn bộ PHP Code ra một trình biên soạn cho dễ nhìn (mình dùng Notepad++):
Code gốc khi chưa lọc input



Code sau khi lọc input (sử dụng hàm Anti SQL)

Code gốc khi chưa lọc input:

if($_POST['do'] == 'check_name') {
         $vbulletin->input->clean_array_gpc('p', array(                    
                    'name'         => TYPE_STR)
              );
     $u = explode(',',$_POST['name']);
                             $found = ''; 
                             $lost = '';
                             foreach($u as $v) {
                             $m = $vbulletin->db->query_first("SELECT * FROM ". TABLE_PREFIX ."user WHERE username = '".$v."'"); 
                             if($m[userid] > 0) {$q = $vbulletin->db->query_first("SELECT * FROM ". TABLE_PREFIX ."usergroup WHERE usergroupid = '".$m[usergroupid]."'"); 
                                  $m[username] = $q[opentag].$m[username].$q[closetag];
                                  $found = $found.$m[username].',';} else { $lost = $lost.$v.',';}
                             }      
                             $answer = '';  
                             if($found <> '') $answer = "&#272;&#227; t&#236;m &#273;&#432;&#7907;c <b> ".$found."</b>.  H&#7879; th&#7889;ng s&#7869; g&#7917;i tin nh&#7855;n &#273;&#7871;n b&#7841;n &#7845;y &#273;&#7875; th&#244;ng b&#225;o v&#7873; m&#243;n qu&#224; c&#7911;a b&#7841;n.";
     if($lost <> '') $answer = $answer."<br>Kh&#244;ng t&#236;m &#273;&#432;&#7907;c <b><font color='red'>".$lost."</font></b> N&#7871;u b&#7841;n g&#7917;i b&#224;i h&#225;t n&#224;y &#273;&#7871;n t&#7845;t c&#7843; m&#7885;i ng&#432;&#7901;i, b&#7841;n kh&#244;ng c&#7847;n nh&#7853;p t&#234;n ch&#237;nh x&#225;c.";  
     echo $answer;     
                }

Chúng ta sửa thành như sau (sử dụng hàm Anti SQL ở trên để lọc input được người dùng nhập vào):

if($_POST['do'] == 'check_name') {
         $vbulletin->input->clean_array_gpc('p', array(                    
                    'name'         => TYPE_STR)
              );
     $_name = anti_sql($_POST['name']); // Clean Input
     $u = explode(',',$_name);
                             $found = ''; 
                             $lost = '';
                             foreach($u as $v) {
                             $m = $vbulletin->db->query_first("SELECT * FROM ". TABLE_PREFIX ."user WHERE username = '".$v."'"); 
                             if($m[userid] > 0) {$q = $vbulletin->db->query_first("SELECT * FROM ". TABLE_PREFIX ."usergroup WHERE usergroupid = '".$m[usergroupid]."'"); 
                                  $m[username] = $q[opentag].$m[username].$q[closetag];
                                  $found = $found.$m[username].',';} else { $lost = $lost.$v.',';}
                             }      
                             $answer = '';  
                             if($found <> '') $answer = "&#272;&#227; t&#236;m &#273;&#432;&#7907;c <b> ".$found."</b>.  H&#7879; th&#7889;ng s&#7869; g&#7917;i tin nh&#7855;n &#273;&#7871;n b&#7841;n &#7845;y &#273;&#7875; th&#244;ng b&#225;o v&#7873; m&#243;n qu&#224; c&#7911;a b&#7841;n.";
     if($lost <> '') $answer = $answer."<br>Kh&#244;ng t&#236;m &#273;&#432;&#7907;c <b><font color='red'>".$lost."</font></b> N&#7871;u b&#7841;n g&#7917;i b&#224;i h&#225;t n&#224;y &#273;&#7871;n t&#7845;t c&#7843; m&#7885;i ng&#432;&#7901;i, b&#7841;n kh&#244;ng c&#7847;n nh&#7853;p t&#234;n ch&#237;nh x&#225;c.";  
     echo $answer;     
                }

Các bạn Save lại và sửa tiếp Plugin có hook là misc_start, các bạn nhấn Ctrl+F và tìm dòng sau:

$m = $vbulletin->db->query_first("SELECT * FROM ". TABLE_PREFIX ."hqth_music WHERE id = " . $_GET['id']) . ";"); 

Thêm hàm addslashes để clean input:

$m = $vbulletin->db->query_first("SELECT * FROM ". TABLE_PREFIX ."hqth_music WHERE id = '".addslashes($_GET['id'])."';");

Cuối cùng là Save.

Chúc các bạn thành công!

Tutorial by Juno_okyo - Juno_okyo's Blog.
Great thanks to Neods and James.

* Update: các bạn có thể dùng bộ lọc vBulletin đã có sẵn:
  • $db->escape_string($input)
Hoặc:
  • POST (Ví dụ $_POST['input_name']):  $vbulletin->input->clean_gpc('p', 'input_name', TYPE_NOHTML)
  • GET (Ví dụ: $_GET['input_name']): $vbulletin->input->clean_gpc('g', 'input_name', TYPE_NOHTML)
Leader at J2TEAM. Website: https://j2team.dev/

Bạn có thể thích những bài đăng này

  • How to do Hydra (Brute force Attack) to hack any E-mail Password Brute-force attack A password attack that does not attempt to decrypt any information, but continue to try di…
  • Muchas veces cuando realizamos alguna Auditoria enfocada hacia Servidores Web, uno de los pasos mas importante que se debe realizar es Information Gathering (Recopilación&nb…
  • Many of us try to hack sites every day and most of time we fail. But there are some peoples with great talent to hack any site and we thought " GOD ... I want to be like h…
  • Sometimes we need to browse forum to read some articles and they asks to register to view the topic so now you can skip the process of registration. Here are some pics of forum w…
  • Esta vez, vamos a ver algo sobre 0-days, gracias a un amigo con el seudónimo Join7 del foro ZentrixPlus donde ha realizado un tutorial en la cual explica d…
  • Here is a beautiful Tut From my dear friend H4x4rwOw on DNS SPOOFING   Recommended to download and watch Download Here Note:- Only for Educational purpose …

Đăng nhận xét

Cảm ơn bạn đã đọc bài viết!

- Bạn có gợi ý hoặc bình luận xin chia sẻ bên dưới.

- Hãy viết tiếng Việt có dấu nếu có thể!