收藏 分销(赏)

计算机网络安全技术实验.docx

上传人:pc****0 文档编号:8785919 上传时间:2025-03-02 格式:DOCX 页数:27 大小:190.55KB 下载积分:10 金币
下载 相关 举报
计算机网络安全技术实验.docx_第1页
第1页 / 共27页
计算机网络安全技术实验.docx_第2页
第2页 / 共27页


点击查看更多>>
资源描述
计算机网络安全技术 实验 n 案例名称:操作注册表 n 程序名称:#include <stdio.h> n #include <windows.h> n   n main() n { n HKEY hKey1; n DWORD dwDisposition; n LONG lRetCode; n //创建 n lRetCode = RegCreateKeyEx ( HKEY_LOCAL_MACHINE, n "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\IniFileMapping\\WebSecurity", n 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, n NULL, &hKey1, &dwDisposition); n n //如果创建失败,显示出错信息 n if (lRetCode != ERROR_SUCCESS){ n printf ("Error in creating WebSecurity key\n"); n return (0) ; n } n //设置第一个键值 n lRetCode = RegSetValueEx ( hKey1, n "Hack_Name", n 0, n REG_SZ, n (byte*)"sixage", n 100); n //设置第二个键值 n lRetCode = RegSetValueEx ( hKey1, n "Hack_Hobby", n 0, n REG_SZ, n (byte*)"Running", n 100); n n //如果创建失败,显示出错信息 n if (lRetCode != ERROR_SUCCESS) { n printf ( "Error in setting Section1 value\n"); n return (0) ; n } n printf("注册表编写成功!\n"); n return(0); n } n 案例名称:判断是否中了“冰河” n 程序名称:proj3_13.cpp n   n #include <stdio.h> n #include <windows.h> n main() n { n HKEY hKEY; n LPCTSTR data_Set = "txtfile\\shell\\open\\command"; n long ret0 = (RegOpenKeyEx(HKEY_CLASSES_ROOT, n data_Set, 0, KEY_READ,&hKEY)); n if(ret0 != ERROR_SUCCESS) //如果无法打开hKEY,则终止程序的执行 n { n return 0; n } n //查询有关的数据 n LPBYTE owner_Get = new BYTE[80]; n DWORD type_1 = REG_EXPAND_SZ ; n DWORD cbData_1 = 80; n long ret1=RegQueryValueEx(hKEY, NULL, NULL, n &type_1, owner_Get, &cbData_1); n if(ret1!=ERROR_SUCCESS) n { n return 0; n } n n if(strcmp((const char *)owner_Get,"%systemroot%\\system32\\notepad.exe %1") == 0) n { n printf("没有中冰河"); n } n else n { n printf("可能中了冰河"); n } n printf("\n"); n } 编译运行会有下面结果 然后在注册表中HKEY_CLASSES_ROOT主键下的“txtfile\shell\open\command” 将值改为其他的,然后再运行。会有下面结果。 n 案例名称:更改系统登录用户 n 程序名称:proj3_14.cpp n   n #include <stdio.h> n #include <windows.h> n   n main() n { n HKEY hKey1; n LONG lRetCode; n lRetCode = RegOpenKeyEx ( HKEY_LOCAL_MACHINE, n "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", n 0, KEY_WRITE, n &hKey1 n ); n n if (lRetCode != ERROR_SUCCESS){ n printf ("Error in creating appname.ini key\n"); n return (0) ; n } n   n lRetCode = RegSetValueEx ( hKey1, n "DefaultUserName", n 0, n REG_SZ, n (byte*)"Hacker_sixage", n 20); n n if (lRetCode != ERROR_SUCCESS) { n printf ( "Error in setting Section1 value\n"); n return (0) ; n n } n printf("已经将登录名该成Hacker_sixage"); n return(0); n } n 文件系统编程非常的重要,可以在DOS命令行下执行的操作都可以使用程序实现。 n 在DOS命令行下使用命令“net user Hacker /add”添加一个用户,同样可以在程序中实现,如程序proj3_15.cpp所示。 n n 案例名称:添加系统用户 n 程序名称:proj3_15.cpp n   n #include <stdio.h> n #include <windows.h> n main() n { n char * szCMD = "net user Hacker /add"; n BOOL bSuccess; n PROCESS_INFORMATION piProcInfo; n STARTUPINFO Info; n Info.cb=sizeof(STARTUPINFO); n Info.lpReserved=NULL; n Info.lpDesktop=NULL; n Info.lpTitle=NULL; n Info.cbReserved2=0; n Info.lpReserved2=NULL; n bSuccess=CreateProcess(NULL,szCMD,NULL,NULL,false,NULL,NULL,NULL,&Info,&piProcInfo); n if(!bSuccess) n printf("创建进程失败!"); n return 1; n } n 案例名称:系统时间 n 程序名称:proj3_17.cpp n   n #include <windows.h> n #include <stdio.h> n main() n { n SYSTEMTIME sysTime; n GetLocalTime(&sysTime); n printf("%d年%d月%d日%d时%d分%d秒\n", n sysTime.wYear,sysTime.wMonth,sysTime.wDay,sysTime.wHour, n sysTime.wMinute,sysTime.wSecond); n return 1; n } n 案例名称:定时器编程 n 程序名称:proj3_18.cpp n   n #include <windows.h> n WNDCLASS wc; n HWND h_wnd; n MSG msg; n   n /* 消息处理函数wndProc的声明*/ n long WINAPI WindowProc(HWND,UINT,WPARAM,LPARAM); n   n /* winMain 函数的声明*/ n int PASCAL WinMain(HINSTANCE h_CurInstance, n HINSTANCE h_PrevInstance,LPSTR p_CmdLine,int m_Show) n { n /*初始化wndclass结构变量*/ n wc.lpfnWndProc =WindowProc; n wc.hInstance =h_CurInstance; n wc.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH); n wc.lpszClassName ="TheMainClass"; n n /* 注册WndClass结构变量*/ n RegisterClass(&wc); n n /* 创建窗口*/ n h_wnd=CreateWindow("TheMainClass","Our first Window", n WS_OVERLAPPEDWINDOW,0,0,400,500,0,0,h_CurInstance,0); n n /* 显示窗口*/ n ShowWindow(h_wnd,SW_SHOWMAXIMIZED); n n /*消息循环*/ n while(GetMessage(&msg,NULL,0,0)) n DispatchMessage(&msg); n return (msg.wParam ); n } n #define ID_TIMER 1 n   n /* 定义消息处理函数*/ n long WINAPI WindowProc(HWND h_wnd,UINT WinMsg, n WPARAM w_param,LPARAM l_param) n { n static BOOL fFlipFlop = FALSE ; n HBRUSH hBrush ; n HDC hdc ; n PAINTSTRUCT ps ; n RECT rc ; n n switch (WinMsg) n { n case WM_CREATE: n SetTimer (h_wnd, ID_TIMER, 1000, NULL) ; n return 0 ; n n case WM_TIMER : n MessageBeep (-1) ; n fFlipFlop = !fFlipFlop ; n InvalidateRect (h_wnd, NULL, FALSE) ; n return 0 ; n n case WM_PAINT : n hdc = BeginPaint (h_wnd, &ps) ; n GetClientRect (h_wnd, &rc) ; n hBrush = CreateSolidBrush (fFlipFlop ? RGB(255,0,0) : RGB(0,0,255)) ; n FillRect (hdc, &rc, hBrush) ; n n EndPaint (h_wnd, &ps) ; n DeleteObject (hBrush) ; n return 0 ; n n case WM_DESTROY : n KillTimer (h_wnd, ID_TIMER) ; n PostQuitMessage (0) ; n return 0 ; n } n return DefWindowProc(h_wnd,WinMsg,w_param,l_param); n } 案例名称:内存驻留程序的编写 n 程序名称:proj3_19.cpp n   n #include <windows.h> n WNDCLASS wc; n HWND h_wnd; n MSG msg; n   n /* 消息处理函数wndProc的声明*/ n long WINAPI WindowProc(HWND,UINT,WPARAM,LPARAM); n   n /* winMain 函数的声明*/ n int PASCAL WinMain(HINSTANCE h_CurInstance, n HINSTANCE h_PrevInstance,LPSTR p_CmdLine,int m_Show) n { n /*初始化wndclass结构变量*/ n wc.lpfnWndProc =WindowProc; n wc.hInstance =h_CurInstance; n wc.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH); n wc.lpszClassName ="TheMainClass"; n n /* 注册WndClass结构变量*/ n RegisterClass(&wc); n n /* 创建窗口*/ n h_wnd=CreateWindow("TheMainClass","Our first Window", n WS_OVERLAPPEDWINDOW,0,0,400,500,0,0,h_CurInstance,0); n n /* 显示窗口*/ n ShowWindow(h_wnd, SW_HIDE); n n /*消息循环*/ n while(GetMessage(&msg,NULL,0,0)) n DispatchMessage(&msg); n return (msg.wParam ); n } n #define ID_TIMER 1 n   n /* 定义消息处理函数*/ n long WINAPI WindowProc(HWND h_wnd,UINT WinMsg, n WPARAM w_param,LPARAM l_param) n { n static BOOL fFlipFlop = FALSE ; n HBRUSH hBrush ; n HDC hdc ; n PAINTSTRUCT ps ; n RECT rc ; n n switch (WinMsg) n { n case WM_CREATE: n SetTimer (h_wnd, ID_TIMER, 1000, NULL) ; n return 0 ; n n case WM_TIMER : n MessageBeep (-1) ; n fFlipFlop = !fFlipFlop ; n InvalidateRect (h_wnd, NULL, FALSE) ; n return 0 ; n n case WM_PAINT : n hdc = BeginPaint (h_wnd, &ps) ; n GetClientRect (h_wnd, &rc) ; n hBrush = CreateSolidBrush (fFlipFlop ? RGB(255,0,0) : RGB(0,0,255)) ; n FillRect (hdc, &rc, hBrush) ; n n EndPaint (h_wnd, &ps) ; n DeleteObject (hBrush) ; n return 0 ; n n case WM_DESTROY : n KillTimer (h_wnd, ID_TIMER) ; n PostQuitMessage (0) ; n return 0 ; n } n return DefWindowProc(h_wnd,WinMsg,w_param,l_param); n } n 案例3-7 “冰河”原型 n #include <windows.h> n WNDCLASS wc; n HWND h_wnd; n MSG msg; n n /* 消息处理函数wndProc的声明*/ n long WINAPI WindowProc(HWND,UINT,WPARAM,LPARAM); n n /* winMain 函数的声明*/ n int PASCAL WinMain(HINSTANCE h_CurInstance, n HINSTANCE h_PrevInstance,LPSTR p_CmdLine,int m_Show) n { n //MessageBox(NULL,p_CmdLine,"",MB_OK); n BOOL bSuccess; n PROCESS_INFORMATION piProcInfo; n STARTUPINFO Info; n Info.cb = sizeof(STARTUPINFO); n Info.lpReserved = NULL; n Info.lpDesktop = NULL; n Info.lpTitle = NULL; n Info.cbReserved2 = 0; n Info.lpReserved2 = NULL; n char lpAppName[100]; n strcpy(lpAppName, "notepad.exe "); n //MessageBox(NULL,lpAppName,"",MB_OK); n if(strcmp(p_CmdLine,"")!=0) n strcat(lpAppName, p_CmdLine); n //MessageBox(NULL,lpAppName,"",MB_OK); n bSuccess=CreateProcess(NULL,lpAppName,NULL,NULL,false,NULL,NULL,NULL,&Info,&piProcInfo); n n /*初始化wndclass结构变量*/ n wc.lpfnWndProc =WindowProc; n wc.hInstance =h_CurInstance; n wc.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH); n wc.lpszClassName ="TheMainClass"; n n /* 注册WndClass结构变量*/ n RegisterClass(&wc); n n /* 创建窗口*/ n h_wnd=CreateWindow("TheMainClass","Our first Window", n WS_OVERLAPPEDWINDOW,0,0,400,500,0,0,h_CurInstance,0); n n /* 显示窗口*/ n ShowWindow(h_wnd,SW_HIDE); n n /*消息循环*/ n while(GetMessage(&msg,NULL,0,0)) n DispatchMessage(&msg); n return (msg.wParam ); n } n n /* 定义消息处理函数*/ n long WINAPI WindowProc(HWND h_wnd,UINT WinMsg, n WPARAM w_param,LPARAM l_param) n { n n switch (WinMsg) n { n case WM_DESTROY : n PostQuitMessage (0) ; n return 0 ; n } n return DefWindowProc(h_wnd,WinMsg,w_param,l_param); n } n 案例名称:独立线程程序的编写 n 程序名称:proj3_21.cpp n   n #include <process.h> n #include <stdlib.h> n #include <stdio.h> n   n int addem(int); n int main(int argc, char *argv[]) n { n _beginthread((void (*)(void *))addem, 0, (void *)10); n _beginthread((void (*)(void *))addem, 0, (void *)11); n addem(12); n return 0; n } n   n int addem(int count) n { n int i; n long sum; n n sum = 0; n for (i=0; i<=count; ++i) { n printf("The value of %d is %d\n", count, i); n sum += i; n } n printf("The sum is %d\n", sum); n return 0; n } n 案例名称:多个线程共享参数 n 程序名称:proj3_22.cpp n   n #include <process.h> n #include <stdlib.h> n #include <stdio.h> n int addem(int); n int x; //全局变量 n   n int main(int argc, char *argv[]) n { n x=0; n _beginthread((void (*)(void *))addem, 0, (void *)1); n _beginthread((void (*)(void *))addem, 0, (void *)2); n addem(3); n return 0; n } n   n int addem(int index) n { n while (x <= 50){ n x = x+1; n printf("%d: %d\n", index, x); n } n return 0; n }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 管理财经 > 管理学资料

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服