2

Hackredis Enhanced Edition Script

 2 years ago
source link: https://joychou.org/web/hackredis-enhanced-edition-script.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Hackredis Enhanced Edition Script

发布于Apr 15, 2016 | WEB安全 | 阅读5,744次 | 0 评论

redis

0x01. redis的利用方式

  1. root权限

所以,
如果存在/root/.ssh目录,直接root权限写/root/.ssh/authorized_keys
如果不存在/root/.ssh目录,直接root写crontab定时任务

0x02. 利用写crontab创建.ssh目录

由于不同的linux环境,用户的定时任务并不通用。
所以如果想采取一种通用的脚本方式,有两种方法

  1. 先判断是否存在/var/spool/cron/crontabs/目录,可以有,则写该目录。反之写/var/spool/cron/root
  2. 利用通用的/etc/crontab

针对第一种方法:

ubuntu有点骚,/var/spool/cron/crontabs/root,默认redis写文件后是644的权限,但ubuntu要求执行定时任务文件权限必须是600
否则报错INSECURE MODE (mode 0600 expected) (crontabs/root)

所以ubuntu,利用redis写crontab到/var/spool/cron/crontabs/root已经不能实现。

而且redis写的也会报语法错误,因为乱码导致实行失败。报错信息如下:

May 22 00:17:01 ubuntu cron[9587]: Error: bad minute; while reading crontab for user root
May 22 00:17:01 ubuntu cron[9587]: (root) ERROR (Syntax error, this crontab file will be ignored)

并且用crontab命令创建的用户定时任务文件权限也是600(无论是在ubuntu还是centos)

*/1 * * * * mkdir /root/.ssh/
`/1 * root mkdir /root/.ssh/
`
但是,centos 644权限执行成功,乱码也能识别!


针对第二种方法:

ubuntu系统,redis在写/etc/crontab时候,由于存在一些乱码,导致ubuntu不能正确识别,导致执行定时任务失败,报错如下:

May 22 00:01:01 ubuntu cron[9587]: (*system*) RELOAD (/etc/crontab)
May 22 00:01:01 ubuntu cron[9587]: Error: bad minute; while reading /etc/crontab
May 22 00:01:01 ubuntu cron[9587]: (*system*) ERROR (Syntax error, this crontab file will be ignored)

写的/etc/crontab内容如图:
1

但是centos系统能执行成功,乱码也能识别!

0x03. 总结

从上面可以得出结果,ubuntu利用写文件执行crontab不会成功。原因有两点:

  1. 如果写/etc/crontab,语法不识别
  2. 如果写/var/spool/cron/crontabs/root,权限不是600,而且语法也不识别

0x04. 脚本具体功能:

  1. 写入ssh公钥
  2. 反弹shell
  3. 如果没有.ssh目录,非ubuntu系统利用crontab定时任务新建/root/.ssh目录,再写公钥、反弹shell
  4. 如果没有/root/.ssh/目录,该脚本不支持ubuntu系统,所以反弹shell使用了bash -i,导致也无关紧要

脚本运行截图:
2

脚本用法和代码我放github上了 https://github.com/JoyChou93/hackredis

本文仅供学习使用!

本文由 JoyChou 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jun 3, 2016 at 10:25 am


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK