目的
- 远程管理功能的实现细节,做到使用工具的过程中知其所以然。
- 二开
环境准备
- IDEA
- tomcat
- php
- ASP
- dnspy
- 3.0t00ls专版
源码获取
通过使用IDEA自带的java反编译工具反编译冰蝎jar包获得java源码
| java -cp /home/kali/Tools/idea-IC-212.5457.46/plugins/java-decompiler/lib/java-decompiler.jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -dgs=true <src.jar> <dest dir>
|
结构分析
| net └── rebeyond └── behinder ├── core ├── dao ├── entity ├── payload ├── resource ├── ui └── utils
|
core目录存放的是项目的核心代码

| core ├── Constants.java ├── Crypt.java ├── Decrypt.java ├── Params.java ├── PluginResultCallBack.java ├── PluginSubmitCallBack.java ├── PluginTools.java └── ShellService.java
|

ua信息可以修改成自定义的信息。

解密jsp返回包用ECB,可以改成其他方式。
ShellService实现远程管理功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| public class ShellService { public String currentUrl; public String currentPassword; public String currentKey; public String currentType; public Map<String, String> currentHeaders; public int encryptType; public int beginIndex; public int endIndex; public JSONObject shellEntity; public static int BUFFSIZE = 46080; public static Map<String, Object> currentProxy; public ShellService(JSONObject shellEntity); private void initHeaders();
private String getReferer(); private String getCurrentUserAgent();
public static void setProxy(Map<String, Object> proxy);
public static Map<String, Object> getProxy(Map<String, Object> proxy);
public JSONObject getShellEntity();
private void mergeCookie(Map<String, String> headers, String cookie);
private void mergeHeaders(Map<String, String> headers, String headerTxt);
private String formatHeaderName(String beforeName);
public boolean doConnect() throws Exception;
public String eval(String sourceCode) throws Exception;
public JSONObject runCmd(String cmd, String path) throws Exception;
public JSONObject createBShell(String target, String localPort) throws Exception;
public JSONObject sendBShellCommand(String target, String action, String actionParams) throws Exception;
public JSONObject submitPluginTask(String taskID, String payloadPath, Map<String, String> pluginParams) throws Exception;
public JSONObject getPluginTaskResult(String taskID) throws Exception;
public JSONObject loadJar(String libPath) throws Exception;
public JSONObject createRealCMD(String bashPath) throws Exception;
public JSONObject stopRealCMD() throws Exception;
public JSONObject readRealCMD() throws Exception;
public JSONObject writeRealCMD(String cmd) throws Exception;
public JSONObject listFiles(String path) throws Exception;
public JSONObject getTimeStamp(String path) throws Exception;
public JSONObject updateTimeStamp(String path, String createTimeStamp, String modifyTimeStamp, String accessTimeStamp) throws Exception;
public JSONObject updateModifyTimeStamp(String path, String modifyTimeStamp) throws Exception;
public JSONObject deleteFile(String path) throws Exception;
public JSONObject showFile(String path, String charset) throws Exception;
public JSONObject renameFile(String oldName, String newName) throws Exception;
public JSONObject createFile(String fileName) throws Exception;
public JSONObject createDirectory(String dirName) throws Exception;
public void downloadFile(String remotePath, String localPath) throws Exception;
public JSONObject execSQL(String type, String host, String port, String user, String pass, String database, String sql) throws Exception;
public JSONObject uploadFile(String remotePath, byte[] fileContent, boolean useBlock) throws Exception;
public JSONObject uploadFile(String remotePath, byte[] fileContent) throws Exception;
public JSONObject appendFile(String remotePath, byte[] fileContent) throws Exception;
public boolean createRemotePortMap(String targetIP, String targetPort, String remoteIP, String remotePort) throws Exception;
public boolean createRemoteSocks(String targetIP, String targetPort, String remoteIP, String remotePort) throws Exception;
public boolean createVPSSocks(String remoteIP, String remotePort) throws Exception;
public JSONObject stopVPSSocks() throws Exception;
public boolean createPortMap(String targetIP, String targetPort, String socketHash) throws Exception;
public byte[] readPortMapData(String targetIP, String targetPort, String socketHash) throws Exception;
public boolean writePortMapData(byte[] proxyData, String targetIP, String targetPort, String socketHash) throws Exception;
public boolean closeLocalPortMap(String targetIP, String targetPort) throws Exception;
public boolean closeLocalPortMapWorker(String socketHash) throws Exception;
public boolean closeRemotePortMap() throws Exception;
public byte[] readProxyData(String socketHash) throws Exception;
public boolean writeProxyData(byte[] proxyData, String socketHash) throws Exception;
public boolean closeProxy(String socketHash) throws Exception;
public boolean openProxy(String destHost, String destPort, String socketHash) throws Exception;
public boolean openProxyAsyc(String destHost, String destPort, String socketHash) throws Exception;
public JSONObject echo(String content) throws Exception;
public String getBasicInfo(String whatever) throws Exception;
private void showErrorMessage(String title, String msg);
public void keepAlive() throws Exception;
public JSONObject connectBack(String type, String ip, String port) throws Exception;
public JSONObject loadNativeLibrary(String libraryPath) throws Exception;
public JSONObject executePayload(String uploadLibPath, String payload) throws Exception;
public JSONObject loadLibraryAndexecutePayload(String fileContent, String payload) throws Exception;
public JSONObject loadLibraryAndfreeFile(String fileContent, String filePath) throws Exception;
public JSONObject freeFile(String uploadLibPath, String filePath) throws Exception;
public JSONObject loadLibraryAndAntiAgent(String fileContent) throws Exception;
public JSONObject antiAgent(String uploadLibPath) throws Exception;
public JSONObject loadLibraryAndtest() throws Exception;
public JSONObject injectMemShell(String type, String libPath, String path, String password, boolean isAntiAgent) throws Exception;
public JSONObject createReversePortMap(String listenPort) throws Exception;
public byte[] readReversePortMapData(String socketHash) throws Exception;
public boolean writeReversePortMapData(byte[] proxyData, String socketHash) throws Exception;
public JSONObject listReversePortMap() throws Exception;
public JSONObject stopReversePortMap(String listenPort) throws Exception;
public JSONObject closeReversePortMap(String socketHash) throws Exception; }
|
启动流程
graph TD
id1[net.rebeyond.behinder.ui.Launcher.main]
id2[net.rebeyond.behinder.ui.Main.start]
id3[FXMLLoader.load Main.fxml]
id4[new ShellManager]
id5[initCatagoryList]
id6[initShellList]
id7[initToolbar]
id8[initBottomBar]
id9[loadProxy]
id1 --> id2
id2 --> id3
id3 --> id4
id4 --> id5
id5 --> id6
id6 --> id7
id7 --> id8
id8 --> id9
功能实现分析
Shell管理
MainController
graph TD
loadContextMenu --> 新增
新增 --> shellManager.addShell
loadContextMenu --> 更新
更新 --> shellManager.updateShell
loadContextMenu --> 删除
删除 --> shellManager.deleteShell
loadContextMenu --> 打开
打开 --> 加载MainWindow.fxml
加载MainWindow.fxml --> 加载Tabs页面
加载MainWindow.fxml --> currentShellService.getBasicInfo
加载MainWindow.fxml --> shellManager.setShellStatus
远程管理
命令执行
CmdViewController
graph TD
onCMDKeyPressed --> addHistory
addHistory --> currentShellService.runCmd
文件管理
FileManagerViewController
graph TD
loadContextMenu --> 刷新
刷新 --> currentShellService.listFiles
loadContextMenu --> 打开
打开 --> |文件|currentShellService.showFile
打开 --> |目录|currentShellService.listFiles
loadContextMenu --> 删除
删除 --> currentShellService.deleteFile
graph TD
loadContextMenu --> 重命名
重命名 --> currentShellService.renameFile
loadContextMenu --> 下载
下载 --> currentShellService.downloadFile
loadContextMenu --> 上传
上传 --> currentShellService.uploadFile
graph TD
loadContextMenu --> 新建文件夹
新建文件夹 --> currentShellService.createDirectory
loadContextMenu --> 修改时间戳
修改时间戳 --> currentShellService.updateTimeStamp
loadContextMenu --> 克隆时间戳未实现
数据库管理
DatabaseViewController
graph TD
initDatabaseView --> initDatabaseType
initDatabaseType --> loadContextMenu
loadContextMenu --> loadTreeContextMenu
loadContextMenu --> loadTableContextMenu
loadTreeContextMenu --> 查询前10条
查询前10条 --> executeSQL
loadTreeContextMenu --> 查询全部
查询全部 --> executeSQL
loadTreeContextMenu --> 导出当前表
导出当前表 --> executeSQL
loadTableContextMenu --> 复制单元格
loadTableContextMenu --> 复制整行
loadTableContextMenu --> 导出全部查询结果
交互式命令执行
RealCmdViewController
graph TD
initRealCmdView --> initCmdQueue
initCmdQueue --> createRealCmd
createRealCmd --> initWorkers
createRealCmd --> currentShellService.readRealCMD
initWorkers --> currentShellService.writeRealCMD
流量加密分析
Utils、Crypt
graph TD
getData --> |jsp|Encrypt
getData --> |php|EncryptForPhp
getData --> |aspx|EncryptForCSharp
getData --> |asp|EncryptForAsp
Encrypt --> AES/ECB/PKCS5Padding
EncryptForPhp --> AES/CBC/PKCS5Padding
EncryptForCSharp --> AES/CBC/PKCS5Padding
EncryptForAsp --> 循环异或
攻击载荷分析
ShellService、payload
BasicInfo
graph TD
ShellService.getBasicInfo --> BasicInfo
BasicInfo --> |jsp|Java
Java --> System.getenv
Java --> System.getProperties
Java --> getAbsolutePath
Java --> File.listRoots
BasicInfo --> |php|Php
Php --> phpinfo
Php --> driveList
Php --> getcwd
graph TD
ShellService.getBasicInfo --> BasicInfo
BasicInfo --> |asp|Asp
Asp --> Server.MapPath
Asp --> envlist
Asp --> GetWS
BasicInfo --> |aspx|CSharp
CSharp --> Environment.GetLogicalDrives
CSharp --> Environment.GetEnvironmentVariables
BShell
graph TD
ShellService.createBShell --> BShell
BShell --> |jsp|Java
Java --> Create
Create --> createBShell
createBShell --> serverSocketChannel.accept
serverSocketChannel.accept --> Session.setAttribute
graph TD
ShellService.sendBShellCommand --> BShell
BShell --> |jsp|Java
Java --> doWork
doWork --> listFile
Cmd
graph TD
ShellService.runCmd --> |jsp|Java
Java --> RunCMD
RunCMD --> |linux|/bin/sh
RunCMD --> |windows|cmd.exe
ShellService.runCmd --> |php|Php
Php --> system
Php --> proc_open
Php --> passthru
Php --> shell_exec
Php --> exec
graph TD
ShellService.runCmd --> |asp|Asp
Asp --> WScript.shell
Asp --> WScript.shell.1
Asp --> shell.application
Asp --> shell.application.1
ShellService.runCmd --> |aspx|CSharp
CSharp --> execCMD
execCMD --> cmd.exe