{"id":1935,"date":"2023-12-05T11:38:41","date_gmt":"2023-12-05T03:38:41","guid":{"rendered":"https:\/\/www.aqwu.net\/wp\/?p=1935"},"modified":"2023-12-05T12:12:48","modified_gmt":"2023-12-05T04:12:48","slug":"%e6%88%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e7%9b%b8%e5%90%8c%e7%9a%84-md5-%e5%93%88%e5%b8%8c%e5%88%9b%e5%bb%ba%e4%b8%a4%e4%b8%aa-php-%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.aqwu.net\/wp\/?p=1935","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u76f8\u540c\u7684 MD5 \u54c8\u5e0c\u521b\u5efa\u4e24\u4e2a PHP \u6587\u4ef6"},"content":{"rendered":"\n<p>\u6211\u6700\u8fd1\u5728 twitter \u4e0a\u53d1\u5e03\u4e86\u4e00\u4e2a\u6307\u5411\u4e24\u4e2a PHP \u811a\u672c\u7684\u94fe\u63a5\uff0c\u5b83\u4eec\u5177\u6709\u4e0d\u540c\u7684\u884c\u4e3a\uff0c\u4f46\u5177\u6709\u76f8\u540c\u7684 MD5 \u54c8\u5e0c\u503c\u3002\u8981\u9a8c\u8bc1\u8fd9\u4e00\u70b9\uff0c\u8bf7\u4e0b\u8f7d\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>$ wget https:\/\/aqwu.net\/md5collisions\/a.php \n$ wget https:\/\/aqwu.net\/md5collisions\/b.php<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u68c0\u67e5\u4ed6\u4eec\u7684 MD5 \u54c8\u5e0c\u503c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ openssl md5 a.php b.php\nMD5(a.php)= 62e1d0d1620581693435aa75f5b6c964\nMD5(b.php)= 62e1d0d1620581693435aa75f5b6c964<\/code><\/pre>\n\n\n\n<p>\u73b0\u5728\u8fd0\u884c\u6bcf\u4e2a\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>$ php a.php\nBehaviour A\n$ php b.php\nBehaviour B<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e9b\u6587\u4ef6\u7684\u884c\u4e3a\u4e0d\u540c\uff0c\u4f46\u4f7f\u7528 MD5 \u6563\u5217\u5230\u76f8\u540c\u7684\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u3002\u4f7f\u7528\u53e6\u4e00\u79cd\u54c8\u5e0c\u7b97\u6cd5\uff08\u5728\u672c\u4f8b\u4e2d\u4e3a SHA1\uff09\u8fdb\u884c\u5feb\u901f\u68c0\u67e5\uff0c\u786e\u8ba4\u8fd9\u4e24\u4e2a\u6587\u4ef6\u5b9e\u9645\u4e0a\u662f\u4e0d\u540c\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>$ openssl sha1 a.php b.php\nSHA1(a.php)= 6ef81f904b84d6ea53048004a26157816a85cfa3\nSHA1(b.php)= d191a5eb7557231f461c09cb4dc565a23336778a<\/code><\/pre>\n\n\n\n<p>\u90a3\u4e48\u8fd9\u4e9b\u6587\u4ef6\u662f\u5982\u4f55\u5236\u4f5c\u7684\u5462\uff1f\u597d\u5427\uff0c\u5982\u679c\u4f60\u770b\u4e00\u4e0b\u6587\u4ef6\u7684\u6e90\uff0c\u4f60\u4f1a\u53d1\u73b0\u8fd9\u4e24\u4e2a\u6587\u4ef6\u4e4b\u95f4\u51e0\u4e4e\u6ca1\u6709\u533a\u522b\u3002<\/p>\n\n\n\n<p>cat a.php<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;?php\n\n$space = \"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\";\nif ('?G.???-)?????+?B?8????A???P?;\"??P?ZU?5?$q4F?1c?-\u014fC?S\n?e?MIM???~?2?:?]b??\\??\/5???^?gn~3D7' == '?G.???-)?????+?B?8????A???P?;\"??P?ZU?5?$q4F?1c?-\u014fC?S\n?e?MIM???~?2?:?]b??\\??\/5???^?gn~3D7' ) {\n    echo 'Behaviour A',PHP_EOL;\n} else {\n    echo 'Behaviour B',PHP_EOL;\n}\n<\/code><\/pre>\n\n\n\n<p>$ cat b.php<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;?php\n\n\n$space = \"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\";\nif ('?G.???-)??????+?B?8????A???P?;\"??Py&#91;U?5?$q4F?1??-\u014fC?S\n?e?MIM???~?2?:?]b?p?\\??\/5???^?g?~3D7' == '?G.???-)?????+?B?8????A???P?;\"??P?ZU?5?$q4F?1c?-\u014fC?S\n?e?MIM???~?2?:?]b??\\??\/5???^?gn~3D7' ) {\n    echo 'Behaviour A',PHP_EOL;\n} else {\n    echo 'Behaviour B',PHP_EOL;\n}<\/code><\/pre>\n\n\n\n<p>\u53d1\u73b0\u6709\u4ec0\u4e48\u4e0d\u540c\u5417\uff1f\u5b83\u53ef\u80fd\u5f88\u96be\u53d1\u73b0\uff0c\u4f46\u5b9e\u9645\u4e0a\u5728\u4e8c\u8fdb\u5236\u6570\u636e\u7684\u7b2c\u4e00\u4e2a\u5757\u4e2d\u5b58\u5728\u7ec6\u5fae\u7684\u5dee\u5f02\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\uff0c\u6240\u6709\u8fd9\u4e9b\u4e8c\u8fdb\u5236\u6570\u636e\u662f\u600e\u4e48\u56de\u4e8b\u5462\uff1f\u4e8c\u8fdb\u5236\u6570\u636e\u8868\u793a MD5 \u7b97\u6cd5\u4e2d\u7684\u51b2\u7a81\u3002\u5728 Wang \u4e8e 2004 \u5e74\u9996\u6b21\u53d1\u8868\u7684\u5bf9 MD5 \u7684\u653b\u51fb\u4e4b\u540e\uff0c\u4e3a MD5 \u521b\u5efa\u78b0\u649e\u975e\u5e38\u5bb9\u6613\u3002\u6b64\u5916\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u8981\u521b\u5efa\u7684\u78b0\u649e\u7684\u8d77\u59cb\u503c\uff0c\u8fd9\u6837\u5b83\u5c31\u4e0d\u5fc5\u4f4d\u4e8e\u6587\u4ef6\u7684\u5f00\u5934\u3002&nbsp;\u8fd9\u662f\u56e0\u4e3a MD5 \u4e0e\u5927\u591a\u6570\u54c8\u5e0c\u7b97\u6cd5\u4e00\u6837\uff0c\u4e00\u6b21\u5bf9\u4e00\u4e2a\u6570\u636e\u5757\uff08\u5728 MD5s \u60c5\u51b5\u4e0b\u4e3a 64 \u4e2a\u5b57\u8282\uff09\u8fdb\u884c\u64cd\u4f5c\uff0c\u7136\u540e\u4f7f\u7528\u6b64\u503c\u4f5c\u4e3a\u4e0b\u4e00\u4e2a\u5757\u7684\u8d77\u70b9\u3002\u63a5\u4e0b\u6765\u7684\u4e24\u4e2a\u5757\u5728\u4e24\u4e2a\u6587\u4ef6\u4e4b\u95f4\u6709\u6240\u4e0d\u540c\uff0c\u4f46\u662f\uff0c\u5b83\u4eec\u662f\u4e13\u95e8\u521b\u5efa\u7684\uff0c\u4ee5\u4fbf\u5728\u63d2\u5165\u5230\u6b64\u4f4d\u7f6e\u65f6\u53d1\u751f\u78b0\u649e\u3002\u4e24\u4e2a\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u540e\u7eed\u5757\u90fd\u76f8\u540c\u3002\u8fd9\u662f\u6211\u7528\u6765\u751f\u6210\u6587\u4ef6\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>1\uff09 \u9996\u5148\uff0c\u6211\u521b\u5efa\u4e86\u4e00\u4e2a\u6b63\u597d 64 \u5b57\u8282\u957f\u7684\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u7b2c\u4e00\u4e2a\u5355\u5f15\u53f7\u4e4b\u524d\u7684\u6240\u6709\u5185\u5bb9\u3002A \u53ea\u662f\u4e3a\u4e86\u8ba9\u5b83\u6b63\u597d\u6709 64 \u4e2a\u5b57\u8282\u957f<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;?php\n\n$space = \"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\";\nif (\u2018<\/code><\/pre>\n\n\n\n<p>2\uff09 \u901a\u8fc7 MD5 \u7b97\u6cd5\u8fd0\u884c\u6b64\u5185\u5bb9\uff0c\u4f46\u7565\u5fae\u4fee\u6539\u7684\u7248\u672c\u4e0d\u4f1a\u5728\u6d88\u606f\u4e2d\u6dfb\u52a0\u957f\u5ea6\u6216\u4efb\u4f55\u586b\u5145\uff0c\u6211\u5728 PHP \u4e2d\u4f7f\u7528\u4e86\u6211\u81ea\u5df1\u7684 MD5 \u5b9e\u73b0\uff0c\u5e76\u6ce8\u91ca\u6389\u4e86\u9644\u52a0\u586b\u5145\u7684\u90e8\u5206\u3002\u60a8\u53ef\u4ee5\u5728\u6b64\u5904\u83b7\u53d6\u6b64\u4ee3\u7801 https:\/\/gist.github.com\/natmchugh\/fbea8efeced195a2acf2. \u751f\u6210\u54c8\u5e0c\u503c 32f6df28e4a110970fb7f9938bee1686\u3002<\/p>\n\n\n\n<p>3\uff09 \u4f7f\u7528\u6b64\u54c8\u5e0c\u503c\u4f5c\u4e3a\u521d\u59cb\u503c\u6765\u67e5\u627e MD5 \u51b2\u7a81\u3002\u6211\u53d1\u73b0\u7684\u6700\u5feb\u7684\u78b0\u649e\u811a\u672c\u662f Marc Stevens fastcoll, https:\/\/marc-stevens.nl\/research\/&nbsp;\u5982\u679c\u5728 MD5 \u4e2d\u521b\u5efa\u51b2\u7a81\u542c\u8d77\u6765\u9700\u8981\u5f88\u957f\u65f6\u95f4 &#8211; \u4f46\u4e8b\u5b9e\u5e76\u975e\u5982\u6b64\u3002\u5b83\u9700\u8981\u591a\u5c11\u65f6\u95f4\uff0c\u4f46\u5728\u672c\u4f8b\u4e2d\uff0c\u5927\u7ea6\u9700\u8981 15 \u79d2\u624d\u80fd\u751f\u6210 2 \u6761\u6d88\u606f\uff0c\u8fd9\u4e9b\u6d88\u606f\u4e0e\u521d\u59cb\u503c 32f6df28e4a110970fb7f9938bee1686 \u53d1\u751f\u51b2\u7a81\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>$ time .\/fastcoll -i 32f6df28e4a110970fb7f9938bee1686 -o a b\nMD5 collision generator v1.5\nby Marc Stevens (http:\/\/www.win.tue.nl\/hashclash\/)\n\nUsing output filenames: 'a' and 'b'\nUsing initial value: 32f6df28e4a110970fb7f9938bee1686\n\nGenerating first block: .....................................\nGenerating second block: S10.............................................\nRunning time: 14.9727 s\n\nreal     0m14.981s\nuser     0m14.969s\nsys     0m0.006s\n<\/code><\/pre>\n\n\n\n<p>4\uff09\u7136\u540e\uff0c\u6211\u5c06\u751f\u6210\u7684\u4e24\u6761\u6d88\u606f\u9644\u52a0\u52301\u4e2d\u521b\u5efa\u7684\u6587\u4ef6\u4e2d\uff0c\u4ee5\u63d0\u4f9b\u4e24\u4e2a\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>5\uff09. \u8fd9\u4e24\u4e2a\u6587\u4ef6\u73b0\u5728\u5e94\u8be5\u5177\u6709\u76f8\u7b49\u7684\u957f\u5ea6\u5e76\u4e14\u5177\u6709\u76f8\u540c\u7684 MD5\uff0c\u4f46\u5b83\u4eec\u4e0d\u4f1a\u4f5c\u4e3a PHP \u8fd0\u884c\u3002\u6240\u4ee5\u6211\u5728\u4e24\u6279\u4e8c\u8fdb\u5236\u6570\u636e\u4e4b\u95f4\u6dfb\u52a0\u4e86\u8bed\u53e5\u3002<br>\u2018 == \u2018&nbsp;&#8216; == &#8216;<\/p>\n\n\n\n<p>6\uff09\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u78b0\u649ea\u9644\u52a0\u5230\u4e24\u4e2a\u6587\u4ef6\u4e2d\u3002\u8fd9\u5c06\u751f\u6210\u4e00\u4e2a\u8bed\u53e5\uff0c\u8be5\u8bed\u53e5\u5728\u6587\u4ef6 a \u4e2d\u4e3a true\uff08\u56e0\u4e3a 2 \u4e2a\u4e8c\u8fdb\u5236 blob \u786e\u5b9e\u76f8\u540c\uff09\uff0c\u4f46\u5728\u6587\u4ef6 b \u4e2d\u4e3a false\u3002<\/p>\n\n\n\n<p>7\uff09 \u6211\u5728\u4e24\u6761\u6d88\u606f\u4e2d\u9644\u52a0\u4e86\u76f8\u540c\u7684 PHP \u4ee5\u5b8c\u6210 if \u8bed\u53e5\u5e76\u751f\u6210\u60a8\u770b\u5230\u7684\u8f93\u51fa\u3002\u56e0\u6b64\uff0c\u5b9e\u9645\u4e0a\u6211\u4eec\u6709\u4e24\u4e2a\u6587\u4ef6\uff0c\u5176\u4e2d\u524d 64 \u4e2a\u5b57\u8282\u662f\u76f8\u540c\u7684\u3002\u63a5\u4e0b\u6765\u7684 128 \u4e2a\u5b57\u8282\u662f MD5 \u4e2d\u7684\u51b2\u7a81\uff0c\u7136\u540e\u662f\u76f8\u540c\u7684\u6240\u6709\u5176\u4ed6\u6587\u672c\u3002\u6beb\u4e0d\u5947\u602a\uff0c\u5f53\u901a\u8fc7\u6574\u4e2a MD5 \u7b97\u6cd5\uff08\u5305\u62ec\u586b\u5145\uff09\u4f20\u9012\u65f6\uff0c\u8fd9\u4f1a\u4ea7\u751f\u76f8\u540c\u7684 MD5 \u54c8\u5e0c\u503c\u3002<\/p>\n\n\n\n<p>\u867d\u7136\u8fd9\u79cd\u653b\u51fb\u53ef\u80fd\u770b\u8d77\u6765\u6beb\u65e0\u7528\u5904\uff0c\u56e0\u4e3a\u6587\u4ef6\u5145\u6ee1\u4e86 gobbledygook \u5e76\u4e14\u4f9d\u8d56\u4e8e\u76f8\u5f53\u660e\u663e\u7684 if \u8bed\u53e5\uff0c\u4f46\u6709\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u521b\u5efa\u5177\u6709\u76f8\u540c MD5 \u54c8\u5e0c\u503c\u7684\u6587\u4ef6\uff0c\u8fd9\u4e9b\u54c8\u5e0c\u503c\u4e0d\u4f9d\u8d56\u4e8e\u5f00\u5173\uff0c\u5e76\u4e14\u5176\u4f59\u6587\u4ef6\u5185\u5bb9\u53ef\u4ee5\u5b8c\u5168\u4e0d\u540c.<\/p>\n\n\n\n<p>\u53c2\u8003\u94fe\u63a5\uff1a<a href=\"https:\/\/www.aqwu.net\/wp\/?p=1942\">\u5982\u4f55\u4f7f\u7528\u76f8\u540c\u7684 MD5 \u54c8\u5e0c\u521b\u5efa\u4e24\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6<\/a><\/p>\n\n\n\n<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/natmchugh.blogspot.com\/2014\/10\/how-i-made-two-php-files-with-same-md5.html\">Nat McHugh: How I made two PHP files with the same MD5 hash &#8212; Nat McHugh\uff1a\u6211\u662f\u5982\u4f55\u7528\u76f8\u540c\u7684 MD5 \u54c8\u5e0c\u503c\u5236\u4f5c\u4e24\u4e2a PHP \u6587\u4ef6\u7684<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u6700\u8fd1\u5728 twitter \u4e0a\u53d1\u5e03\u4e86\u4e00\u4e2a\u6307\u5411\u4e24\u4e2a PHP \u811a\u672c\u7684\u94fe\u63a5\uff0c\u5b83\u4eec\u5177\u6709\u4e0d\u540c\u7684\u884c\u4e3a\uff0c\u4f46\u5177\u6709\u76f8\u540c\u7684 MD5  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[43],"tags":[385],"class_list":["post-1935","post","type-post","status-publish","format-standard","hentry","category-infoarticle","tag-md5"],"views":1080,"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1935"}],"version-history":[{"count":9,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1935\/revisions"}],"predecessor-version":[{"id":1952,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1935\/revisions\/1952"}],"wp:attachment":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}