专业网站建设品牌,17年专业建站经验,服务6000+客户--广州松河
免费热线:400-963-0016
微信咨询
|
联系我们
扫二维码关注公众号
网站首页
网站建设
短视频
网站推广
网站模板
客户案例
资讯动态
关于我们
网站首页
网站建设
短视频
网站推广
网站模板
客户案例
资讯动态
关于我们
位置:
广州松河
>
技术支持
> c# 监控服务器上传木马(包含可疑文件)
c# 监控服务器上传木马(包含可疑文件)
来源:网络整理 时间:2023/2/14 1:07:12 共
3624
浏览
using
System;
using
System.IO;
using
System.Threading;
using
System.Windows.Forms;
using
System.Net;
namespace
TrojanMonitor
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
delegate
void
SetTextCallback(
string
text);
private
string
fname,code,emailkey,ip;
private
Thread thr;
private
void
fsw_Changed(
object
sender, FileSystemEventArgs e)
{//文件改动监控(包含了新增)
fname
=
e.Name;
thr
=
new
Thread(
new
ThreadStart(chkfile));
thr.IsBackground
=
true
;
thr.Start();
}
private
void
fsw_Renamed(
object
sender, RenamedEventArgs e)
{//重命名监控
fname
=
e.Name;
thr
=
new
Thread(
new
ThreadStart(chkfile));
thr.IsBackground
=
true
;
thr.Start();
}
private
void
chkfile(){
string
filename
=
fname;
string
content
=
""
,filepath
=
fsw.Path
+
@"
\
"
+
filename,fileName
=
""
,hzhui
=
""
;
fileName
=
Path.GetFileName(filename);
hzhui
=
Path.GetExtension(filename).ToLower();
if
(hzhui
==
"
.asp
"
||
hzhui
==
"
.aspx
"
||
hzhui
==
"
.php
"
||
hzhui
==
"
.jpg
"
||
hzhui
==
"
.gif
"
)
{
try
{
if
(IsFileInUse(filename)) { System.Threading.Thread.Sleep(
2000
); chkfile(); }
StreamReader sr
=
new
StreamReader(filepath);
content
=
sr.ReadToEnd();
sr.Close();
if
(chkcontent(content)){
try
{
string
bakpath
=
Application.StartupPath
+
@"
\TrojanMonitorbak
"
,
logfile
=
bakpath
+
@"
\log
"
+
DateTime.Today.ToShortDateString()
+
"
.dat
"
,
newfile
=
bakpath
+
@"
\
"
+
DateTime.Today.ToShortDateString()
+
@"
\
"
,
newfilepath
=
newfile
+
DateTime.Now.Hour.ToString()
+
"
点
"
+
DateTime.Now.Minute.ToString()
+
"
分
"
+
DateTime.Now.Second.ToString()
+
"
秒
"
+
DateTime.Now.Millisecond.ToString()
+
"
毫秒-
"
+
fileName;
if
(
!
Directory.Exists(bakpath)) { Directory.CreateDirectory(bakpath); }
if
(
!
Directory.Exists(newfile)) { Directory.CreateDirectory(newfile);}
if
(File.Exists(newfilepath)){File.Delete(newfilepath);}
File.Move(filepath,newfilepath);
string
str
=
"
[
"
+
DateTime.Now
+
"
] 发现可疑文件: [
"
+
filepath
+
"
] To [
"
+
newfilepath
+
"
]
"
;
addtiem(str);
StreamWriter sw
=
File.AppendText(logfile);
sw.WriteLine(str
+
"
\r\n
"
);//写入日志
sw.Flush();
sw.Close();
sw.Dispose();
downurl(
"
http://www.cqeh.com/mail/?EmailSubject=发现可疑文件(
"
+
ip
+
"
)&EmailKey=
"
+
emailkey
+
"
&SendHtml=[
"
+
ip
+
"
][
"
+
DateTime.Now
+
"
] 发现可疑文件: [
"
+
filepath
+
"
]
"
);//发送Email
sw
=
File.AppendText(filepath);
sw.WriteLine(
"
此文件检测到有可疑问题!请联系管理员!
"
);
sw.Flush();
sw.Close();
sw.Dispose();
}
catch
(Exception ex) { addtiem(ex.ToString()); }
}
}
catch
(Exception ex) { addtiem(ex.ToString()); }
}
}
private
string
downurl(
string
url){
WebClient client
=
new
WebClient();
string
result
=
client.DownloadString(url);
return
result;
}
private
void
addtiem(
string
text){
if
(
this
.lb.InvokeRequired){
SetTextCallback d
=
new
SetTextCallback(addtiem);
this
.Invoke(d,
new
object
[] { text });
}
else
{
this
.lb.Items.Add(text);
}
}
private
bool
chkcontent(
string
content)
{
bool
returnval
=
false
;
string
[] sArray
=
code.ToLower().Split(
'
|
'
);
content
=
content.ToLower();
foreach
(
string
i
in
sArray)
{
if
(content.IndexOf(i)
>-
1
){returnval
=
true
;
break
;}
}
return
returnval;
}
private
void
Form1_Load(
object
sender, EventArgs e){
ip
=
Dns.GetHostEntry(Environment.MachineName).AddressList[
0
].ToString();
string
config
=
File.ReadAllText(Application.StartupPath
+
"
//monitorpath.ini
"
);//获取监控路径 d:\wwwroot
try
{
code
=
downurl(
"
http://www.cqeh.com/txt/trojan.txt
"
);
//获取木马特征库
filepath.Text
=
config;
fsw.Path
=
config;
emailkey
=
downurl(
"
http://www.cqeh.com/txt/trojanemailkey.txt
"
);
//获取发送email许可key;
this
.ShowInTaskbar
=
false
;
this
.Visible
=
false
;
}
catch
(Exception ex){
MessageBox.Show(
"
错误:
"
+
ex.Message,
"
无法启动程序!
"
, MessageBoxButtons.OK); Application.Exit();
}
finally
{ }
}
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
notifyIcon1_MouseDoubleClick(
object
sender, MouseEventArgs e)
{
this
.Visible
=
true
;
this
.WindowState
=
FormWindowState.Normal;
this
.ShowInTaskbar
=
true
;
}
private
void
Form1_Resize(
object
sender, EventArgs e)
{
if
(
this
.WindowState
==
FormWindowState.Minimized){
this
.ShowInTaskbar
=
false
;
this
.Visible
=
false
;
}
}
private
void
退出系统ToolStripMenuItem_Click_1(
object
sender, EventArgs e){
Application.Exit();
}
private
void
显示窗口ToolStripMenuItem_Click(
object
sender, EventArgs e){
this
.Visible
=
true
;
this
.WindowState
=
FormWindowState.Normal;
this
.ShowInTaskbar
=
true
;
}
private
void
Form1_FormClosing(
object
sender, FormClosingEventArgs e){
this
.ShowInTaskbar
=
false
;
this
.Visible
=
false
;
e.Cancel
=
true
;
}
}
}
源码包下载
版权说明:
本网站凡注明“广州松河 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
相关主题:
邛崃专注网站制作公司电话
如何注册绿盾公司网站
大庆油田公司举报网站
本溪网站运营公司招聘信息
永川蔬菜网站建设公司
昆明高端网站模板设计公司
网站优化公司怎样收费的
公司文档下载网站有哪些
晋宁网站营销咨询公司电话
哪个网站的公司靠谱
·上一条:
c#.net全站防止SQL注入类的代码
|
·下一条:
IIS取消文件夹下的文件脚本执行权限,禁止webshell木马运行
同类资讯
如何构建自己的网页认证PORTAL服务器_服务器
c语言怎么编写王者荣耀_服务器
饥荒联机和专用服务器有什么区别_服务器
下一代处理器会叫什么_服务器
做网络推广利润怎么来_服务器
哈利波特中的书籍_服务器
服务器休眠如何设置_服务器
手机浏览器怎么设置25倍加速_服务器
网易邮箱注册的时候_服务器
google离线地图怎么下_服务器
安装操作系统教程_服务器
服务器可以作为个人电脑使用吗_服务器
明日之后等待进入游戏要等多久_服务器
台达伺服电机参数怎么设密码_服务器
DNF从晚上23点到早上8点关闭服务器_服务器
反恐精英起源怎么联机_服务器
linux服务器怎么恢复原先出厂设置_服务器
dns服务器没检测到是什么意思_服务器
以太网卡驱动程序如何安装_服务器
保险公司信息部负责人岗位职责_服务器
资讯动态
公司新闻
互联网资讯
电商资讯
优化推广
技术支持
关于我们
公司简介
企业文化
服务项目
公司新闻
服务项目
网站建设
网站推广
品牌策划
移动应用
服务支持
在线咨询
服务流程
产品报价
售后服务
联系我们
代理加盟
付款方式
在线留言
联系方式
联系方式
电话:400-963-0016
邮箱:sales@itwy.com
QQ:250211130
微信:18520775521
Copyright © 广州松河信息科技有限公司 2005-2025 版权所有
粤ICP备16019765号
广州松河信息科技有限公司 版权所有
18520775521
QQ洽谈
sales@itwy.com