-
Notifications
You must be signed in to change notification settings - Fork 0
/
antifuzz.py
126 lines (75 loc) · 2.44 KB
/
antifuzz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'''
File: antifuzz.py
Authors: Kaitlin Keenan and Ryan Frank
'''
# Import needed modules
import sys
import re
import random
import argparse
import subprocess
from shutil import copy2
import ssdeep #http://python-ssdeep.readthedocs.io/en/latest/installation.html
'''
Name: main
Purpose: The main method performs the antifuzzing operations to show the percentage of similarity between two mp3 files.
Parameters: None
Return: 1 if incorrect arguments are passed
0 if operation has been succesfully run
'''
def main():
parser = argparse.ArgumentParser()
parser.add_argument("originalFile", help="File to antifuzz")
parser.add_argument("--newFile", help="Name of the antifuzzed file")
parser.add_argument("-m", action='store_true', default=False, help="Change the metadata of the file instead, will still change the ssdeep hash")
args = parser.parse_args()
pattern = re.compile('mp3$')
if args.newFile is None:
args.newFile = args.originalFile
if not args.originalFile.endswith('.mp3'):
print "Please use a file with the .mp3 extension for your original file"
return 1
if not args.newFile.endswith('.mp3'):
print "Please use a file with the .mp3 extension for your newfile"
return 1
# Take in file
ogFile = args.originalFile
# Make copy of file
nFile = args.newFile
# Hash original file
ogHash = ssdeep.hash_from_file(ogFile)
# Make changes to given file
mp3(ogFile, nFile, args)
# Hash new file
newHash = ssdeep.hash_from_file(nFile)
# Compare the hashes
diff = str(ssdeep.compare(ogHash, newHash))
print("The files are " + diff + "% similar")
return 0
'''
Name: mp3
Purpose: Changes mp3 file by using lame to change volume by a scale of 1
Parameters: ogFile - Original mp3 file to be antifuzzed
newFile - Antifuzzed mp3 file
args - Contains all arguments passed into antifuzz.py
Return: None
'''
def mp3(ogFile, newFile, args):
if args.m is None:
cmd(['lame','--quiet', '--scale', '1', ogFile])
else:
cmd(['lame','--quiet','--tc', str(random.randrange(0, 27)), ogFile])
cmd(['mv', ogFile + ".mp3", newFile])
'''
Name: cmd
Purpose: Runs a shell command
Parameters: command - String array where each argument is a command line argument
Return: out - Standard ouput of shell command
'''
def cmd(command):
p = subprocess.Popen(command, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
out, err = p.communicate()
return out
# Run main method
if __name__ == "__main__":
main()