帮同学做了个小作业,相信大家也可以是试一试,勤动手。脚本要求如下:
from urllib import parse
from urllib import request
import binascii
def unincode(strtest):
print(strtest.encode('utf8').decode('unicode_escape'))
def urlcode(strtest):
strtest.encode('utf8').decode('unicode_escape')
urlcode2 = parse.unquote(strtest)
print(urlcode2)
def hexcode(strtest):
hex = strtest.encode('utf-8')
str_bin = binascii.unhexlify(hex)
print(str_bin.decode('utf-8'))
url_code= "%"
unincode_code="\/"
input_psd="\sdada"
string = "[]\/"
string1 = "%/"
flag=True
file_path = "/root/codetest.txt"
with open("/root/codetest.txt", "r") as f:
for line in f.readlines():
line = line.strip('\n') #去掉列表中每一个元素的换行符
for i in string:
if i in line:
unincode(line)
for i in string1:
if i in line:
urlcode(line)
if line.isdigit()==flag:
hexcode(line)
脚本存在如下问题:
1.脚本的判断编码格式存在问题,我暂时还没想到有什么非常优秀的解决方案,当然换一种思考方式,我可以增加参数选项,但是这就和自动化去跑解码没关系了。
2.脚本目前实现了解码hex,解码url编码,解码unicode,反正是readlines按行读取文本,暴力的按照题意解决了题目问题。
3.脚本可以拿来直接用,但是我觉得放着已有的优秀工具不用就是找苦吃。
可以编解码工具,burp,小葵转码,chrome插件------等我csdn上传工具即可