コード例 #1
0
    def upload_html(self):
        request = self.request
        response_data = {
            'description': '',
            'status': 'error',
        }
        if request.method != 'POST':
            msg = 'Method not Supported!'
            logger.error(msg)
            response_data['description'] = msg
            return self.resp_json(response_data)

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

        self.file = request.FILES['file']
        self.file_type = FileType(self.file)
        if not self.file_type.is_allow_file():
            msg = 'File format not Supported!'
            logger.error(msg)
            response_data['description'] = msg
            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
                return self.resp_json(response_data)

        response_data = self.upload()
        return self.resp_json(response_data)
コード例 #2
0
 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 = request.FILES['file']
     self.file_type = FileType(self.file)
     if not self.file_type.is_allow_file():
         api_response['error'] = 'File format not Supported!'
         return api_response, HTTP_BAD_REQUEST
     api_response = self.upload()
     return api_response, 200
コード例 #3
0
 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
コード例 #4
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)
コード例 #5
0
 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
コード例 #6
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)
        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()
コード例 #7
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)
        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()