Reputation: 135
I am trying to run a grep on a .doc file to get the strings and match it to evidence of macros in order to detect it.
I have:
filename = raw_input("file name: ") <--- using malicious.doc
s1 = os.popen("grep '/vbaProject\|/vbaData' " + filename).read()
s2 = 'Binary file ' + filename + ' matches'
if s1 == s2:
print("true")
else:
print("false")
if I run:
if s1 == s2:
print("true")
else:
print("false")
print(s1)
print(s2)
I get the following output:
false
Binary file malicious.doc matches
Binary file malicious.doc matches
the text matches, and I've even tried doing s1 = str(s1) and s2 = str(s2)
and still getting false.
Thanks in advance.
Upvotes: 1
Views: 143
Reputation: 2526
By your comment, you got an additional newline in the result.
I generally advise to strip results from whitespace before comparing them. In your case I would do:
s1 = os.popen("grep '/vbaProject\|/vbaData' " + filename).read().strip()
Upvotes: 1