Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
binwalk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
binwalk
Commits
65ea6d1d
Commit
65ea6d1d
authored
Dec 21, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed potential bug in smart signature parser.
parent
4102d1f0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
9 deletions
+18
-9
smart.py
src/binwalk/core/smart.py
+12
-2
heuristics.py
src/binwalk/modules/heuristics.py
+2
-4
signature.py
src/binwalk/modules/signature.py
+4
-3
No files found.
src/binwalk/core/smart.py
View file @
65ea6d1d
...
@@ -76,13 +76,13 @@ class SmartSignature:
...
@@ -76,13 +76,13 @@ class SmartSignature:
# If smart signatures are disabled, or the result data is not valid (i.e., potentially malicious),
# If smart signatures are disabled, or the result data is not valid (i.e., potentially malicious),
# don't parse anything, just return the raw data as the description.
# don't parse anything, just return the raw data as the description.
if
self
.
ignore_smart_signatures
or
not
self
.
_is_valid
(
data
)
:
if
self
.
ignore_smart_signatures
:
results
[
'description'
]
=
data
results
[
'description'
]
=
data
else
:
else
:
# Calculate and replace special keywords/values
# Calculate and replace special keywords/values
data
=
self
.
_replace_maths
(
data
)
data
=
self
.
_parse_raw_strings
(
data
)
data
=
self
.
_parse_raw_strings
(
data
)
data
=
self
.
_parse_string_len
(
data
)
data
=
self
.
_parse_string_len
(
data
)
data
=
self
.
_replace_maths
(
data
)
# Parse the offset-adjust value. This is used to adjust the reported offset at which
# Parse the offset-adjust value. This is used to adjust the reported offset at which
# a signature was located due to the fact that MagicParser.match expects all signatures
# a signature was located due to the fact that MagicParser.match expects all signatures
...
@@ -152,6 +152,15 @@ class SmartSignature:
...
@@ -152,6 +152,15 @@ class SmartSignature:
return
False
return
False
return
True
return
True
def
_safe_string
(
self
,
data
):
'''
Strips out quoted data (i.e., data taken directly from a file).
'''
quoted_string
=
get_quoted_strings
(
data
)
if
quoted_string
:
data
=
data
.
replace
(
quoted_string
,
""
)
return
data
def
_one_of_many
(
self
,
data
):
def
_one_of_many
(
self
,
data
):
'''
'''
Determines if a given data string is one result of many.
Determines if a given data string is one result of many.
...
@@ -184,6 +193,7 @@ class SmartSignature:
...
@@ -184,6 +193,7 @@ class SmartSignature:
Returns a blank string on failure.
Returns a blank string on failure.
'''
'''
arg
=
''
arg
=
''
data
=
self
.
_safe_string
(
data
)
if
has_key
(
self
.
KEYWORDS
,
keyword
)
and
self
.
KEYWORDS
[
keyword
]
in
data
:
if
has_key
(
self
.
KEYWORDS
,
keyword
)
and
self
.
KEYWORDS
[
keyword
]
in
data
:
arg
=
data
.
split
(
self
.
KEYWORDS
[
keyword
])[
1
]
.
split
(
self
.
KEYWORD_DELIM_END
)[
0
]
arg
=
data
.
split
(
self
.
KEYWORDS
[
keyword
])[
1
]
.
split
(
self
.
KEYWORD_DELIM_END
)[
0
]
...
...
src/binwalk/modules/heuristics.py
View file @
65ea6d1d
...
@@ -64,7 +64,7 @@ class ChiSquare(object):
...
@@ -64,7 +64,7 @@ class ChiSquare(object):
return
self
.
xc2
return
self
.
xc2
class
Entrop
ic
Block
(
object
):
class
Entrop
y
Block
(
object
):
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
self
.
start
=
None
self
.
start
=
None
...
@@ -95,8 +95,6 @@ class HeuristicCompressionAnalyzer(Module):
...
@@ -95,8 +95,6 @@ class HeuristicCompressionAnalyzer(Module):
kwargs
=
{
'enabled'
:
True
,
'do_plot'
:
False
,
'display_results'
:
False
,
'block_size'
:
ENTROPY_BLOCK_SIZE
}),
kwargs
=
{
'enabled'
:
True
,
'do_plot'
:
False
,
'display_results'
:
False
,
'block_size'
:
ENTROPY_BLOCK_SIZE
}),
]
]
{
'config'
:
'Configuration'
,
'entropy'
:
'Entropy'
}
CLI
=
[
CLI
=
[
Option
(
short
=
'H'
,
Option
(
short
=
'H'
,
long
=
'heuristic'
,
long
=
'heuristic'
,
...
@@ -129,7 +127,7 @@ class HeuristicCompressionAnalyzer(Module):
...
@@ -129,7 +127,7 @@ class HeuristicCompressionAnalyzer(Module):
self
.
blocks
[
result
.
file
.
name
]
=
[]
self
.
blocks
[
result
.
file
.
name
]
=
[]
if
result
.
entropy
>=
self
.
trigger_level
and
(
not
self
.
blocks
[
result
.
file
.
name
]
or
self
.
blocks
[
result
.
file
.
name
][
-
1
]
.
end
is
not
None
):
if
result
.
entropy
>=
self
.
trigger_level
and
(
not
self
.
blocks
[
result
.
file
.
name
]
or
self
.
blocks
[
result
.
file
.
name
][
-
1
]
.
end
is
not
None
):
self
.
blocks
[
result
.
file
.
name
]
.
append
(
Entrop
ic
Block
(
start
=
result
.
offset
+
self
.
BLOCK_OFFSET
))
self
.
blocks
[
result
.
file
.
name
]
.
append
(
Entrop
y
Block
(
start
=
result
.
offset
+
self
.
BLOCK_OFFSET
))
elif
result
.
entropy
<
self
.
trigger_level
and
self
.
blocks
[
result
.
file
.
name
]
and
self
.
blocks
[
result
.
file
.
name
][
-
1
]
.
end
is
None
:
elif
result
.
entropy
<
self
.
trigger_level
and
self
.
blocks
[
result
.
file
.
name
]
and
self
.
blocks
[
result
.
file
.
name
][
-
1
]
.
end
is
None
:
self
.
blocks
[
result
.
file
.
name
][
-
1
]
.
end
=
result
.
offset
-
self
.
BLOCK_OFFSET
self
.
blocks
[
result
.
file
.
name
][
-
1
]
.
end
=
result
.
offset
-
self
.
BLOCK_OFFSET
...
...
src/binwalk/modules/signature.py
View file @
65ea6d1d
...
@@ -115,10 +115,11 @@ class Signature(Module):
...
@@ -115,10 +115,11 @@ class Signature(Module):
# Pass the data to libmagic, and split out multiple results into a list
# Pass the data to libmagic, and split out multiple results into a list
magic_result
=
self
.
magic
.
buffer
(
candidate_data
)
magic_result
=
self
.
magic
.
buffer
(
candidate_data
)
# The smart filter parser returns a binwalk.core.module.Result object
r
=
self
.
smart
.
parse
(
magic_result
)
if
self
.
config
.
filter
.
valid_result
(
magic_result
):
if
self
.
config
.
filter
.
valid_result
(
r
.
description
):
# The smart filter parser returns a binwalk.core.module.Result object
r
=
self
.
smart
.
parse
(
magic_result
)
# Set the absolute offset inside the target file
# Set the absolute offset inside the target file
r
.
offset
=
block_start
+
candidate_offset
+
r
.
adjust
r
.
offset
=
block_start
+
candidate_offset
+
r
.
adjust
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment