This document is a report described by Team.ENVY (Kim Chan-in, Park Myung-hoon, Shin Myung-jin, Yang Kang-min, Lee Yu-kyeong) who carried out the BoB 12th NVR Vulnability Analysis project.
1.1. Necessity
Analysis of web service operation method is essential for Dahua's vulnerability analysis. Therefore, we want to analyze the binary used by Dahua for vulnerability analysis.
2. challenge
2.1. main
When the binary is executed, the main function first goes through the device initialization process.
After sending arbitrary commands to the /dev/dh_resource device using the ioctl function, the initialization work is performed using the acquired data.
Change the string after the dot to factory.instance.
Check reference
You can check the address that is the .rodata area of the reference. If you follow the address, you can see that it is listed in the form of Method Name, Function Address as follows, so you can check the processing method by checking the function under the desired method name.
In the case of Dahua, since it is implemented in C++, most functions that process actual logic are indirect calls.
Therefore, analysis should be conducted after establishing an analysis environment such as gdb and watchdog feeding.
int __fastcall sub_FAA420(int a1, int a2, int a3, int a4)
{
int v7; // r0
int v8; // r10
unsigned __int8 *v9; // r0
int v10; // r9
int v11; // r7
int v12; // r0
int v13; // r0
int v14; // r0
int v15; // r0
int v16; // r0
int v18; // [sp+4h] [bp-2Ch] BYREF
int v19; // [sp+8h] [bp-28h]
int v20; // [sp+Ch] [bp-24h]
v18 = a2;
v19 = a3;
v20 = a4;
v7 = sub_15EFA30(a4, "result");
sub_15EF7C0(v7, 0);
if ( sub_DF5390(a2) )
{
v18 = 0;
v8 = sub_DF3EB8(a2, ".params.proc", &v18);
v9 = sub_15EEA14(a2, "id");
v10 = sub_15EE608(v9);
v11 = sub_DE5BD2(a1);
v12 = sub_15EEA14(a2, "object");
v13 = sub_15EE6AC(v12);
v18 = v11;
v19 = v8;
v20 = v10;
if ( sub_FAA2A0(a1, v13, &v18) )
{
v14 = sub_15EFA30(a4, "params");
v15 = sub_15EFA30(v14, "SID");
sub_15EF6B8(v15, v11);
v16 = sub_15EFA30(a4, "result");
sub_15EF7C0(v16, 1);
}
}
else
{
sub_146F36C(3, "RPCServer", "get component pointer failed or invalid request! \n");
sub_146AF90(-267976703);
}
return 1;
}
2.2.2. RPC order of operation
When requesting the deviceDiscovery.attach method, the backtrace is as follows.
#0 0x00faa420 in ?? ()
#1 0x00de5fba in ?? ()
#2 0x00de6100 in ?? ()
#3 0x00de134e in ?? ()
#4 0x00de271e in ?? ()
#5 0x00de28b4 in ?? ()
#6 0x00de305c in ?? ()
#7 0x01470874 in ?? ()
#8 0xb6cdb390 in ?? () from /lib/libpthread.so.0
start_routine
sub_DE2F86
sub_DE2878
sub_DE245C(proc_request_arrive)
sub_DE1134(deal_request)
sub_DE6090(_Method_Call)
sub_DE5F40(GetSubService)
Execute method
2.3. Additional Analysis Methods
2.3.1. Challenge Log
In the case of Challenge binary, a log is output to the terminal when it is executed.
Since it is output in great detail, it is convenient to analyze by searching for a string that appears in the log.
[2023-11-27T18:25:06 trace WebApp:1303297 2697 RequestHandler.cpp:554]Close called, this=0x7165eb8[2023-11-27T18:25:06 trace WebApp:1303297 2697 RequestHandler.cpp:565]ref_count is 0[2023-11-27T18:25:06 trace NetFramework:1184332 2697 Message.cpp:79]Ready to close NetHandler object:0x7165eb8, obj_id: -1405940, class_type:N5Dahua6WebApp18CRPCRequestHandlerE[2023-11-27T18:25:06 trace NetFramework:1184332 2694 Message.cpp:79]Ready to close NetHandler object:0xb6203f38, obj_id: -1283070, class_type:N5Dahua12NetFramework13CStreamSenderE[2023-11-27T18:25:06 warn NetFramework:1184332 2698 SslStream.cpp:528]this:0xb62a5e78 SSL_peek error!fd:110,len:131071,ERR_get_error=0,errno:0,Success[LIBMED@68650] WARN (DH_SSM_VDEC_CACHE_Notify|1122): cach[1] stream cutoff, need reset.[2023-11-27T18:25:06 info NetApp_V4:1174208 2698 Ipv6ConflictChecker.cpp:663]IPAddr is NULL[2023-11-27T18:25:06 warn NetProtocol:1198304 2698 IPv6ConflictCheckNew.cpp:173]Invalid IPv6 address!
2.3.2. Settings File
The challenge is that the configuration file is located in /mnt/mtd/Config and is managed in a special format or JSON format.
The configuration files are encrypted and stored in the memory after initial decryption when the binary is executed.
2.3.3. Legacy Code
In the case of Dahua, as the size of the binary is large, there are codes that are not used, and codes that do not exist on websites but can be used. Therefore, it will be an important point to find vulnerabilities by targeting the area.