Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CTF Search
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CTF Search Team
CTF Search
Commits
fb7d6bff
Commit
fb7d6bff
authored
5 years ago
by
Timmy Chan
Browse files
Options
Downloads
Patches
Plain Diff
Add get gcc by kernel version
parent
628858e6
Branches
Branches containing commit
No related tags found
1 merge request
!5
Feat/cve linux kernel
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
exploitdb/ctfsetup/qemu/utils.py
+52
-3
52 additions, 3 deletions
exploitdb/ctfsetup/qemu/utils.py
with
52 additions
and
3 deletions
exploitdb/ctfsetup/qemu/utils.py
+
52
−
3
View file @
fb7d6bff
...
@@ -10,7 +10,7 @@ from lib.html_table_parser import KernelTableHTMLParser
...
@@ -10,7 +10,7 @@ from lib.html_table_parser import KernelTableHTMLParser
def
main
():
def
main
():
gcc_table
=
get_gcc_version_
table
(
)
print
(
get_gcc_version_
by_kernel_version
(
"
2.6.36
"
)
)
def
get_available_architectures
():
def
get_available_architectures
():
...
@@ -30,6 +30,57 @@ def run_bash_command(command, verbose=True):
...
@@ -30,6 +30,57 @@ def run_bash_command(command, verbose=True):
subprocess
.
check_call
(
command
.
split
(
'
'
),
stdout
=
sys
.
stdout
,
stderr
=
subprocess
.
STDOUT
)
subprocess
.
check_call
(
command
.
split
(
'
'
),
stdout
=
sys
.
stdout
,
stderr
=
subprocess
.
STDOUT
)
def
get_gcc_version_by_kernel_version
(
kernel_version
):
"""
Return the latest gcc version supporting this kernel based on date
"""
kernel_version_table
=
get_kernel_version_table
()
gcc_version_table
=
get_gcc_version_table
()
formatted_kv
=
format_kernel_version_for_table_lookup
(
kernel_version
)
kernel_date
=
None
print
(
formatted_kv
)
try
:
for
kernel
in
kernel_version_table
:
if
kernel
[
0
]
==
formatted_kv
:
kernel_date
=
kernel
[
1
]
break
# Loop the version in reversed chronological order
# Take the first gcc version that is released earlier than the kernel
for
gcc
in
gcc_version_table
:
if
gcc
[
1
]
<
kernel_date
:
a
=
format_gcc_version_for_buildroot
(
gcc
[
0
])
return
a
raise
Exception
()
except
Exception
:
print
(
"
Could not find gcc version by kernel version
"
)
return
None
def
format_gcc_version_for_buildroot
(
gcc_version
):
result
=
''
gcc_version_splitted
=
gcc_version
.
split
(
'
.
'
)
if
int
(
gcc_version_splitted
[
0
])
<=
4
:
result
=
"
gcc {}.{}.x
"
.
format
(
gcc_version_splitted
[
0
],
gcc_version_splitted
[
1
])
else
:
result
=
"
gcc {}.x
"
.
format
(
gcc_version_splitted
[
0
])
return
result
def
format_kernel_version_for_table_lookup
(
kernel_version
):
"""
Return formatted kernel version
For:
version != 2.6.x.y -> a.b
version == 2.6.x.y -> 2.6.x
"""
if
kernel_version
[:
3
]
==
"
2.6
"
:
return
'
.
'
.
join
(
kernel_version
.
split
(
'
.
'
)[:
3
])
else
:
return
'
.
'
.
join
(
kernel_version
.
split
(
'
.
'
)[:
2
])
def
get_gcc_version_table
():
def
get_gcc_version_table
():
try
:
try
:
url
=
'
https://gcc.gnu.org/releases.html
'
url
=
'
https://gcc.gnu.org/releases.html
'
...
@@ -39,7 +90,6 @@ def get_gcc_version_table():
...
@@ -39,7 +90,6 @@ def get_gcc_version_table():
parser
=
GccTableHTMLParser
()
parser
=
GccTableHTMLParser
()
parser
.
feed
(
html_content
)
parser
.
feed
(
html_content
)
releases
=
parser
.
tables
[
0
]
releases
=
parser
.
tables
[
0
]
print
(
releases
)
if
not
releases
:
if
not
releases
:
raise
Exception
(
"
Cannot get gcc versions
"
)
raise
Exception
(
"
Cannot get gcc versions
"
)
...
@@ -58,7 +108,6 @@ def get_kernel_version_table():
...
@@ -58,7 +108,6 @@ def get_kernel_version_table():
parser
=
KernelTableHTMLParser
()
parser
=
KernelTableHTMLParser
()
parser
.
feed
(
html_content
)
parser
.
feed
(
html_content
)
releases
=
parser
.
tables
[
2
]
releases
=
parser
.
tables
[
2
]
print
(
releases
)
if
not
releases
:
if
not
releases
:
raise
Exception
(
"
Cannot get kernel versions
"
)
raise
Exception
(
"
Cannot get kernel versions
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment