{"id":5566,"date":"2023-11-30T20:02:00","date_gmt":"2023-11-30T12:02:00","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=5566"},"modified":"2023-11-29T20:37:19","modified_gmt":"2023-11-29T12:37:19","slug":"%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%9a%84%e7%bc%96%e7%a0%81-%e5%8a%a0%e5%af%86%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/5566.html","title":{"rendered":"\u5982\u4f55\u5224\u65ad\u5b57\u7b26\u4e32\u7684\u7f16\u7801\/\u52a0\u5bc6\u7c7b\u578b"},"content":{"rendered":"\n<p>=Start=<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7f18\u7531\uff1a<\/h4>\n\n\n\n<p>\u7531\u524d\u6bb5\u65f6\u95f4\u7684\u4e00\u4e2a\u6570\u636e\u53d8\u5f62\uff08\u52a0\u5bc6\u3001\u7f16\u7801\uff09case\u5f15\u8d77\u7684\u4e00\u4e9b\u601d\u8003\u548c\u5c1d\u8bd5\uff0c\u7b80\u5355\u8bb0\u5f55\u4e00\u4e0b\uff0c\u65b9\u4fbf\u540e\u9762\u6709\u9700\u8981\u7684\u65f6\u5019\u53c2\u8003\u3002<\/p>\n\n\n\n<p>\u5c5e\u4e8e\u9690\u5199\u672f\u7684\u4e00\u4e2a\u521d\u7ea7\u7248\u672c\uff0c\u7aef\u4e0a\u7684\u8fd9\u79cd\u53d8\u5f62\u5343\u53d8\u4e07\u5316\uff0c\u6ca1\u6709\u5b8c\u5168\u7a77\u4e3e\u7684\u53ef\u80fd\uff0c\u8fd9\u91cc\u53ea\u662f\u505a\u4e2a\u601d\u8003\uff0c\u771f\u6b63\u60f3\u8981\u505a\u597d\u6570\u636e\u5b89\u5168\u5de5\u4f5c\uff0c\u9700\u8981\u5f3a\u5316\u201c\u5de6\u79fb\u201d\u7684\u601d\u60f3\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b63\u6587\uff1a<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n\n\n\n<p>Ciphey\u7684\u5b9e\u9645\u8bd5\u7528\u6548\u679c\u4e00\u822c\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u5b83\u5177\u5907\u7684\u529f\u80fd\u548c\u6211\u7684\u671f\u671b\u4e0d\u4e00\u81f4\uff0c<strong>\u6211\u671f\u671b\u7684\u662f\u8ba9\u5b83\u5e2e\u6211\u5feb\u901f\u5224\u5b9a\u8f93\u5165\u7684\u5b57\u7b26\u4e32\/\u6587\u4ef6\u7684\u7f16\u7801\/\u52a0\u5bc6\u7c7b\u578b\u662f\u4ec0\u4e48\uff08\u4ee5\u8f85\u52a9\u5224\u65ad\u540e\u9762\u8be5\u5982\u4f55\u64cd\u4f5c\uff09\uff0c\u4f46\u662f\u6839\u636e\u5b83\u7684\u63cf\u8ff0\u5b83\u7684\u529f\u80fd\u662f\u81ea\u52a8\u89e3\u5bc6\u3001\u89e3\u7801\u548c\u7834\u89e3\u54c8\u5e0c\u503c<\/strong>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5728macOS\u7cfb\u7edf\u4e0a\u5b89\u88c5 Ciphey\nbrew install ciphey\n\n# \u8fd0\u884c Ciphey \u76843\u79cd\u65b9\u5f0f\n\n1. \u6587\u4ef6\u8f93\u5165\n\nciphey -f encrypted.txt\n\n2. \u4e0d\u7b26\u5408\u8981\u6c42\u7684\u8f93\u5165(Unqualified input)\n\nciphey -- \"Encrypted input\"\n\n3. \u5e38\u89c4\u65b9\u5f0f\n\nciphey -t \"Encrypted input\"<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7\u4f7f\u7528Python\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u7136\u540e\u5224\u65ad\u8bfb\u53d6\u7684\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u5305\u542b\u53ef\u6253\u5370\u5b57\u7b26\u7684\u65b9\u5f0f\u4e5f\u4e0d\u592a\u53ef\u884c\uff08\u7f16\u7801\u540e\u5b58\u50a8\u7684\u65f6\u5019\u6709\u4eba\u4e60\u60ef\u7528\u5b57\u7b26\u4e32\u7684\u65b9\u5f0f\u6709\u4eba\u4e60\u60ef\u7528bytes\u7684\u65b9\u5f0f\uff0c\u5b57\u7b26\u4e32\u7684\u5224\u65ad\u4e0d\u5224\u65ad\u610f\u4e49\u4e0d\u5927\u2014\u2014\u56e0\u4e3a\u57fa\u672c\u8fdb\u884c\u8fc7base64\u7b49\u7f16\u7801\u5904\u7406\uff0cbytes\u7684\u65b9\u5f0f\u4f60\u4e5f\u5224\u65ad\u4e0d\u51fa\u6765\uff09\u3002<\/p>\n\n\n\n<p>\u6211\u60f3\u4e86\u60f3\uff0c\u4e00\u4e2a\u57fa\u672c\u53ef\u4ee5\u8dd1\u901a\u7684\u6d41\u7a0b\u662f\u2014\u2014<strong>\u5148\u501f\u52a9 file\/wc \u7b49\u547d\u4ee4\u5224\u65ad\u6587\u4ef6\u7c7b\u578b\uff0c\u7136\u540e\u518d\u5bf9\u6587\u4ef6\u7684 base64 \u884c\u6570\u91cf\u7b49\u6307\u6807\u8fdb\u884c\u7edf\u8ba1\uff0c\u7ed9\u51fa\u4e00\u4e9b\u5173\u4e8e\u8fd9\u4e2a\u6587\u4ef6\u7684\u6807\u7b7e\u3001\u9884\u6d4b\u4fe1\u606f\u5373\u53ef\uff0c\u4e0d\u9700\u8981\u8fdb\u884c\u81ea\u52a8\u89e3\u5bc6\u3001\u89e3\u7801\u5904\u7406\uff0c\u5148\u8bb0\u5f55\u540e\u5904\u7406\uff08\u56e0\u4e3a\u4f60\u5f53\u65f6\u5904\u7406\u4e0d\u4e00\u5b9a\u80fd\u5904\u7406\u7684\u8fc7\u6765\uff0c\u51c6\u786e\u6027\u548c\u6027\u80fd\u635f\u8017\u53ef\u80fd\u90fd\u4e0d\u884c\uff09<\/strong>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import subprocess\n'''\nfile\u547d\u4ee4\u8fd4\u56de\u7684\u6587\u4ef6\u7c7b\u578b\u4fe1\u606f\u4e2d\u5305\u542b\u4ee5\u4e0b\u7684\u5173\u952e\u8bcd\u65f6\u9700\u8981\u5173\u6ce8\uff1a\nwith very long lines\nMultitracker Version\ndata\n'''\ndef get_file_info(filepath, info_type='file'):\n    # \u6784\u5efa\u547d\u4ee4\n    if info_type.strip().lower() == 'wc':\n        cmd = 'wc {}'.format(filepath)\n    else:\n        cmd = 'file -b {}'.format(filepath)\n\n    # \u6267\u884c\u547d\u4ee4\u5e76\u8fd4\u56de\u7ed3\u679c\n    try:\n        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\n    except (OSError, ValueError) as e:\n        print(\"{0} failed, reason {1}\".format(cmd, str(e)))\n        return -1, str(e)\n    stdout_data, stderr_data = p.communicate()\n    if p.returncode != 0:\n        print(\"{0} failed, status code {1} stdout {2} stderr {3}\".format(cmd, p.returncode, stdout_data, stderr_data))\n        return p.returncode, stderr_data\n    return p.returncode, stdout_data.strip()\n\nprint(get_file_info(\"1.txt\"))\nprint(get_file_info(\"2.txt\"))\nprint(get_file_info(\"3.txt\"))\nprint(get_file_info(\"1.txt\", \"wc\"))\nprint(get_file_info(\"2.txt\", \"wc\"))\nprint(get_file_info(\"3.txt\", \"wc\"))<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env python3\n# coding=utf-8\n\nimport base64\nimport sys\n\n'''\na    YQ==\nab    YWI=\nabc    YWJj\n\nhello    aGVsbG8=\nhello7    aGVsbG83\n'''\n\nbase64_char_set = {\n    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'\n    ,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'\n    ,'0','1','2','3','4','5','6','7','8','9'\n    ,'+','\/','='\n}\n\n# true-&gt;1, false-&gt;0\ndef is_str_base64_encode(astr):\n\n    # base64\u7f16\u7801\u540e\u7684\u6570\u636e\u957f\u5ea6\u80af\u5b9a\u662f 4 \u7684\u500d\u6570\n    str_len = len(astr)\n    if 0 == str_len or str_len%4 != 0:\n        return 0\n\n    # base64\u7f16\u7801\u540e\u7684\u6570\u636e\u4e2d\uff0c\u7b49\u53f7(=)\u53ea\u4f1a\u51fa\u73b0\u5728\u5b57\u7b26\u4e32\u6700\u540e\uff0c\u53ef\u80fd\u6ca1\u6709\u6216\u8005\u4e00\u4e2a\u7b49\u53f7\u6216\u8005\u4e24\u4e2a\u7b49\u53f7\n    if astr.count('=') &gt; 2:\n        return 0\n    elif astr.count('=') != astr&#91;-2:].count('='):\n        return 0\n\n    # base64\u7f16\u7801\u540e\u7684\u5b57\u7b26\u4e32\u53ea\u53ef\u80fd\u5305\u542b(A-Z,a-z,0-9,+,\/,=)\u5b57\u7b26\n    # \u4f46\u8fd9\u4e2a\u5224\u65ad\u6d89\u53ca\u5230\u6b63\u5219\u5904\u7406\u6bd4\u8f83\u6d88\u8017\u8d44\u6e90\u5c31\u4e0d\u8fdb\u884c\u4e86\uff0c\u6700\u4e3b\u8981\u662f\uff0c\u5373\u4fbf\u6ee1\u8db3\u8fd9\u79cd\u60c5\u51b5\u4e5f\u4e0d\u4e00\u5b9a\u662fbase64\u7f16\u7801\n    for x in astr:\n        if x in base64_char_set:\n            continue\n        else:\n            return 0\n    #for\n\n    # \u76f4\u63a5\u5c1d\u8bd5\u89e3\u7801\uff0c\u80fd\u89e3\u7801\u6210\u529f\u5219\u8bf4\u660eOK\uff0c\u8fd9\u4e2a\u6700\u51c6\u786e\n    try:\n        base64.b64decode(astr)\n    except Exception as e:\n        print(e)\n        return 0\n\n    return 1\n\ndef main():\n    line_count = 0\n    b64_count = 0\n    with open(sys.argv&#91;1], 'rb') as fp:\n        for line in fp:\n            line = line.decode(errors='ignore').strip() # https:\/\/stackoverflow.com\/a\/50359833\n            if line:\n                line_count += 1\n                b64_count += is_str_base64_encode(line)\n            #if\n        #for\n        print('{0}:b64_line_rate = {3}\\nline_count = {1}\\nb64_count = {2}\\n'.format(sys.argv&#91;1], line_count, b64_count, b64_count\/line_count))\n    #with\n\nif __name__ == '__main__':\n    main()<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n\n\n\n<p>Ciphey\u7684\u5b9e\u9645\u8bd5\u7528\u6548\u679c\u4e00\u822c\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u5b83\u7684\u529f\u80fd\u548c\u6211\u7684\u671f\u671b\u4e0d\u4e00\u81f4\uff0c\u6211\u671f\u671b\u7684\u662f\u8ba9\u5b83\u5e2e\u6211\u5224\u5b9a\u8f93\u5165\u7684\u5b57\u7b26\u4e32\/\u6587\u4ef6\u7684\u7f16\u7801\/\u52a0\u5bc6\u7c7b\u578b\uff0c\u4f46\u662f\u5b83\u7684\u63cf\u8ff0\u662f\u81ea\u52a8\u89e3\u5bc6\u3001\u89e3\u7801\u548c\u7834\u89e3\u54c8\u5e0c\u503c<br>Hacker Tools: Ciphey \u2013 Automatic decryption, decoding &amp; cracking (\u5728\u4e0d\u77e5\u9053\u5bc6\u94a5\u6216\u5bc6\u7801\u7684\u60c5\u51b5\u4e0b\u81ea\u52a8\u89e3\u5bc6\u3001\u89e3\u7801\u548c\u7834\u89e3\u54c8\u5e0c\u503c)<br><a href=\"https:\/\/blog.intigriti.com\/2021\/08\/11\/hacker-tools-ciphey\/\">https:\/\/blog.intigriti.com\/2021\/08\/11\/hacker-tools-ciphey\/<\/a><br><a href=\"https:\/\/github.com\/Ciphey\/Ciphey\">https:\/\/github.com\/Ciphey\/Ciphey<\/a><\/p>\n\n\n\n<p>Ciphey currently supports 51 encryptions, encodings, compression methods, and hashes.<br><a href=\"https:\/\/github.com\/Ciphey\/Ciphey\/wiki\/Supported-Ciphers\">https:\/\/github.com\/Ciphey\/Ciphey\/wiki\/Supported-Ciphers<\/a><\/p>\n\n\n\n<p>The Cyber Swiss Army Knife &#8211; a web app for encryption, encoding, compression and data analysis<br><a href=\"https:\/\/github.com\/gchq\/CyberChef\">https:\/\/github.com\/gchq\/CyberChef<\/a><br><a href=\"https:\/\/gchq.github.io\/CyberChef\/\">https:\/\/gchq.github.io\/CyberChef\/<\/a><\/p>\n\n\n\n<p>Cipher Identifier &#8211; Tool to identify\/recognize the type of encryption\/encoding applied to a message (more 200 ciphers\/codes are detectable). Cipher identifier to quickly decrypt\/decode any text.<br><a href=\"https:\/\/www.dcode.fr\/cipher-identifier\">https:\/\/www.dcode.fr\/cipher-identifier<\/a><\/p>\n\n\n\n<p>Enjoy Encoding &amp; Decoding!<br><a href=\"https:\/\/dencode.com\/\">https:\/\/dencode.com\/<\/a><\/p>\n\n\n\n<p>Encryption vs. Hashing vs. Salting &#8211; What&#8217;s the Difference?<br><a href=\"https:\/\/www.pingidentity.com\/en\/resources\/blog\/post\/encryption-vs-hashing-vs-salting.html\">https:\/\/www.pingidentity.com\/en\/resources\/blog\/post\/encryption-vs-hashing-vs-salting.html<\/a><\/p>\n\n\n\n<p>Encryption vs Encoding vs Hashing<br><a href=\"https:\/\/www.geeksforgeeks.org\/encryption-encoding-hashing\/\">https:\/\/www.geeksforgeeks.org\/encryption-encoding-hashing\/<\/a><\/p>\n\n\n\n<p>Cryptography with Python &#8211; Quick Guide<br><a href=\"https:\/\/www.tutorialspoint.com\/cryptography_with_python\/cryptography_with_python_quick_guide.htm\">https:\/\/www.tutorialspoint.com\/cryptography_with_python\/cryptography_with_python_quick_guide.htm<\/a><\/p>\n\n\n\n<p>How to Encrypt and Decrypt Files in Python<br><a href=\"https:\/\/thepythoncode.com\/article\/encrypt-decrypt-files-symmetric-python\">https:\/\/thepythoncode.com\/article\/encrypt-decrypt-files-symmetric-python<\/a><\/p>\n\n\n\n<p>How to determine what type of encoding\/encryption has been used?<br><a href=\"https:\/\/security.stackexchange.com\/questions\/3989\/how-to-determine-what-type-of-encoding-encryption-has-been-used\">https:\/\/security.stackexchange.com\/questions\/3989\/how-to-determine-what-type-of-encoding-encryption-has-been-used<\/a><\/p>\n\n\n\n<p>Test if a python string is printable<br><a href=\"https:\/\/stackoverflow.com\/questions\/3636928\/test-if-a-python-string-is-printable\/50731077#50731077\">https:\/\/stackoverflow.com\/questions\/3636928\/test-if-a-python-string-is-printable\/50731077#50731077<\/a><\/p>\n\n\n\n<p>TypeError: a bytes-like object is required, not &#8216;str&#8217;<br><a href=\"https:\/\/bobbyhadz.com\/blog\/python-typeerror-bytes-like-object-is-required-not-str\">https:\/\/bobbyhadz.com\/blog\/python-typeerror-bytes-like-object-is-required-not-str<\/a><\/p>\n\n\n\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u7531\u524d\u6bb5\u65f6\u95f4\u7684\u4e00\u4e2a\u6570\u636e\u53d8\u5f62\uff08\u52a0\u5bc6\u3001\u7f16\u7801\uff09case\u5f15\u8d77\u7684\u4e00\u4e9b\u601d\u8003\u548c\u5c1d\u8bd5\uff0c\u7b80\u5355\u8bb0\u5f55\u4e00\u4e0b\uff0c\u65b9\u4fbf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,7,25,12],"tags":[369,2069,2070,8,71],"class_list":["post-5566","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-programing","category-security","category-tools","tag-base64","tag-ciphey","tag-file","tag-python","tag-tools"],"views":2363,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=5566"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5566\/revisions"}],"predecessor-version":[{"id":5567,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5566\/revisions\/5567"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=5566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=5566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=5566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}