Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T1168 - Test to schedule cron job #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions red_ttp/schedule_cron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Name: Scheduling Local Job with crontab
# rta: schedule_cron.py
# ATT&CK: T1168
# Description: Writes a cron job to a temporary crontab file schedules it for execution.

import os
import common

CRONTAB_BINARY = '/usr/bin/crontab'
TMP_CRON = '/tmp/cron_tmp'
CRON_SCHEDULE = '* * * * * '
CRON_PAYLOAD = 'bash -c "echo file marker > /tmp/file_marker.txt"'

def main():

common.log('Writing temporary crontab file...')
with open(TMP_CRON,'w') as evil_cron:
evil_cron.write(CRON_SCHEDULE + CRON_PAYLOAD + '\n')
if os.path.exists(TMP_CRON):
common.log('Successfully created temporary crontab file!')
else:
common.log('Failed to create temporary crontab file.')

common.log('Replacing current user crontab file...')
code, output = common.execute([CRONTAB_BINARY, TMP_CRON],shell=True)
if code == 0:
common.log('Current user crontab replaced!')
else:
common.log('Failed to replace current user crontab.')

common.remove_file(TMP_CRON)


if __name__ == "__main__":
exit(main())