Skip to content

Commit

Permalink
fix at OpCodeFile file format
Browse files Browse the repository at this point in the history
  • Loading branch information
lucascarvalhoroncoroni committed Jun 11, 2017
1 parent 0ebc9b4 commit c05b42a
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 5 deletions.
Binary file removed mainProject/SFAnalytics/DataBase/Malwares/7zFM.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed mainProject/SFAnalytics/DataBase/Softwares/7zFM.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified mainProject/SFAnalytics/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified mainProject/SFAnalytics/__pycache__/tools.cpython-36.pyc
Binary file not shown.
Binary file modified mainProject/SFAnalytics/__pycache__/views.cpython-36.pyc
Binary file not shown.
22 changes: 22 additions & 0 deletions mainProject/SFAnalytics/migrations/0004_stringlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-06-11 14:34
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('SFAnalytics', '0003_auto_20170609_0148'),
]

operations = [
migrations.CreateModel(
name='StringList',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('Strings', models.CharField(max_length=10)),
],
),
]
34 changes: 34 additions & 0 deletions mainProject/SFAnalytics/migrations/0005_auto_20170611_1512.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-06-11 18:12
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('SFAnalytics', '0004_stringlist'),
]

operations = [
migrations.RemoveField(
model_name='stringlist',
name='Strings',
),
migrations.AddField(
model_name='stringlist',
name='string',
field=models.CharField(default='', max_length=250),
),
migrations.AlterField(
model_name='dlllist',
name='name',
field=models.CharField(default='', max_length=100),
),
migrations.AlterField(
model_name='opcodelist',
name='instruction',
field=models.CharField(default='', max_length=10),
),
]
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions mainProject/SFAnalytics/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from django.db import models

class DllList(models.Model):
name = models.CharField(max_length=100)
name = models.CharField(default="", max_length=100)

class OpCodeList(models.Model):
instruction = models.CharField(max_length=10)
instruction = models.CharField(default="", max_length=10)

class StringList(models.Model):
Strings = models.CharField(max_length=10)
string = models.CharField(default="", max_length=250)

class EntryFile(models.Model):
hashMd5 = models.CharField(max_length=32)
Expand Down
2 changes: 2 additions & 0 deletions mainProject/SFAnalytics/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def saveFile(data, path):
#improve this to get file locations and path
class OpCodeFile(object):
def __init__(self, path):
#Chaging to windows path format
path = re.sub(r'/', '\\\\', path)
#subprocess.run executes a cmd command : ['.\objdump.exe', '-d','7zFM.exe']
out = subprocess.run(['C:\\Users\\lucas\\Documents\\TCC\\MalwareAnalysis\\Tools\\objdump.exe', '-d', path], stdout=subprocess.PIPE, shell=True).stdout.decode().splitlines()
self.opcodes = []
Expand Down
31 changes: 29 additions & 2 deletions mainProject/SFAnalytics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def uploadDataBaseView(request):
if form.is_valid():
for m in request.FILES.getlist('malwareUpload'):
HandleFile.saveFile(m, malwaresPath)
#addLearn(m, malwaresPath, True)
addLearn(m, malwaresPath, True)
for s in request.FILES.getlist('softwareUpload'):
HandleFile.saveFile(s, softwaresPath)
#addLearn(s, softwaresPath, False)
addLearn(s, softwaresPath, False)
return HttpResponseRedirect('/SFAnalytics/uploadDataBase/')
else:
form = UploadDataBaseForm()
Expand All @@ -44,3 +44,30 @@ def addLearn(data, path, malwareLabel):
entry = EntryFile(hashMd5=fileHashs.getHashMd5(), hashSha256=fileHashs.getHashSha256(), malware=malwareLabel,
dataSectionEntropy=pe.getDataSectionEntropy(), textSectionEntropy=pe.getTextSectionEntropy())
entry.save()
# Adding strings to string list
for s in strings.getStrings():
#Don't accept string lengths higher than 250 bytes
if len(s) < 251:
query = StringList.objects.all().filter(string__exact=s)
if query == None:
stringItem = StringList(string=s)
stringItem.save()

# Adding opcodes to OpCodeList
for op in opcodes.getOpcodes():
#Don't accept Operation Codes with length higher than 10 bytes
#X86 don't have any, this is here just to avoid software crash
if len(op) < 11:
query = OpCodeList.objects.all().filter(instruction__exact=op)
if query == None:
opItem = OpCodeList(instruction=op)
opItem.save()

# Adding dlls to DllList
for dll in pe.getDlls():
#Don't accept dll name lengths higher than 100 bytes
if len(dll) < 101:
query = OpCodeList.objects.all().filter(instruction__name=dll)
if query == None:
dllItem = DllList(name=dll)
dllItem.save()
Binary file modified mainProject/db.sqlite3
Binary file not shown.

0 comments on commit c05b42a

Please sign in to comment.