C # access the socket via HTTP proxy to get mail
Code for critical penetration agent (get tcpclent via HTTP proxy)
public class Clienthelper {public static TcpClient Connectviahttpproxy (String targethost, int Targetport, string httpproxyhost, int httpproxyport, String proxyusername, String Proxypassword) {var uribuilder = new UriBuilder {Scheme = Uri.uris Chemehttp, Host = httpproxyhost, Port = Httpproxyport}; var Proxyuri = Uribuilder.uri; var request = WebRequest.Create ("/http" + Targethost + ":" + targetport); var webProxy = new WebProxy (Proxyuri); Request. Proxy = WebProxy; Request. Method = "CONNECT"; var credentials = new NetworkCredential (Proxyusername, Proxypassword); Webproxy.credentials = Credentials; var response = Request. GetResponse (); var responsestream = response. GetResponseStream (); Debug.Assert (Responsestream! = null); Const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance; var rstype = Responsestream.gettype (); var connectionproperty = Rstype.getproperty ("Connection", Flags); var connection = Connectionproperty.getvalue (responsestream, NULL); var connectiontype = connection. GetType (); var networkstreamproperty = Connectiontype.getproperty ("NetworkStream", Flags); var NetworkStream = Networkstreamproperty.getvalue (connection, NULL); var nstype = Networkstream.gettype (); var socketproperty = Nstype.getproperty ("Socket", Flags); var socket = (socket) socketproperty.getvalue (networkstream, NULL); return new TcpClient {Client = socket}; } }
Original address: Http://www.replicator.org/journal/201011170043-net-connecting-a-tcpclient-through-an-http-proxy-with-authentication
C # access the socket via HTTP proxy to get mail