您好,欢迎访问一九零五行业门户网

w3wp.exe修改php-cgi的内存是什么情况?

出现“w3wp.exe修改php-cgi的内存”是因为d盾为了支持同一个服务器支持多php版本,所以d盾是在加载php的php-cgi.exe进程时加入d盾保护的。
本文操作环境:windows7系统、php7.1版、dell g3电脑
w3wp.exe怎么修改php-cgi的内存?
关于使用d盾,安全狗提示w3wp.exe修改php-cgi.exe内存的说明
关于使用d盾,服务器安全狗提示 w3wp.exe 修改 php-cgi.exe 内存的一些说明
最近看到安全狗新版,会有这样的提示。
为了减少误解,还是说说这事!
d盾为了支持同一个服务器支持多php版本,所以d盾是在加载php的php-cgi.exe进程时加入d盾保护的。
需要在启动php-cgi.exe时修改内存并让php-cgi.exe加载d盾的保护模块的dll。
(最开始想通过php.ini配置来设置启动,但有些服务器上可能存在多个php版本,很容易疏漏,
也有可能用户动态修改或新增,无法及时得状态时就容易导致php没有做到保护,所以放弃这方案)
帖出一部份d盾的启动php-cgi并开启d盾保护的delphi代码
(为防止黑客了解太多细节,忽略一些细节):
// ########################################################// hook执行函数会到这里过滤处理// ########################################################function my_createprocessinternalw(dw1_: pointer; lpapplicationname: lpcwstr;lpcommandline: lpwstr; lpprocessattributes, lpthreadattributes: psecurityattributes; binherithandles: bool; dwcreationflags: dword;lpenvironment: pointer; lpcurrentdirectory: lpcwstr;const lpstartupinfo: tstartupinfow;var lpprocessinformation: tprocessinformation; dw2: pointer): bool; stdcall;varre_add: hmodule;is_64_pe: boolean;err_index: integer;imagebaseaddress, addressofentrypoint_: pvoid64;p_nt_head_32: pimagentheaders32; // nt头p_nt_head_64: pimagentheaders64; // nt头nthead_: timagentheaders64; // nt头dwsize: size_t;d_safe_x32_load_manage_a: widestring;str: string;lpenvironment_str: ansistring;inf_: pweb_http_context;re_fun_add: hmodule;app_, com_, com_exe_path, dir_: string;re_app_, re_cs_: string;app_len, com_len: dword;comlin_inf_: tfilepath_pak;app_inf_: tfilepath_pak;ex_style_: dword;state_: integer;nt_head_add_: pvoid64;//简化了的进程创建函数function createprocessinternalw_do(): bool;beginresult := createprocessinternalw_(dw1_, lpapplicationname, lpcommandline,lpprocessattributes, lpthreadattributes, binherithandles, dwcreationflags,lpenvironment, lpcurrentdirectory, lpstartupinfo,lpprocessinformation, dw2);end;//执行php-cgi.exe并加载d盾的保护function run_php_fcgi(): boolean;varerr_: integer;function kill_pro(pid_: dword): boolean;beginresult := false;// 显示不支持保护信息// 32位池的d盾保护模块无法对64位的php做保护,请把池改为64位或使用32位的php版本d_msg_(c_no_support_64_php, niif_error_);// 结束进程terminateprocess(openprocess(process_terminate, false, pid_), $ffffffff);setlasterror(5);end;begin// 创建php-cgi进程result := createprocessinternalw_do();if result thenbegin// 读到指定进程的nt头信息imagebaseaddress := d_get_process_ntheaders(lpprocessinformation.hprocess,nthead_, is_64_pe, nt_head_add_);if imagebaseaddress > 0 thenbegin// 如果是64位进程时if is_64_pe thenbeginp_nt_head_64 := @nthead_;addressofentrypoint_ := imagebaseaddress +p_nt_head_64.optionalheader.addressofentrypoint;//如果当前的iis进程不是64位的,并 php-cgi 的入口位置大于0x100000000时if (d_is_win64_project() = false) and(addressofentrypoint_ >= $100000000) thenbegincase win_ver_ of_win_ver_2003, _win_ver_2008:begin// 写入d盾的 64位的 load_manage.dllif run_x64_ldrloaddll(lpprocessinformation.hprocess,win_inf_.d_safe_x64_load_manage) = false thenbegin// 失败时,结束进程result := kill_pro(lpprocessinformation.hprocess);exit;endelsebeginresult := true;setlasterror(0);exit;end;end;_win_ver_2012:begin// 不支持保护时,结束进程result := kill_pro(lpprocessinformation.hprocess);exit;end;end;endelsebegin// 写入d盾的 load_manage.dllif d_write_dll_to_process(lpprocessinformation.hprocess,addressofentrypoint_, win_inf_.d_safe_x64_load_manage, true) thenbeginresult := true;setlasterror(0);exit;endelsebegin// 写入失败时结束php-cgi进程result := kill_pro(lpprocessinformation.hprocess);exit;end;end;endelsebegin// 32位程序时p_nt_head_32 := @nthead_;addressofentrypoint_ := imagebaseaddress +p_nt_head_32.optionalheader.addressofentrypoint;dwsize := sizeof(tset_fun_add_head_32);// 写入d盾的 load_manage.dllif d_write_dll_to_process(lpprocessinformation.hprocess,addressofentrypoint_, win_inf_.d_safe_x32_load_manage, false) thenbeginresult := true;setlasterror(0);exit;endelsebegin// 写入失败时结束php-cgi进程result := kill_pro(lpprocessinformation.hprocess);exit;end;end;endelsebegin// 结束php-cgi进程result := kill_pro(lpprocessinformation.hprocess);exit;end;end;end;begin.... //前面的代码,忽略// ######################################################// 如果是 php-cgi.exe// ######################################################if (.... //忽略掉一些代码) and (pos(const_php_cgi, app_) > 0) and ((com_len - app_len) = 2) thenbegin// 执行php-cgi.exe,并加入d盾的保护模块result := run_php_fcgi();exit;end;... //后面的代码,忽略
如需查看汇编代码,可以运行d盾web保护的情况下,用ollyice调试 w3wp.exe 进程。
并选定并调试 web_safe.dll,查找字符 php-cgi.exe 即可快速定位相关代码位置
如下代码为 d_safe_2.1.4.4版本的 x32\web_safe.dll 汇编代码
05ed9b20 /e9 73010000 jmp web_safe.05ed9c9805ed9b25 |8b45 28 mov eax, dword ptr [ebp+28]05ed9b28 |50 push eax05ed9b29 |8b85 b0feffff mov eax, dword ptr [ebp-150]05ed9b2f |e8 5c0bdeff call web_safe.05cba69005ed9b34 |8d95 5efcffff lea edx, dword ptr [ebp-3a2]05ed9b3a |33c9 xor ecx, ecx05ed9b3c |e8 bf82faff call web_safe.05e81e0005ed9b41 |8d85 b8feffff lea eax, dword ptr [ebp-148]05ed9b47 |8b95 5efcffff mov edx, dword ptr [ebp-3a2]05ed9b4d |e8 a60bdeff call web_safe.05cba6f805ed9b52 |8d85 5efcffff lea eax, dword ptr [ebp-3a2]05ed9b58 |e8 1f67faff call web_safe.05e8027c05ed9b5d |837d 20 00 cmp dword ptr [ebp+20], 005ed9b61 |74 3b je short web_safe.05ed9b9e05ed9b63 |0fb785 62fcffff movzx eax, word ptr [ebp-39e]05ed9b6a |3bf0 cmp esi, eax05ed9b6c |75 30 jnz short web_safe.05ed9b9e05ed9b6e |b9 01000000 mov ecx, 105ed9b73 |8b95 c0feffff mov edx, dword ptr [ebp-140]05ed9b79 |b8 e49ced05 mov eax, web_safe.05ed9ce4 ; php-cgi.exe05ed9b7e |e8 f910deff call web_safe.05cbac7c05ed9b83 |85c0 test eax, eax05ed9b85 |7e 17 jle short web_safe.05ed9b9e05ed9b87 |2bfe sub edi, esi05ed9b89 |83ff 02 cmp edi, 205ed9b8c |75 10 jnz short web_safe.05ed9b9e05ed9b8e |55 push ebp05ed9b8f |e8 a8fbffff call web_safe.05ed973c ; 进入 run_php_fcgi 函数05ed9b94 |59 pop ecx05ed9b95 |f6d8 neg al05ed9b97 |1bdb sbb ebx, ebx05ed9b99 |e9 fa000000 jmp web_safe.05ed9c98
d盾程序无壳,易调试,欢迎技术朋友监督。一直认为第三方的监督才是最好的监督。
--------------------------------------------------------------------------------
最后想说的是,如果禁止d盾在启动php-cgi.exe时修改内存,将会结束php-cgi.exe或无法保护,请不要禁止。
如果用户觉得需要一个开关来设置保护或不保护php的话,请和 啊d qq:9269563 说说,视用户反馈情况看
是否要增加一个关掉php保护的开关。
d盾为了实现保护,需要大量hook相关api来实现保护,大部份都是需要修改汇编代码的内存来实现的,
所以以后不再讨论修改内存之类的问题,在此声明一下!
推荐学习:《php视频教程》
以上就是w3wp.exe修改php-cgi的内存是什么情况?的详细内容。
其它类似信息

推荐信息