a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

c# 可疑文件掃描代碼(找到木馬)(簡)

2020-01-24 03:44:50
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Net;
namespace TrojanScanning
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
delegate void SetTextCallback(string text);
delegate void SetTextCallback2(bool b);
delegate void SetTextCallback3(ListViewItem item);
private string fname, code;
private Thread thr;
private string[] sArray;
private void button1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
scanpath.Text = folderBrowserDialog1.SelectedPath;
}
}
private void startbtn_Click(object sender, EventArgs e)
{
list.Items.Clear();
fname = scanpath.Text;
thr = new Thread(new ThreadStart(scan));
thr.IsBackground = true;
thr.Start();
}
private void scan(){
FileSystemInfo s = GetFileSystemInfo(fname);
if (s != null) { scanbtn(false); ListFiles(s); scantext("掃描完成"); scanbtn(true); } else { MessageBox.Show("請先選擇要掃描的目錄"); }
}
public FileSystemInfo GetFileSystemInfo(string path){
if (File.Exists(path))
return new FileInfo(path);
else if (Directory.Exists(path))
return new DirectoryInfo(path);
else
return null;
}

private void ListFiles(FileSystemInfo info){
if (info.Exists){
DirectoryInfo dir = info as DirectoryInfo;
if (dir == null) return;
try{
FileSystemInfo[] files = dir.GetFileSystemInfos();
for (int i = 0; i < files.Length; i++){
FileInfo file = files[i] as FileInfo;
if (file != null && (file.Extension.ToLower() == ".asp" || file.Extension.ToLower() == ".php" || file.Extension.ToLower() == ".aspx" || file.Extension.ToLower() == ".master"))
{
scantext("掃描 " + file.FullName);
chkfile(file.FullName,file.Length);
}else{
ListFiles(files[i]);
}
}
}
catch{}
}
}
private void chkfile(string filepath,long filesize)
{
try{
if (IsFileInUse(filepath)) { System.Threading.Thread.Sleep(2000); chkfile(filepath,filesize); }
StreamReader sr = new StreamReader(filepath);
string content = sr.ReadToEnd();
sr.Close();
string chkr=chkcontent(content);
if (chkr!=""){
ListViewItem item = new ListViewItem("可疑");
item.SubItems.Add(File.GetLastAccessTime(filepath).ToString());
item.SubItems.Add(chkr);
item.SubItems.Add(filepath);
item.SubItems.Add((filesize/1024).ToString() + " kb");
addtiem(item);
}
}
catch { }
}
private string downurl(string url)
{
WebClient client = new WebClient();
string result = client.DownloadString(url);
return result;
}
private void addtiem(ListViewItem item)
{
if (this.list.InvokeRequired){
SetTextCallback3 d = new SetTextCallback3(addtiem);
this.Invoke(d, new object[] { item });
}else{
this.list.Items.Add(item);
}
}
private void scantext(string text)
{
if (this.scanstate.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(scantext);
this.Invoke(d, new object[] { text });
}else{
this.scanstate.Text=text;
}
}
private void scanbtn(bool b){
if (this.startbtn.InvokeRequired){
SetTextCallback2 d = new SetTextCallback2(scanbtn);
this.Invoke(d, new object[] { b });
}else{
this.startbtn.Enabled = b;
this.scanpath.Enabled = b;
this.button1.Enabled = b;
}
}
private string chkcontent(string content){
string returnval = "";
content = content.ToLower();
foreach (string i in sArray)
{
if (content.IndexOf(i)> -1){ returnval+=i+","; }
}
if (returnval != "") { returnval=returnval.Substring(0, returnval.Length - 1); }
return returnval;
}
bool IsFileInUse(string fileName)
{
bool inUse = true;
if (File.Exists(fileName))
{
FileStream fs = null;
try { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None); inUse = false; }
catch { }
finally { if (fs != null)fs.Close(); }
return inUse;
}
else { return false; }
}
private void Form1_Load(object sender, EventArgs e)
{
try{
code = downurl("http://www.cqeh.com/txt/trojan.txt");
sArray = code.ToLower().Split('|');
}
catch (Exception ex)
{
MessageBox.Show("錯誤:" + ex.Message, "無法啟動程序!", MessageBoxButtons.OK); Application.Exit();
}
}
private void list_DoubleClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("NOTEPAD.EXE", list.SelectedItems[0].SubItems[3].Text);
}
}
}

/201005/tools/TrojanScanning.rar
哦 寫錯了個地方 最后修改時間 GetLastAccessTime -> GetLastWriteTime

復制代碼 代碼如下:

if (file != null && (file.Extension.ToLower() == ".asp" || file.Extension.ToLower() == ".php" || file.Extension.ToLower() == ".aspx" || file.Extension.ToLower() == ".master"))
{
scantext("掃描 " + file.FullName);
chkfile(file.FullName,file.Length);


可改


復制代碼 代碼如下:

if (file != null)
{
string fe=file.Extension.ToLower();
if (fe == ".asp" || fe == ".php" || fe == ".aspx" || fe == ".master"){
  scantext("掃描 " + file.FullName);
   chkfile(file.FullName, file.Length);
  }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成人久久久 | 国产欧美日韩精品在线 | 国产精品成人免费一区二区视频 | 日本成人三级 | ririsao久久精品一区 | 久久精品影视 | 欧美日韩视频 | 久久av一区二区三区 | 一级久久久 | 日本另类αv欧美另类aⅴ | 亚洲人在线 | 四虎影视在线 | 久久久久久国产精品 | 免费看片91 | 国产免费一区二区 | 精品久久久久久久久久久 | 99九九久久 | 美女黄在线观看 | 国产成人午夜片在线观看高清观看 | 天堂一区二区三区在线 | 欧美日韩成人精品 | 国产精品视频一区二区三区四区国 | 欧美日韩中 | 亚洲黄色免费观看 | 成人黄色在线观看 | 午夜成人免费影院 | 精品日韩 | 不卡视频一区二区 | 中文字幕一级 | 精国产品一区二区三区 | 亚洲国产天堂久久综合 | 爱爱视频网站 | 国产精品成人一区二区 | 青青免费视频 | 日摸夜操 | 99精品久久99久久久久 | 岛国视频在线 | 色视频一区二区三区 | 日本在线一区二区 | 免费观看一级特黄欧美大片 | 亚洲中出 |