产业气象站|Strike一个历史遗留漏洞的研究,对红队利器Cobalt( 三 )


PUBLIC_KEY_TEMPLATE="-----BEGINPUBLICKEY-----{}-----ENDPUBLICKEY-----"
classMetadata(object):
"""
ClasstorepresentabeaconMetadataobject
"""
def__init__(self,data="",private_key="",public_key="",cs_version=4):
self.cs_version=cs_version
self.data=https://pcff.toutiao.jxnews.com.cn/p/20200712/data
self.public_key=public_key
self.private_key=private_key
self.port=0
self.ciphertext=""
self.charset=""
self.charset_oem=""
self.ver=""
self.intz=""
self.comp=""
self.user=""
self.pid=""
self.bid=""
self.barch=""
self.raw_aes_keys=""
self.aes_key=""
self.hmac_key=""
self.is64=False
self.high_integrity=False
ifdataandlen(data)!=128:
raiseAttributeError("Metadatashouldbe128bytes")
ifdataandprivate_key:
self.rsa_decrypt()
self.unpack()
defcalculate_aes(self):
h=hashlib.sha256(self.raw_aes_keys)
digest=h.digest()
self.aes_key=digest[0:16]
self.hmac_key=digest[16:]
defrsa_decrypt(self):
pkey=M2Crypto.RSA.load_key_string(PRIVATE_KEY_TEMPLATE.format(self.private_key))
plaintext=pkey.private_decrypt(self.data,M2Crypto.RSA.pkcs1_padding)
assertplaintext[0:4]=="x00x00xBExEF"
self.data=https://pcff.toutiao.jxnews.com.cn/p/20200712/StringIO.StringIO(plaintext[8:])
defreadInt(self,byteorder="&gt"):
fmt=byteorder+"L"
returnstruct.unpack(fmt,self.data.read(struct.calcsize(fmt)))[0]
defreadShort(self,byteorder="&gt"):
fmt=byteorder+"H"
returnstruct.unpack(fmt,self.data.read(struct.calcsize(fmt)))[0]
defreadByte(self):
fmt="b"
returnstruct.unpack(fmt,self.data.read(struct.calcsize(fmt)))[0]
defflag(self,b,s):
returnb&amps==s
defprint_config(self):
print"rawAESkey:%s"%self.raw_aes_keys[0:8].encode("hex")
print"rawHMACkey:%s"%self.raw_aes_keys[8:].encode("hex")
print"AESkey:%s"%self.aes_key.encode("hex")
print"HMACkey:%s"%self.hmac_key.encode("hex")
print"ver:%s"%self.ver
print"host:%s"%self.intz


推荐阅读