Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

docs: tutorials: distro: security: binsec operations to scan a distro #595

@johnandersen777

Description

@johnandersen777

We introduced the binsec operations back into the main tree recently. We need to use them to write a blog post to compare distros enabling of ALSR.

We could cross this workstream with Rolling Alice: Architecting Alice: OS DecentrAlice as an integration test.

@op(inputs={"download": URLBytes}, outputs={"rpm": RPMObject})
async def urlbytes_to_rpmfile(download: URLBytesObject):
fileobj = io.BytesIO(download.body)
try:
rpm = RPMFile(name=download.URL, fileobj=fileobj)
return {"rpm": rpm.__enter__()}
except AssertionError as error:
LOGGER.debug(
"urlbytes_to_rpmfile: Failed to instantiate " "RPMFile(%s): %s",
download.URL,
error,
)
except RPMError as error:
LOGGER.debug(
"urlbytes_to_rpmfile: Failed to instantiate " "RPMFile(%s): %s",
download.URL,
error,
)
@op(
inputs={"rpm": RPMObject},
outputs={"files": rpm_filename},
expand=["files"],
)
async def files_in_rpm(rpm: RPMFile):
return {"files": list(map(lambda rpminfo: rpminfo.name, rpm.getmembers()))}
@op(
inputs={"rpm": RPMObject, "filename": rpm_filename},
outputs={"is_pie": binary_is_PIE},
)
async def is_binary_pie(rpm: RPMFile, filename: str) -> Dict[str, Any]:
with rpm.extractfile(filename) as handle:
sig = handle.read(4)
if len(sig) != 4 or sig != b"\x7fELF":
return
handle.seek(0)
return {
"is_pie": bool(
describe_e_type(ELFFile(handle).header.e_type).split()[0]
== "DYN"
)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationChanges to documentationp3Average PrioritysecuritySecurity related issues or improvementstMEsitmated Time To Complete: Medium

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions