Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,209 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import tensorflow as tf
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
else:
|
| 17 |
-
pred=
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import tensorflow as tf
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from joblib import load
|
| 4 |
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
model_multi_path = "bestmodel_attack.h5"
|
| 9 |
+
model_bin_path = "model_binary.joblib"
|
| 10 |
+
|
| 11 |
+
model_multi= tf.keras.models.load_model('bestmodel_attack.h5')
|
| 12 |
+
model_bin = load("model_binary.joblib")
|
| 13 |
+
# protocol icmp tcp udp
|
| 14 |
+
|
| 15 |
+
# service IRC X11 Z3950 aol auth bgp courier csnet_ns ctf daytime discard domain domain_u echo eco_i ecr_i
|
| 16 |
+
# efs exec finger ftp ftp_data gopher harvest hostnames http http_2784 http_443 http_8001 imap4
|
| 17 |
+
# iso_tsap klogin kshell ldap link login mtp name netbios_dgm netbios_ns netbios_ssn
|
| 18 |
+
# netstat nnsp nntp ntp_u other pm_dump pop_2 pop_3 printer private red_i remote_job rje
|
| 19 |
+
# shell smtp sql_net ssh sunrpc supdup systat telnet tftp_u tim_i time urh_i urp_i uucp
|
| 20 |
+
# uucp_path vmnet whois
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# flag
|
| 24 |
+
# OTH RSTO RSTOS0 RSTR S0 S1 S2 S3 SF SH
|
| 25 |
+
|
| 26 |
+
# duration
|
| 27 |
+
|
| 28 |
+
# src_bytes
|
| 29 |
+
|
| 30 |
+
# dst_bytes
|
| 31 |
+
|
| 32 |
+
# urgent
|
| 33 |
+
|
| 34 |
+
# root_shell
|
| 35 |
+
|
| 36 |
+
# su_attempted
|
| 37 |
+
|
| 38 |
+
# num_file_creations
|
| 39 |
+
|
| 40 |
+
# num_shells
|
| 41 |
+
|
| 42 |
+
# num_access_files
|
| 43 |
+
|
| 44 |
+
# is_guest_login
|
| 45 |
+
|
| 46 |
+
data_mining = {
|
| 47 |
+
"protocol": ["icmp", "tcp", "udp"],
|
| 48 |
+
"service":['IRC', 'X11', 'Z39_50', 'aol','auth', 'bgp', 'courier', 'csnet_ns','ctf', 'daytime',
|
| 49 |
+
'discard', 'domain','domain_u', 'echo', 'eco_i', 'ecr_i','efs', 'exec', 'finger', 'ftp',
|
| 50 |
+
'ftp_data', 'gopher', 'harvest','hostnames', 'http', 'http_2784','http_443', 'http_8001',
|
| 51 |
+
'imap4','iso_tsap', 'klogin', 'kshell', 'ldap','link', 'login', 'mtp', 'name','netbios_dgm',
|
| 52 |
+
'netbios_ns', 'netbios_ssn','netstat', 'nnsp', 'nntp', 'ntp_u','other', 'pm_dump',
|
| 53 |
+
'pop_2', 'pop_3','printer', 'private', 'red_i','remote_job', 'rje', 'shell', 'smtp',
|
| 54 |
+
'sql_net', 'ssh', 'sunrpc', 'supdup','systat', 'telnet', 'tftp_u', 'tim_i','time',
|
| 55 |
+
'urh_i', 'urp_i', 'uucp','uucp_path', 'vmnet', 'whois'],
|
| 56 |
+
'flag':['OTH', 'REJ', 'RSTO', 'RSTOS0', 'RSTR','S0', 'S1', 'S2', 'S3', 'SF', 'SH']
|
| 57 |
+
}
|
| 58 |
+
def greet(choix,protocol,services, flag,duration,src_bytes,dst_bytes,land,wrong_fragment,urgent,hot, # ok
|
| 59 |
+
num_failed_logins,logged_in,num_compromised,root_shell,su_attempted,num_root,num_file_creations,num_shells # ok
|
| 60 |
+
,num_access_files,num_outbound_cmds,is_host_login,is_guest_login,count,srv_count,serror_rate,srv_serror_rate #ok
|
| 61 |
+
,rerror_rate,srv_rerror_rate,same_srv_rate,diff_srv_rate,srv_diff_host_rate,dst_host_count,dst_host_srv_count #ok
|
| 62 |
+
,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
|
| 63 |
+
,dst_host_srv_serror_rate,dst_host_rerror_rate,dst_host_srv_rerror_rate):
|
| 64 |
+
liste_head = [0]* len(data_mining["protocol"])
|
| 65 |
+
liste_head[data_mining["protocol"].index(protocol)] = 1
|
| 66 |
+
liste_head2 = [0]* len(data_mining["service"])
|
| 67 |
+
liste_head2[data_mining["service"].index(services)] = 1
|
| 68 |
+
liste_head3 = [0]* len(data_mining["flag"])
|
| 69 |
+
liste_head3[data_mining["flag"].index(flag)] = 1
|
| 70 |
+
list1 = list()
|
| 71 |
+
pred = None
|
| 72 |
+
name = str()
|
| 73 |
+
|
| 74 |
+
list1 = liste_head + liste_head2 + liste_head3 + [duration,src_bytes,dst_bytes,land,wrong_fragment,urgent,hot,
|
| 75 |
+
num_failed_logins,logged_in,num_compromised,root_shell,su_attempted,num_root,num_file_creations,num_shells
|
| 76 |
+
,num_access_files,num_outbound_cmds,is_host_login,is_guest_login,count,srv_count,serror_rate,srv_serror_rate
|
| 77 |
+
,rerror_rate,srv_rerror_rate,same_srv_rate,diff_srv_rate,srv_diff_host_rate,dst_host_count,dst_host_srv_count
|
| 78 |
+
,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
|
| 79 |
+
,dst_host_srv_serror_rate,dst_host_rerror_rate,dst_host_srv_rerror_rate]
|
| 80 |
+
arr = np.array(list1)
|
| 81 |
+
if choix == "Binaire":
|
| 82 |
+
pred = int(model_bin.predict(arr.reshape(1,arr.shape[0])))
|
| 83 |
+
if pred == 0:
|
| 84 |
+
name = "Aucune Attaque détectée"
|
| 85 |
+
else:
|
| 86 |
+
name= "Attaque détectée"
|
| 87 |
else:
|
| 88 |
+
pred = int(model_multi.predict(arr.reshape(1,arr.shape[0])))
|
| 89 |
+
if pred == 0:
|
| 90 |
+
name = "Aucune Attaque détectée"
|
| 91 |
+
elif pred == 1:
|
| 92 |
+
name = "Attaque DOS détecté"
|
| 93 |
+
elif pred == 2:
|
| 94 |
+
name = "Attaque Probe détecté"
|
| 95 |
+
elif pred == 3:
|
| 96 |
+
name = "Attaque de Privilège détecté"
|
| 97 |
+
else:
|
| 98 |
+
name = "Attaque d'accès détecter"
|
| 99 |
+
return f"La prédiction est : {name} "
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
iface = gr.Interface(
|
| 104 |
+
fn=greet,
|
| 105 |
+
title="API de Test de pénétration",
|
| 106 |
+
description="Cette API est utilisé pour deux actions binaires et multidetection assisté d'un environnement test continuel",
|
| 107 |
+
inputs=[
|
| 108 |
+
gr.inputs.Radio(["Binaire", "Catégorisation"],label="Choix de Prediction"), # choix
|
| 109 |
+
gr.inputs.Radio(["icmp", "tcp", "udp"],label="protocol de communication"), # protocol
|
| 110 |
+
gr.inputs.Radio(['IRC', 'X11', 'Z39_50', 'aol','auth', 'bgp', 'courier', 'csnet_ns','ctf', 'daytime',
|
| 111 |
+
'discard', 'domain','domain_u', 'echo', 'eco_i', 'ecr_i','efs', 'exec', 'finger', 'ftp',
|
| 112 |
+
'ftp_data', 'gopher', 'harvest','hostnames', 'http', 'http_2784','http_443', 'http_8001',
|
| 113 |
+
'imap4','iso_tsap', 'klogin', 'kshell', 'ldap','link', 'login', 'mtp', 'name','netbios_dgm',
|
| 114 |
+
'netbios_ns', 'netbios_ssn','netstat', 'nnsp', 'nntp', 'ntp_u','other', 'pm_dump',
|
| 115 |
+
'pop_2', 'pop_3','printer', 'private', 'red_i','remote_job', 'rje', 'shell', 'smtp',
|
| 116 |
+
'sql_net', 'ssh', 'sunrpc', 'supdup','systat', 'telnet', 'tftp_u', 'tim_i','time',
|
| 117 |
+
'urh_i', 'urp_i', 'uucp','uucp_path', 'vmnet', 'whois']
|
| 118 |
+
,label="services de communication"), # service
|
| 119 |
+
gr.inputs.Radio(['OTH', 'REJ', 'RSTO', 'RSTOS0', 'RSTR','S0', 'S1', 'S2', 'S3', 'SF', 'SH'], # 10
|
| 120 |
+
label="drapeau de communication"), # flag
|
| 121 |
+
gr.inputs.Slider(minimum=0, maximum=360,label="durée de l'execution"), # duration
|
| 122 |
+
gr.inputs.Slider(minimum=0, maximum=360,label="nombre de bits sources"), # src_bytes
|
| 123 |
+
gr.inputs.Slider(minimum=0, maximum=360,label="nombre de bits destination"), # dst_bytes
|
| 124 |
+
gr.inputs.Slider(minimum=0, maximum=360,label="land"), # land
|
| 125 |
+
gr.inputs.Slider(minimum=0, maximum=360,label="wrong_fragment"), # wrong_fragment
|
| 126 |
+
gr.inputs.Slider(minimum=0, maximum=150,step=1,label="l'urgence de l'execution"), # urgent
|
| 127 |
+
gr.inputs.Slider(minimum=0, maximum=45,step=1,label="hot"), # hot
|
| 128 |
+
gr.inputs.Slider(minimum=0, maximum=100,step=1,label="num_failed_logins"), # num_failed_logins
|
| 129 |
+
gr.inputs.Slider(minimum=0, maximum=3,step=1,label="logged_in"), # logged_in
|
| 130 |
+
gr.inputs.Slider(minimum=0, maximum=350,step=1,label="num_compromised"), # num_compromised
|
| 131 |
+
gr.inputs.Slider(minimum=0, maximum=35,step=1,label="ouverture du shell en super utilisateur"), # root_shell
|
| 132 |
+
gr.inputs.Slider(minimum=0, maximum=50,step=1,label="utilisation du mode super utilisateur"), # su_attempted
|
| 133 |
+
gr.inputs.Slider(minimum=0, maximum=315,step=1,label="num_root"), # num_root
|
| 134 |
+
gr.inputs.Slider(minimum=0, maximum=200,step=1,label="nombre de fichier en création"), # num_file_creations
|
| 135 |
+
gr.inputs.Slider(minimum=0, maximum=200,step=1,label="nombre de shell"), # num_shells
|
| 136 |
+
gr.inputs.Slider(minimum=0, maximum=200,step=1,label="nombre d'accès de fichier"), # num_access_files
|
| 137 |
+
gr.inputs.Slider(minimum=0, maximum=1,step=1,label="num_outbound_cmds"), # num_outbound_cmds
|
| 138 |
+
gr.inputs.Slider(minimum=0, maximum=400,step=1,label="is_host_login"), # is_host_login
|
| 139 |
+
gr.inputs.Slider(minimum=0, maximum=15,step=1,label="is_guest_login"), # is_guest_login
|
| 140 |
+
gr.inputs.Slider(minimum=0, maximum=5,step=1,label="count"), # count
|
| 141 |
+
gr.inputs.Slider(minimum=0, maximum=7,step=1,label="srv_count"), # srv_count
|
| 142 |
+
gr.inputs.Slider(minimum=0, maximum=1.6,step=.1,label="serror_rate"), # serror_rate
|
| 143 |
+
gr.inputs.Slider(minimum=0, maximum=2,step=.1,label="srv_serror_rate"), # srv_rerror_rate
|
| 144 |
+
gr.inputs.Slider(minimum=0, maximum=3,step=.1,label="rerror_rate"), # rerror_rate
|
| 145 |
+
gr.inputs.Slider(minimum=0, maximum=4,step=.1,label="srv_rerror_rate"), # srv_rerror_rate
|
| 146 |
+
gr.inputs.Slider(minimum=0, maximum=1,step=.1,label="same_srv_rate"), # same_srv_rate
|
| 147 |
+
gr.inputs.Slider(minimum=0, maximum=6,step=1,label="diff_srv_rate"), # diff_srv_rate
|
| 148 |
+
gr.inputs.Slider(minimum=0, maximum=6,step=1,label="srv_diff_host_rate"), # srv_diff_host_rate
|
| 149 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="dst_host_count"), # dst_host_count
|
| 150 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="dst_host_srv_count"), # dst_host_srv_count
|
| 151 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="d,st_host_same_srv_rate"), # dst_host_same_srv_rate
|
| 152 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="dst_host_same_srv_rate"), # dst_host_diff_srv_rate
|
| 153 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="dst_host_same_src_port_rate"), # dst_host_same_src_port_rate
|
| 154 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="dst_host_srv_diff_host_rate"), # dst_host_srv_diff_host_rate
|
| 155 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="dst_host_serror_rate"), # dst_host_serror_rate
|
| 156 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="dst_host_srv_serror_rate"), # dst_host_srv_serror_rate
|
| 157 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="dst_host_rerror_rate"), # dst_host_rerror_rate
|
| 158 |
+
gr.inputs.Slider(minimum=0, maximum=10,step=1,label="dst_host_srv_rerror_rate") #, # dst_host_srv_rerror_rate
|
| 159 |
+
# gr.inputs.Number(label="sources bytes de la chaine d'execution"),
|
| 160 |
+
# gr.inputs.Number(label="destination bytes de la chaine d'execution"),
|
| 161 |
+
# gr.inputs.Slider(minimum=0, maximum=80,step=1,label="land"), # land
|
| 162 |
+
# gr.inputs.Number(label="wrong fragment"),
|
| 163 |
+
# gr.inputs.Slider(minimum=0, maximum=150,step=1,label="l'urgence de l'execution"),
|
| 164 |
+
# gr.inputs.Slider(minimum=0, maximum=45,step=1,label="hot"),
|
| 165 |
+
# gr.inputs.Slider(minimum=0, maximum=100,step=1,label="num_failed_logins"),
|
| 166 |
+
# gr.inputs.Slider(minimum=0, maximum=3,step=1,label="logged_in"),
|
| 167 |
+
# gr.inputs.Slider(minimum=0, maximum=350,step=1,label="num_compromised"),
|
| 168 |
+
# gr.inputs.Slider(minimum=0, maximum=35,step=1,label="ouverture du shell en super utilisateur"),
|
| 169 |
+
# gr.inputs.Slider(minimum=0, maximum=50,step=1,label="utilisation du mode super utilisateur"),
|
| 170 |
+
# gr.inputs.Slider(minimum=0, maximum=315,step=1,label=",num_root"),
|
| 171 |
+
# gr.inputs.Slider(minimum=0, maximum=200,step=1,label=",nombre de fichier en création"),
|
| 172 |
+
# gr.inputs.Slider(minimum=0, maximum=200,step=1,label=",nombre de shell"),
|
| 173 |
+
# gr.inputs.Slider(minimum=0, maximum=200,step=1,label=",nombre d'accès de fichier"),
|
| 174 |
+
# gr.inputs.Slider(minimum=0, maximum=1,step=1,label="num_outbound_cmds"),
|
| 175 |
+
# gr.inputs.Slider(minimum=0, maximum=400,step=1,label=",is_host_login"),
|
| 176 |
+
# gr.inputs.Slider(minimum=0, maximum=15,step=1,label="i,s_guest_login"),
|
| 177 |
+
# gr.inputs.Slider(minimum=0, maximum=5,step=1,label="co,unt"),
|
| 178 |
+
# gr.inputs.Slider(minimum=0, maximum=7,step=1,label="sr,v_count"),
|
| 179 |
+
# gr.inputs.Slider(minimum=0, maximum=1.6,step=.1,label=,"serror_rate"),
|
| 180 |
+
# gr.inputs.Slider(minimum=0, maximum=2,step=.1,label="s,rv_serror_rate"),
|
| 181 |
+
# gr.inputs.Slider(minimum=0, maximum=3,step=.1,label="r,error_rate"),
|
| 182 |
+
# gr.inputs.Slider(minimum=0, maximum=4,step=.1,label="s,rv_rerror_rate"),
|
| 183 |
+
# gr.inputs.Slider(minimum=0, maximum=1,step=.1,label="s,ame_srv_rate"),
|
| 184 |
+
# gr.inputs.Slider(minimum=0, maximum=6,step=1,label="di,ff_srv_rate"),
|
| 185 |
+
# gr.inputs.Slider(minimum=0, maximum=6,step=1,label="sr,v_diff_host_rate"),
|
| 186 |
+
# gr.inputs.Slider(minimum=0, maximum=10,step=1,label="d,st_host_count"),
|
| 187 |
+
# gr.inputs.Slider(minimum=0, maximum=10,step=1,label="d,st_host_srv_count"),
|
| 188 |
+
# gr.inputs.Slider(minimum=0, maximum=10,step=1,label="d,st_host_same_srv_rate"),
|
| 189 |
+
# gr.inputs.Slider(minimum=0, maximum=10,step=1,label="d,st_host_same_src_port_rate"),
|
| 190 |
+
# gr.inputs.Slider(minimum=0, maximum=10,step=1,label="d,st_host_srv_diff_host_rate"),
|
| 191 |
+
# gr.inputs.Slider(minimum=0, maximum=10,step=1,label="d,st_host_serror_rate"),
|
| 192 |
+
# gr.inputs.Slider(minimum=0, maximum=10,step=1,label="d,st_host_srv_serror_rate"),
|
| 193 |
+
# gr.inputs.Slider(minimum=0, maximum=10,step=1,label="d,st_host_srv_rerror_rate")#,
|
| 194 |
+
# gr.inputs.Slider(minimum=0, maximum=15,step=1,label=,"nombre de shell crée"),
|
| 195 |
+
# gr.inputs.Slider(minimum=0, maximum=15,step=1,label=,"accès aux fichiers systèmes"),
|
| 196 |
+
# gr.inputs.Slider(minimum=0, maximum=1,step=1,label="est en login")
|
| 197 |
+
], # ok
|
| 198 |
+
|
| 199 |
+
outputs="text",
|
| 200 |
+
examples=[
|
| 201 |
+
["Binaire", "icmp", 'IRC','OTH',4000,45,35,2,0,1,20,5,7,0],
|
| 202 |
+
["Catégorisation", "tcp", 'netstat','REJ',3500,25,15,0,1,0,17,10,2,0],
|
| 203 |
+
["Catégorisation", "udp", 'login','S0',150,30,5,0,1,20,2,15,1,1]
|
| 204 |
+
],
|
| 205 |
+
flagging_options=["this", "or", "that"],
|
| 206 |
+
theme="dark-seafoam",
|
| 207 |
+
thumbnail='images.jpg'
|
| 208 |
+
)
|
| 209 |
+
iface.launch(inbrowser=True,favicon_path='images.jpg',share= True)# share= True,auth=("admin", "pass1234"))
|