This repository was archived by the owner on Apr 12, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Phase-1 Contributions for Analyzer #12
Open
ashish493
wants to merge
15
commits into
OWASP:develop
Choose a base branch
from
ashish493:develop-analyzer
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6561f33
Merge pull request #6 from OWASP/develop
hardlyhuman 0cca333
setup django github action
hardlyhuman aabf006
Update issue templates
hardlyhuman 0278d55
Create FUNDING.yml
hardlyhuman f6c8662
added classifiers for prediction from the dataset
ashish493 bcad1a2
added dataset
ashish493 0dcf917
Extraction of important features using RfeCV from the dataset
ashish493 67a50af
Data preprocessing of dataset
ashish493 5b92b29
Update views
ashish493 4bab5ac
Delete Feature_Extraction.ipynb
ashish493 68bb3c7
Replacing the feature extraction notebook
ashish493 2f5c9fb
added single model
ashish493 06977a0
added Rest
ashish493 af6f606
added input serializers
ashish493 791db47
Delete kdd_preprocessing.ipynb
ashish493 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # These are supported funding model platforms | ||
|
|
||
| github: hardlyhuman | ||
| patreon: gsriharsha | ||
| custom: ["https://www.paypal.me/SRIHARSHAGAJAVALLI"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --- | ||
| name: Bug report | ||
| about: Create a report to help us improve | ||
| title: '' | ||
| labels: '' | ||
| assignees: '' | ||
|
|
||
| --- | ||
|
|
||
| **Describe the bug** | ||
| A clear and concise description of what the bug is. | ||
|
|
||
| **To Reproduce** | ||
| Steps to reproduce the behavior: | ||
| 1. Go to '...' | ||
| 2. Click on '....' | ||
| 3. Scroll down to '....' | ||
| 4. See error | ||
|
|
||
| **Expected behavior** | ||
| A clear and concise description of what you expected to happen. | ||
|
|
||
| **Screenshots** | ||
| If applicable, add screenshots to help explain your problem. | ||
|
|
||
| **Desktop (please complete the following information):** | ||
| - OS: [e.g. iOS] | ||
| - Browser [e.g. chrome, safari] | ||
| - Version [e.g. 22] | ||
|
|
||
| **Smartphone (please complete the following information):** | ||
| - Device: [e.g. iPhone6] | ||
| - OS: [e.g. iOS8.1] | ||
| - Browser [e.g. stock browser, safari] | ||
| - Version [e.g. 22] | ||
|
|
||
| **Additional context** | ||
| Add any other context about the problem here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| name: Custom issue template | ||
| about: Describe this issue template's purpose here. | ||
| title: '' | ||
| labels: '' | ||
| assignees: '' | ||
|
|
||
| --- | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --- | ||
| name: Feature request | ||
| about: Suggest an idea for this project | ||
| title: '' | ||
| labels: '' | ||
| assignees: '' | ||
|
|
||
| --- | ||
|
|
||
| **Is your feature request related to a problem? Please describe.** | ||
| A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
|
||
| **Describe the solution you'd like** | ||
| A clear and concise description of what you want to happen. | ||
|
|
||
| **Describe alternatives you've considered** | ||
| A clear and concise description of any alternative solutions or features you've considered. | ||
|
|
||
| **Additional context** | ||
| Add any other context or screenshots about the feature request here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| name: Django CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ master ] | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| max-parallel: 4 | ||
| matrix: | ||
| python-version: [3.6, 3.7, 3.8] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v1 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install Dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r requirements.txt | ||
| - name: Run Tests | ||
| run: | | ||
| python manage.py test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #importing libraries | ||
| import numpy as np | ||
| import pandas as pd | ||
| import os | ||
| import matplotlib as mpl | ||
| import matplotlib.pyplot as plt | ||
| print(os.listdir("/")) | ||
|
|
||
| #change it according ur directory | ||
| df = pd.read_csv('/Intelligent-Intrusion-Detection-System/datasets/kddcup.data.gz') | ||
| print(df.shape()) | ||
|
|
||
| df.columns =["duration","protocol_type","service","flag","src_bytes", | ||
| "dst_bytes","land","wrong_fragment","urgent","hot","num_failed_logins", | ||
| "logged_in","num_compromised","root_shell","su_attempted","num_root", | ||
| "num_file_creations","num_shells","num_access_files","num_outbound_cmds", | ||
| "is_host_login","is_guest_login","count","srv_count","serror_rate", | ||
| "srv_serror_rate","rerror_rate","srv_rerror_rate","same_srv_rate", | ||
| "diff_srv_rate","srv_diff_host_rate","dst_host_count","dst_host_srv_count", | ||
| "dst_host_same_srv_rate","dst_host_diff_srv_rate","dst_host_same_src_port_rate", | ||
| "dst_host_srv_diff_host_rate","dst_host_serror_rate","dst_host_srv_serror_rate", | ||
| "dst_host_rerror_rate","dst_host_srv_rerror_rate","label"] | ||
|
|
||
| X = df.iloc[:,:41] | ||
| y = df.iloc[:,-1] | ||
| X.head() | ||
|
|
||
| #Pre-processing of categorial data columns | ||
| from sklearn import preprocessing | ||
| le = preprocessing.LabelEncoder() | ||
| df['protocol_type'] = le.fit_transform(df['protocol_type']) | ||
| df['service']= le.fit_transform(df['service']) | ||
| df['flag'] = le.fit_transform(df['flag']) | ||
|
|
||
| #Splitting of data | ||
| from sklearn.model_selection import train_test_split | ||
| X_train,X_test,y_train,y_test = train_test_split(X,y,random_state = 42,test_size = 0.3) | ||
|
|
||
| #Scaling of data | ||
| from sklearn.preprocessing import MinMaxScaler | ||
| scaler = MinMaxScaler(feature_range=(0, 1)) | ||
| X_train_scaled = scaler.fit_transform(X_train) | ||
| X_test_scaled = scaler.transform(X_test) | ||
|
|
||
| from sklearn.feature_selection import RFECV | ||
| from sklearn.ensemble import RandomForestClassifier | ||
| from sklearn.model_selection import StratifiedKFold | ||
|
|
||
| #U can easily change the model by just replacing here | ||
| from sklearn.ensemble import RandomForestClassifier | ||
| model1 = RandomForestClassifier(n_estimators=100, max_depth=2,random_state=0,class_weight='balanced') | ||
|
|
||
| rfecv = RFECV(estimator=model1, step=1, cv=StratifiedKFold(2), scoring='accuracy' ) | ||
| rfecv.fit(X_train_scaled,y_train) | ||
|
|
||
|
|
||
| print('Optimal number of features: {}'.format(rfecv.n_features_)) | ||
|
|
||
| #Feature Selection plot | ||
| plt.figure(figsize=(16, 9)) | ||
| plt.title('Recursive Feature Elimination with Cross-Validation', fontsize=18, fontweight='bold', pad=20) | ||
| plt.xlabel('Number of features selected', fontsize=14, labelpad=20) | ||
| plt.ylabel('% Correct Classification', fontsize=14, labelpad=20) | ||
| plt.plot(range(1, len(rfecv.grid_scores_) + 1), rfecv.grid_scores_, color='#303F9F', linewidth=3) | ||
|
|
||
| plt.show() | ||
|
|
||
| dset = pd.DataFrame() | ||
| dset['attr'] = X.columns | ||
| dset['importance'] = rfecv.estimator_.feature_importances_ | ||
| dset = dset.sort_values(by='importance', ascending=False) | ||
|
|
||
| #Feature Ranking plot | ||
| plt.figure(figsize=(16, 14)) | ||
| plt.barh(y=dset['attr'], width=dset['importance'], color='#1976D2') | ||
| plt.title('RFECV - Feature Importances', fontsize=20, fontweight='bold', pad=20) | ||
| plt.xlabel('Importance', fontsize=14, labelpad=20) | ||
| plt.show() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import os | ||
| print(os.listdir("/")) | ||
|
|
||
| df = pd.read_csv('/mnt/d/GSOC/Intelligent-Intrusion-Detection-System/datasets/kddcup.data.gz') | ||
| ##Change according to the directory of the cloned repo w.r.t dataset location. | ||
|
|
||
| df.columns =["duration","protocol_type","service","flag","src_bytes", | ||
| "dst_bytes","land","wrong_fragment","urgent","hot","num_failed_logins", | ||
| "logged_in","num_compromised","root_shell","su_attempted","num_root", | ||
| "num_file_creations","num_shells","num_access_files","num_outbound_cmds", | ||
| "is_host_login","is_guest_login","count","srv_count","serror_rate", | ||
| "srv_serror_rate","rerror_rate","srv_rerror_rate","same_srv_rate", | ||
| "diff_srv_rate","srv_diff_host_rate","dst_host_count","dst_host_srv_count", | ||
| "dst_host_same_srv_rate","dst_host_diff_srv_rate","dst_host_same_src_port_rate", | ||
| "dst_host_srv_diff_host_rate","dst_host_serror_rate","dst_host_srv_serror_rate", | ||
| "dst_host_rerror_rate","dst_host_srv_rerror_rate","label"] | ||
|
|
||
|
|
||
| from sklearn.preprocessing import LabelEncoder,OneHotEncoder | ||
| le = LabelEncoder() | ||
| df['protocol_type'] = le.fit_transform(df['protocol_type']) | ||
| df['service']= le.fit_transform(df['service']) | ||
| df['flag'] = le.fit_transform(df['flag']) | ||
|
|
||
| X = df.iloc[:,:41] | ||
| y = df.iloc[:,-1] | ||
|
|
||
| from sklearn.model_selection import train_test_split | ||
| X_train,X_test,y_train,y_test = train_test_split(X,y,random_state = 42,test_size = 0.4) | ||
|
|
||
| from sklearn.preprocessing import MinMaxScaler | ||
| scaler = MinMaxScaler(feature_range=(0, 1)) | ||
| X_train_scaled = scaler.fit_transform(X_train) | ||
| X_test_scaled = scaler.transform(X_test) | ||
|
|
||
|
|
||
|
|
||
| from sklearn.ensemble import AdaBoostClassifier | ||
| ab_model = AdaBoostClassifier() | ||
| ab_model.fit(X_train,y_train) | ||
|
|
||
| score = ab_model.score(X_test, y_test) | ||
| print(f'The score by AdaBoostClassifier is {score}') | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import os | ||
| print(os.listdir("/")) | ||
|
|
||
| df = pd.read_csv('/mnt/d/GSOC/Intelligent-Intrusion-Detection-System/datasets/kddcup.data.gz') | ||
| ##Change according to the directory of the cloned repo w.r.t dataset location. | ||
|
|
||
| df.columns =["duration","protocol_type","service","flag","src_bytes", | ||
| "dst_bytes","land","wrong_fragment","urgent","hot","num_failed_logins", | ||
| "logged_in","num_compromised","root_shell","su_attempted","num_root", | ||
| "num_file_creations","num_shells","num_access_files","num_outbound_cmds", | ||
| "is_host_login","is_guest_login","count","srv_count","serror_rate", | ||
| "srv_serror_rate","rerror_rate","srv_rerror_rate","same_srv_rate", | ||
| "diff_srv_rate","srv_diff_host_rate","dst_host_count","dst_host_srv_count", | ||
| "dst_host_same_srv_rate","dst_host_diff_srv_rate","dst_host_same_src_port_rate", | ||
| "dst_host_srv_diff_host_rate","dst_host_serror_rate","dst_host_srv_serror_rate", | ||
| "dst_host_rerror_rate","dst_host_srv_rerror_rate","label"] | ||
|
|
||
|
|
||
| from sklearn.preprocessing import LabelEncoder,OneHotEncoder | ||
| le = LabelEncoder() | ||
| df['protocol_type'] = le.fit_transform(df['protocol_type']) | ||
| df['service']= le.fit_transform(df['service']) | ||
| df['flag'] = le.fit_transform(df['flag']) | ||
|
|
||
| X = df.iloc[:,:41] | ||
| y = df.iloc[:,-1] | ||
|
|
||
| from sklearn.model_selection import train_test_split | ||
| X_train,X_test,y_train,y_test = train_test_split(X,y,random_state = 42,test_size = 0.4) | ||
|
|
||
| from sklearn.preprocessing import MinMaxScaler | ||
| scaler = MinMaxScaler(feature_range=(0, 1)) | ||
| X_train_scaled = scaler.fit_transform(X_train) | ||
| X_test_scaled = scaler.transform(X_test) | ||
|
|
||
| from sklearn.tree import DecisionTreeClassifier | ||
| dt_model = DecisionTreeClassifier(max_depth=5) | ||
| dt_model.fit(X_train,y_train) | ||
|
|
||
| score = dt_model.score(X_test, y_test) | ||
| print(f'The score by DecisionTreeClassifier is {score}') | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import os | ||
| print(os.listdir("/")) | ||
|
|
||
| df = pd.read_csv('/mnt/d/GSOC/Intelligent-Intrusion-Detection-System/datasets/kddcup.data.gz') | ||
| ##Change according to the directory of the cloned repo w.r.t dataset location. | ||
|
|
||
| df.columns =["duration","protocol_type","service","flag","src_bytes", | ||
| "dst_bytes","land","wrong_fragment","urgent","hot","num_failed_logins", | ||
| "logged_in","num_compromised","root_shell","su_attempted","num_root", | ||
| "num_file_creations","num_shells","num_access_files","num_outbound_cmds", | ||
| "is_host_login","is_guest_login","count","srv_count","serror_rate", | ||
| "srv_serror_rate","rerror_rate","srv_rerror_rate","same_srv_rate", | ||
| "diff_srv_rate","srv_diff_host_rate","dst_host_count","dst_host_srv_count", | ||
| "dst_host_same_srv_rate","dst_host_diff_srv_rate","dst_host_same_src_port_rate", | ||
| "dst_host_srv_diff_host_rate","dst_host_serror_rate","dst_host_srv_serror_rate", | ||
| "dst_host_rerror_rate","dst_host_srv_rerror_rate","label"] | ||
|
|
||
|
|
||
| from sklearn.preprocessing import LabelEncoder,OneHotEncoder | ||
| le = LabelEncoder() | ||
| df['protocol_type'] = le.fit_transform(df['protocol_type']) | ||
| df['service']= le.fit_transform(df['service']) | ||
| df['flag'] = le.fit_transform(df['flag']) | ||
|
|
||
| X = df.iloc[:,:41] | ||
| y = df.iloc[:,-1] | ||
|
|
||
| from sklearn.model_selection import train_test_split | ||
| X_train,X_test,y_train,y_test = train_test_split(X,y,random_state = 42,test_size = 0.4) | ||
|
|
||
| from sklearn.preprocessing import MinMaxScaler | ||
| scaler = MinMaxScaler(feature_range=(0, 1)) | ||
| X_train_scaled = scaler.fit_transform(X_train) | ||
| X_test_scaled = scaler.transform(X_test) | ||
|
|
||
| # n_neighbors are set to 3, after getting max accuracy | ||
| from sklearn.neighbors import KNeighborsClassifier | ||
| knn_model = KNeighborsClassifier(n_neighbors=3) | ||
| knn_model.fit(X_train,y_train) | ||
|
|
||
| score = knn_model.score(X_test, y_test) | ||
| print(f'The score by KNClassifier is {score}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
|
|
||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import os | ||
| print(os.listdir("/")) | ||
|
|
||
| df = pd.read_csv('/mnt/d/GSOC/Intelligent-Intrusion-Detection-System/datasets/kddcup.data.gz') | ||
| ##Change according to the directory of the cloned repo w.r.t dataset location. | ||
|
|
||
| df.columns =["duration","protocol_type","service","flag","src_bytes", | ||
| "dst_bytes","land","wrong_fragment","urgent","hot","num_failed_logins", | ||
| "logged_in","num_compromised","root_shell","su_attempted","num_root", | ||
| "num_file_creations","num_shells","num_access_files","num_outbound_cmds", | ||
| "is_host_login","is_guest_login","count","srv_count","serror_rate", | ||
| "srv_serror_rate","rerror_rate","srv_rerror_rate","same_srv_rate", | ||
| "diff_srv_rate","srv_diff_host_rate","dst_host_count","dst_host_srv_count", | ||
| "dst_host_same_srv_rate","dst_host_diff_srv_rate","dst_host_same_src_port_rate", | ||
| "dst_host_srv_diff_host_rate","dst_host_serror_rate","dst_host_srv_serror_rate", | ||
| "dst_host_rerror_rate","dst_host_srv_rerror_rate","label"] | ||
|
|
||
|
|
||
| from sklearn.preprocessing import LabelEncoder,OneHotEncoder | ||
| le = LabelEncoder() | ||
| df['protocol_type'] = le.fit_transform(df['protocol_type']) | ||
| df['service']= le.fit_transform(df['service']) | ||
| df['flag'] = le.fit_transform(df['flag']) | ||
|
|
||
| X = df.iloc[:,:41] | ||
| y = df.iloc[:,-1] | ||
|
|
||
| from sklearn.model_selection import train_test_split | ||
| X_train,X_test,y_train,y_test = train_test_split(X,y,random_state = 42,test_size = 0.4) | ||
|
|
||
| from sklearn.preprocessing import MinMaxScaler | ||
| scaler = MinMaxScaler(feature_range=(0, 1)) | ||
| X_train_scaled = scaler.fit_transform(X_train) | ||
| X_test_scaled = scaler.transform(X_test) | ||
|
|
||
| from sklearn.ensemble import RandomForestClassifier | ||
| rf_model = RandomForestClassifier(n_estimators=100, max_depth=2,random_state=0,class_weight='balanced') | ||
| rf_model.fit(X_train,y_train) | ||
|
|
||
| score = rf_model.score(X_test, y_test) | ||
| print(f'The score by Random Forest is {score}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #Serializers for input | ||
| from rest_framework import serializers | ||
| from rest_framework.renderers import JSONRenderer | ||
|
|
||
| class EndpointSerializer(serializers.ModelSerializer): | ||
| read_only_fields = ("model_name", "param1", "param2", "param3") | ||
|
|
||
|
|
||
| serializer = EndpointSerializer(data) | ||
| json = JSONRenderer().render(serializer.data) | ||
|
|
||
| #Deserializinf of data | ||
| from StringIO import StringIO | ||
| from rest_framework.parsers import JSONParser | ||
|
|
||
| stream = StringIO(json) | ||
| data = JSONParser().parse(stream) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will modify it as soon as the necessary changes are made