Last active
August 20, 2019 15:59
-
-
Save Sicalxy/435c78326371d479f842dcb6eae08a30 to your computer and use it in GitHub Desktop.
Here are some python3 scripts for Bugku Writeup
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
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) |
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
cipher = 'szzyfimhyzd' | |
plain = '' | |
for c in cipher: | |
y = ord(c) - ord('a') | |
x = (y + 8) * 23 % 26 | |
plain += chr(x + ord('a')) | |
print(plain) |
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
import base91 | |
b91 = '@iH<,{bdR2H;i6*Tm,Wx2izpx2!' | |
flag = base91.decode(b91).decode() | |
print(flag) |
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
jefferson_origin = ['ZWAXJGDLUBVIQHKYPNTCRMOSFE', | |
'KPBELNACZDTRXMJQOYHGVSFUWI', | |
'BDMAIZVRNSJUWFHTEQGYXPLOCK', | |
'RPLNDVHGFCUKTEBSXQYIZMJWAO', | |
'IHFRLABEUOTSGJVDKCPMNZQWXY', | |
'AMKGHIWPNYCJBFZDRUSLOQXVET', | |
'GWTHSPYBXIZULVKMRAFDCEONJQ', | |
'NOZUTWDCVRJLXKISEFAPMYGHBQ', | |
'QWATDSRFHENYVUBMCOIKZGJXPL', | |
'WABMCXPLTDSRJQZGOIKFHENYVU', | |
'XPLTDAOIKFZGHENYSRUBMCQWVJ', | |
'TDSWAYXPLVUBOIKZGJRFHENMCQ', | |
'BMCSRFHLTDENQWAOXPYVUIKZGJ', | |
'XPHKZGJTDSENYVUBMLAOIRFCQW'] | |
key = [2, 5, 1, 3, 6, 4, 9, 7, 8, 14, 10, 13, 11, 12] | |
cipher = 'HCBTSXWCRQGLES' | |
jefferson = [] | |
for i in range(14): | |
current = jefferson_origin[key[i] - 1] | |
start = current.index(cipher[i]) | |
current = current[start:] + current[:start] | |
jefferson.append(current) | |
for i in range(26): | |
for s in jefferson: | |
print(s[i], end='') | |
print() |
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
with open('text.txt') as f: | |
text = f.read() | |
numbers = text.split(' ') | |
base = {'d':10, | |
'b':2, | |
'o':8, | |
'x':16, | |
} | |
flag = '' | |
for number in numbers: | |
flag += chr(int(number[1:], base[number[0]])) | |
print(flag) |
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
import base64 | |
hexStr = '636A56355279427363446C4A49454A7154534230526D684356445A31614342354E326C4B4946467A5769426961453067' | |
print(hexStr) | |
hex2bytes = bytes.fromhex(hexStr) | |
print(hex2bytes) | |
b64dec = base64.b64decode(hex2bytes) | |
print(b64dec) |
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
cipher = '666c61677b616537333538376261353662616566357d' | |
print(bytes.fromhex(cipher)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment