Files
sigma-rules/rta/linux_persistence_apt_package_manager_execution.py
T
2024-08-08 19:19:44 +05:30

51 lines
1.5 KiB
Python

# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
from . import common
from . import RtaMetadata
metadata = RtaMetadata(
uuid="305b2daa-2ef4-4cdd-8ed2-d751174cbdcc",
platforms=["linux"],
endpoint=[
{
"rule_name": "APT Package Manager Command Execution",
"rule_id": "cd0844ea-6112-453f-a836-cc021a2b6afb"
}
],
techniques=["T1543", "T1059", "T1546"],
)
@common.requires_os(*metadata.platforms)
def main():
common.log("Creating a fake apt executable..")
masquerade = "/tmp/apt"
source = common.get_path("bin", "netcon_exec_chain.elf")
common.copy_file(source, masquerade)
common.log("Granting execute permissions...")
common.execute(['chmod', '+x', masquerade])
common.log("Creating a fake openssl executable..")
masquerade2 = "/tmp/openssl"
source = common.get_path("bin", "linux.ditto_and_spawn")
common.copy_file(source, masquerade2)
common.log("Granting execute permissions...")
common.execute(['chmod', '+x', masquerade2])
commands = [masquerade, 'exec', '-c', '/tmp/openssl']
common.execute([*commands], timeout=5, kill=True)
common.log("Cleaning...")
common.remove_file(masquerade)
common.remove_file(masquerade2)
common.log("Simulation successfull!")
if __name__ == "__main__":
exit(main())