File: setup.py

package info (click to toggle)
pyrit 0.5.1%2Bgit20180801-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,596 kB
  • sloc: python: 4,667; ansic: 3,352; cpp: 1,490; asm: 394; lisp: 192; makefile: 15; sed: 7; sh: 6
file content (146 lines) | stat: -rwxr-xr-x 5,640 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
#    Copyright 2008-2011, Lukas Lueg, lukas.lueg@gmail.com
#
#    This file is part of Pyrit.
#
#    Pyrit is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Pyrit is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Pyrit.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import with_statement
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext
from distutils.command.clean import clean
import os
import re
import subprocess
import sys
import zlib

VERSION = '0.5.0'

OPENCL_INC_DIRS = []
OPENCL_LIB_DIRS = []
EXTRA_LINK_ARGS = []
LIBRARIES = ['crypto', 'z']
if sys.platform == 'darwin':
    # Use the built-in framework on MacOS
    EXTRA_LINK_ARGS.extend(('-framework', 'OpenCL'))
    OPENCL_INC_DIRS.append('/System/Library/Frameworks/OpenCL.framework/Headers')
else:
    LIBRARIES.append('OpenCL')
    try:
        if os.path.exists(os.environ['ATISTREAMSDKROOT']):
            OPENCL_INC_DIRS.append(os.path.join(os.environ['ATISTREAMSDKROOT'], 'include'))
            for path in ('lib/x86_64','lib/x86'):
                if os.path.exists(os.path.join(os.environ['ATISTREAMSDKROOT'], path)):
                    OPENCL_LIB_DIRS.append(os.path.join(os.environ['ATISTREAMSDKROOT'], path))
                    break
    except:
        pass
    for path in ('/usr/local/opencl/OpenCL/common/inc', \
                '/opt/opencl/OpenCL/common/inc', \
                '/usr/local/opencl/include', \
                '/usr/local/cuda/include'):
        if os.path.exists(path):
            OPENCL_INC_DIRS.append(path)
            break
    else:
        print >>sys.stderr, "The headers required to build the OpenCL-kernel " \
                            "were not found. Trying to continue anyway..."


EXTRA_COMPILE_ARGS = ['-Wall', '-fno-strict-aliasing', \
                      '-DVERSION="%s"' % (VERSION,)]


class GPUBuilder(build_ext):
    def run(self):
        with open("_cpyrit_opencl.h", 'rb') as f:
            header = f.read()
        with open("_cpyrit_oclkernel.cl", 'rb') as f:
            kernel = f.read()
        oclkernel_code = header + '\n' + kernel + '\x00'
        oclkernel_inc = zlib.compress(oclkernel_code)
        with open("_cpyrit_oclkernel.cl.h", 'wb') as f:
            f.write("unsigned char oclkernel_packedprogram[] = {")
            f.write(",".join(("0x%02X" % ord(c) for c in oclkernel_inc)))
            f.write("};\nsize_t oclkernel_size = %i;\n" % len(oclkernel_code))
        print "Building modules..."
        build_ext.run(self)


class GPUCleaner(clean):
    def _unlink(self, node):
        try:
            if os.path.isdir(node):
                os.rmdir(node)
            else:
                os.unlink(node)
        except OSError:
            pass

    def run(self):
        print "Removing temporary files and pre-built GPU-kernels..."
        try:
            for f in ('_cpyrit_oclkernel.cl.h',):
                self._unlink(f)
        except Exception, (errno, sterrno):
            print >>sys.stderr, "Exception while cleaning temporary " \
                                "files ('%s')" % sterrno
        clean.run(self)


opencl_extension = Extension('cpyrit._cpyrit_opencl',
                    libraries = LIBRARIES,
                    sources = ['_cpyrit_opencl.c'],
                    include_dirs = OPENCL_INC_DIRS,
                    library_dirs = OPENCL_LIB_DIRS,
                    extra_compile_args = EXTRA_COMPILE_ARGS,
                    extra_link_args = EXTRA_LINK_ARGS)

setup_args = dict(
        name = 'cpyrit-opencl',
        version = VERSION,
        description = 'GPU-accelerated attack against WPA-PSK authentication',
        long_description = \
            "Pyrit allows to create massive databases, pre-computing part " \
            "of the WPA/WPA2-PSK authentication phase in a space-time-" \
            "tradeoff. Exploiting the computational power of Many-Core- " \
            "and other platforms through ATI-Stream, Nvidia CUDA, OpenCL " \
            "and VIA Padlock, it is currently by far the most powerful " \
            "attack against one of the world's most used security-protocols.",
        license = 'GNU General Public License v3',
        author = 'Lukas Lueg',
        author_email = 'lukas.lueg@gmail.com',
        url = 'https://github.com/JPaulMora/Pyrit',
        maintainer = 'John Mora',
        maintainer_email = 'johmora12@engineer.com',
        classifiers = \
              ['Development Status :: 4 - Beta',
               'Environment :: Console',
               'License :: OSI Approved :: GNU General Public License (GPL)',
               'Natural Language :: English',
               'Operating System :: OS Independent',
               'Programming Language :: Python',
               'Topic :: Security'],
        platforms = ['any'],
        ext_modules = [opencl_extension],
        cmdclass = {'build_ext': GPUBuilder, 'clean': GPUCleaner},
        options = {'install': {'optimize': 1}, \
                   'bdist_rpm': {'requires': 'pyrit = 0.4.0-1'}}
        )

if __name__ == "__main__":
    setup(**setup_args)