纯 Python 解 fun.coolshell.cn

admin 2021年4月2日20:24:06评论29 views字数 3904阅读13分0秒阅读模式

一个有意思的挑战解谜,http://fun.coolshell.cn

0-Fuck your brain

根据 title 在 Google 搜索 “fuck brain”,结果第一条

Brainfuck - Wikipedia, the free encyclopedia

根据维基百科内容,确定是 barinfuck 语言 Google 搜索 brainfuck online 找到在线解释器

http://esoteric.sange.fi/brainfuck/impl/interp/i.html

解密后内容 welcome.html

1-Multiply

先计算数列最后一项为 1944,访问 1944.html,提示 x = 1944

Google 搜索 “生命、宇宙以及任何事情的终极答案” 得到 y = 42

x * y

2-Keyboard

图片链接指向https://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard,显然需要把 Dvorak 和 QWERTY 做转换

Google 搜索 “dvorak online converter”, 用在线转换器转换后结果如下

main() { printf(&unix["21%six12"],(unix)["have"]+"fun"-0x60);}

继续用 Google,需要注意的地方,代码中有减号,搜索时需要在减号后面加空格,不然会被理解为排除关键字

printf(&unix["21%six12"],(unix)["have"]+"fun"- 0x60);

找到一篇文章 http://blog.sina.com.cn/s/blog_6adee4450100m6o9.html

最终代码为

printf("%sixn","un");

结果是 unix。

3-QR Code

二维码识别结果[abcdefghijklmnopqrstuvwxyz] [pvwdgazxubqfsnrhocitlkeymj]

简单的字符替换,Python 2.7 还原代码如下

import string
T = string.maketrans('pvwdgazxubqfsnrhocitlkeymj', 'abcdefghijklmnopqrstuvwxyz')
s = 'Wxgcg txgcg ui p ixgff, txgcg ui p epm. I gyhgwt mrl lig txg ixgff wrsspnd tr irfkg txui hcrvfgs, nre, hfgpig tcm liunz txg crt13 ra "ixgff" tr gntgc ngyt fgkgf.'
s.translate(T)

还原后内容

Where there is a shell, there is a way. I expect you use the shell command to solve this problem, now, please try using the rot13 of "shell" to enter next level

虽然作者希望用 shell 来做 rot13 变换,我还是继续用 Python

'shell'.encode('rot13')

4-cat

回文,仔细观察后规律为:必须包含大写字母和数字,中间为小写字母

在网页源码中找到代码,继续用 Python 处理

import re
l = re.findall(r'([A-Z])(d)([a-z])21|(d)([A-Z])([a-z])54', s)
''.join([i[2] if i[2] else i[5] for i in l])

结果

variables

5-variables

点击图片跳到 http://fun.coolshell.cn/n/2014,页面显示 32722

访问 http://fun.coolshell.cn/n/32722,页面显示 13310

上代码

import requests
u = 'http://fun.coolshell.cn/n/%d'
n = 2014
while 1:
  try:
    m = int(requests.get(u%n).text)
    n = m
  except:
    print n, m
    break

得到 20446

访问 http://fun.coolshell.cn/n/20446,拿到答案

Cool! the next level is "tree"

6-tree

需要根据中序遍历序列和后序遍历序列还原二叉树,然后找出最长路径

算法太渣,参考大量实例,用 Python 写了个二叉树实现 https://github.com/4ft35t/utils/blob/master/tree.py

from tree import Tree
in_list = 'T, b, H, V, h, 3, o, g, P, W, F, L, u, A, f, G, r, m, 1, x, J, 7, w, e, 0, i, Q, Y, n, Z, 8, K, v, q, k, 9, y, 5, C, N, B, D, 2, 4, U, l, c, p, I, E, M, a, j, 6, S, R, O, X, s, d, z, t'.split(',')
post_list = 'T, V, H, o, 3, h, P, g, b, F, f, A, u, m, r, 7, J, x, e, w, 1, Y, Q, i, 0, Z, n, G, L, K, y, 9, k, q, v, N, D, B, C, 5, 4, c, l, U, 2, 8, E, I, R, S, 6, j, d, s, X, O, a, M, p, W, t, z'.split(',')

t = Tree()
t.build_tree(in_order=in_list, post_order=post_list)
depth = t.get_all_depth()
max_depth = sorted(depth.items(), key= lambda x:x[1], reverse=True)[0]
print ''.join(t.get_path(max_depth[0])).replace(' ', '')

得到最长路径

zWp8LGn01wxJ7

再用 openssl 解密

$ echo U2FsdGVkX1+gxunKbemS2193vhGGQ1Y8pc5gPegMAcg=|openssl enc -aes-128-cbc -a -d -pass pass:zWp8LGn01wxJ7
nqueens

7-N Queens

N 皇后问题,需要解出 N = 9, code 需要从右往左写

依旧不会,继续 Google,关键字 “n queens problem python”

找到答案 n-queen-problem-in-python

原来 python 的 test 模块可以直接生成 N-Queens,并求解,高大上。解出的 code 需要和上一关的最长路径拼接,计算 sha1 == e48d316ed573d3273931e19f9ac9f9e6039a4242

完整代码如下

import hashlib
from test import test_generators as tg

n = tg.Queens(9)
s = n.solve()

def convert(lst):
  return ''.join(map(lambda x:str(x+1), lst[::-1]))

pw = 'zWp8LGn01wxJ7%sn'
for i in s:
  code = convert(i)
  sha1 = hashlib.sha1()
  sha1.update(pw % code)
  if sha1.hexdigest() == 'e48d316ed573d3273931e19f9ac9f9e6039a4242':
    print code
    break

结果

953172864

8-Excel Column

用 excel 的技术方法来表示 26 进制,和常规的区别是没有 0

def get_n(s):
  return sum(26 ** i * (ord(v) - ord('A') + 1) for i,v in enumerate(s[::-1]))

def get_str(n):
  ret = []
  while n:
    n, m = divmod(n, 26)
    ret.append(m)
  return ''.join(chr(i + ord('A') - 1) for i in ret[::-1])

s0 = 'COOLSHELL'
s1 = 'SHELL'

n0 = get_n(s0)
n1 = get_n(s1)
n = n0 / n1
print  n
print get_str(n)

最终结果 DUYO

9-Fraternal Organisation

Google 搜索两张图片,得到两个关键字 “猪圈” 和 “共济会”

两个关键字一起搜索,结果第一条

猪圈密码 - 维基百科,自由的百科全书

按右上角密码表解出答案 helloworld

隐藏关

源码中有一行

Did you even think vi a image file

下载图片用文本编辑器打开,看到

  • This Image actually is a RAR file as well.
  • 是个图片和压缩包合成的文件,该后缀为 rar,解压,helloworld.txt 倒数第二行

    next level: DennisRitchie.html

    PS: 写短代码用 Ipython,对效率提升非常有帮助。个人感觉比 Bpython 好用。

    == EOF ==

    原文地址:http://blog.4ft35t.tk/2014/08/09/Write-up-for-fun.coolshell.cn(提示:需翻墙,blog 在 GAE,用 Cloudflare 做代理。打不开请 FUCK 寡妇王

    文章来源于lcx.cc:纯 Python 解 fun.coolshell.cn

    相关推荐: Java爆破SVN、FTP、任何数据库、SMTP、SSH、LDAP。。。

    Java爆破SVN、FTP、任何数据库、SMTP、SSH、LDAP。。。 园长 (你在身边就是缘,缘分写在数据库里面。) | 2013-12-07 15:31 Java有很多开源的项目,用java求连接FTP、数据库、SVN之类的其实都很方便。既然可以很eas…

    • 左青龙
    • 微信扫一扫
    • weinxin
    • 右白虎
    • 微信扫一扫
    • weinxin
    admin
    • 本文由 发表于 2021年4月2日20:24:06
    • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                     纯 Python 解 fun.coolshell.cnhttp://cn-sec.com/archives/317310.html

    发表评论

    匿名网友 填写信息