## Jeesns Group Store XSS
### Introduction to Vulnerability
JEESNS is a social management system based on JAVA enterprise-level platform. Based on the advantages of enterprise-level JAVA, such as high efficiency, security and stability, it creates a pioneering domestic Java version of open source SNS. JEESNS can be used to build portals, forums, communities, Weibo, Q&A, knowledge payment platform, etc. In Jeesns <= 1.4.2, the input filtering to the user at the group is incomplete, resulting in a stored XSS vulnerability.
### Vulnerability Impact
* Jeesns <= 1.4.2
### Vulnerability Analysis
The data submitted by the user foreground will pass XSSFilter, and the doFilter will call XssWrapper.
```java
Package com.lxinet.jeesns.core.utils;
Import java.util.regex.Matcher;
Import java.util.regex.Pattern;
Import javax.servlet.http.HttpServletRequest;
Import javax.servlet.http.HttpServletRequestWrapper;
Import org.springframework.web.util.HtmlUtils;
Public class XssWrapper extends HttpServletRequestWrapper {
Private static final String REGEX_SCRIPT = "<script[\\s\\S]*?<\\/script>";
Private static final String REGEX_STYLE = "<style[^>]*?>[\\s\\S]*?<\\/style>";
......
Public String getParameter(String parameter) {
String value = super.getParameter(parameter);
Return value == null ? null : this.cleanXSS(value);
}
Public String getHeader(String name) {
String value = super.getHeader(name);
Return value == null ? null : this.cleanXSS(value);
}
Private String cleanXSS(String value) {
Value = dealScript(value);
Value = dealStyle(value);
String[] eventKeywords = new String[]{"onmouseover", "onmouseout", "onmousedown", "onmouseup", "onmousemove", "onclick", "ondblclick", "onkeypress", "onkeydown", "onkeyup", "ondragstart", "onerrorupdate", "onhelp", "onreadystatechange", "onrowenter", "onrowexit", "onselectstart", "onload", "onunload", "onbeforeunload", "onblur", "onerror", "onfocus ", "onresize", "onscroll", "oncontextmenu", "alert"};
For(int i = 0; i < eventKeywords.length; ++i) {
Value = value.replaceAll("(?i)" + eventKeywords[i], "_" + eventKeywords[i]);
}
Return value;
}
Private static String dealScript(String val) {
Pattern p = Pattern.compile("<script[\\s\\S]*?<\\/script>");
Return htmlEscape(p, val);
}
Private static String dealStyle(String val) {
Pattern p = Pattern.compile("<style[^>]*?>[\\s\\S]*?<\\/style>");
Return htmlEscape(p, val);
}
Private static String htmlEscape(Pattern p, String val) {
String s;
String newVal;
For(Matcher m = p.matcher(val); m.find(); val = val.replace(s, newVal)) {
s = m.group();
newVal = HtmlUtils.htmlEscape(s);
}
Return val;
}
}
```
As you can see, the `<script>` and `<style>` tags are filtered, and some HTML events are escaped and filtered. However, when matching tags, there is no case processing, which can be bypassed by capitalization.
See the `save()` of the function `jeesns-service\src\main\java\com\lxinet\jeesns\service\group\impl\GroupServiceImpl.java` that saves the group.
```java
@Override
@Transactional
Public boolean save(Member loginMember, Group group) {
loginMember = memberService.findById(loginMember.getId());
Map<String,String> config = configService.getConfigToMap();
group.setCreator(loginMember.getId());
If(loginMember.getIsAdmin() > 0){
group.setStatus(1);
}else {
If("0".equals(config.get(ConfigUtil.GROUP_APPLY))){
Throw new OpeErrorException("group request function is closed");
}
ScoreRule scoreRule = scoreRuleService.findById(ScoreRuleConsts.APPLY_GROUP);
If (scoreRule != null && loginMember.getScore() < Math.abs(scoreRule.getScore())){
Throw new OpeErrorException("The account is not enough to apply for the group, the application group needs points:" + Math.abs(scoreRule.getScore()) + ", the current point balance is:" + loginMember.getScore());
}
If("0".equals(config.get(ConfigUtil.GROUP_APPLY_REVIEW)))){
group.setStatus(0);
}else {
group.setStatus(1);
}
}
//default icon
If(StringUtils.isEmpty(group.getLogo())){
group.setLogo(Const.DEFAULT_IMG_URL);
}
/ / Set the administrator
String managerIds = String.valueOf(loginMember.getId());
group.setManagers(managerIds);
group.setCanPost(1);
group.setTopicReview(0);
If (group.getFollowPay() == 0){
group.setPayMoney(0d);
}
Boolean result = groupDao.save(group) == 1;
If(result){
//Creater default focus group
groupFansService.save(loginMember,group.getId());
/ / Apply for group rewards, deductions
scoreDetailService.scoreBonus(loginMember.getId(), ScoreRuleConsts.APPLY_GROUP, group.getId());
}
Return result;
}
```
The data of the user condition is not further filtered, and is directly saved to the database, and then the front end directly renders, resulting in a storage type XSS.
### Vulnerability recurrence
1. Register a user
2. Apply for the group and fill in the name XS payload `<Script>prompt(/xss/)</Script>`
![](https://images.seebug.org/1557816354386-w331s)
3. The application group needs to be reviewed, and the XSS is triggered when the background administrator views the group application.
![](https://images.seebug.org/1557816361259-w331s)
暂无评论