首页
社区
课程
招聘
[原创]简单云查杀客户端源代码
2011-4-10 23:24 14303

[原创]简单云查杀客户端源代码

2011-4-10 23:24
14303

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

//
//+++++++++++++++++++++++++++++++++++++++++++++
//
// CloudScanner 
//
// Written by Spark.   nkspark_at_gmail.com
// 
//          2011.03.26
//+++++++++++++++++++++++++++++++++++++++++++++
//

namespace CloudScanner
{
    class Program
    {
        static string GetScanResult(string strFileName)
        {
            //VirusTotal的查询请求链接。
            string strQueryURL = "http://www.virustotal.com/search.html"
            string strMD5;

            FileStream fsSource = new FileStream(strFileName, FileMode.Open, FileAccess.ReadWrite);

            byte[] bIn = new byte[fsSource.Length];
            fsSource.Read(bIn, 0, (int)fsSource.Length);
            fsSource.Close();

            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            strMD5 = BitConverter.ToString(md5.ComputeHash(bIn)).Replace("-", "");
            strMD5 = "chain=" + strMD5;



            WebClient webClient = new WebClient();
            webClient.Encoding = System.Text.Encoding.UTF8;
            System.Net.ServicePointManager.Expect100Continue = false;


            return webClient.UploadString(strQueryURL, strMD5);
        }

        //从VirusTotal的返回结果中提取病毒名称。
        static string ExtractResult(string strPage)
        {
            string strAVProductName;
            string strVersion;
            string strUpdate;
            string strVirusName = "";

            
            int iStartPos = -1;
            int iEndPos = -1;

            iStartPos = strPage.IndexOf("id=\"tablaMotores\"");
            if (iStartPos == -1) return "";           
            iEndPos = strPage.IndexOf("</table>", iStartPos);
            strPage = strPage.Substring(iStartPos, iEndPos-iStartPos);

            TagInfo ti = new TagInfo();

            string strTRLine;
            ti.TagName = "tr";
            ti.GetPos(strPage);
            strTRLine = ti.GetContext(strPage);
            strPage = strPage.Substring(ti.EndPos);           

            while (strTRLine != "")
            {                
                ti.TagName = "tr";
                ti.GetPos(strPage);
                strTRLine = ti.GetContext(strPage);
                if (strTRLine == "") return "";
                strPage = strPage.Substring(ti.EndPos);

                //AV Product
                ti.TagName = "td";
                ti.GetPos(strTRLine);
                strAVProductName = ti.GetContext(strTRLine);
                

                //Version
                strTRLine = strTRLine.Substring(ti.EndPos);
                ti.TagName = "td";
                ti.GetPos(strTRLine);
                strVersion = ti.GetContext(strTRLine);
                
                //Last Update
                strTRLine = strTRLine.Substring(ti.EndPos);
                ti.TagName = "td";
                ti.GetPos(strTRLine);
                strUpdate = ti.GetContext(strTRLine);
                
                //Result
                strTRLine = strTRLine.Substring(ti.EndPos);
                ti.TagName = "td";
                ti.GetPos(strTRLine);
                strVirusName = ti.GetContext(strTRLine);
                if (strVirusName != "-")
                    return strVirusName;                        
            }

            return ""; 
        }
        static void Main(string[] args)
        {
 
            string strResult;
            string strFileName="";
            long lTime;

            if (args.Length < 1)
            {
                Console.WriteLine("Usage: CloudScanner.exe FileName");
                return;
            }

            strFileName = args[0];

            if (!File.Exists(strFileName))
            {
                Console.WriteLine("文件不存在!");
                return;
            }

            lTime = DateTime.Now.Ticks;            
            strResult = GetScanResult(strFileName);

            strResult = ExtractResult(strResult);
            lTime = (DateTime.Now.Ticks - lTime) / TimeSpan.TicksPerSecond;

            if(strResult != "")               
                Console.WriteLine("发现病毒 " + strResult + ",扫描用时" + lTime.ToString() + "秒。");
            else               
                Console.WriteLine("正常文件,扫描用时" + lTime.ToString() + "秒。");

        }

 

    }

    public class TagInfo
    {
        public string TagName;
        public int StartPos = -1;
        public int EndPos = -1;

        public void GetPos(string strIn)
        {


            string strScriptStart = "<" + TagName;
            string strScriptEnd = "/" + TagName + ">";

            StartPos = strIn.IndexOf(strScriptStart);
            if (StartPos != -1)
                EndPos = strIn.IndexOf(strScriptEnd, StartPos);
        }

        public string GetContext(string strIn)
        {

            string strTemp = "";
            string strScriptStart = ">";
            string strScriptEnd = "<";
            int iScriptStart;
            int iScriptEnd;

            if (StartPos != -1 && EndPos != -1)
            {
                iScriptStart = strIn.IndexOf(strScriptStart, StartPos) + 1;
                iScriptEnd = strIn.LastIndexOf(strScriptEnd, EndPos);
                strTemp = strIn.Substring(iScriptStart, iScriptEnd - iScriptStart);
            }
            return strTemp;
        }

    }

}



思路非常简单,将本地文件的MD5值发送到VirusTotal,分析返回结果,如果查找到病毒名称,则报出。对上述代码稍加改动,可实现更多云查杀客户端功能。

1、由于VirusTotal在云端集成了43款不同的杀毒引擎,所以此客户端虽然简单,但查杀率极高。
2、直接使用链接查询方式,而非VirusTotal提供的API,所以不受查询次数限制(限制为5分钟20次)。

附件增加了文件夹递归扫描和病毒文件删除功能。

[培训]《安卓高级研修班(网课)》月薪三万计划

上传的附件:
收藏
点赞6
打赏
分享
最新回复 (28)
雪    币: 2320
活跃值: (3971)
能力值: ( LV12,RANK:530 )
在线值:
发帖
回帖
粉丝
熊猫正正 9 2011-4-10 23:46
2
0
谢谢分享~~
雪    币: 72
活跃值: (10)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
yasm 2011-4-11 00:00
3
0
谢谢分享…学习
雪    币: 855
活跃值: (284)
能力值: ( LV11,RANK:180 )
在线值:
发帖
回帖
粉丝
Vsbat 4 2011-4-11 00:48
4
0
猛男~~
雪    币: 284
活跃值: (16)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
jerrynpc 2011-4-11 08:29
5
0
不错的吖,怎么没人顶呢/
雪    币: 695
活跃值: (70)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
reggie 2011-4-11 09:04
6
0
nice,原来云查杀是这样一个原理
雪    币: 169
活跃值: (90)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
竹君 5 2011-4-11 09:19
7
0
云查杀依据庞大的黑白名单库+N种反病毒的软件扫描+人工分析
1、黑白名单(关键就是及时、全面)
2、N种反病毒查杀(速度)
3、人工分析(都没扫出来的,人再去看一看,不确定有这一环节)
4、杀掉发现的病毒(杀完病毒,系统可否正常使用)
雪    币: 169
活跃值: (90)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
竹君 5 2011-4-11 09:19
8
0
云查杀在互联网时代效果还是蛮好的吧。
雪    币: 217
活跃值: (67)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
liein 2011-4-11 10:44
9
0
思路很好这个 代码
雪    币: 266
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
雪妖 2011-4-11 10:58
10
0
这个 前年 就玩过了
雪    币: 46
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
xiaocaijk 2011-4-11 12:22
11
0
顶贴支持  ~~
雪    币: 10012
活跃值: (1649)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
wzmooo 2011-4-11 12:27
12
0
期待更新这个软件    不错
雪    币: 33
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
spide 2011-4-11 18:03
13
0
估计国内那些云也是如此
雪    币: 258
活跃值: (40)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
hawkish 1 2011-4-11 21:24
14
0
思路很好,花了点时间,用MFC重写了。。。。
KillVirus.rar
上传的附件:
雪    币: 169
活跃值: (90)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
竹君 5 2011-4-12 08:53
15
0
单机用户。。。。亿级试试
雪    币: 86
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
xnop 2011-4-12 16:52
16
0

思路那是相当的棒
雪    币: 578
活跃值: (14)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
winddyj 2011-4-12 18:20
17
0
很强悍,收藏了,研究下
雪    币: 239
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
yinning 2011-4-15 01:28
18
0
谢谢楼主,思路不错呀
雪    币: 23
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
小P孩儿 2011-4-15 08:03
19
0
[QUOTE=hawkish;946697]思路很好,花了点时间,用MFC重写了。。。。
KillVirus.rar
[/QUOTE]

嘿嘿…不错…看看
雪    币: 1542
活跃值: (300)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
木羊 2011-4-15 09:04
20
0
感谢LZ

不过如果只是MD5的话 多加一个字节就可以洗洗睡了吧?
雪    币: 48
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
notmorw 2011-4-17 09:38
21
0
流量很贵的,哈哈,云端表示都这么玩,情何以堪
雪    币: 291
活跃值: (25)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
crazycode 1 2011-4-17 21:47
22
0
思路很好~~~支持一下~
雪    币: 6
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
FanTasyXX 2011-4-17 23:27
23
0
同感,这个贵在思路清晰
雪    币: 49
活跃值: (29)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
付崇碧 2011-4-18 00:20
24
0
国内云查杀估计都是这样么?
雪    币: 249
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
kaso 2011-4-27 21:26
25
0
總感覺這不是雲查殺吧...........
游客
登录 | 注册 方可回帖
返回