惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Scott Helme
Scott Helme
宝玉的分享
宝玉的分享
B
Blog RSS Feed
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
H
Help Net Security
T
The Blog of Author Tim Ferriss
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
F
Full Disclosure
爱范儿
爱范儿
罗磊的独立博客
G
Google Developers Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
量子位
Hacker News: Ask HN
Hacker News: Ask HN
aimingoo的专栏
aimingoo的专栏
PCI Perspectives
PCI Perspectives
酷 壳 – CoolShell
酷 壳 – CoolShell
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Secure Thoughts
L
LINUX DO - 最新话题
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
V
V2EX
H
Heimdal Security Blog
Engineering at Meta
Engineering at Meta
I
InfoQ
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
S
Security Affairs
Security Archives - TechRepublic
Security Archives - TechRepublic
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
T
Tor Project blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
Know Your Adversary
Know Your Adversary
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
D
Docker
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
有赞技术团队
有赞技术团队
J
Java Code Geeks

Bluemangoo's Blog

看一点答辩Issue 在 Vercel 上部署 MCSManager 的 UI 项目 Python 语言基础 Vercel 折腾笔记 建站一周年纪念! Bing Points 辅助工具 白象过湾 Windows 10 触摸键盘大小调整 尘烟 One一个 文章推荐 Markdown 加载器 力扣 0899 - 有序队列 【芒果快评】安倍晋三遭枪击 常用软件下载链接 那些震惊了我的文案(持续更新) 一个抛鸡蛋的小游戏 《1984》书评 Explorer Patcher 推荐 英语书也会出错啊 图片转Python的turtle库代码 Phigros电脑版 Windows 11 子系统(WSA)安装方法
内存填充器
Bluemangoo · 2022-08-08 · via Bluemangoo's Blog

本文章的内容很危险,会导致电脑死机、蓝屏,请勿在实体机上尝试。

朋友要录视频,虚拟机里面养病毒,有一些经典的病毒,还有一些自己写的 C++ 程序。

我: C++ ? 我来,保证你电脑死机。

原理

C++ 没有 GC(Garbage Collection, 垃圾回收)机制,一切病毒都要自己手动管理。

如果我疯狂申请内存,但是坚决不释放,就可以达到内存泄露的效果。

new 申请内存,用 delete 释放内存。如果不 delete 会在程序运行结束后由系统自动释放。(反正也结束不了)

内存泄露是指不用的内存没有及时释放一直占用空间。

代码

1
2
3
4
5
6
7
#define NUM 1000000
int main(){
int **a=new int*[NUM];
for(int j=0;j<NUM;j++){
a[j]=new int[NUM];
}
}

改进

第一个版本可以导致巨量卡顿,但是会因为报错而退出。

为了解决这个问题只要套个 try 就行了。

这里用了一个 for 代替 goto ,也算是奇技淫巧了 (不是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define NUM 1000000
int main(){
for(int i=0;i<1;i++){
try{
int **a=new int*[NUM];
for(int j=0;j<NUM;j++){
a[j]=new int[NUM];
}
}
catch(...){
i--;
}
}
}

再改进

new 分配内存的效率不高,要想效率高需要用 malloc

malloc 在头文件 malloc.h 中。

函数原型:

1
2
extern void *malloc(unsigned int num_bytes);
//void *__cdecl malloc(size_t _Size); //(in malloc.h 78:3)

改进后的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#define NUM 1000000
#include<malloc.h>
int main(){
for(int i=0;i<1;i++){
try{
int **a=new int*[NUM];
for(int j=0;j<NUM;j++){
a[j]=(int*)malloc(NUM);
}
}
catch(...){
i--;
}
}
}

备注

NUM 是火力,小了可以成功运行,只要足够大就能榨干内存。

会申请 NUM * NUMint 类型的存储空间,1int 类型占 4字节16384 * 16384int 类型占 1G,普通电脑 NUM 打到 65,536 大概就受不了了。

请大家千(yí)万(dìng)不(shì)要(shì)把 NUM 打到这么高。