python—base64
今天在写题时,执行脚本又报错了
脚本如下
#! /usr/bin/env python3 # _*_ coding:utf-8 _*_ import base64 # 字典文件路径 dic_file_path = ‘./10_million_password_list_top_100.txt‘ with open(dic_file_path, ‘r‘) as f: password_dic = f.readlines() username = ‘admin:‘ # 用户名 for password in password_dic: encodestr = base64.b64encode("admin:" + password.strip()) print(encodestr)
报错如下
Traceback (most recent call last): File "D:/python file/ctf/ctfhub http 基础认证密码/密码payload生成.py", line 12, in <module> encodestr = base64.b64encode("admin:" + password.strip()) File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\base64.py", line 58, in b64encode encoded = binascii.b2a_base64(s, newline=False) TypeError: a bytes-like object is required, not ‘str‘
上面最后一句话的意思是“类型错误:需要类似字节的对象,而不是字符串”。
于是更改为如下脚本
#! /usr/bin/env python3 # _*_ coding:utf-8 _*_ import base64 # 字典文件路径 dic_file_path = ‘./10_million_password_list_top_100.txt‘ with open(dic_file_path, ‘r‘) as f: password_dic = f.readlines() username = ‘admin:‘ # 用户名 for password in password_dic: str1=str.encode(username + password.strip()) encodestr = base64.b64encode(str1) encodestr=str(encodestr) encodestr=encodestr.strip(‘b\‘‘) encodestr=encodestr.replace("=","\=") #避免“=”被转译 print(encodestr)
成功运行
相关推荐
pythonjw 2020-11-17
hedongli 2020-09-01
浪味仙 2020-08-17
IT兄弟团 2020-08-01
凉白开 2020-07-19
kjh00abc 2020-07-08
Skyline 2020-06-28
苦咖啡flask 2020-06-18
万物weiyi 2020-06-16
半纸药笺 2020-06-14
chenhaimeimeng 2020-06-13
JF0 2020-06-13
逍遥友 2020-06-02
kyelu 2020-06-02
northwindx 2020-05-31
tengyuan 2020-05-30
singer 2020-05-30
GreatZhou 2020-05-28
coolhty 2020-05-20