首页
社区
课程
招聘
一秒钟让windows pc端微信开启自杀模式,理论支持windows的全平台以及所有版本
2021-3-12 19:09 10474

一秒钟让windows pc端微信开启自杀模式,理论支持windows的全平台以及所有版本

2021-3-12 19:09
10474

操作方法:
打开wechat.exe,甚至不需要登陆
只需要将鼠标放置于右下角,右键点击调整时间
图片描述
手动将时间2038年以后
图片描述
即可触发pc端wechat.exe进程超高cpu占比
如下通过任务管理器可查看到其cpu占比
图片描述

 

我们对其原因进行分析:
研究了下,对GetSystemTimeAsFileTime进行下断,发现在获取时间的时候、
对于溢出的情况下,将结构体中的第一个变量赋值为0了
图片描述
导致boost得到的时间有关逻辑错误
图片描述
线程的wait失效

 

进一步通过mars库进行分析分析:
发现在实现条件变量condition的相关代码中
其wait的实现逻辑采用了boost::get_system_time()等函数去获取时间
在create_time[mars\boost\date_time\ microsec_time_clock.hpp]去获取有关本机时间的时候

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
    static time_type create_time(time_converter converter)
    {
#ifdef BOOST_HAS_GETTIMEOFDAY
      timeval tv;
      gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux.
      std::time_t t = tv.tv_sec;
      boost::uint32_t sub_sec = tv.tv_usec;
#elif defined(BOOST_HAS_FTIME)
      winapi::file_time ft;
      winapi::get_system_time_as_file_time(ft);
      uint64_t micros = winapi::file_time_to_microseconds(ft); // it will not wrap, since ft is the current time
                                                               // and cannot be before 1970-Jan-01
      std::time_t t = static_cast<std::time_t>(micros / 1000000UL); // seconds since epoch
      // microseconds -- static casts suppress warnings
      mars_boost::uint32_t sub_sec = static_cast<mars_boost::uint32_t>(micros % 1000000UL);
#else
#error Internal Boost.DateTime error: BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK is defined, however neither gettimeofday nor FILETIME support is detected.
#endif
 
      std::tm curr;
      std::tm* curr_ptr = converter(&t, &curr);
      date_type d(static_cast< typename date_type::year_type::value_type >(curr_ptr->tm_year + 1900),
                  static_cast< typename date_type::month_type::value_type >(curr_ptr->tm_mon + 1),
                  static_cast< typename date_type::day_type::value_type >(curr_ptr->tm_mday));
 
      //The following line will adjust the fractional second tick in terms
      //of the current time system.  For example, if the time system
      //doesn't support fractional seconds then res_adjust returns 0
      //and all the fractional seconds return 0.
      int adjust = static_cast< int >(resolution_traits_type::res_adjust() / 1000000);
 
      time_duration_type td(static_cast< typename time_duration_type::hour_type >(curr_ptr->tm_hour),
                            static_cast< typename time_duration_type::min_type >(curr_ptr->tm_min),
                            static_cast< typename time_duration_type::sec_type >(curr_ptr->tm_sec),
                            sub_sec * adjust);
 
      return time_type(d,td);
    }

走到了BOOST_HAS_GETTIMEOFDAY的代码逻辑里面
原因是未注意其boost库在windows端的有关配置

 

以及日志库appender.cc为了跨平台操作,采用了结构体timeval + gettimeofday自实现[mars\comm\windows\sys\time.c]的方法使其编译可正常通过

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
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
  FILETIME ft;
  unsigned __int64 tmpres = 0;
  static int tzflag;
 
  if (NULL != tv)
  {
    GetSystemTimeAsFileTime(&ft);
 
    tmpres |= ft.dwHighDateTime;
    tmpres <<= 32;
    tmpres |= ft.dwLowDateTime;
 
    /*converting file time to unix epoch*/
    tmpres /= 10/*convert into microseconds*/
    tmpres -= DELTA_EPOCH_IN_MICROSECS;
 
    tv->tv_sec = ((long)(tmpres / 1000000UL)<0 ? 0 : (long)(tmpres / 1000000UL)); // 注意这里
    tv->tv_usec = (long)(tmpres % 1000000UL);
  }
 
  if (NULL != tz)
  {
    if (!tzflag)
    {
      tzset();
      tzflag++;
    }
    tz->tz_minuteswest = _timezone / 60;
    tz->tz_dsttime = _daylight;
  }
 
  return 0;
}

但如果我们将windows 本机时间变成2038年以后
由于微软所提供的头文件struct timeval里面的tv_sec为4字节,使得tv->tvsec=0
从而导致线程中cond
.wait相关功能失效,相当于没有sleep,从而导致cpu高
以及日志库不正常

 

需要修改

1
2
3
4
#ifndef WIN32
#define BOOST_HAS_GETTIMEOFDAY
#endif
[mars\boost\config\user.php]

并更新boost库(过于老,而且也存在2038相关逻辑错误)以及建议日志库不使用 timeval 因为这种情况下会导致日志名始终为MM_19700101.xlog以及日志库里时间不正常

 

ps:
还有一些相关bug可参考
https://github.com/Tencent/mars/issues/924
另若mars相关开发人员看见了
能否可以考虑开源一下mars的cdn库!!!


[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界

收藏
点赞5
打赏
分享
最新回复 (7)
雪    币: 2604
活跃值: (231)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
星雪鸢尾 2021-3-12 22:29
2
0
是2038年虫吗
雪    币: 182
活跃值: (576)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
柒雪天尚 2021-3-12 23:40
3
0
雪    币: 3523
活跃值: (3454)
能力值: ( LV9,RANK:150 )
在线值:
发帖
回帖
粉丝
psycongroo 2 2021-3-16 08:57
4
0
这种bug是怎么被发现的,一般怎么也不会想到去调时间吧,还调到那么后。
雪    币: 12776
活跃值: (16307)
能力值: (RANK:730 )
在线值:
发帖
回帖
粉丝
有毒 10 2021-3-16 09:21
5
0
这个有意思啊,同问是如何注意到的
雪    币: 9704
活跃值: (3885)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Willarcap 2021-3-16 10:04
6
0
有毒 这个有意思啊,同问是如何注意到的[em_78]
https://www.v2ex.com/t/760166
雪    币: 0
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
mb_socdjdjb 2021-3-22 11:48
7
0
我改完没有微信进程了,桌面疯狂闪屏,时间改不回去
雪    币: 0
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
mb_socdjdjb 2021-3-22 11:49
8
0
老哥救我公司的电脑啊!
游客
登录 | 注册 方可回帖
返回