25.12.2014 Views

Analysis and Evaluation of the Windows Event Log - Bill Buchanan

Analysis and Evaluation of the Windows Event Log - Bill Buchanan

Analysis and Evaluation of the Windows Event Log - Bill Buchanan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Barrie Codona, BSc (Hons) Network Computing, 2007<br />

5.3.3 Receiving Message<br />

The data archiving system will continue to listen <strong>and</strong> accept messages (see Figure 28)<br />

that have been received from <strong>the</strong> client until <strong>the</strong> client disconnects. All <strong>the</strong> messages<br />

that are received are passed through to <strong>the</strong> decrypt class, where <strong>the</strong> data archiving<br />

systems private key is applied to <strong>the</strong> cipher text <strong>and</strong> thus decrypting it back to plain<br />

text.<br />

while (true)<br />

{<br />

// Specify <strong>the</strong> size <strong>of</strong> <strong>the</strong> packet.<br />

data = new byte[10240];<br />

// Accept <strong>the</strong> packet from <strong>the</strong> Client.<br />

recv = client.Receive(data);<br />

// If <strong>the</strong> Client disconnects <strong>the</strong>n exit.<br />

if (recv == 0)<br />

break;<br />

}<br />

// Send <strong>the</strong> packet back to <strong>the</strong> Client.<br />

client.Send(data, recv, SocketFlags.None);<br />

Figure 28: Receiving a Message<br />

5.3.4 Decrypting Message<br />

Figure 29 shows <strong>the</strong> code that is used to decrypt <strong>the</strong> received message; <strong>the</strong> code for it<br />

is from a program by Ma<strong>the</strong>w Schlabaugh on <strong>the</strong> codeproject.com which can be found<br />

at (http://www.codeproject.com/KB/security/RSACryptoPad.aspx).<br />

// Convert <strong>the</strong> encrypted message back into a string<br />

string encryptedMessage = Encoding.ASCII.GetString(data, 0, recv);<br />

// Use <strong>the</strong> private key to decrypt <strong>the</strong> message<br />

RSAProvider.FromXmlString(publicAndPrivateKeys);<br />

int base64BlockSize = ((dwKeySize / 8) % 3 != 0) (((dwKeySize / 8)<br />

/ 3) * 4) + 4 : ((dwKeySize / 8) / 3) * 4;<br />

// Break <strong>the</strong> message apart into blocks.<br />

int iterations = encryptedMessage.Length / base64BlockSize;<br />

ArrayList arrayList = new ArrayList();<br />

for (int i = 0; i < iterations ; i++)<br />

{<br />

byte[] encryptedBytes =<br />

Convert.FromBase64String(encryptedMessage.Substring(base64BlockSize *<br />

i, base64BlockSize));<br />

arrayList.AddRange(RSAProvider.Decrypt(encryptedBytes, true));<br />

}<br />

// Convert <strong>the</strong> decrypted message to a string.<br />

string decryptedMessage =<br />

Encoding.UTF32.GetString(arrayList.ToArray(Type.GetType("System.Byte"<br />

)) as byte[]);<br />

decryptedMessage = "" + DateTime.Now + "" +<br />

decryptedMessage;<br />

Figure 29: Decrypting a message<br />

46

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!