資訊安全:惡作劇程式
3 min readNov 22, 2019
此篇文章將使用C++程式寫些惱人的程式。測試環境為 Virtualbox 虛擬機上的 Windows XP Pro版本,C++ IDE為 Code::Blocks 。
吃光記憶體C程式碼:
#include <stdio.h>
#include <stdlib.h>int main()
{
char *data; // the data
long long int N = (1024 * 1024 * 1024); // Memory size data = (char *) malloc(N); // Generate Random value
for(int i=0;i< N;i++){
data[i] = (char) rand();
} return 0;
}
結果:還沒吃記憶體前,XP作業系統會刪掉此程式(當記憶體使用率 Mem Usage快暴時,下圖中的Hi.exe會突然不見)。
灌爆硬碟C程式碼:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *data; // data to be written
int N = (1024*1024); // 10M for each flush
data = (char *) malloc(N);
// Generate Random value
for(int i=0;i< N;i++){
data[i] = (char) rand();
}
// This is the output file:"hd.dat"
FILE *f = fopen("hd.dat", "w");
while(1)
{
// Write the random data to "hd.dat"
fwrite(data, 1, N, f);
fflush(f);
}
fclose(f);
return 0;
}
此程式請讀者自行在虛擬機上測試。XP會出現如下訊息:
加上兩個按鈕的程式碼而做成的程式( Windows 程式設計可參考此處):
想想看,按下 Hi 與 Quit 按鈕會發生什麼事情呢?結果有沒有如預期呢?
示範程式碼:
該休息了程式碼:
shutdown 是Windows的指令:
當然還有其他的惱人程式,例如讓滑鼠不受使用者控制、一直開啟瀏覽器的分頁等,還請讀者自行發揮想像力囉。
Originally published at https://yunlinsong.blogspot.com.