1、计算机网络安全技术 实验
n 案例名称:操作注册表
n 程序名称:#include
2、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,
3、 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 s
4、etting Section1 value\n");
n return (0) ;
n }
n printf("注册表编写成功!\n");
n return(0);
n }
n 案例名称:判断是否中了“冰河”
n 程序名称:proj3_13.cpp
n
n #include
5、 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=RegQueryValue
6、Ex(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("\
7、n");
n }
编译运行会有下面结果
然后在注册表中HKEY_CLASSES_ROOT主键下的“txtfile\shell\open\command”
将值改为其他的,然后再运行。会有下面结果。
n 案例名称:更改系统登录用户
n 程序名称:proj3_14.cpp
n
n #include
8、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 "Defau
9、ltUserName", 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命令行下执行的
10、操作都可以使用程序实现。
n 在DOS命令行下使用命令“net user Hacker /add”添加一个用户,同样可以在程序中实现,如程序proj3_15.cpp所示。
n
n 案例名称:添加系统用户
n 程序名称:proj3_15.cpp
n
n #include
11、PINFO 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("创建进程失败!");
12、
n return 1;
n }
n 案例名称:系统时间
n 程序名称:proj3_17.cpp
n
n #include
13、wSecond);
n return 1;
n }
n 案例名称:定时器编程
n 程序名称:proj3_18.cpp
n
n #include
14、 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);
15、 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.wPara
16、m ); 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 (WinM
17、sg) 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
18、) ; 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 Post
19、QuitMessage (0) ;
n return 0 ;
n }
n return DefWindowProc(h_wnd,WinMsg,w_param,l_param);
n }
案例名称:内存驻留程序的编写
n 程序名称:proj3_19.cpp
n
n #include
20、 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.lpszCla
21、ssName ="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(GetMessa
22、ge(&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 h
23、dc ; 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 re
24、turn 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
25、
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
26、ndowProc(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 I
27、nfo.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,"")!
28、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)G
29、etStockObject(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_HI
30、DE); 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 PostQu
31、itMessage (0) ;
n return 0 ;
n }
n return DefWindowProc(h_wnd,WinMsg,w_param,l_param);
n }
n 案例名称:独立线程程序的编写
n 程序名称:proj3_21.cpp
n
n #include
32、)(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 +=
33、i;
n }
n printf("The sum is %d\n", sum);
n return 0;
n }
n 案例名称:多个线程共享参数
n 程序名称:proj3_22.cpp
n
n #include






