def writeToFile(self,instance): prefix=self.prefix ''' PEM_write_RSAPrivateKey(f, rsa_p, None, None, 0, None, None) PEM_write_RSAPrivateKey(fp,x, [enc,kstr,klen,cb,u]) -> PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp, (char *)x, [enc,kstr,klen,cb,u]) int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, char *x, [const EVP_CIPHER *, unsigned char *kstr,int , pem_password_cb *, void *]) -> PEM_ASN1_write_bio(i2d, name, b, x [,enc,kstr,klen,callback,u] ); int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, char *x , [..] -> i2d_RSAPrivateKey( sur x ) -> ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); -> i=BIO_write(out,&(b[j]),n); -> i=PEM_write_bio(bp,name,buf,data,i); en gros, c'est ctypes_openssl.RSA().writeASN1(file) ''' filename=self.get_valid_filename() f=libc.fopen(filename,"w") ret=_libssl.PEM_write_RSAPrivateKey(f, ctypes.byref(instance), None, None, 0, None, None) libc.fclose(f) if ret < 1: log.error("Error saving key to file %s"% filename) return False log.info ("[X] Key saved to file %s"%filename) return True
def writeToFile(self,instance): prefix=self.prefix filename=self.get_valid_filename() f=libc.fopen(filename,"w") ret=_libssl.PEM_write_DSAPrivateKey(f, ctypes.byref(instance), None, None, 0, None, None) if ret < 1: log.error("Error saving key to file %s"% filename) return False log.info ("[X] Key saved to file %s"%filename) return True
def writeWithLibDSA(addr): ssl=cdll.LoadLibrary("libssl.so") dsa=readDsa(addr) dsa_p=ctypes.addressof(dsa) print 'dsa acquired 0x%lx copied to 0x%lx'%(addr,dsa_p) f=libc.fopen("test.out","w") print 'file opened',f ret=ssl.PEM_write_DSAPrivateKey(f, dsa_p, None, None, 0, None, None) print 'key written' print ret,f
def writeWithLibRSA(addr): ssl=cdll.LoadLibrary("libssl.so") # need original data struct #rsa=process.readBytes(addr, ctypes.sizeof(ctypes_openssl.RSA) ) #rsa=ctypes.addressof(process.readStruct(addr,ctypes_openssl.RSA)) rsa=readRsa(addr) rsa_p=ctypes.addressof(rsa) print 'rsa acquired 0x%lx copied to 0x%lx'%(addr,rsa_p) f=libc.fopen("test.out","w") print 'file opened',f ret=ssl.PEM_write_RSAPrivateKey(f, rsa_p, None, None, 0, None, None) print 'key written' print ret,f