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.

C:\Documents <strong>and</strong> Settings\Barrie\My ...-aes\simpletcpserver-aes\Program.cs<br />

using System;<br />

using System.Collections;<br />

using System.Net;<br />

using System.Net.Sockets;<br />

using System.Text;<br />

using System.IO;<br />

using System.Security.Cryptography;<br />

using System.Xml;<br />

1<br />

public class SimpleTcpSrvr<br />

{<br />

public static void Main()<br />

{<br />

int recv;<br />

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

IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 13000);<br />

Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,<br />

ProtocolType.Tcp);<br />

newsock.Bind(ipep);<br />

newsock.Listen(10);<br />

Console.WriteLine("Waiting for a client...");<br />

Socket client = newsock.Accept();<br />

IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint;<br />

Console.WriteLine("Connected with {0} at port {1}", clientep.Address, clientep.<br />

Port);<br />

string welcome = "You are connected to <strong>the</strong> server.";<br />

data = Encoding.ASCII.GetBytes(welcome);<br />

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

//Generate r<strong>and</strong>om keys<br />

Console.Write("Generating new key pairs... ");<br />

int dwKeySize = 1024;<br />

RSACryptoServiceProvider RSAProvider = new RSACryptoServiceProvider(dwKeySize);<br />

string publicAndPrivateKeys = RSAProvider.ToXmlString(true);<br />

string justPublicKey = RSAProvider.ToXmlString(false);<br />

Console.WriteLine("Done!");<br />

Console.Write("Sending public key to client... ");<br />

data = Encoding.ASCII.GetBytes(justPublicKey);<br />

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

Console.WriteLine("Done!");<br />

// Receive Encrypted Shared Key from Client<br />

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

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

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

// Decrypt With Private Key<br />

RSAProvider.FromXmlString(publicAndPrivateKeys);<br />

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

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

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

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

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

{<br />

byte[] encryptedBytes = Convert.FromBase64String(encryptedKey.Substring<br />

(base64BlockSize * i, base64BlockSize));<br />

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

}<br />

string decryptedKey = Encoding.UTF32.GetString(arrayList.ToArray(Type.GetType(<br />

"System.Byte")) as byte[]);<br />

// Assign values from XML string<br />

XmlDocument doc = new XmlDocument();<br />

doc.LoadXml(@decryptedKey);<br />

XmlNode element = doc.SelectSingleNode("/AES/passPhrase");<br />

string passPhrase = element.InnerText;<br />

element = doc.SelectSingleNode("/AES/saltValue");<br />

string saltValue = element.InnerText;<br />

element = doc.SelectSingleNode("/AES/hashAlgorithm");<br />

string hashAlgorithm = element.InnerText;

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

Saved successfully!

Ooh no, something went wrong!