Last active
August 15, 2019 15:12
-
-
Save Sicalxy/973efad061a6d5cedcaf9962c0e240b7 to your computer and use it in GitHub Desktop.
bugku 的“一段Base64”是洋葱
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- encoding: utf-8 -*- | |
''' | |
https://ctf.bugku.com/challenges#%E4%B8%80%E6%AE%B5Base64 | |
''' | |
import base64 | |
import html | |
from urllib import parse | |
# 打开文件 | |
with open('1.txt') as f: | |
cipher_base64 = f.read() | |
# base64 解密 | |
cipher_oct = base64.b64decode(cipher_base64.encode()).decode() | |
# 8 进制分割成列表 | |
list_oct = cipher_oct.split('\\') | |
list_oct.pop(0) | |
# 连接 8 进制数成 bytes 再成 str | |
cipher_hex = bytes([int(i, 8) for i in list_oct]).decode() | |
# 解析 16 进制数成 bytes | |
cipher_unicode = bytes.fromhex(cipher_hex.replace('\\x', '')) | |
# 解析 unicode_escape | |
# cipher_charcode = bytes.fromhex(cipher_unicode.replace('\\u00', '')).decode() | |
cipher_charcode = cipher_unicode.decode('unicode_escape') | |
# 取出括号中内容并分割 ascii 码 | |
list_charcode = cipher_charcode[20:-1].split(',') | |
# 连接 ascii 码并转成 str | |
cipher_html_1 = bytes([int(i) for i in list_charcode]).decode() | |
# 解析 html 转义符两次 | |
cipher_html_2 = html.unescape(cipher_html_1) | |
cipher_url = html.unescape(cipher_html_2) | |
# 解析 url 转义符 | |
flag = parse.unquote(cipher_url) | |
print(flag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment