A CyStack Team Member - Simplifying Cybersecurity From A to Z
0 lượt xem
0 lượt xem
Reading Time: 2minutes
PHPobject injection như chúng ta đã biết những đối tượng trong ngôn ngữ lập trình nói chung là một thực thể sống, chúng tồn tại trên bộ nhớ trong khi chương trình đang được thực thi. Vậy nếu ta muốn lưu trữ chúng lại để có thể tái sử dụng lại nó lần sau thì làm thế nào? Hàm serialize() trong PHP sẽ giúp ta làm được điều này. Hàm này chịu trách nhiệm dump một đối tượng (object) ra thành một chuỗi (string) dạng O:7:"MyClass":2:{s:3:"foo";i:10;s:3:"bar";i:20} .
Và đương nhiên cần hàm unserialize() để chuyển từ một chuỗi đã được serialized về object ban đầu. Khi sử dụng hàm unserialize() nếu chúng ta không kiểm soát tốt dữ liệu truyền vào hàm này tốt thì sẽ rất dễ dàng bị hacker tấn công thông qua lỗi PHP object injection. Để hiểu rõ hơn chúng ta hãy cùng xem xét ví dụ sau: Đầu tiên website của bạn nhận vào biến $_GET['in'], khi nhận được giá trị của biến này bạn tiến hành thực thi đoạn code sau echo unserialize($_GET['in']); Giả sử một hacker viết một đoạn mã khai thác như sau :
PHP Object injection trên WordPressKết quả trả về của hàm serialize($foo) là chuỗi O:3:"Foo":1:{s:4:"file";s:11:"/etc/passwd";} sẽ được hacker truyền vào biến $_GET['in'] theo request sau: http://yoursite.com?in=O:3:"Foo":1:{s:4:"file";s:11:"/etc/passwd";}. Có lẽ bạn sẽ hình dung được kết quả trả về của request trên:). Với lỗi này Hacker có thể dễ dàng thực thi những code để khai thác website của bạn. Lời khuyên dành cho bạn ở đây đó là kiểm soát kĩ lưỡng data đi vào hàm unserialize() để loại bỏ những dữ liệu fuzz bất hợp lệ.
Sơn VõA CyStack Team Member - Simplifying Cybersecurity From A to Z
A CyStack Team Member - Simplifying Cybersecurity From A to Z
Cập nhật thông tin mới nhấtNhận các thông tin mới nhất về mối đe dọa, báo cáo an ninh mạng từ CyStack về hòm thư điện tử của bạn
Thảo luận (0)
Đăng nhập để thảo luận
Bài viết liên quan
{"success":true,"head":"<title>PHP Object injection trên WordPress - Phần I - CyStack Tutorial</title>\n<meta name=\"description\" content=\"PHP object injection như chúng ta đã biết những đối tượng trong ngôn ngữ lập trình nói chung là một thực thể sống, chúng tồn tại trên bộ nhớ trong khi chương\"/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-video-preview:-1, max-image-preview:large\"/>\n<link rel=\"canonical\" href=\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/\" />\n<meta property=\"og:locale\" content=\"en_US\" />\n<meta property=\"og:type\" content=\"article\" />\n<meta property=\"og:title\" content=\"PHP Object injection trên WordPress - Phần I - CyStack Tutorial\" />\n<meta property=\"og:description\" content=\"PHP object injection như chúng ta đã biết những đối tượng trong ngôn ngữ lập trình nói chung là một thực thể sống, chúng tồn tại trên bộ nhớ trong khi chương\" />\n<meta property=\"og:url\" content=\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/\" />\n<meta property=\"og:site_name\" content=\"CyStack Tutorial\" />\n<meta property=\"article:tag\" content=\"Hướng dẫn\" />\n<meta property=\"article:tag\" content=\"Kiến thức\" />\n<meta property=\"article:tag\" content=\"Kiến thức cơ bản\" />\n<meta property=\"article:tag\" content=\"Lỗ hổng bảo mật\" />\n<meta property=\"article:tag\" content=\"migration\" />\n<meta property=\"article:tag\" content=\"Phát triển phần mềm an toàn\" />\n<meta property=\"article:tag\" content=\"vi\" />\n<meta property=\"article:section\" content=\"An toàn thông tin\" />\n<meta property=\"og:updated_time\" content=\"2026-03-05T14:13:22+07:00\" />\n<meta property=\"og:image\" content=\"https://i2.wp.com/securitydaily.net/wp-content/uploads/Critical-Vulnerabilities-Patched-in-PHP-2.jpg\" />\n<meta property=\"og:image:secure_url\" content=\"https://i2.wp.com/securitydaily.net/wp-content/uploads/Critical-Vulnerabilities-Patched-in-PHP-2.jpg\" />\n<meta property=\"og:image:width\" content=\"320\" />\n<meta property=\"og:image:height\" content=\"259\" />\n<meta property=\"og:image:alt\" content=\"PHP Object injection\" />\n<meta property=\"og:image:type\" content=\"image/jpeg\" />\n<meta property=\"article:published_time\" content=\"2014-02-26T16:12:52+07:00\" />\n<meta property=\"article:modified_time\" content=\"2026-03-05T14:13:22+07:00\" />\n<meta name=\"twitter:card\" content=\"summary_large_image\" />\n<meta name=\"twitter:title\" content=\"PHP Object injection trên WordPress - Phần I - CyStack Tutorial\" />\n<meta name=\"twitter:description\" content=\"PHP object injection như chúng ta đã biết những đối tượng trong ngôn ngữ lập trình nói chung là một thực thể sống, chúng tồn tại trên bộ nhớ trong khi chương\" />\n<meta name=\"twitter:image\" content=\"https://i2.wp.com/securitydaily.net/wp-content/uploads/Critical-Vulnerabilities-Patched-in-PHP-2.jpg\" />\n<meta name=\"twitter:label1\" content=\"Written by\" />\n<meta name=\"twitter:data1\" content=\"Sơn Võ\" />\n<meta name=\"twitter:label2\" content=\"Time to read\" />\n<meta name=\"twitter:data2\" content=\"1 minute\" />\n<script type=\"application/ld+json\" class=\"rank-math-schema\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https://blog.cystack.org/tutorial/#person\",\"name\":\"CyStack Tutorial\"},{\"@type\":\"WebSite\",\"@id\":\"https://blog.cystack.org/tutorial/#website\",\"url\":\"https://blog.cystack.org/tutorial\",\"name\":\"CyStack Tutorial\",\"publisher\":{\"@id\":\"https://blog.cystack.org/tutorial/#person\"},\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https://i2.wp.com/securitydaily.net/wp-content/uploads/Critical-Vulnerabilities-Patched-in-PHP-2.jpg?fit=320%2C259&ssl=1\",\"url\":\"https://i2.wp.com/securitydaily.net/wp-content/uploads/Critical-Vulnerabilities-Patched-in-PHP-2.jpg?fit=320%2C259&ssl=1\",\"width\":\"320\",\"height\":\"259\",\"inLanguage\":\"en-US\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":\"1\",\"item\":{\"@id\":\"https://blog.cystack.org/tutorial\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":\"2\",\"item\":{\"@id\":\"https://blog.cystack.org/tutorial/category/an-toan-thong-tin/\",\"name\":\"An to\\u00e0n th\\u00f4ng tin\"}},{\"@type\":\"ListItem\",\"position\":\"3\",\"item\":{\"@id\":\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/\",\"name\":\"PHP Object injection tr\\u00ean WordPress – Ph\\u1ea7n I\"}}]},{\"@type\":\"WebPage\",\"@id\":\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/#webpage\",\"url\":\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/\",\"name\":\"PHP Object injection tr\\u00ean WordPress - Ph\\u1ea7n I - CyStack Tutorial\",\"datePublished\":\"2014-02-26T16:12:52+07:00\",\"dateModified\":\"2026-03-05T14:13:22+07:00\",\"isPartOf\":{\"@id\":\"https://blog.cystack.org/tutorial/#website\"},\"primaryImageOfPage\":{\"@id\":\"https://i2.wp.com/securitydaily.net/wp-content/uploads/Critical-Vulnerabilities-Patched-in-PHP-2.jpg?fit=320%2C259&ssl=1\"},\"inLanguage\":\"en-US\",\"breadcrumb\":{\"@id\":\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/#breadcrumb\"}},{\"@type\":\"Person\",\"@id\":\"https://blog.cystack.org/tutorial/author/sonvt/\",\"name\":\"S\\u01a1n V\\u00f5\",\"url\":\"https://blog.cystack.org/tutorial/author/sonvt/\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https://secure.gravatar.com/avatar/2ecc46dab0853cd3875309faad14bde0eb72099f5358ad072968dad8cbf55cd3?s=96&d=mm&r=g\",\"url\":\"https://secure.gravatar.com/avatar/2ecc46dab0853cd3875309faad14bde0eb72099f5358ad072968dad8cbf55cd3?s=96&d=mm&r=g\",\"caption\":\"S\\u01a1n V\\u00f5\",\"inLanguage\":\"en-US\"},\"sameAs\":[\"http://project-jgaiv.vercel.app/\"]},{\"@type\":\"BlogPosting\",\"headline\":\"PHP Object injection tr\\u00ean WordPress - Ph\\u1ea7n I - CyStack Tutorial\",\"keywords\":\"PHP Object injection\",\"datePublished\":\"2014-02-26T16:12:52+07:00\",\"dateModified\":\"2026-03-05T14:13:22+07:00\",\"articleSection\":\"An to\\u00e0n th\\u00f4ng tin, DevSecOps\",\"author\":{\"@id\":\"https://blog.cystack.org/tutorial/author/sonvt/\",\"name\":\"S\\u01a1n V\\u00f5\"},\"publisher\":{\"@id\":\"https://blog.cystack.org/tutorial/#person\"},\"description\":\"PHP object injection nh\\u01b0 ch\\u00fang ta \\u0111\\u00e3 bi\\u1ebft nh\\u1eefng \\u0111\\u1ed1i t\\u01b0\\u1ee3ng trong ng\\u00f4n ng\\u1eef l\\u1eadp tr\\u00ecnh n\\u00f3i chung l\\u00e0 m\\u1ed9t th\\u1ef1c th\\u1ec3 s\\u1ed1ng, ch\\u00fang t\\u1ed3n t\\u1ea1i tr\\u00ean b\\u1ed9 nh\\u1edb trong khi ch\\u01b0\\u01a1ng\",\"name\":\"PHP Object injection tr\\u00ean WordPress - Ph\\u1ea7n I - CyStack Tutorial\",\"@id\":\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/#richSnippet\",\"isPartOf\":{\"@id\":\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/#webpage\"},\"image\":{\"@id\":\"https://i2.wp.com/securitydaily.net/wp-content/uploads/Critical-Vulnerabilities-Patched-in-PHP-2.jpg?fit=320%2C259&ssl=1\"},\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https://blog.cystack.org/tutorial/2014/02/26/php-object-injection-tren-wordpress-phan-i/#webpage\"}}]}</script>\n"}