那些年做过的ctf之加密篇(加强版)

时间:2021-06-30 08:12:54

MarkdownPad Document

*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}

h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* TABLES
=============================================================================*/

table th {
font-weight: bold;
}

table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}

table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}

table tr:nth-child(2n) {
background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->

那些年做过的ctf之加密篇(加强版)

大部分转自WooYun知识库,加入了笔者自己的理解

0x01 Base64

Base64: ZXZhbCgkX1BPU1RbcDRuOV96MV96aDNuOV9qMXVfU2gxX0oxM10pNTU2NJC3ODHHYWJIZ3P4ZWY=

Base64编码要求把3个8位字节(3*8=24)转化为4个6位的字节(4*6=24),之后在6位的前面补两个0,形成8位一个字节的形式。 如果剩下的字符不足3个字节,则用0填充,输出字符使用'=',因此编码后输出的文本末尾可能会出现1或2个'='

Base32: Base32和Base64相比只有一个区别就是,用32个字符表示256个ASC字符,也就是说5个ASC字符一组可以生成8个Base字符,反之亦然。

base64在线编解码:http://base64.xpcha.com/
base32在线解码(需*):http://emn178.github.io/online-tools/base32_decode.html
或者使用python脚本解码:

 C:\Python27>python
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import base64
>>> str = 'haha'
>>> base64.b64encode(str)
'aGFoYQ=='
>>> base64.b64decode('aGFoYQ==')
'haha'

把脚本中的b64decode换为b32decode即可实现base32的解码

0x02 希尔密码

希尔密码:密文: 22,09,00,12,03,01,10,03,04,08,01,17 (明文:wjamdbkdeibr)
解题思路:使用的矩阵是 1 2 3 4 5 6 7 8 10

百度百科:http://baike.baidu.com/link?url=R6oWhCdKvzlG8hB4hdIdUT1cZPbFOCrpU6lJAkTtdiKodD7eRTbASpd_YVfi4LMl7N8yFyhVNOz5ki6TC7_5eq

暂没找到合适的在线解密网站或者好用的脚本,只能对具体问题求解;如有好用的工具,忘不啬指教!

0x03 栅栏密码

栅栏密码:把要加密的明文分成N个一组,然后把每组的第1个字连起来,形成一段无规律的话。

密文样例:tn c0afsiwal kes,hwit1r g,npt ttessfu}ua u hmqik e {m, n huiouosarwCniibecesnren.

解密程序:

 char s[]= "tn c0afsiwal kes,hwit1r  g,npt  ttessfu}ua u  hmqik e {m,  n huiouosarwCniibecesnren.";
char t[]= "";
int i,j,k;
k=;
for (i=;i<;i++)
{
for(j=;j<;j++)
{
t[k++]= ch[j*+i];
}
}
for(i=;i<;i++)
{
printf("%c",t[i]);
}

或者利用本篇末尾提供的密码机器

0x04 凯撒密码

凯撒密码:通过把字母移动一定的位数来实现加密和解密。明文中的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文。
密文样例:U8Y]:8KdJHTXRI>XU#?!K_ecJH]kJGbRH7YJH7YSH]=93dVZ3^S8$:8"&:9U]RH;g=8Y!U92'=j$KH]ZSj&[S#!gU#*dK9.

解题思路:得知是凯撒加密之后,尝试进行127次轮转爆破:或者利用本篇末尾提供的密码机器;

lstr="""U8Y]:8KdJHTXRI>XU#?!K_ecJH]kJGbRH7YJH7YSH]=93dVZ3^S8$:8"&:9U]RH;g=8Y!U92'=j$KH]ZSj&[S#!gU#*dK9."""

解密脚本:

 for p in range(127):
str1 = ''
for i in lstr:
temp = chr((ord(i)+p)%127)
if 32<ord(temp)<127 :
str1 = str1 + temp
feel = 1
else:
feel = 0
break
if feel == 1:
print(str1)

0x05 Unicode

类似于ASCII码的一种编码方式:(详细资料http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html
密文样例:\u5927\u5bb6\u597d\uff0c\u6211\u662f\u0040\u65e0\u6240\u4e0d\u80fd\u7684\u9b42\u5927\u4eba\uff01\u8bdd\u8bf4\u5fae\u535a\u7c89\u4e1d\u8fc7\

在线解密:tool.chinaz.com/Tools/Unicode.aspx

0x06 brainfuck

请看我的另一篇关于Barinfuck与Ook!的博文http://www.cnblogs.com/WangAoBo/p/6373318.html

0x07 摩斯密码

就是影视剧中经常见到的那种密码
密文样例:-- --- .-. ... .

在线解密:http://www.jb51.net/tools/morse.htm
在线解密:http://www.zou114.com/mesm/

或者利用本篇末尾提供的密码机器

0x08 jsfuck

类似于brainfuck,也是一种替换密码,由( ) [ ] { } ! + 等符号组成

在线解密:http://utf-8.jp/public/jsfuck.html
在线解密:http://www.jsfuck.com/
在线解密:http://patriciopalladino.com/files/hieroglyphy/

或者直接再Chrome或者FIrefox的控制台中运行即可解码

0x09 培根密码

培根所用的密码是一种本质上用二进制数设计的。不过,他没有用通常的0和1来表示,而是采用a和b。

百科:http://baike.baidu.com/link?url=acaeI3babB7MogPQFh98rDAVSwHfPwh-HnEFTb9cx7DZ5Nz4MkMA14H4SDjBNnOdBsJpliNYa1vnfikQGqvA7K

0x0A 猪圈密码又称共济会密码

也是一种替换密码,替换方式如下:
那些年做过的ctf之加密篇(加强版)
或者可以表示成:
那些年做过的ctf之加密篇(加强版)

百度百科:http://baike.baidu.com/link?url=yN39kWG2pGd9XHo3RjeUAbd7xs0QlnJ2uHzCJfxC03V-fJcQUdfcJ-WuGoAkKGFVE0AxFK4-98wa4FtzvxRA0_

0x0B CRC32

密文样例:4D1FAE0B

 import zlib
def crc32(st):
crc = zlib.crc32(st)
if crc > 0:
return "%x" % (crc)
else:
return "%x" % (~crc ^ 0xffffffff)

本文持续更新,密码机器v1.0下载链接:http://pan.baidu.com/s/1hrIvpWS 密码:pdhx