python—base64

Today, when writing the title, and being given a script execution

Script as follows

#! /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)

 

Given as follows

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'

Last sentence above means " Type Error: byte-like object, rather than a string ."

Then changed to the following script

#! /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)

Successful operation

 

Guess you like

Origin www.cnblogs.com/anweilx/p/12403902.html