Coder Social home page Coder Social logo

e-safenet's Introduction

E-Safenet

This GitHub repository contains files that assist in cryptanalytic attacks on E-Safenet encryption. Several attacks were developed that may partially or fully recover E-Safenet encryption keys.

  • Known-plaintext attack
  • Probable-plaintext attack
    • Against source code files
    • Against binary files
  • Ciphertext-only attack

All specifics and attacks are document in the research paper on E-Safenet encryption.

Python scripts

The python scripts provided can be used to encrypt and decrypt using the E-Safenet encryption, or to extract encryption keys.

Two main files are available:

  • esafenet.py: command-line interface to known-plaintext and probable-plaintext attacks
  • esafenet_gui.py: GUI interface for the ciphertext-only attack
Setup

Prior to using these scripts, the simplelzo1x module has to be compiled first. This module provides an interface to the LZO v1.00 compression library.

cd simplelzo1x && sudo python setup.py install

More information about the library can be found in the README file in the simplelzo1x directory.

esafenet.py

usage: esafenet.py [-h] [--infile INFILE] [--key KEY] [--outfile OUTFILE]
                   [--infolder INFOLDER] [--outfolder OUTFOLDER]
                   [--comp_file COMP_FILE] [--type pattern_type]
                   [--language text_pattern_language]
                   action

E-safenet encryption/decryption/key generation

positional arguments:
  action                Action to perform
                        Should be one of ['encrypt', 'decrypt', 'encrypt_folder', 
                        'decrypt_folder', 'keygen', 'findkey', 'pattern_decrypt']

optional arguments:
  -h, --help            show this help message and exit
  --infile INFILE       Input file
  --key KEY             Key file
  --outfile OUTFILE     Output file
  --infolder INFOLDER   Input folder
  --outfolder OUTFOLDER
                        Output folder
  --comp_file COMP_FILE
                        Plaintext comparison file used by findkey
  --type pattern_type   Type for pattern decrypt (binary or text)
  --language text_pattern_language
                        Language for text pattern decrypt (C, PHP or CS)
Examples
  • Recovering the encryption key of a binary file (probable-plaintext attack):
$ python esafenet.py pattern_decrypt --type binary --infile encrypted.xls --outfile key.dat
Decryption: key written to key.dat (4 0-bytes)
  • Decrypting an E-Safenet file using a provided key:
$ python esafenet.py decrypt --infile encrypted.xls --key key.dat --outfile decrypted.xls
Decryption: 153400 bytes written to decrypted.xls
  • Recovering the key using the known-plaintext attack:
$ python esafenet.py findkey --infile encrypted.xls --comp_file decrypted.xls --outfile key.dat
Succes: key written to key.dat
  • Recovering the encryption key of source code files (probable-plaintext attack, C#):
$ python esafenet.py pattern_decrypt --type text --infolder srcfiles --outfolder /tmp --language CS --outfile key.dat
Match found!! ...
Troubleshooting

If you get errors/crashes, they are probably caused by the LZO compression library. The first 512 bytes of an E-Safenet encrypted file are compressed. When using a wrong key, decompression may fail and lead to a crash. You can temporarily disable decompression of the first block by changing the plain_header variable in esafenet.py to an empty string:

             plain_header = ""
#            plain_header = simplelzo1x.decompress(decr_header)

esafenet_gui.py

The GUI app esafenet_gui.py can be used for the ciphertext-only attack. More information about this attack can be found in the research paper.

  1. menu -> Open folder or file, select an E-Safenet file, or a folder containing only E-Safenet files encrypted with the same key.
  2. menu -> Analyze, analyzes the files, tries to maximize plaintext in the file(s), as described in the report.

Note: The analyze step may take some time (15s for 200kB on my 5y/o laptop, displaying results in thhe grid takes even longer...)

Results are displayed as-is, this program is not complete. Feel free to do with it as you see fit.

COA tool

CPLEX model

For the mathematical implementation of the ciphertext-only attack, cplex_coa.mod provides a CPLEX model for the Binary Integer Programming problem that represents the maximization of printable characters in an E-Safenet encrypted document.

Credits

The code was released under the GPLv2 license.

e-safenet's People

Contributors

c3c avatar janlaan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

e-safenet's Issues

Installing simplelzo1x on Win32 Environment

Hello

I'm having some issues trying to install simplelzo1x on Win32 environment with the following configuration :

  • Python v2.7.12
  • MinGW32 GCC v4.9.3-1
  • LZO 32bit v1.11

I keep on getting these error messages (ignored warnings) when executing from an Administrative Command Prompt :

C:\XPMODEFILES\Stonex\One_ROM_0\E-Safenet-master\simplelzo1x>python setup.py install
running install
running build
running build_ext
building 'simplelzo1x' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -Iliblzo -IC:\Python27\include -IC:\Python27\PC -c simplelzo1xmodule.c -o build\temp.win32-2.7\Release\simplelzo1xmodule.o
simplelzo1xmodule.c: In function 'compress':
simplelzo1xmodule.c:103:5: warning: "/*" within comment [-Wcomment]
     /* return */
 ^
simplelzo1xmodule.c: In function 'decompress':
simplelzo1xmodule.c:119:9: warning: variable 'err' set but not used [-Wunused-but-set-variable]
     int err;
         ^
writing build\temp.win32-2.7\Release\simplelzo1x.def
C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\simplelzo1xmodule.o build\temp.win32-2.7\Release\simplelzo1x.def -Lliblzo/32bit -LC:\Python27\libs -LC:\Python27\PCbuild -LC:\Python27\PC\VS9.0 -llzo -lpython27 -lmsvcr90 -o build\lib.win32-2.7\simplelzo1x.pyd
build\temp.win32-2.7\Release\simplelzo1xmodule.o:simplelzo1xmodule.c:(.text+0x80): undefined reference to `lzo1x_decompress'
build\temp.win32-2.7\Release\simplelzo1xmodule.o:simplelzo1xmodule.c:(.text+0x181): undefined reference to `lzo1x_1_compress'
build\temp.win32-2.7\Release\simplelzo1xmodule.o:simplelzo1xmodule.c:(.text+0x24d): undefined reference to `__lzo_init'
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1

Thanks in advance for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.