in cortado/rtas/linux_sus_netcon_file_creation.py [0:0]
def main() -> None:
script_path = "/dev/shm/evil"
file_path = "/dev/shm/evil.txt"
# Create a bash script that performs network connection and file creation
script_content = textwrap.dedent(
f"""
#!/bin/bash
# Perform network connection using bash built-in tools
exec 3<>/dev/tcp/8.8.8.8/53
# Create a file
echo "Hello, World!" > {file_path}
"""
).strip()
# Write the script content to the file
with Path(script_path).open("w", encoding="utf-8") as script_file:
_ = script_file.write(script_content)
# Grant execute permissions to the script
Path(script_path).chmod(0o755)
# Execute the script
log.info("Executing the bash script...")
_ = _common.execute_command([script_path], timeout_secs=5)
# Verify if the file was created
if Path(file_path).exists():
log.info("File creation successful.")
# Clean up
log.info("Cleaning up...")
_common.remove_file(script_path)
_common.remove_file(file_path)
log.info("Cleanup successful.")