SlideShare a Scribd company logo
Python program to build deep learning algorithm using a CNNs model to detect malware attacks.
The code is working, but I faced issues with the last part of the code, and I needed to know
precisely where the problem was.
I have the dataset of malware and benign in exe, I convert them to grayscale images, and it goes
through the filters, and it shows me the output.
this is the code
import keras from keras.models import Sequential from keras.layers import Dense, Dropout,
Activation, Flatten from keras.layers import Conv2D, MaxPooling2D import numpy as np from
os import listdir from PIL import Image import os.path import numpy as np path =
'/media/malkuwari/New Volume/Ransomware_Detection_using _CNN/mixEXE' h = 256
#height of image w = 256 #width of image # be careful with using this function, it will consume
memory, access to disk and time images = [] for f in listdir('/media/malkuwari/New
Volume/Ransomware_Detection_using _CNN/mixEXE'): with
open(os.path.join('/media/malkuwari/New Volume/Ransomware_Detection_using
_CNN/mixEXE', f), 'rb') as img_set: img_arr = img_set.read(h*w) while img_arr: if len(img_arr)
== h*w and img_arr not in images: images.append(img_arr) img_arr = img_set.read(h*w) #And
you can save them into png files # count = 0 # for img in images: # png =
Image.fromarray(np.reshape(list(img), (h,w)).astype('float32'), mode='L') #
png.save('image_l%d.png'%count) # count += 1 #reshape images to fit into the CNN model
img_list = np.zeros(shape = (len(images), h,w,1), dtype = np.uint8) for j in range(len(images)):
img_list[j,:,:,0] = np.reshape(list(images[j]), (h,w)) img_list = img_list.astype('float32') img_list
/= 255 # ################################################################
#approca 1 failed go back from scrtuch # implement the architecture of the CNN model =
Sequential() #Conv2D Layers model.add(Conv2D(12, (25, 25),
padding='same',input_shape=img_list.shape[1:], activation = 'relu')) model.add(Conv2D(12, (25,
25), activation = 'relu')) #Max Pooling Layer model.add(MaxPooling2D(pool_size=(2, 2)))
#Conv2D Layer model.add(Conv2D(12, (13, 13), padding='same', activation = 'relu'))
model.add(Conv2D(12, (13, 13), activation = 'relu')) #Max Pooling
model.add(MaxPooling2D(pool_size=(2, 2))) #Flattening Layer model.add(Flatten()) #Dense
Layer model.add(Dense(1024, activation = 'relu')) model.add(Dense(1, activation = 'sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['binary_accuracy'])
model.summary()
''' FINALLY If you have a set of executable files from both types (benign and malicious) you can
try to fit the model. You should prepare a list of images for malwares and a list for benign and
here how you fit the model. ''' #Change the parameters to whatever suits you
I already have to files that contain benign files and malicious images, but it shows me
syntax error!
batch_size = 512 epochs = 100 labels = [0 for _ in benign_images ] + [1 for _ in
malicious_images ] model.fit( benign_images + malicious_images , labels, batch_size =
batch_size, epochs = epochs, validation_split = 0.25,
please, if you can help me with this issue and if there is additional coding needed to my project,
thank you

More Related Content

PDF
Using the code below- I need help with creating code for the following.pdf
PDF
Using the code below- I need help with the following 3 things- 1) Writ.pdf
PDF
Can someone please explain what the code below is doing and comment on.pdf
PDF
Need helping adding to the code below to plot the images from the firs.pdf
PPTX
29-kashyap-mask-detaction.pptx
PDF
Need an detailed analysis of what this code-model is doing- Thanks #St.pdf
PDF
lab91_lab92_merged.pdfbbbbbbbbbbbbbbbbbbb
PDF
AIML4 CNN lab256 1hr (111-1).pdf
Using the code below- I need help with creating code for the following.pdf
Using the code below- I need help with the following 3 things- 1) Writ.pdf
Can someone please explain what the code below is doing and comment on.pdf
Need helping adding to the code below to plot the images from the firs.pdf
29-kashyap-mask-detaction.pptx
Need an detailed analysis of what this code-model is doing- Thanks #St.pdf
lab91_lab92_merged.pdfbbbbbbbbbbbbbbbbbbb
AIML4 CNN lab256 1hr (111-1).pdf

Similar to Python program to build deep learning algorithm using a CNNs model to.docx (20)

PDF
GANS Project for Image idetification.pdf
PDF
I have to understand this code and i have to explain the each line of.pdf
PDF
Denis Sergienko "Pip install driven deep learning"
PDF
I have tried running this code below- and it is working- but the accur.pdf
PDF
What is the UML Class diagram for accident detection using CNN- i have.pdf
PPTX
Image classification using cnn
DOCX
assignment_7_sc report for soft comptuing
PDF
#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf
PPT
Generation of Deepfake images using GAN and Least squares GAN.ppt
PDF
could you draw uml diagram for this code from PIL import Image, Im.pdf
PDF
Hello- I hope you are doing well- I am doing my project- which is Rans (1).pdf
PDF
Intro to computer vision in .net
PPTX
Introduction to Image Processing with MATLAB
PDF
Python openCV codes
DOCX
I need  An expert person in machine learning  that can help me . I n.docx
PDF
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
PDF
[AI07] Revolutionizing Image Processing with Cognitive Toolkit
PPTX
Introduction to Deep Learning and Tensorflow
PDF
Python과 node.js기반 데이터 분석 및 가시화
PDF
How the Go runtime implement maps efficiently
GANS Project for Image idetification.pdf
I have to understand this code and i have to explain the each line of.pdf
Denis Sergienko "Pip install driven deep learning"
I have tried running this code below- and it is working- but the accur.pdf
What is the UML Class diagram for accident detection using CNN- i have.pdf
Image classification using cnn
assignment_7_sc report for soft comptuing
#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf
Generation of Deepfake images using GAN and Least squares GAN.ppt
could you draw uml diagram for this code from PIL import Image, Im.pdf
Hello- I hope you are doing well- I am doing my project- which is Rans (1).pdf
Intro to computer vision in .net
Introduction to Image Processing with MATLAB
Python openCV codes
I need  An expert person in machine learning  that can help me . I n.docx
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
[AI07] Revolutionizing Image Processing with Cognitive Toolkit
Introduction to Deep Learning and Tensorflow
Python과 node.js기반 데이터 분석 및 가시화
How the Go runtime implement maps efficiently
Ad

More from LukeQVdGrantg (20)

DOCX
Provide examples of the -monkey- attempting to be transferred from a s.docx
DOCX
Provide 3 substantive audit procedures chosen among the following topi.docx
DOCX
Provide an appropriate response- Determine the probability distributio.docx
DOCX
Punnett square problems continued Complete the following problems- Lis.docx
DOCX
public class ThreeTenDLList-T- implements Iterable-T- { -- doubly.docx
DOCX
Public - Week 12- Interactive activity 12-1 Learning Outcomes- Discuss.docx
DOCX
public class Bitset implements Set{ private boolean set--- pub.docx
DOCX
Protecting the Business 14- Briefly describe any business insurance yo.docx
DOCX
ProShares UltraPro QQQ has a total asset turnover of 1-29- a debt-equi.docx
DOCX
Properties that Define Life ( 10 points) Matching- Please write the le.docx
DOCX
Prompt 3- 70- of the light aircraft that disappear while in flight in.docx
DOCX
Prompt- (Part 1) Is life in the metaverse inevitable or unlikely- Are.docx
DOCX
Prokaryotes are all gram positive- eukaryotes are all gram negative Pr.docx
DOCX
Prolessor fsadore (Lmy) Invest-a-Lot retired two years ago from Except.docx
DOCX
PROLOG Convert this proposition to Object-Attribute-Value proposition(.docx
DOCX
Project Part 1- Analysis of the opportunities and risks of a company i.docx
DOCX
Project Objectives- To write a program that implements the following A.docx
DOCX
Project gamesmanship in organizations performs what purpose- Creates c.docx
DOCX
Project managers should turn customer needs into requirements- The sum.docx
DOCX
Project managers use this conflict resolution technique most often- A-.docx
Provide examples of the -monkey- attempting to be transferred from a s.docx
Provide 3 substantive audit procedures chosen among the following topi.docx
Provide an appropriate response- Determine the probability distributio.docx
Punnett square problems continued Complete the following problems- Lis.docx
public class ThreeTenDLList-T- implements Iterable-T- { -- doubly.docx
Public - Week 12- Interactive activity 12-1 Learning Outcomes- Discuss.docx
public class Bitset implements Set{ private boolean set--- pub.docx
Protecting the Business 14- Briefly describe any business insurance yo.docx
ProShares UltraPro QQQ has a total asset turnover of 1-29- a debt-equi.docx
Properties that Define Life ( 10 points) Matching- Please write the le.docx
Prompt 3- 70- of the light aircraft that disappear while in flight in.docx
Prompt- (Part 1) Is life in the metaverse inevitable or unlikely- Are.docx
Prokaryotes are all gram positive- eukaryotes are all gram negative Pr.docx
Prolessor fsadore (Lmy) Invest-a-Lot retired two years ago from Except.docx
PROLOG Convert this proposition to Object-Attribute-Value proposition(.docx
Project Part 1- Analysis of the opportunities and risks of a company i.docx
Project Objectives- To write a program that implements the following A.docx
Project gamesmanship in organizations performs what purpose- Creates c.docx
Project managers should turn customer needs into requirements- The sum.docx
Project managers use this conflict resolution technique most often- A-.docx
Ad

Recently uploaded (20)

PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
01-Introduction-to-Information-Management.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Classroom Observation Tools for Teachers
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Presentation on HIE in infants and its manifestations
PDF
RMMM.pdf make it easy to upload and study
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
master seminar digital applications in india
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Module 4: Burden of Disease Tutorial Slides S2 2025
01-Introduction-to-Information-Management.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Computing-Curriculum for Schools in Ghana
Final Presentation General Medicine 03-08-2024.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Classroom Observation Tools for Teachers
VCE English Exam - Section C Student Revision Booklet
A systematic review of self-coping strategies used by university students to ...
202450812 BayCHI UCSC-SV 20250812 v17.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Presentation on HIE in infants and its manifestations
RMMM.pdf make it easy to upload and study
Anesthesia in Laparoscopic Surgery in India
Microbial diseases, their pathogenesis and prophylaxis
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
master seminar digital applications in india
Supply Chain Operations Speaking Notes -ICLT Program
Pharmacology of Heart Failure /Pharmacotherapy of CHF

Python program to build deep learning algorithm using a CNNs model to.docx

  • 1. Python program to build deep learning algorithm using a CNNs model to detect malware attacks. The code is working, but I faced issues with the last part of the code, and I needed to know precisely where the problem was. I have the dataset of malware and benign in exe, I convert them to grayscale images, and it goes through the filters, and it shows me the output. this is the code import keras from keras.models import Sequential from keras.layers import Dense, Dropout, Activation, Flatten from keras.layers import Conv2D, MaxPooling2D import numpy as np from os import listdir from PIL import Image import os.path import numpy as np path = '/media/malkuwari/New Volume/Ransomware_Detection_using _CNN/mixEXE' h = 256 #height of image w = 256 #width of image # be careful with using this function, it will consume memory, access to disk and time images = [] for f in listdir('/media/malkuwari/New Volume/Ransomware_Detection_using _CNN/mixEXE'): with open(os.path.join('/media/malkuwari/New Volume/Ransomware_Detection_using _CNN/mixEXE', f), 'rb') as img_set: img_arr = img_set.read(h*w) while img_arr: if len(img_arr) == h*w and img_arr not in images: images.append(img_arr) img_arr = img_set.read(h*w) #And you can save them into png files # count = 0 # for img in images: # png = Image.fromarray(np.reshape(list(img), (h,w)).astype('float32'), mode='L') # png.save('image_l%d.png'%count) # count += 1 #reshape images to fit into the CNN model img_list = np.zeros(shape = (len(images), h,w,1), dtype = np.uint8) for j in range(len(images)): img_list[j,:,:,0] = np.reshape(list(images[j]), (h,w)) img_list = img_list.astype('float32') img_list /= 255 # ################################################################ #approca 1 failed go back from scrtuch # implement the architecture of the CNN model = Sequential() #Conv2D Layers model.add(Conv2D(12, (25, 25), padding='same',input_shape=img_list.shape[1:], activation = 'relu')) model.add(Conv2D(12, (25, 25), activation = 'relu')) #Max Pooling Layer model.add(MaxPooling2D(pool_size=(2, 2))) #Conv2D Layer model.add(Conv2D(12, (13, 13), padding='same', activation = 'relu')) model.add(Conv2D(12, (13, 13), activation = 'relu')) #Max Pooling model.add(MaxPooling2D(pool_size=(2, 2))) #Flattening Layer model.add(Flatten()) #Dense Layer model.add(Dense(1024, activation = 'relu')) model.add(Dense(1, activation = 'sigmoid')) model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['binary_accuracy']) model.summary() ''' FINALLY If you have a set of executable files from both types (benign and malicious) you can try to fit the model. You should prepare a list of images for malwares and a list for benign and here how you fit the model. ''' #Change the parameters to whatever suits you I already have to files that contain benign files and malicious images, but it shows me syntax error!
  • 2. batch_size = 512 epochs = 100 labels = [0 for _ in benign_images ] + [1 for _ in malicious_images ] model.fit( benign_images + malicious_images , labels, batch_size = batch_size, epochs = epochs, validation_split = 0.25, please, if you can help me with this issue and if there is additional coding needed to my project, thank you