Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,136 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
pipeline_tag: zero-shot-classification
|
| 6 |
---
|
| 7 |
+
# Model Card for Model ID
|
| 8 |
+
|
| 9 |
+
<!-- Based on https://huggingface.co/t5-small, model generates SQL from text given table list with "CREATE TABLE" statements.
|
| 10 |
+
This is a very light weigh model and could be used in multiple analytical applications. -->
|
| 11 |
+
|
| 12 |
+
Based 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**.
|
| 14 |
+
Contact us for more info: [email protected]
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
## Model Details
|
| 18 |
+
|
| 19 |
+
### Model Description
|
| 20 |
+
|
| 21 |
+
<!-- Provide a longer summary of what this model is. -->
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
- **Developed by:** cssupport ([email protected])
|
| 26 |
+
- **Model type:** Language model
|
| 27 |
+
- **Language(s) (NLP):** English
|
| 28 |
+
- **License:** Apache 2.0
|
| 29 |
+
- **Finetuned from model :** [google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased)
|
| 30 |
+
|
| 31 |
+
### Model Sources
|
| 32 |
+
|
| 33 |
+
<!-- Provide the basic links for the model. -->
|
| 34 |
+
|
| 35 |
+
Please refer [google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased) for Model Sources.
|
| 36 |
+
|
| 37 |
+
## How to Get Started with the Model
|
| 38 |
+
|
| 39 |
+
Use the code below to get started with the model.
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
import torch
|
| 43 |
+
from transformers import MobileBertTokenizer, MobileBertForSequenceClassification
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 47 |
+
tokenizer = MobileBertTokenizer.from_pretrained('google/mobilebert-uncased')
|
| 48 |
+
model = MobileBertForSequenceClassification.from_pretrained('cssupport/mobilebert-sql-injection-detect')
|
| 49 |
+
model.to(device)
|
| 50 |
+
model.eval()
|
| 51 |
+
|
| 52 |
+
def predict(text):
|
| 53 |
+
inputs = tokenizer(text, padding=False, truncation=True, return_tensors='pt', max_length=512)
|
| 54 |
+
input_ids = inputs['input_ids'].to(device)
|
| 55 |
+
attention_mask = inputs['attention_mask'].to(device)
|
| 56 |
+
|
| 57 |
+
with torch.no_grad():
|
| 58 |
+
outputs = model(input_ids=input_ids, attention_mask=attention_mask)
|
| 59 |
+
|
| 60 |
+
logits = outputs.logits
|
| 61 |
+
probabilities = torch.softmax(logits, dim=1)
|
| 62 |
+
predicted_class = torch.argmax(probabilities, dim=1).item()
|
| 63 |
+
return predicted_class, probabilities[0][predicted_class].item()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
#text = "SELECT * FROM users WHERE username = 'admin' AND password = 'password';"
|
| 67 |
+
#text = "select * from users where username = 'admin' and password = 'password';"
|
| 68 |
+
#text = "SELECT * from USERS where id = '1' or @ @1 = 1 union select 1,version ( ) -- 1'"
|
| 69 |
+
#text = "select * from data where id = '1' or @"
|
| 70 |
+
text ="select * from users where id = 1 or 1#\"? = 1 or 1 = 1 -- 1"
|
| 71 |
+
predicted_class, confidence = predict(text)
|
| 72 |
+
|
| 73 |
+
if predicted_class > 0.7:
|
| 74 |
+
print("Prediction: SQL Injection Detected")
|
| 75 |
+
else:
|
| 76 |
+
print("Prediction: No SQL Injection Detected")
|
| 77 |
+
|
| 78 |
+
print(f"Confidence: {confidence:.2f}")
|
| 79 |
+
# OUTPUT
|
| 80 |
+
# Prediction: SQL Injection Detected
|
| 81 |
+
# Confidence: 1.00
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
## Uses
|
| 86 |
+
|
| 87 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 88 |
+
|
| 89 |
+
[More Information Needed]
|
| 90 |
+
|
| 91 |
+
### Direct Use
|
| 92 |
+
|
| 93 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 94 |
+
Could used in application where natural language is to be converted into SQL queries.
|
| 95 |
+
[More Information Needed]
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
### Out-of-Scope Use
|
| 100 |
+
|
| 101 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 102 |
+
|
| 103 |
+
[More Information Needed]
|
| 104 |
+
|
| 105 |
+
## Bias, Risks, and Limitations
|
| 106 |
+
|
| 107 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 108 |
+
|
| 109 |
+
[More Information Needed]
|
| 110 |
+
|
| 111 |
+
### Recommendations
|
| 112 |
+
|
| 113 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 114 |
+
|
| 115 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
## Technical Specifications
|
| 120 |
+
|
| 121 |
+
### Model Architecture and Objective
|
| 122 |
+
|
| 123 |
+
[google/mobilebert-uncased](https://huggingface.co/google/mobilebert-uncased)
|
| 124 |
+
|
| 125 |
+
### Compute Infrastructure
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
#### Hardware
|
| 130 |
+
|
| 131 |
+
one P6000 GPU
|
| 132 |
+
|
| 133 |
+
#### Software
|
| 134 |
+
|
| 135 |
+
Pytorch and HuggingFace
|
| 136 |
+
|