{"id":952,"date":"2023-06-17T15:18:28","date_gmt":"2023-06-17T07:18:28","guid":{"rendered":"https:\/\/swordofmorning.com\/?p=952"},"modified":"2025-10-09T13:55:19","modified_gmt":"2025-10-09T05:55:19","slug":"jpeg-steganography","status":"publish","type":"post","link":"https:\/\/swordofmorning.com\/index.php\/2023\/06\/17\/jpeg-steganography\/","title":{"rendered":"JPEG\u56fe\u50cf\u9690\u5199"},"content":{"rendered":"<p>&emsp;&emsp;\u73b0\u5728\u6211\u4eec\u6709\u5982\u4e0b\u9700\u6c42\uff1a\u5728\u4e00\u5f20\u56fe\u7247\u4e2d\u6dfb\u52a0\u4e00\u6bb5\u8bed\u97f3\u6ce8\u91ca\u3002\u5bf9\u4e8eJPEG\u683c\u5f0f\u6765\u8bf4\uff0c\u5176\u5b58\u5728<code>JPEG_COM(0xFF 0xFE)<\/code>\uff0c\u56e0\u6b64\u53ef\u4ee5\u7528\u6765\u5199\u5165\u6ce8\u91ca\uff0c\u4f46\u5176\u957f\u5ea6\u53ea\u670965536\u4e2a\u5b57\u8282\uff08<code>JPEG_COM<\/code>\u540e\u4e24\u4e2a\u5b57\u8282\u8868\u793a\u957f\u5ea6\uff09\uff0c\u56e0\u6b64\u5e76\u4e0d\u9002\u7528\u4e8e\u957f\u6570\u636e\u6d41\u7684\u5b58\u653e\u3002\u5bf9\u6b64\u6211\u4eec\u8003\u8651\u4f7f\u7528\u6587\u4ef6\u9690\u5199\uff08Steganography\uff09\u7684\u65b9\u5f0f\u6765\u5b8c\u6210\u56fe\u50cf\u540e\uff08\u6587\u4ef6\u5c3e\u6807\u8bc6\u7b26\u4e4b\u540e\uff09\u6dfb\u52a0\u5176\u4ed6\u4fe1\u606f\u7684\u529f\u80fd\u3002<\/p>\n<h2>\u4e00\u3001JPEG\u683c\u5f0f\u548c\u6807\u8bb0<\/h2>\n<p>\u5728\u672c\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u4e0d\u53bb\u8ba8\u8bbaJPEG\u7684\u5177\u4f53\u7f16\u7801\u95ee\u9898\uff0c\u800c\u76f4\u63a5\u4ece\u6807\u8bb0\u5165\u624b\uff0c\u5feb\u901f\u4e86\u89e3JPEG\u7684\u5927\u6982\u6837\u8c8c\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u540d\u79f0<\/th>\n<th style=\"text-align: center;\">\u6807\u8bb0\u7801<\/th>\n<th style=\"text-align: center;\">\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">SOI<\/td>\n<td style=\"text-align: center;\">D8<\/td>\n<td style=\"text-align: center;\">Start of Image<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">SOF0<\/td>\n<td style=\"text-align: center;\">C0<\/td>\n<td style=\"text-align: center;\">Start of Frame<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">SOF1<\/td>\n<td style=\"text-align: center;\">C1<\/td>\n<td style=\"text-align: center;\">Start of Frame<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">DHT<\/td>\n<td style=\"text-align: center;\">C4<\/td>\n<td style=\"text-align: center;\">Define Huffman Tables<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">DQT<\/td>\n<td style=\"text-align: center;\">DB<\/td>\n<td style=\"text-align: center;\">Define Quantization Tables<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">DRI<\/td>\n<td style=\"text-align: center;\">DD<\/td>\n<td style=\"text-align: center;\">Define Restart Interval<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">SOS<\/td>\n<td style=\"text-align: center;\">DA<\/td>\n<td style=\"text-align: center;\">Start of Scan<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">RSTn<\/td>\n<td style=\"text-align: center;\">Dn<\/td>\n<td style=\"text-align: center;\">Restart n\u2208{0...7}<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">APPn<\/td>\n<td style=\"text-align: center;\">En<\/td>\n<td style=\"text-align: center;\">Application Specific n\u2208{0...7}<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">COM<\/td>\n<td style=\"text-align: center;\">FE<\/td>\n<td style=\"text-align: center;\">Comment<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">EOI<\/td>\n<td style=\"text-align: center;\">D9<\/td>\n<td style=\"text-align: center;\">End of Image<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e0a\u9762\u7684\u6807\u8bb0\u5747\u4e3a\u4e24\u4f4d\uff0c\u7b2c\u4e00\u4f4d\u4e3a<code>0xFF<\/code>\uff0c\u7b2c\u4e8c\u4f4d\u4e3a\u6807\u8bb0\u3002\u4f8b\u5982\uff0cCOM\u7684\u5b8c\u6574\u6807\u8bc6\u7b26\u4e3a<code>FF FE<\/code>\u3002\u5bf9\u4e8e\u4e0a\u9762\u7684\u6807\u8bb0\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5173\u6ce8\uff1a<code>EOI<\/code>\u3001<code>COM<\/code>\u5373\u53ef\u3002\u5bf9\u4e8eJPEG\u7684\u89e3\u6790\uff0c\u8bfb\u53d6\u5230<code>EOI<\/code>\u4e4b\u540e\u5c31\u7ed3\u675f\u4e86\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5728<code>EOI<\/code>\u4e4b\u540e\u8ffd\u52a0\u6211\u4eec\u60f3\u8981\u6dfb\u52a0\u7684\u5185\u5bb9\u3002<\/p>\n<pre><code class=\"language-python\">txt = &#039;\u4f60\u597d PyHub!&#039;\n\n# \u8bfb\u53d6\u539f\u59cbJPEG\u56fe\u50cf\u6570\u636e\nwith open(&quot;input.jpg&quot;, &quot;rb&quot;) as f:\n    f_bytes = f.read()\n    print(f_bytes[:2])\n    print(f_bytes[-2:])\n\n# \u7f16\u7801\nwith open(&quot;input.jpg&quot;, &quot;rb&quot;) as f:\n    with open(&quot;output.jpg&quot;, &quot;wb&quot;) as output:\n        output.write(f.read())\n        output.write(&#039;\u4f60\u597d PyHub!&#039;.encode())\n\n# \u89e3\u7801\nwith open(&quot;output.jpg&quot;, &quot;rb&quot;) as f:\n    content = f.read()\n    eoi = content.find(b&#039;\\xff\\xd9&#039;)\n    print(content[eoi+2:].decode())<\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u8bfb\u53d6\u4e86\u4e00\u5f20\u56fe\u7247\uff0c\u7136\u540e\u5728\u6587\u4ef6\u7684\u672b\u5c3e\u76f4\u63a5\u6dfb\u52a0\u5b57\u7b26\u4e32<code>txt<\/code>\uff08\u5bf9\u4e8e\u666e\u901a\u7684JPEG\u6765\u8bf4\uff0cEOI\u4f4d\u4e8e\u6587\u4ef6\u672b\u5c3e\uff09\u3002\u5728\u89e3\u7801\u7684\u65f6\u5019\uff0c\u6211\u4eec\u67e5\u627e\u5230<code>0xFF 0xD9<\/code>\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u8bfb\u53d6\u4e4b\u540e\u7684\u4ee3\u7801\uff0c\u5373\u53ef\u5b9e\u73b0\u9690\u5199\u3002<\/p>\n<h3>\u4e8c\u3001\u9690\u5199\u6587\u4ef6<\/h3>\n<p>\u5bf9\u4e8e\u9690\u5199\u6587\u4ef6\uff0c\u5219\u8981\u591a\u4e00\u6b65\u3002\u5982\u679c\u6587\u4ef6\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u88ab\u6dfb\u52a0\u5728\u4e86<code>EOI<\/code>\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u62c5\u5fc3\u662f\u5426\u4f1a\u51fa\u73b0<code>0xFF 0xNN<\/code>\u7684\u60c5\u51b5\uff0c\u56e0\u6b64\u8fd9\u91cc\u63a8\u8350\u4f7f\u7528base64\u7f16\u7801\u4e4b\u540e\u518d\u8fdb\u884c\u8ffd\u52a0\uff0c\u907f\u514d\u53d1\u751f\u610f\u5916\u60c5\u51b5\u3002<\/p>\n<pre><code class=\"language-python\">import base64\n\n# \u8bfb\u53d6WAV\u6587\u4ef6\u5e76\u8f6c\u6362\u4e3aBase64\u5b57\u7b26\u4e32\nwith open(&quot;CantinaBand3.wav&quot;, &quot;rb&quot;) as wav_file:\n    wav_data = wav_file.read()\n    base64_data = base64.b64encode(wav_data).decode()\n\n# \u8bfb\u53d6\u539f\u59cbJPEG\u56fe\u50cf\u6570\u636e\nwith open(&quot;input.jpg&quot;, &quot;rb&quot;) as f:\n    f_bytes = f.read()\n    print(f_bytes[:2])\n    print(f_bytes[-2:])\n\n# \u7f16\u7801\nwith open(&quot;input.jpg&quot;, &quot;rb&quot;) as f:\n    with open(&quot;output.jpg&quot;, &quot;wb&quot;) as output:\n        output.write(f.read())\n        output.write(base64_data.encode())\n\n# \u89e3\u7801\nwith open(&quot;output.jpg&quot;, &quot;rb&quot;) as f:\n    content = f.read()\n    eoi = content.find(b&#039;\\xff\\xd9&#039;)\n    base64_str = content[eoi+2:].decode()\n    wav_data = base64.b64decode(base64_str)\n\n# \u5c06Base64\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3aWAV\u6587\u4ef6\nwith open(&quot;output.wav&quot;, &quot;wb&quot;) as wav_file:\n    wav_file.write(wav_data)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&emsp;&emsp;\u73b0\u5728\u6211\u4eec\u6709\u5982\u4e0b\u9700\u6c42\uff1a\u5728\u4e00\u5f20\u56fe\u7247\u4e2d\u6dfb\u52a0\u4e00\u6bb5\u8bed\u97f3\u6ce8\u91ca\u3002\u5bf9\u4e8eJPEG\u683c\u5f0f\u6765\u8bf4\uff0c\u5176\u5b58\u5728JPEG_COM(0xFF  &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[236],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/952"}],"collection":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/comments?post=952"}],"version-history":[{"count":1,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/952\/revisions"}],"predecessor-version":[{"id":953,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/952\/revisions\/953"}],"wp:attachment":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/media?parent=952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/categories?post=952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/tags?post=952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}