Python pyasn1.codec.der.encoder.encode() Examples
The following are 30
code examples of pyasn1.codec.der.encoder.encode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyasn1.codec.der.encoder
, or try the search function
.
Example #1
Source File: test_rfc4490.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testOpenTypes(self): substrate = pem.readBase64fromText(self.signed_pem_text) asn1Object, rest = der_decoder( substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) self.assertEqual(rfc5652.id_signedData, asn1Object['contentType']) si = asn1Object['content']['signerInfos'][0] self.assertEqual(rfc4357.id_GostR3411_94, si['digestAlgorithm']['algorithm']) self.assertEqual(univ.Null(""), si['digestAlgorithm']['parameters']) self.assertEqual(rfc4357.id_GostR3410_2001, si['signatureAlgorithm']['algorithm']) self.assertEqual(univ.Null(""), si['signatureAlgorithm']['parameters']) sig = rfc4490.GostR3410_2001_Signature() sig = si['signature'] self.assertEqual(64, len(sig))
Example #2
Source File: cert_parser.py From octavia with Apache License 2.0 | 6 votes |
def _read_private_key(private_key_pem, passphrase=None): """Reads a private key PEM block and returns a RSAPrivatekey :param private_key_pem: The private key PEM block :param passphrase: Optional passphrase needed to decrypt the private key :returns: a RSAPrivatekey object """ if passphrase and isinstance(passphrase, str): passphrase = passphrase.encode("utf-8") if isinstance(private_key_pem, str): private_key_pem = private_key_pem.encode('utf-8') try: return serialization.load_pem_private_key(private_key_pem, passphrase, backends.default_backend()) except Exception: LOG.exception("Passphrase required.") raise exceptions.NeedsPassphrase
Example #3
Source File: EncryptedPfx.py From ADFSpoof with Apache License 2.0 | 6 votes |
def _derive_keys(self, password=None): label = encode(self.encryption_oid) + encode(self.mac_oid) context = self.nonce.asOctets() backend = default_backend() kdf = KBKDFHMAC( algorithm=hashes.SHA256(), mode=Mode.CounterMode, length=48, rlen=4, llen=4, location=CounterLocation.BeforeFixed, label=label, context=context, fixed=None, backend=backend ) key = kdf.derive(password) if self.DEBUG: sys.stderr.write("Derived key: {0}\n".format(key)) self.encryption_key = key[0:16] self.mac_key = key[16:]
Example #4
Source File: smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def check_dir(self, service, path, password = None): path = string.replace(path,'/', '\\') tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password) try: smb = NewSMBPacket() smb['Tid'] = tid smb['Mid'] = 0 cmd = SMBCommand(SMB.SMB_COM_CHECK_DIRECTORY) cmd['Parameters'] = '' cmd['Data'] = SMBCheckDirectory_Data(flags = self.__flags2) cmd['Data']['DirectoryName'] = path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else path smb.addCommand(cmd) self.sendSMB(smb) while 1: s = self.recvSMB() if s.isValidAnswer(SMB.SMB_COM_CHECK_DIRECTORY): return finally: self.disconnect_tree(tid)
Example #5
Source File: smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def rmdir(self, service, path, password = None): path = string.replace(path,'/', '\\') # Check that the directory exists self.check_dir(service, path, password) tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password) try: path = path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else path smb = NewSMBPacket() smb['Tid'] = tid createDir = SMBCommand(SMB.SMB_COM_DELETE_DIRECTORY) createDir['Data'] = SMBDeleteDirectory_Data(flags=self.__flags2) createDir['Data']['DirectoryName'] = path smb.addCommand(createDir) self.sendSMB(smb) while 1: s = self.recvSMB() if s.isValidAnswer(SMB.SMB_COM_DELETE_DIRECTORY): return finally: self.disconnect_tree(tid)
Example #6
Source File: smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def mkdir(self, service, path, password = None): path = string.replace(path,'/', '\\') tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password) try: path = path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else path smb = NewSMBPacket() smb['Tid'] = tid smb['Mid'] = 0 createDir = SMBCommand(SMB.SMB_COM_CREATE_DIRECTORY) createDir['Data'] = SMBCreateDirectory_Data(flags=self.__flags2) createDir['Data']['DirectoryName'] = path smb.addCommand(createDir) self.sendSMB(smb) smb = self.recvSMB() if smb.isValidAnswer(SMB.SMB_COM_CREATE_DIRECTORY): return 1 return 0 finally: self.disconnect_tree(tid)
Example #7
Source File: smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def rename(self, service, old_path, new_path, password = None): old_path = string.replace(old_path,'/', '\\') new_path = string.replace(new_path,'/', '\\') tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password) try: smb = NewSMBPacket() smb['Tid'] = tid smb['Mid'] = 0 renameCmd = SMBCommand(SMB.SMB_COM_RENAME) renameCmd['Parameters'] = SMBRename_Parameters() renameCmd['Parameters']['SearchAttributes'] = ATTR_SYSTEM | ATTR_HIDDEN | ATTR_DIRECTORY renameCmd['Data'] = SMBRename_Data(flags = self.__flags2) renameCmd['Data']['OldFileName'] = old_path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else old_path renameCmd['Data']['NewFileName'] = new_path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else new_path smb.addCommand(renameCmd) self.sendSMB(smb) smb = self.recvSMB() if smb.isValidAnswer(SMB.SMB_COM_RENAME): return 1 return 0 finally: self.disconnect_tree(tid)
Example #8
Source File: ccache.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def toTGT(self): tgt_rep = AS_REP() tgt_rep['pvno'] = 5 tgt_rep['msg-type'] = int(constants.ApplicationTagNumbers.AS_REP.value) tgt_rep['crealm'] = self['server'].realm['data'] # Fake EncryptedData tgt_rep['enc-part'] = None tgt_rep['enc-part']['etype'] = 1 tgt_rep['enc-part']['cipher'] = '' seq_set(tgt_rep, 'cname', self['client'].toPrincipal().components_to_asn1) ticket = types.Ticket() ticket.from_asn1(self.ticket['data']) seq_set(tgt_rep,'ticket', ticket.to_asn1) cipher = crypto._enctype_table[self['key']['keytype']]() tgt = dict() tgt['KDC_REP'] = encoder.encode(tgt_rep) tgt['cipher'] = cipher tgt['sessionKey'] = crypto.Key(cipher.enctype, str(self['key']['keyvalue'])) return tgt
Example #9
Source File: cert_parser.py From octavia with Apache License 2.0 | 6 votes |
def get_intermediates_pems(intermediates=None): """Split the input string into individual x509 text blocks :param intermediates: PEM or PKCS7 encoded intermediate certificates :returns: A list of strings where each string represents an X509 pem block surrounded by BEGIN CERTIFICATE, END CERTIFICATE block tags """ if isinstance(intermediates, str): try: intermediates = intermediates.encode("utf-8") except UnicodeDecodeError: LOG.debug("Couldn't encode intermediates string, it was probably " "in binary DER format.") if X509_BEG in intermediates: for x509Pem in _split_x509s(intermediates): yield _prepare_x509_cert(_get_x509_from_pem_bytes(x509Pem)) else: for x509Pem in _parse_pkcs7_bundle(intermediates): yield _prepare_x509_cert(_get_x509_from_der_bytes(x509Pem))
Example #10
Source File: pkcs7_to_pem.py From octavia with Apache License 2.0 | 6 votes |
def _process_pkcs7_substrate(substrate): contentInfo, _ = der_decoder.decode(substrate, asn1Spec=rfc2315.ContentInfo()) contentType = contentInfo.getComponentByName('contentType') if contentType != rfc2315.signedData: raise Exception content, _ = der_decoder.decode( contentInfo.getComponentByName('content'), asn1Spec=rfc2315.SignedData()) for blob in content.getComponentByName('certificates'): cert = x509.load_der_x509_certificate(der_encoder.encode(blob), backends.default_backend()) print(cert.public_bytes( encoding=serialization.Encoding.PEM).decode( 'unicode_escape'), end='') # Main program code
Example #11
Source File: smb.py From cracke-dit with MIT License | 6 votes |
def check_dir(self, service, path, password = None): path = string.replace(path,'/', '\\') tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password) try: smb = NewSMBPacket() smb['Tid'] = tid smb['Mid'] = 0 cmd = SMBCommand(SMB.SMB_COM_CHECK_DIRECTORY) cmd['Parameters'] = '' cmd['Data'] = SMBCheckDirectory_Data(flags = self.__flags2) cmd['Data']['DirectoryName'] = path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else path smb.addCommand(cmd) self.sendSMB(smb) while 1: s = self.recvSMB() if s.isValidAnswer(SMB.SMB_COM_CHECK_DIRECTORY): return finally: self.disconnect_tree(tid)
Example #12
Source File: smb.py From cracke-dit with MIT License | 6 votes |
def mkdir(self, service, path, password = None): path = string.replace(path,'/', '\\') tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password) try: path = path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else path smb = NewSMBPacket() smb['Tid'] = tid smb['Mid'] = 0 createDir = SMBCommand(SMB.SMB_COM_CREATE_DIRECTORY) createDir['Data'] = SMBCreateDirectory_Data(flags=self.__flags2) createDir['Data']['DirectoryName'] = path smb.addCommand(createDir) self.sendSMB(smb) smb = self.recvSMB() if smb.isValidAnswer(SMB.SMB_COM_CREATE_DIRECTORY): return 1 return 0 finally: self.disconnect_tree(tid)
Example #13
Source File: smb.py From cracke-dit with MIT License | 6 votes |
def rename(self, service, old_path, new_path, password = None): old_path = string.replace(old_path,'/', '\\') new_path = string.replace(new_path,'/', '\\') tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password) try: smb = NewSMBPacket() smb['Tid'] = tid smb['Mid'] = 0 renameCmd = SMBCommand(SMB.SMB_COM_RENAME) renameCmd['Parameters'] = SMBRename_Parameters() renameCmd['Parameters']['SearchAttributes'] = ATTR_SYSTEM | ATTR_HIDDEN | ATTR_DIRECTORY renameCmd['Data'] = SMBRename_Data(flags = self.__flags2) renameCmd['Data']['OldFileName'] = old_path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else old_path renameCmd['Data']['NewFileName'] = new_path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else new_path smb.addCommand(renameCmd) self.sendSMB(smb) smb = self.recvSMB() if smb.isValidAnswer(SMB.SMB_COM_RENAME): return 1 return 0 finally: self.disconnect_tree(tid)
Example #14
Source File: test_rfc3279.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testDerCodec(self): substrate = pem.readBase64fromText(self.rsa_cert_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] self.assertEqual(rfc3279.rsaEncryption, spki_a['algorithm']) spki_pk = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'].asOctets() pk, rest = der_decoder(spki_pk, asn1Spec=rfc3279.RSAPublicKey()) self.assertFalse(rest) self.assertTrue(pk.prettyPrint()) self.assertEqual(spki_pk, der_encoder(pk)) self.assertEqual(65537, pk['publicExponent']) self.assertEqual(rfc3279.sha1WithRSAEncryption, asn1Object['tbsCertificate']['signature']['algorithm']) self.assertEqual(rfc3279.sha1WithRSAEncryption, asn1Object['signatureAlgorithm']['algorithm'])
Example #15
Source File: smb.py From cracke-dit with MIT License | 6 votes |
def rmdir(self, service, path, password = None): path = string.replace(path,'/', '\\') # Check that the directory exists self.check_dir(service, path, password) tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password) try: path = path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else path smb = NewSMBPacket() smb['Tid'] = tid createDir = SMBCommand(SMB.SMB_COM_DELETE_DIRECTORY) createDir['Data'] = SMBDeleteDirectory_Data(flags=self.__flags2) createDir['Data']['DirectoryName'] = path smb.addCommand(createDir) self.sendSMB(smb) while 1: s = self.recvSMB() if s.isValidAnswer(SMB.SMB_COM_DELETE_DIRECTORY): return finally: self.disconnect_tree(tid)
Example #16
Source File: test_rfc8209.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testDerCodec(self): substrate = pem.readBase64fromText(self.cert_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) extn_list = [] for extn in asn1Object['tbsCertificate']['extensions']: extn_list.append(extn['extnID']) if extn['extnID'] in rfc5280.certificateExtensionsMap.keys(): extnValue, rest = der_decoder( extn['extnValue'], asn1Spec=rfc5280.certificateExtensionsMap[extn['extnID']]) self.assertEqual(extn['extnValue'], der_encoder(extnValue)) if extn['extnID'] == rfc5280.id_ce_extKeyUsage: self.assertIn(rfc8209.id_kp_bgpsec_router, extnValue) self.assertIn(rfc5280.id_ce_extKeyUsage, extn_list)
Example #17
Source File: test_rfc2876.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testDerCodec(self): substrate = pem.readBase64fromText(self.smime_capabilities_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) found_wrap_alg = False for cap in asn1Object: if cap['capabilityID'] in rfc5751.smimeCapabilityMap.keys(): if cap['parameters'].hasValue(): param, rest = der_decoder( cap['parameters'], asn1Spec=rfc5751.smimeCapabilityMap[cap['capabilityID']]) self.assertFalse(rest) self.assertTrue(param.prettyPrint()) self.assertEqual(cap['parameters'], der_encoder(param)) if cap['capabilityID'] == rfc2876.id_kEAKeyEncryptionAlgorithm: self.assertEqual(rfc2876.id_fortezzaWrap80, param['algorithm']) found_wrap_alg = True self.assertTrue(found_wrap_alg)
Example #18
Source File: test_rfc2876.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testOpenTypes(self): substrate = pem.readBase64fromText(self.env_data_pem_text) asn1Object, rest = der_decoder( substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) self.assertIn(asn1Object['contentType'], rfc5652.cmsContentTypesMap.keys()) kari_kea = asn1Object['content']['recipientInfos'][0]['kari']['keyEncryptionAlgorithm'] self.assertEqual(rfc2876.id_kEAKeyEncryptionAlgorithm, kari_kea['algorithm']) self.assertEqual(rfc2876.id_fortezzaWrap80, kari_kea['parameters']['algorithm']) cea = asn1Object['content']['encryptedContentInfo']['contentEncryptionAlgorithm'] self.assertEqual(rfc2876.id_fortezzaConfidentialityAlgorithm, cea['algorithm']) iv = univ.OctetString(hexValue='424f4755535f4956') self.assertEqual(iv, cea['parameters']['initialization-vector'])
Example #19
Source File: test_rfc8649.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testDerCodec(self): substrate = pem.readBase64fromText(self.extn_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) self.assertEqual(rfc8649.id_ce_hashOfRootKey, asn1Object['extnID']) hashed_root_key, rest = der_decoder( asn1Object['extnValue'], rfc8649.HashedRootKey()) self.assertFalse(rest) self.assertTrue(hashed_root_key.prettyPrint()) self.assertEqual(asn1Object['extnValue'], der_encoder(hashed_root_key)) self.assertEqual( rfc4055.id_sha512, hashed_root_key['hashAlg']['algorithm'])
Example #20
Source File: test_rfc3279.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testOpenTypes(self): substrate = pem.readBase64fromText(self.dh_cert_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] self.assertEqual(rfc3279.dhpublicnumber, spki_a['algorithm']) q_value = 65838278260281264030127352144753816831178774189428428256716126077244217603537 self.assertEqual(q_value, spki_a['parameters']['q'])
Example #21
Source File: test_rfc3279.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testDerCodec(self): substrate = pem.readBase64fromText(self.dh_cert_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] self.assertEqual(rfc3279.dhpublicnumber, spki_a['algorithm']) spki_a_p, rest = der_decoder( spki_a['parameters'], asn1Spec=rfc3279.DomainParameters()) self.assertFalse(rest) self.assertTrue(spki_a_p.prettyPrint()) self.assertEqual(spki_a['parameters'], der_encoder(spki_a_p)) q_value = 65838278260281264030127352144753816831178774189428428256716126077244217603537 self.assertEqual(q_value, spki_a_p['q'])
Example #22
Source File: test_rfc3279.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testOpenTypes(self): substrate = pem.readBase64fromText(self.kea_cert_pem_text) asn1Object, rest = der_decoder( substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] self.assertEqual(rfc3279.id_keyExchangeAlgorithm, spki_a['algorithm']) self.assertEqual( univ.OctetString(hexValue='5cf8f127e6569d6d88b3'), spki_a['parameters']) self.assertEqual(rfc3279.id_dsa_with_sha1, asn1Object['tbsCertificate']['signature']['algorithm']) self.assertEqual( rfc3279.id_dsa_with_sha1, asn1Object['signatureAlgorithm']['algorithm'])
Example #23
Source File: test_rfc3279.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testOpenTypes(self): substrate = pem.readBase64fromText(self.dsa_cert_pem_text) asn1Object, rest = der_decoder( substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] self.assertEqual(rfc3279.id_dsa, spki_a['algorithm']) q_value = 1260916123897116834511257683105158021801897369967 self.assertEqual(q_value, spki_a['parameters']['q'])
Example #24
Source File: test_rfc3279.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 6 votes |
def testDerCodec(self): substrate = pem.readBase64fromText(self.ec_cert_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] self.assertEqual(rfc3279.id_ecPublicKey, spki_a['algorithm']) spki_a_p, rest = der_decoder( spki_a['parameters'], asn1Spec=rfc3279.EcpkParameters()) self.assertFalse(rest) self.assertTrue(spki_a_p.prettyPrint()) self.assertEqual(spki_a['parameters'], der_encoder(spki_a_p)) self.assertEqual(univ.ObjectIdentifier('1.3.132.0.34'), spki_a_p['namedCurve'])
Example #25
Source File: ccache.py From cracke-dit with MIT License | 6 votes |
def toTGT(self): tgt_rep = AS_REP() tgt_rep['pvno'] = 5 tgt_rep['msg-type'] = int(constants.ApplicationTagNumbers.AS_REP.value) tgt_rep['crealm'] = self['server'].realm['data'] # Fake EncryptedData tgt_rep['enc-part'] = noValue tgt_rep['enc-part']['etype'] = 1 tgt_rep['enc-part']['cipher'] = '' seq_set(tgt_rep, 'cname', self['client'].toPrincipal().components_to_asn1) ticket = types.Ticket() ticket.from_asn1(self.ticket['data']) seq_set(tgt_rep,'ticket', ticket.to_asn1) cipher = crypto._enctype_table[self['key']['keytype']]() tgt = dict() tgt['KDC_REP'] = encoder.encode(tgt_rep) tgt['cipher'] = cipher tgt['sessionKey'] = crypto.Key(cipher.enctype, str(self['key']['keyvalue'])) return tgt
Example #26
Source File: smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def nt_create_andx(self,tid,filename, smb_packet=None, cmd = None, shareAccessMode = FILE_SHARE_READ | FILE_SHARE_WRITE, disposition = FILE_OPEN, accessMask = 0x2019f): filename = filename.replace('/', '\\') filename = filename.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else filename if smb_packet is None: smb = NewSMBPacket() smb['Tid'] = tid else: smb = smb_packet if cmd is None: ntCreate = SMBCommand(SMB.SMB_COM_NT_CREATE_ANDX) ntCreate['Parameters'] = SMBNtCreateAndX_Parameters() ntCreate['Data'] = SMBNtCreateAndX_Data(flags=self.__flags2) ntCreate['Parameters']['FileNameLength'] = len(filename) ntCreate['Parameters']['CreateFlags'] = 0x16 ntCreate['Parameters']['AccessMask'] = accessMask ntCreate['Parameters']['CreateOptions'] = 0x40 ntCreate['Parameters']['ShareAccess'] = shareAccessMode ntCreate['Parameters']['Disposition'] = disposition ntCreate['Data']['FileName'] = filename if self.__flags2 & SMB.FLAGS2_UNICODE: ntCreate['Data']['Pad'] = 0x0 else: ntCreate = cmd smb.addCommand(ntCreate) self.sendSMB(smb) while 1: smb = self.recvSMB() if smb.isValidAnswer(SMB.SMB_COM_NT_CREATE_ANDX): # XXX Here we are ignoring the rest of the response ntCreateResponse = SMBCommand(smb['Data'][0]) ntCreateParameters = SMBNtCreateAndXResponse_Parameters(ntCreateResponse['Parameters']) self.fid = ntCreateParameters['Fid'] return ntCreateParameters['Fid']
Example #27
Source File: test_rfc4334.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 5 votes |
def testDerCodec(self): substrate = pem.readBase64fromText(self.cert_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object))
Example #28
Source File: test_rfc3279.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 5 votes |
def testOpenTypes(self): substrate = pem.readBase64fromText(self.ec_cert_pem_text) asn1Object, rest = der_decoder( substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] self.assertEqual(rfc3279.id_ecPublicKey, spki_a['algorithm']) self.assertEqual( univ.ObjectIdentifier('1.3.132.0.34'), spki_a['parameters']['namedCurve'])
Example #29
Source File: smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def open_andx(self, tid, filename, open_mode, desired_access): filename = string.replace(filename,'/', '\\') filename = filename.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else filename smb = NewSMBPacket() smb['Tid'] = tid openFile = SMBCommand(SMB.SMB_COM_OPEN_ANDX) openFile['Parameters'] = SMBOpenAndX_Parameters() openFile['Parameters']['DesiredAccess'] = desired_access openFile['Parameters']['OpenMode'] = open_mode openFile['Parameters']['SearchAttributes'] = ATTR_READONLY | ATTR_HIDDEN | ATTR_ARCHIVE openFile['Data'] = SMBOpenAndX_Data(flags=self.__flags2) openFile['Data']['FileName'] = filename if self.__flags2 & SMB.FLAGS2_UNICODE: openFile['Data']['Pad'] = 0x0 smb.addCommand(openFile) self.sendSMB(smb) smb = self.recvSMB() if smb.isValidAnswer(SMB.SMB_COM_OPEN_ANDX): # XXX Here we are ignoring the rest of the response openFileResponse = SMBCommand(smb['Data'][0]) openFileParameters = SMBOpenAndXResponse_Parameters(openFileResponse['Parameters']) return ( openFileParameters['Fid'], openFileParameters['FileAttributes'], openFileParameters['LastWriten'], openFileParameters['FileSize'], openFileParameters['GrantedAccess'], openFileParameters['FileType'], openFileParameters['IPCState'], openFileParameters['Action'], openFileParameters['ServerFid'], )
Example #30
Source File: test_rfc3279.py From pyasn1-modules with BSD 2-Clause "Simplified" License | 5 votes |
def testDerCodec(self): substrate = pem.readBase64fromText(self.kea_cert_pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] self.assertEqual(rfc3279.id_keyExchangeAlgorithm, spki_a['algorithm']) spki_a_p, rest = der_decoder(spki_a['parameters'], asn1Spec=rfc3279.KEA_Parms_Id()) self.assertFalse(rest) self.assertTrue(spki_a_p.prettyPrint()) self.assertEqual(spki_a['parameters'], der_encoder(spki_a_p)) self.assertEqual(univ.OctetString(hexValue='5cf8f127e6569d6d88b3'), spki_a_p) self.assertEqual( rfc3279.id_dsa_with_sha1, asn1Object['tbsCertificate']['signature']['algorithm']) self.assertEqual( rfc3279.id_dsa_with_sha1, asn1Object['signatureAlgorithm']['algorithm']) sig_value, rest = der_decoder(asn1Object['signature'].asOctets(), asn1Spec=rfc3279.Dss_Sig_Value()) self.assertFalse(rest) self.assertTrue(sig_value.prettyPrint()) self.assertEqual(asn1Object['signature'].asOctets(), der_encoder(sig_value)) self.assertTrue(sig_value['r'].hasValue()) self.assertTrue(sig_value['s'].hasValue())