Skip to content

Commit 0782930

Browse files
committed
Adding missing lookup files
1 parent b3447c9 commit 0782930

3 files changed

+16
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
algo,model,options
2+
MLTKContainer,"{""__mlspl_type"": [""mltkc.MLTKContainer"", ""MLTKContainer""], ""dict"": {""endpoint_url"": ""https://localhost:62645"", ""out_params"": {""params"": {""mode"": ""stage"", ""algo"": ""detect_dns_data_exfiltration_using_pretrained_model_in_dsdl""}, ""args"": [""is_exfiltration"", ""src"", ""query"", ""rank""], ""target_variable"": [""is_exfiltration""], ""feature_variables"": [""src"", ""query"", ""rank""], ""model_name"": ""detect_dns_data_exfiltration_using_pretrained_model_in_dsdl"", ""algo_name"": ""MLTKContainer"", ""mlspl_limits"": {""handle_new_cat"": ""default"", ""max_distinct_cat_values"": ""100"", ""max_distinct_cat_values_for_classifiers"": ""100"", ""max_distinct_cat_values_for_scoring"": ""100"", ""max_fit_time"": ""600"", ""max_inputs"": ""100000"", ""max_memory_usage_mb"": ""4000"", ""max_model_size_mb"": ""30"", ""max_score_time"": ""600"", ""use_sampling"": ""true""}, ""kfold_cv"": null}, ""feature_variables"": [""src"", ""query"", ""rank""], ""target_variable"": ""is_exfiltration""}}","{""params"": {""mode"": ""stage"", ""algo"": ""detect_dns_data_exfiltration_using_pretrained_model_in_dsdl""}, ""args"": [""is_exfiltration"", ""src"", ""query"", ""rank""], ""target_variable"": [""is_exfiltration""], ""feature_variables"": [""src"", ""query"", ""rank""], ""model_name"": ""detect_dns_data_exfiltration_using_pretrained_model_in_dsdl"", ""algo_name"": ""MLTKContainer"", ""mlspl_limits"": {""handle_new_cat"": ""default"", ""max_distinct_cat_values"": ""100"", ""max_distinct_cat_values_for_classifiers"": ""100"", ""max_distinct_cat_values_for_scoring"": ""100"", ""max_fit_time"": ""600"", ""max_inputs"": ""100000"", ""max_memory_usage_mb"": ""4000"", ""max_model_size_mb"": ""30"", ""max_score_time"": ""600"", ""use_sampling"": ""true""}, ""kfold_cv"": null}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
description: Detect DNS Data Exfiltration using pretrained Model in DSDL
2+
filename: __mlspl_detect_dns_data_exfiltration_using_pretrained_model_in_dsdl.mlmodel
3+
name: __mlspl_detect_dns_data_exfiltration_using_pretrained_model_in_dsdl
4+
case_sensitive_match: 'false'

notebooks/detect_dns_data_exfiltration_using_pretrained_model_in_dsdl.ipynb

+10-13
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@
189189
"class DNSExfiltration(nn.Module):\n",
190190
" def __init__(self,input_size):\n",
191191
" super().__init__()\n",
192-
" self.layer_1 = nn.Linear(input_size, 256) \n",
193-
" self.layer_2 = nn.Linear(256, 256)\n",
194-
" self.layer_out = nn.Linear(256, 1) \n",
192+
" self.layer_1 = nn.Linear(input_size, 128) \n",
193+
" self.layer_2 = nn.Linear(128, 128)\n",
194+
" self.layer_out = nn.Linear(128, 1) \n",
195195
" \n",
196196
" \n",
197197
" self.relu = nn.ReLU()\n",
@@ -212,7 +212,7 @@
212212
"print (len(list(string.printable.strip())))\n",
213213
" \n",
214214
"def init(df,param):\n",
215-
" model = DNSExfiltration(99)\n",
215+
" model = DNSExfiltration(98)\n",
216216
" model.load_state_dict(torch.load(MODEL_DIRECTORY+'detect_dns_data_exfiltration_using_pretrained_model_in_dsdl.pt',map_location=torch.device('cpu')))\n",
217217
" model = model.to('cpu')\n",
218218
" model.eval()\n",
@@ -382,14 +382,11 @@
382382
" # length of domain\n",
383383
" df['len'] = df['request_without_domain'].apply(len)\n",
384384
" \n",
385-
" # number of subdomains\n",
386-
" df['subdomains_count'] = df['request_without_domain'].apply(lambda x: len(str(x).split('.')))\n",
387-
" \n",
388385
" # entropy\n",
389386
" df['entropy'] = df['request_without_domain'].apply(lambda x: entropy(x))\n",
390387
" \n",
391388
" # take most-recent request\n",
392-
" recent_df = df.loc[df['count'] == 1]\n",
389+
" recent_df = df.loc[df['rank'] == 1]\n",
393390
"\n",
394391
" # calculate feature by aggregating events\n",
395392
"\n",
@@ -401,10 +398,10 @@
401398
" \n",
402399
"# apply model on processed dataframe to predict exfiltration\n",
403400
"def apply(model,df,param):\n",
404-
" df.drop(['_time'], axis=1,inplace=True)\n",
401+
" df.drop(['_time'], axis=1,inplace=True, errors='ignore')\n",
405402
" recent_df = prepare_input_df(df)\n",
406-
" input_df = recent_df.drop(['src' ,'query','count','request_without_domain','tld'], axis=1)\n",
407-
" recent_df.drop(['request_without_domain','tld','len','subdomains_count','entropy','size_avg','entropy_avg'], axis=1, inplace=True)\n",
403+
" input_df = recent_df.drop(['src' ,'query','rank','request_without_domain','tld'], axis=1)\n",
404+
" recent_df.drop(['request_without_domain','tld','len','entropy','size_avg','entropy_avg'], axis=1, inplace=True)\n",
408405
" recent_df.drop(range(0, 94),axis=1,inplace=True)\n",
409406
" input_tensor = torch.FloatTensor(input_df.values)\n",
410407
" dataloader = DataLoader(input_tensor, shuffle=True, batch_size=256)\n",
@@ -416,7 +413,7 @@
416413
" text_rows.clear()\n",
417414
" size_avg.clear()\n",
418415
" entropy_avg.clear()\n",
419-
" output = pd.merge(recent_df,df,on=['src','query','count'],how='right')\n",
416+
" output = pd.merge(recent_df,df,on=['src','query','rank'],how='right')\n",
420417
" return output"
421418
]
422419
},
@@ -461,7 +458,7 @@
461458
"source": [
462459
"# load model from name in expected convention \"<algo_name>_<model_name>\"\n",
463460
"def load(name):\n",
464-
" model = DNSExfiltration(99)\n",
461+
" model = DNSExfiltration(98)\n",
465462
" model.load_state_dict(torch.load(MODEL_DIRECTORY+'detect_dns_data_exfiltration_using_pretrained_model_in_dsdl.pt',map_location=torch.device('cpu')))\n",
466463
" model = model.to('cpu')\n",
467464
" model.eval()\n",

0 commit comments

Comments
 (0)