32 lines
519 B
Python
32 lines
519 B
Python
from passlib.hash import sha512_crypt
|
|
import random
|
|
import string
|
|
import time
|
|
|
|
username = "test"
|
|
password = "test"
|
|
|
|
# 生成16位随机salt
|
|
salt = ''.join(
|
|
random.choices(
|
|
string.ascii_letters + string.digits,
|
|
k=16
|
|
)
|
|
)
|
|
|
|
# salt = 'uu2JGUu15xlX4eWn'
|
|
|
|
# Ubuntu SHA512 shadow格式
|
|
hashed = sha512_crypt.hash(
|
|
password,
|
|
salt=salt,
|
|
rounds=5000
|
|
)
|
|
|
|
# Linux shadow日期
|
|
days = int(time.time() / 86400)
|
|
|
|
# 拼接shadow内容
|
|
shadow = f"{username}:{hashed}:{days}:0:99999:7:::"
|
|
|
|
print(shadow) |