标签:字符 require 执行 txt required release span info username
今天在写题时,执行脚本又报错了
脚本如下
#! /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)
成功运行
标签:字符 require 执行 txt required release span info username
原文地址:https://www.cnblogs.com/anweilx/p/12403902.html