Skip to content

Commit 16583e3

Browse files
Maximilian BlenkMaximilian Blenk
Maximilian Blenk
authored and
Maximilian Blenk
committed
main: Add option to ignore symlinks
When analyzing a complete rootfs (which might not be the rootfs of the analyzing system) symlink within that rootfs might be broken. In particular absolute symlinks. However, if by chance such a symlink currently points to a valid binary in your system, this binary pointed to is analyzed. This commit adds the possibility to ignore symlinks to files (symlinks to dirs are already ignored by default). This allows to solve the issue described above, and if the whole rootfs is analyzed there shouldn't be a loss of information (because all the binaries will be analyzed anyway). Additionally, this also saves some time when performing the analysis.
1 parent 7548c94 commit 16583e3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

checksec/__main__.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-w WORKERS --workers=WORKERS Specify the number of process pool workers [default: 4]
99
-j --json Display results as JSON
1010
-s LIBC --set-libc=LIBC Specify LIBC library to use to check for fortify scores (ELF)
11+
-i --ignore-symlinks Ignore symlinks to files
1112
-d --debug Enable debug output
1213
-h --help Display this message
1314
"""
@@ -27,15 +28,15 @@
2728
from .utils import lief_set_logging
2829

2930

30-
def walk_filepath_list(filepath_list: List[Path], recursive: bool = False) -> Iterator[Path]:
31+
def walk_filepath_list(filepath_list: List[Path], recursive: bool = False, ignore_symlinks: bool = False) -> Iterator[Path]:
3132
for path in filepath_list:
3233
if path.is_dir() and not path.is_symlink():
3334
if recursive:
3435
for f in os.scandir(path):
35-
yield from walk_filepath_list([Path(f)], recursive)
36+
yield from walk_filepath_list([Path(f)], recursive, ignore_symlinks)
3637
else:
3738
yield from (Path(f) for f in os.scandir(path))
38-
elif path.is_file():
39+
elif path.is_file() and (not ignore_symlinks or not path.is_symlink()):
3940
yield path
4041

4142

@@ -72,6 +73,7 @@ def main(args):
7273
json = args["--json"]
7374
recursive = args["--recursive"]
7475
libc_path = args["--set-libc"]
76+
ignore_symlinks = args["--ignore-symlinks"]
7577

7678
# logging
7779
formatter = "%(asctime)s %(levelname)s:%(name)s:%(message)s"
@@ -107,7 +109,7 @@ def main(args):
107109
# we need to consume the iterator once to get the total
108110
# for the progress bar
109111
check_output.enumerating_tasks_start()
110-
count = sum(1 for i in walk_filepath_list(filepath_list, recursive))
112+
count = sum(1 for i in walk_filepath_list(filepath_list, recursive, ignore_symlinks))
111113
check_output.enumerating_tasks_stop(count)
112114
with ProcessPoolExecutor(
113115
max_workers=workers, initializer=worker_initializer, initargs=(libc_path,)
@@ -116,7 +118,7 @@ def main(args):
116118
check_output.processing_tasks_start()
117119
future_to_checksec = {
118120
pool.submit(checksec_file, filepath): filepath
119-
for filepath in walk_filepath_list(filepath_list, recursive)
121+
for filepath in walk_filepath_list(filepath_list, recursive, ignore_symlinks)
120122
}
121123
for future in as_completed(future_to_checksec):
122124
filepath = future_to_checksec[future]

0 commit comments

Comments
 (0)