TscanPlus License 生成
看到有分享pj的,遂简单分析了下注册,
关注两个地方
1、TscanGui_conf_CheckExpireAndLic==》TscanGui_conf_VerifyLicense、
校验License.lic
2、TscanGui_conf_GenerateLicense
在线注册
流程很简单,lic结构直接看py脚本。
py
生成License.lic后放到config目录下;仅支持windows和linux;
import binascii
import json
# pip install pycryptodome
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad, pad
from datetime import datetime, timedelta, timezone
import subprocess
#pip install netifaces
import netifaces
import sys
IS_WIN=False
if sys.platform.startswith('linux'):
print('当前系统为 Linux')
elif sys.platform.startswith('win'):
IS_WIN=True
print('当前系统为 Windows')
def expiration_date():
d = b'lOls4LsgND9tbI5iFPehCw=='
d = binascii.a2b_base64(d)
dec = aes_dec(d)
print(dec, dec.hex())
# TscanGui_conf_aesDecrypt
def aes_dec(data: bytes, key=b'TIDETideTidEtide', iv=b'') -> bytes:
if not iv:
iv = key
# iv=b'TIDETideTidEtide'
# key=iv
aes_cipher = AES.new(key=key, iv=iv, mode=AES.MODE_CBC)
enc = aes_cipher.decrypt(data)
enc = unpad(enc, 16)
return enc
# TscanGui_conf_aesEncrypt
def aes_enc(data: bytes, key=b'TIDETideTidEtide', iv=b'') -> bytes:
if not iv:
iv = key
# iv=b'TIDETideTidEtide'
# key=iv
aes_cipher = AES.new(key=key, iv=iv, mode=AES.MODE_CBC)
data = pad(data, 16)
dec = aes_cipher.encrypt(data)
return dec
def get_conf_key_iv() -> tuple:
data = b'po+YtXmdIDSWZ+NbyX8WD55EpALJatOoIAXiL+KyQ+hV5QT4grjCgBGSyRMV5AvC'
bs = binascii.a2b_base64(data)
# print(bs)
conf_key = aes_dec(bs)
print('conf_key:%s\n' % conf_key)
data2 = b'po+YtXmdIDSWZ+NbyX8WD+fUiEEtwIdn2GleQuc0XDM='
bs2 = binascii.a2b_base64(data2)
# print(bs2)
conf_iv = aes_dec(bs2)
print('conf_iv:%s\n' % conf_iv)
return (conf_key, conf_iv)
'''
//c
struct conf_AppLic
{
string ExpiredDateStr;
bool Expired;
string VipStatus;
string VipTime;
string LicenseKey;
};
//c
struct conf_KeyData
{
string PocID;
int64 PocVipTime;
string UUID;
int64 Time;
int64 CheckTime;
};
//go
type conf.KeyData struct {
PocID string `json:"poc_id"`
PocVipTime int64 `json:"poc_vip_time"`
UUID string `json:"uuid,omitempty"`
Time int64 `json:"time,omitempty"`
CheckTime int64 `json:"checktime,omitempty"`
}
'''
# CONF_KEY, CONF_IV = get_conf_key_iv()
CONF_KEY=b'IAa17zZIQ3sGstCJtGOV5RTQbzgUL2su'
CONF_IV=b'IAa17zZIQ3sGstCJ'
def mk_conf_KeyData(mac:bytes,cpuid:bytes,id='xxxx') -> bytes:
conf_AppLic = {
'poc_id': id,
'poc_vip_time': int(datetime.strptime('2099-01-01', '%Y-%m-%d').timestamp()),
'uuid': aes_enc(cpuid+mac, CONF_KEY, CONF_IV).hex().upper(),#op
'time': int(datetime.now().timestamp()),#op
'checktime': int(datetime.strptime('2024-07-21', '%Y-%m-%d').timestamp()),#op
}
# conf_AppLic={}
# conf_AppLic['poc_vip_time'] = int(datetime.strptime('2099-01-01', '%Y-%m-%d').timestamp())
# conf_AppLic['checktime'] = int(datetime.strptime('2024-07-21', '%Y-%m-%d').timestamp())
# conf_AppLic['time'] = int(datetime.now().timestamp())
# conf_AppLic['uuid'] = aes_enc(cpuid+mac, CONF_KEY, CONF_IV).hex().upper()
lic = json.dumps(conf_AppLic).encode()
print('lic:', lic)
enc = aes_enc(lic, CONF_KEY, CONF_IV)
print('key:',enc.hex().upper())
return enc
def get_default_gateway_interface():
# 获取默认网关信息
gateways = netifaces.gateways()
default_gateway = gateways.get('default')
interface=None
if len(default_gateway)==0:
# return None
interface = netifaces.interfaces()[0]
else:
# 取出默认网关接口
_, interface = default_gateway[netifaces.AF_INET]
return interface
def get_mac_address(interface):
# 获取指定接口的MAC地址
addresses = netifaces.ifaddresses(interface)
mac = addresses[netifaces.AF_LINK][0]['addr']
return mac
def get_outbound_mac_str():
interface = get_default_gateway_interface()
if interface:
return get_mac_address(interface)
return None
def get_processor_id()->str:
win_cmd=['wmic', 'cpu', 'get', 'ProcessorId']
linux_cmd=['cat','/proc/cpuinfo']
try:
# 执行命令并获取输出
cmd=win_cmd
if not IS_WIN:
cmd=linux_cmd
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
lines = result.stdout.strip()
return lines
except subprocess.CalledProcessError as e:
print(f"Error executing command: {e}")
return ''
if __name__ == '__main__':
mac= get_outbound_mac_str().encode()
#fix diff with golang
if IS_WIN:
processor_idS=get_processor_id().split()
cpuid=' \r\r\n'.join(processor_idS).encode()
else:
cpuid=get_processor_id().encode()
id='ikun'
print('cpuid:',cpuid)
print('mac:',mac)
print('id:',id)
out=mk_conf_KeyData(mac,cpuid,id)
with open('License.lic','wb') as f:
f.write(out.hex().encode())
print('exit')