cssupport/mobilebert-sql-injection-detect
11474
1---2license: apache-2.03language:4- en5pipeline_tag: text-classification6---7# Model Card for Model ID8 9<!-- Based on https://huggingface.co/t5-small, model generates SQL from text given table list with "CREATE TABLE" statements. 10This is a very light weigh model and could be used in multiple analytical applications. -->11 12Based on [google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased) (MobileBERT is a thin version of BERT_LARGE, while equipped with bottleneck structures and a carefully designed balance between self-attentions and feed-forward networks). This model detects SQLInjection attacks in the input string (check How To Below). This is a very very light model (100mb) and can be used for edge computing use cases. Used dataset from [Kaggle](www.kaggle.com) called [SQl_Injection](https://www.kaggle.com/datasets/sajid576/sql-injection-dataset).13**Please test the model before deploying into any environment**.14Contact us for more info: support@cloudsummary.com15### Code Repo16Here is the code repo https://github.com/cssupport23/AI-Model---SQL-Injection-Attack-Detector17 18## Model Details19 20### Model Description21 22<!-- Provide a longer summary of what this model is. -->23 24 25 26- **Developed by:** cssupport (support@cloudsummary.com)27- **Model type:** Language model28- **Language(s) (NLP):** English29- **License:** Apache 2.030- **Finetuned from model :** [google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased)31 32### Model Sources 33 34<!-- Provide the basic links for the model. -->35 36Please refer [google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased) for Model Sources.37 38## How to Get Started with the Model39 40Use the code below to get started with the model.41 42```python43import torch44from transformers import MobileBertTokenizer, MobileBertForSequenceClassification45 46 47device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')48tokenizer = MobileBertTokenizer.from_pretrained('google/mobilebert-uncased')49model = MobileBertForSequenceClassification.from_pretrained('cssupport/mobilebert-sql-injection-detect')50model.to(device)51model.eval()52 53def predict(text):54 inputs = tokenizer(text, padding=False, truncation=True, return_tensors='pt', max_length=512)55 input_ids = inputs['input_ids'].to(device)56 attention_mask = inputs['attention_mask'].to(device)57 58 with torch.no_grad():59 outputs = model(input_ids=input_ids, attention_mask=attention_mask)60 61 logits = outputs.logits62 probabilities = torch.softmax(logits, dim=1)63 predicted_class = torch.argmax(probabilities, dim=1).item()64 return predicted_class, probabilities[0][predicted_class].item()65 66 67#text = "SELECT * FROM users WHERE username = 'admin' AND password = 'password';"68#text = "select * from users where username = 'admin' and password = 'password';"69#text = "SELECT * from USERS where id = '1' or @ @1 = 1 union select 1,version ( ) -- 1'"70#text = "select * from data where id = '1' or @"71text ="select * from users where id = 1 or 1#\"? = 1 or 1 = 1 -- 1"72predicted_class, confidence = predict(text)73 74if predicted_class > 0.7:75 print("Prediction: SQL Injection Detected")76else:77 print("Prediction: No SQL Injection Detected")78 79print(f"Confidence: {confidence:.2f}")80# OUTPUT81# Prediction: SQL Injection Detected82# Confidence: 1.0083```84 85 86## Uses87 88<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->89 90[More Information Needed]91 92### Direct Use93 94<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->95Could used in application where natural language is to be converted into SQL queries. 96[More Information Needed]97 98 99 100### Out-of-Scope Use101 102<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->103 104[More Information Needed]105 106## Bias, Risks, and Limitations107 108<!-- This section is meant to convey both technical and sociotechnical limitations. -->109 110[More Information Needed]111 112### Recommendations113 114<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->115 116Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.117 118 119 120## Technical Specifications 121 122### Model Architecture and Objective123 124[google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased)125 126### Compute Infrastructure127 128 129 130#### Hardware131 132one P6000 GPU133 134#### Software135 136Pytorch and HuggingFace137 138## Disclaimer139#### Educational/Informational Use Only140This model is provided solely for educational or informational purposes. It is not intended to be used for malicious activities or any other unlawful behavior.141 142#### No Warranty143This model is provided on an "as is" basis, without warranties or conditions of any kind, whether express or implied. We make no guarantees regarding its accuracy, reliability, or performance. Use of this model is at your own risk.144 145#### Limitation of Liability146Under no circumstances shall the creators, maintainers, or contributors of this model be held liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including but not limited to procurement of substitute goods or services; loss of use, data, or profits; or business interruption) arising out of the use or inability to use this model, even if advised of the possibility of such damage.147 148#### No Responsibility for Outcomes149We are not responsible for any damages, security breaches, or other issues that may result from using this model. If the model fails to detect certain SQL injection attacks or produces false positives, we will not be held liable for any consequences arising from such outcomes.150 151#### User Responsibility152By using or downloading this model, you agree to be solely responsible for compliance with all applicable laws and regulations. Any misuse of this model, including using it to facilitate or commit malicious activities, remains the sole responsibility of the user.