190 likes | 371 Views
Computer Security Project Key Logger. 2012/03/15. Project 1 : Windows Socket Programming Project 2 : Key Logger Project 3 : Key Logger and encrypted communication. Computer security. Project 1 : Windows Socket Programming. Requirement. You need to write a client side code
E N D
Computer Security Project Key Logger 2012/03/15
Project 1 : Windows Socket Programming • Project 2 : Key Logger • Project 3 : Key Logger and encrypted communication
Computer security Project 1 : Windows Socket Programming
Requirement • You need to write a client side code • Your program must • Create two threads , one for read and one for write • Send your student ID to server(string format) • Receive response from server • Server ip: 140.113.216.151 port: 2000 • Check webpage to find your ID • Webpage will list all student IDs that already complete • http://bletchley.twbbs.org.tw/comsec/index.html
Environment • OS: windows XP (Recommend) /Windows 7 • Language : C/C++ • IDE • Code Block (Recommend) • VS • Dev C++ • This project may modify OS , it’s recommend to write project in VM environment
Work Flow Client creates a socket and connects to server Server accepts client connection Create two threads Write thread sends student ID Server receives student ID “9717001” Read thread receives and prints msg “congratulation!!” Server responses a msg to client
Socketin Unix-like OS Server Client socket() socket() bind() listen() accept() connect() write() read() read() write() close() close()
WinSock Server Client WSAStarup() WSAStarup() socket() socket() bind() listen() accept() connect() send() recv() recv() send() shutdown() shutdown() closesocket() closesocket() WSACleanup() WSACleanup()
Initial winsock(1/2) • Links to the Winsock Library file Ws2_32.lib • Setting is different between each IDE • Code Block setting • http://bletchley.twbbs.org/wiki/index.php/CodeBlock_libws2_32_dll_link_config • The #pragma comment indicates to the linker that the Ws2_32.lib file is needed • #pragma comment(lib, "Ws2_32.lib") • Include • include <winsock2.h> • include <ws2tcpip.h>
Initial winsock(2/2) • WSDATA • Information about the Windows Sockets implementation • WSAStartup() • Set version of winsock • Initiate the use of WS2_32.dll WSADATA wsaData; Result = WSAStartup(MAKEWORD(2,2), &wsaData);
Create socket • getaddrinfo() • addrinfo is used to hold host address information • getaddrinfo() fill content of addrinfo • Use ip_address for client and null for server • socket() • Create socket for server/client structaddrinfo *result = NULL, *ptr = NULL, hints; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; getaddrinfo(ip_address, port, &hints, &result); ConnectSocket = socket(result->ai_family, result ->ai_socktype, result ->ai_protocol);
Server Site • bind() • Associates a local address with a socket • listen() • Let server socket listens for any incoming connections • accept() • Start user connection bind( ListenSocket, result->ai_addr, (int)result->ai_addrlen); listen( ListenSocket, SOMAXCONN ); ClientSocket = accept(ListenSocket, NULL, NULL);
Client Site • connect() • Establishes a connection to server ConnectSocket = socket(result->ai_family, result ->ai_socktype, result ->ai_protocol); connect( ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
Send/Receive Data • send() • sends data on a connected socket • recv() • receives data from a connected socket send(CliSock,smsg,(int)strlen(smsg),0); recv(CliSock,rebuf,reclen,0);
Clean Up Socket • shutdown() • Disables sends or receives on a socket • closesocket() • Closes an existing socket • WSACleanup() • Terminates the use of the Winsock 2 DLL (Ws2_32.dll) shutdown(ConnectSocket, SD_SEND); shutdown(ConnectSocket, SD_RECEIVE); closesocket(ConnectSocket); WSACleanup();
Thread • CreateThread() • Creates a thread to execute within the virtual address space of the calling process CreateThread( NULL, // default security attributes 0, // use default stack size MyThreadFunction, // thread function name NULL,// argument to thread function 0, // use default creation flags NULL); // returns the thread identifier
You need to… • Log in our server • Upload your work to e3 • Source code • Report • Explain source code • Introduction winsock • Introduction thread • Upload format: <Strudent ID>.zip • Ex: 9617000.zip
Resource • TA provide server source code • http://bletchley.twbbs.org.tw/comsec/winsock.7z • MSDN winsock document • http://msdn.microsoft.com/en-us/library/windows/desktop/ms738545(v=vs.85).aspx • MSDNThread document • http://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx