示例#1
0
    def upload_html(self):
        response_data = {'url': '', 'description': '', 'status': 'error'}
        request = self.request
        resp = HttpResponse(json.dumps(response_data),
                            content_type="application/json; charset=utf-8")
        resp['Access-Control-Allow-Origin'] = '*'

        if request.method != 'POST':
            response_data['description'] = 'Method not Supported!'
            print("\n[ERROR] Method not Supported!")
            form = UploadFileForm()
            resp['status'] = HTTP_BAD_REQUEST
            return resp

        if not self.form.is_valid():
            response_data['description'] = 'Invalid Form Data!'
            print("\n[ERROR] Invalid Form Data!")
            resp['status'] = HTTP_BAD_REQUEST
            return resp

        self.file_content_type = request.FILES['file'].content_type
        self.file_name_lower = request.FILES['file'].name.lower()
        self.file_type = FileType(self.file_content_type, self.file_name_lower)
        if not self.file_type.is_allow_file():
            response_data['description'] = 'File format not Supported!'
            print("\n[ERROR] File format not Supported!")
            resp['status'] = HTTP_BAD_REQUEST
            return resp

        if self.file_type.is_ipa():
            if platform.system() not in LINUX_PLATFORM:
                data = {
                    'error':
                    "Static Analysis of iOS IPA requires Mac or Linux",
                    'url': 'mac_only/',
                    'status': 'success'
                }
                print(
                    "\n[ERROR] Static Analysis of iOS IPA requires Mac or Linux"
                )
                return data

        data = self.upload()

        response_data['url'] = data['url']
        response_data['status'] = data['status']
        return HttpResponse(json.dumps(response_data),
                            content_type="application/json; charset=utf-8")
示例#2
0
    def upload_html(self):
        request = self.request
        response_data = {
            'url': '',
            'description': '',
            'status': ''
        }
        if request.method != 'POST':
            logger.error("Method not Supported!")
            form = UploadFileForm()
            response_data['description'] = 'Method not Supported!'
            response_data['status'] = HTTP_BAD_REQUEST
            return self.resp_json(response_data)

        if not self.form.is_valid():
            logger.error("Invalid Form Data!")
            response_data['description'] = 'Invalid Form Data!'
            response_data['status'] = HTTP_BAD_REQUEST
            return self.resp_json(response_data)

        self.file_content_type = request.FILES['file'].content_type
        self.file_name_lower = request.FILES['file'].name.lower()
        self.file_type = FileType(self.file_content_type, self.file_name_lower)
        if not self.file_type.is_allow_file():
            logger.error("File format not Supported!")
            response_data['description'] = 'File format not Supported!'
            response_data['status'] = HTTP_BAD_REQUEST
            return self.resp_json(response_data)

        if self.file_type.is_ipa():
            if platform.system() not in LINUX_PLATFORM:
                logger.error(
                    "Static Analysis of iOS IPA requires Mac or Linux")
                response_data[
                    'description'] = 'Static Analysis of iOS IPA requires Mac or Linux'
                response_data['status'] = 'success'
                response_data['url'] = 'mac_only/'
                return self.resp_json(response_data)

        response_data = self.upload()
        return self.resp_json(response_data)
示例#3
0
 def __init__(self, request):
     self.request = request
     self.form = UploadFileForm(request.POST, request.FILES)
示例#4
0
class Upload(object):
    """
    Handle File Upload based on App type
    """
    def __init__(self, request):
        self.request = request
        self.form = UploadFileForm(request.POST, request.FILES)

    @staticmethod
    def as_view(request):
        upload = Upload(request)
        return upload.upload_html()

    def upload_html(self):
        response_data = {'url': '', 'description': '', 'status': 'error'}
        request = self.request
        resp = HttpResponse(json.dumps(response_data),
                            content_type="application/json; charset=utf-8")
        resp['Access-Control-Allow-Origin'] = '*'

        if request.method != 'POST':
            response_data['description'] = 'Method not Supported!'
            print("\n[ERROR] Method not Supported!")
            form = UploadFileForm()
            resp['status'] = HTTP_BAD_REQUEST
            return resp

        if not self.form.is_valid():
            response_data['description'] = 'Invalid Form Data!'
            print("\n[ERROR] Invalid Form Data!")
            resp['status'] = HTTP_BAD_REQUEST
            return resp

        self.file_content_type = request.FILES['file'].content_type
        self.file_name_lower = request.FILES['file'].name.lower()
        self.file_type = FileType(self.file_content_type, self.file_name_lower)
        if not self.file_type.is_allow_file():
            response_data['description'] = 'File format not Supported!'
            print("\n[ERROR] File format not Supported!")
            resp['status'] = HTTP_BAD_REQUEST
            return resp

        if self.file_type.is_ipa():
            if platform.system() not in LINUX_PLATFORM:
                data = {
                    'error':
                    "Static Analysis of iOS IPA requires Mac or Linux",
                    'url': 'mac_only/',
                    'status': 'success'
                }
                print(
                    "\n[ERROR] Static Analysis of iOS IPA requires Mac or Linux"
                )
                return data

        data = self.upload()

        response_data['url'] = data['url']
        response_data['status'] = data['status']
        return HttpResponse(json.dumps(response_data),
                            content_type="application/json; charset=utf-8")

    def upload_api(self):
        api_response = {}

        request = self.request
        if not self.form.is_valid():
            api_response['error'] = FormUtil.errors_message(self.form)
            return JsonResponse(data=api_response, status=HTTP_BAD_REQUEST)

        self.file_content_type = request.FILES['file'].content_type
        self.file_name_lower = request.FILES['file'].name.lower()
        self.file_type = FileType(self.file_content_type, self.file_name_lower)

        if not self.file_type.is_allow_file():
            api_response["error"] = "File format not Supported!"
            return JsonResponse(data=api_response, status=HTTP_BAD_REQUEST)
        data = self.upload()
        return JsonResponse({
            'scan_type': data['scan_type'],
            'hash': data['hash'],
            'file_name': data['file_name']
        })

    def upload(self):
        request = self.request
        scanning = Scanning(request)
        file_type = self.file_content_type
        file_name_lower = self.file_name_lower

        print("[INFO] MIME Type: {} FILE: {}".format(file_type,
                                                     file_name_lower))
        if self.file_type.is_apk():
            return scanning.scan_apk()
        elif self.file_type.is_zip():
            return scanning.scan_zip()
        elif self.file_type.is_ipa():
            return scanning.scan_ipa()
        # Windows APPX
        elif self.file_type.is_appx():
            return scanning.scan_appx()
 def __init__(self, request):
     self.request = request
     self.form = UploadFileForm(request.POST, request.FILES)
     self.file_content_type = None
     self.file_name_lower = None
     self.file_type = None
class Upload(object):
    """Handle File Upload based on App type."""
    def __init__(self, request):
        self.request = request
        self.form = UploadFileForm(request.POST, request.FILES)
        self.file_content_type = None
        self.file_name_lower = None
        self.file_type = None

    @staticmethod
    def as_view(request):
        upload = Upload(request)
        return upload.upload_html()

    def resp_json(self, data):
        resp = HttpResponse(json.dumps(data),
                            content_type='application/json; charset=utf-8')
        resp['Access-Control-Allow-Origin'] = '*'
        return resp

    def upload_html(self):
        request = self.request
        response_data = {
            'url': '',
            'description': '',
            'status': '',
        }
        if request.method != 'POST':
            logger.error('Method not Supported!')
            response_data['description'] = 'Method not Supported!'
            response_data['status'] = HTTP_BAD_REQUEST
            return self.resp_json(response_data)

        if not self.form.is_valid():
            logger.error('Invalid Form Data!')
            response_data['description'] = 'Invalid Form Data!'
            response_data['status'] = HTTP_BAD_REQUEST
            return self.resp_json(response_data)

        self.file_content_type = request.FILES['file'].content_type
        self.file_name_lower = request.FILES['file'].name.lower()
        self.file_type = FileType(self.file_content_type, self.file_name_lower)
        if not self.file_type.is_allow_file():
            logger.error('File format not Supported!')
            response_data['description'] = 'File format not Supported!'
            response_data['status'] = HTTP_BAD_REQUEST
            return self.resp_json(response_data)

        if self.file_type.is_ipa():
            if platform.system() not in LINUX_PLATFORM:
                msg = 'Static Analysis of iOS IPA requires Mac or Linux'
                logger.error(msg)
                response_data['description'] = msg
                response_data['status'] = 'success'
                response_data['url'] = 'mac_only/'
                return self.resp_json(response_data)

        response_data = self.upload()
        return self.resp_json(response_data)

    def upload_api(self):
        """API File Upload."""
        api_response = {}
        request = self.request
        if not self.form.is_valid():
            api_response['error'] = FormUtil.errors_message(self.form)
            return api_response, HTTP_BAD_REQUEST
        self.file_content_type = request.FILES['file'].content_type
        self.file_name_lower = request.FILES['file'].name.lower()
        self.file_type = FileType(self.file_content_type, self.file_name_lower)
        if not self.file_type.is_allow_file():
            api_response['error'] = 'File format not Supported!'
            return api_response, HTTP_BAD_REQUEST
        data = self.upload()
        api_response = {
            'scan_type': data['scan_type'],
            'hash': data['hash'],
            'file_name': data['file_name'],
        }
        return api_response, 200

    def upload(self):
        request = self.request
        scanning = Scanning(request)
        file_type = self.file_content_type
        file_name_lower = self.file_name_lower

        logger.info('MIME Type: %s FILE: %s', file_type, file_name_lower)
        if self.file_type.is_apk():
            return scanning.scan_apk()
        elif self.file_type.is_zip():
            return scanning.scan_zip()
        elif self.file_type.is_ipa():
            return scanning.scan_ipa()
        # Windows APPX
        elif self.file_type.is_appx():
            return scanning.scan_appx()
 def __init__(self, request):
     self.request = request
     self.form = UploadFileForm(request.POST, request.FILES)
     self.file_content_type = None
     self.file_name_lower = None
     self.file_type = None
class Upload(object):
    """
    Handle File Upload based on App type
    """

    def __init__(self, request):
        self.request = request
        self.form = UploadFileForm(request.POST, request.FILES)
        self.file_content_type = None
        self.file_name_lower = None
        self.file_type = None

    @staticmethod
    def as_view(request):
        upload = Upload(request)
        return upload.upload_html()

    def resp_json(self, data):
        resp = HttpResponse(json.dumps(data),
                            content_type="application/json; charset=utf-8")
        resp['Access-Control-Allow-Origin'] = '*'
        return resp

    def upload_html(self):
        request = self.request
        response_data = {
            'url': '',
            'description': '',
            'status': ''
        }
        if request.method != 'POST':
            print("\n[ERROR] Method not Supported!")
            form = UploadFileForm()
            response_data['description'] = 'Method not Supported!'
            response_data['status'] = HTTP_BAD_REQUEST
            return self.resp_json(response_data)

        if not self.form.is_valid():
            print("\n[ERROR] Invalid Form Data!")
            response_data['description'] = 'Invalid Form Data!'
            response_data['status'] = HTTP_BAD_REQUEST
            return self.resp_json(response_data)

        self.file_content_type = request.FILES['file'].content_type
        self.file_name_lower = request.FILES['file'].name.lower()
        self.file_type = FileType(self.file_content_type, self.file_name_lower)
        if not self.file_type.is_allow_file():
            print("\n[ERROR] File format not Supported!")
            response_data['description'] = 'File format not Supported!'
            response_data['status'] = HTTP_BAD_REQUEST
            return self.resp_json(response_data)

        if self.file_type.is_ipa():
            if platform.system() not in LINUX_PLATFORM:
                print("\n[ERROR] Static Analysis of iOS IPA requires Mac or Linux")
                response_data['description'] = 'Static Analysis of iOS IPA requires Mac or Linux'
                response_data['status'] = 'success'
                response_data['url'] = 'mac_only/'
                return self.resp_json(response_data)

        response_data = self.upload()
        return self.resp_json(response_data)

    def upload_api(self):
        """
        API File Upload
        """
        api_response = {}
        request = self.request
        if not self.form.is_valid():
            api_response['error'] = FormUtil.errors_message(self.form)
            return api_response, HTTP_BAD_REQUEST
        self.file_content_type = request.FILES['file'].content_type
        self.file_name_lower = request.FILES['file'].name.lower()
        self.file_type = FileType(self.file_content_type, self.file_name_lower)
        if not self.file_type.is_allow_file():
            api_response["error"] = "File format not Supported!"
            return api_response, HTTP_BAD_REQUEST
        data = self.upload()
        api_response = {
            'scan_type': data['scan_type'],
            'hash': data['hash'],
            'file_name': data['file_name']
        }
        return api_response, 200

    def upload(self):
        request = self.request
        scanning = Scanning(request)
        file_type = self.file_content_type
        file_name_lower = self.file_name_lower

        print("[INFO] MIME Type: {} FILE: {}".format(
            file_type, file_name_lower))
        if self.file_type.is_apk():
            return scanning.scan_apk()
        elif self.file_type.is_zip():
            return scanning.scan_zip()
        elif self.file_type.is_ipa():
            return scanning.scan_ipa()
        # Windows APPX
        elif self.file_type.is_appx():
            return scanning.scan_appx()