# 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. import sys from . import RtaMetadata, common metadata = RtaMetadata( uuid="1c088eaa-97a1-4ff7-9fa5-a6bc311e9b1e", platforms=["linux"], endpoint=[ { "rule_name": "Foomatic-rip Shell Execution", "rule_id": "8ccebdc1-9929-4584-ac8f-a96ee8e8c616", }, ], techniques=["T1203"], ) @common.requires_os(*metadata.platforms) def main() -> None: common.log("Creating a fake executable..") masquerade = "/tmp/foomatic-rip" masquerade2 = "/tmp/sh" source = common.get_path("bin", "linux.ditto_and_spawn") common.copy_file(source, masquerade) common.log("Granting execute permissions...") common.execute(["chmod", "+x", masquerade]) 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, masquerade2, "-c", "whoami"] 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__": sys.exit(main())