You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pycryptodome (use it to do a local encryption/decryption function)
docker (as run time, also you can run it in your localhost)
As you can see in this picture, we are going to use linux system authentication to verify user and use file system as the storage backend. that's mean you can integrated the auth part with linux system but not to modified the services code.
0x02 Event Handler
Here is the sequence diagram. as you can see in the below picture, it was mainly with 3 parts. and here's a brief introduction.
login
At the login part, FTP Service will check the kek file path for each user at each login, and decrypt the KEK string to get user's AES key, then use AES key to decrypt user's file.
KEK file should be created on the user's first login, and updated KEK file content with generate random AES key and encrypted it by RSA Key
upload
At the upload part, ftp service was able to handle this event with a pipeline. for example, you can create a malware detection services for each new file. then encrypted it with user's AES key.
logout
At the logout part, there was two main things. one is to encrypt all unencrypted files. then encrypt the AES key by RSA key and save it
0x03 Encrypt/Decrypt
Before we talking about encrypt & decrypt, you should know some basic crypto algorithms. RSA and AES is a common crypto algorithm. AES was a symmetric algorithms , that's mean you can use one aes key to encrypt/decrypt file. RSA was a asymmetric algorithms , and you can use public key to encrypt some message, but only able to use private key to decrypt that. in this case, we use RSA to protected the AES key which is really used to encrypt and decrypt files.
File Encrypt/Decrypt
Here is sample code to encrypt file and decrypt file. in this case, we are use pycryptodome to do a local encryption/decryption. There is no doubt that it will increase the speed compared with the use of encryption services.
tricks: it was recored with asciinema, and you can modified the cast file to delete some personal info.
0x05 Conclusion
In this blog, we use pyftpdliib and eaas to build a FTP services with DARE (you can find the whole project code with this project code). Maybe FTP is a little out of date, but it's still a good example to explain how we build a service to support data at rest encryption. and you can use sftp to do another demo, just handle the login/logout put/download event. Also, you can change the backend with s3 fs, and integrated Auth with LDAP, and so on.
0x01 Intro
In this tutorial, we will build a ftp Service with data at rest encryption. that's mean all the file was encrypted at FTP server.
This is what you need:
As you can see in this picture, we are going to use linux system authentication to verify user and use file system as the storage backend. that's mean you can integrated the auth part with linux system but not to modified the services code.
0x02 Event Handler
Here is the sequence diagram. as you can see in the below picture, it was mainly with 3 parts. and here's a brief introduction.
At the login part, FTP Service will check the kek file path for each user at each login, and decrypt the KEK string to get user's AES key, then use AES key to decrypt user's file.
upload
At the upload part, ftp service was able to handle this event with a pipeline. for example, you can create a malware detection services for each new file. then encrypted it with user's AES key.
logout
At the logout part, there was two main things. one is to encrypt all unencrypted files. then encrypt the AES key by RSA key and save it
0x03 Encrypt/Decrypt
Before we talking about encrypt & decrypt, you should know some basic crypto algorithms.
RSA
andAES
is a common crypto algorithm.AES
was a symmetric algorithms , that's mean you can use one aes key to encrypt/decrypt file.RSA
was a asymmetric algorithms , and you can use public key to encrypt some message, but only able to use private key to decrypt that. in this case, we useRSA
to protected theAES
key which is really used to encrypt and decrypt files.Here is the sample code for encrypt key, also you can change it with your own service.
Here is sample code to encrypt file and decrypt file. in this case, we are use
pycryptodome
to do a local encryption/decryption. There is no doubt that it will increase the speed compared with the use of encryption services.also, as you can see, this class was Inherited from
TLS_FTPHandler
, that's mean it was able to enable FTP over TLS feature.0x04 with Container
we can build a service easily with docker, So I've been using docker to build services recently.
here is the
docker-compose
fileNow, we can run it with
docker-compose
directly.for the whole demo, you can see this recorder:
0x05 Conclusion
In this blog, we use
pyftpdliib
andeaas
to build a FTP services with DARE (you can find the whole project code with this project code). Maybe FTP is a little out of date, but it's still a good example to explain how we build a service to support data at rest encryption. and you can usesftp
to do another demo, just handle the login/logout put/download event. Also, you can change the backend with s3 fs, and integrated Auth with LDAP, and so on.0x06 Resources
The text was updated successfully, but these errors were encountered: