public override bool Run() { // Read the list and check if exists the subdomain. Parallel.ForEach(FileHelper.ReadWordFile(WordList.FullName), subdomain => { string url = subdomain + "." + Domain; try { IPHostEntry hostInfo = Dns.GetHostEntry(url); if (hostInfo.ToString() != "") { string ip = hostInfo.AddressList == null || hostInfo.AddressList.Length == 0 ? "FOUND" : string.Join(",", hostInfo.AddressList.Select(u => u.ToString()).ToArray()); WriteInfo("Subdomain found: " + subdomain.ToString() + "." + Domain.ToString(), ip, ConsoleColor.Green); } } catch { } }); return(true); }
/// <summary> /// Initializes a new instance of the <see cref="T:SIPLib.SIP.SDPOriginator" /> class. /// </summary> /// <param name="value">The input string representing an o line in the SDP.</param> public SDPOriginator(string value = null) { if (value != null) { string[] values = value.Split(' '); Username = values[0]; Sessionid = values[1]; Version = values[2]; Nettype = values[3]; Addrtype = values[4]; Address = values[5]; } else { string hostname = Dns.GetHostName(); IPHostEntry ip = Dns.GetHostEntry(hostname); string ipAddress = ip.ToString(); Username = "******"; Sessionid = Helpers.ToUnixTime(DateTime.Now).ToString(); Version = Helpers.ToUnixTime(DateTime.Now).ToString(); Nettype = "IN"; Addrtype = "IP4"; Address = ipAddress; } }
/* Good2() reverses the bodies in the if statement */ private void Good2() { if (PRIVATE_CONST_FIVE == 5) { TcpListener listener = null; TcpClient tcpConn = null; Stream streamOutput = null; int port = 20000; try { listener = new TcpListener(IPAddress.Parse("10.10.1.10"), port); listener.Start(); tcpConn = listener.AcceptTcpClient(); streamOutput = tcpConn.GetStream(); IPEndPoint endPoint = (IPEndPoint)tcpConn.Client.RemoteEndPoint; IPAddress ipAddress = endPoint.Address; IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); /* FIX: No host-based Logic */ streamOutput.Write(Encoding.UTF8.GetBytes(("Welcome, " + hostEntry.ToString())), 0, ("Welcome, " + hostEntry.ToString()).Length); } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Could not connect to port " + port.ToString()); } finally { try { if (streamOutput != null) { streamOutput.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (tcpConn != null) { tcpConn.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (listener != null) { listener.Stop(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } } } }
/* Good1() changes true to false */ private void Good1() { if (false) { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ IO.WriteLine("Benign, fixed string"); } else { TcpListener listener = null; TcpClient tcpConn = null; Stream streamOutput = null; int port = 20000; try { listener = new TcpListener(IPAddress.Parse("10.10.1.10"), port); listener.Start(); tcpConn = listener.AcceptTcpClient(); streamOutput = tcpConn.GetStream(); IPEndPoint endPoint = (IPEndPoint)tcpConn.Client.RemoteEndPoint; IPAddress ipAddress = endPoint.Address; IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); /* FIX: No host-based Logic */ streamOutput.Write(Encoding.UTF8.GetBytes(("Welcome, " + hostEntry.ToString())), 0, ("Welcome, " + hostEntry.ToString()).Length); } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Could not connect to port " + port.ToString()); } finally { try { if (streamOutput != null) { streamOutput.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (tcpConn != null) { tcpConn.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (listener != null) { listener.Stop(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } } } }
public static void StartListening() { // Data buffer for incoming data. byte[] bytes = new Byte[1024]; // Establish the local endpoint for the socket. // Dns.GetHostName returns the name of the // host running the application. IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); IPAddress ipAddress = null; IPEndPoint localEndPoint = null; for (int i = 0; i < ipHostInfo.AddressList.Length; i++) { Console.WriteLine(i); ipAddress = ipHostInfo.AddressList[i]; localEndPoint = new IPEndPoint(ipAddress, 9001); Console.WriteLine("IPHostEntry:" + ipHostInfo.ToString()); Console.WriteLine("IPAddress:" + ipAddress.ToString()); Console.WriteLine("AddressFamily:" + ipAddress.AddressFamily); Console.WriteLine("IsLoopback:" + IPAddress.IsLoopback(ipAddress)); Console.WriteLine("IPEndPoint:" + localEndPoint.ToString()); if (ipAddress.AddressFamily == AddressFamily.InterNetwork) { break; } } // Create a TCP/IP socket. Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); // Bind the socket to the local endpoint and // listen for incoming connections. try { listener.Bind(localEndPoint); listener.Listen(10); // Start listening for connections. while (true) { Console.WriteLine("Waiting for a connection..."); // Program is suspended while waiting for an incoming connection. Socket handler = listener.Accept(); Console.WriteLine("Accepted"); data = null; // An incoming connection needs to be processed. while (true) { bytes = new byte[1024]; int bytesRec = handler.Receive(bytes); data += Encoding.ASCII.GetString(bytes, 0, bytesRec); Console.WriteLine(data); if (data.IndexOf("<EOF>") > -1) { break; } } // Show the data on the console. Console.WriteLine("Text received : {0}", data); // Echo the data back to the client. byte[] msg = Encoding.ASCII.GetBytes(data); handler.Send(msg); handler.Shutdown(SocketShutdown.Both); handler.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.WriteLine("\nPress ENTER to continue..."); Console.Read(); }
public void connect() { // Data buffer for incoming data. //byte[] bytes = new byte[1024]; if (path == null) { path = inputIP.text; } // Connect to a remote device. try { // Establish the remote endpoint for the socket. // The example uses port 11000 on the local computer. //! Obsolete: IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); Debug.LogFormat("Connecting from {0}", ipHostInfo.ToString()); //IPAddress ipAddressLocal = ipHostInfo.AddressList[0]; // Manually set IP -- fix this?? // byte[] ipBytes = { 169, 254, 152, 40 }; //Ethernet - as of 10/16 //byte[] ipBytes = { 169, 254, 152, 52 }; //Wifi // Grab IP from input (ideally sent from text field) byte[] ipBytes = Array.ConvertAll(path.Split('.'), byte.Parse); IPAddress ipAddressRemote = new IPAddress(ipBytes); //path = ipAddressRemote; //port = 20602; Debug.LogFormat("Connecting to {0}", path.ToString()); IPEndPoint remoteEP = new IPEndPoint(ipAddressRemote, port); // Create a TCP/IP socket. sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect the socket to the remote endpoint. Catch any errors. try { if (isConnected == false) { sender.Connect(remoteEP); Debug.LogFormat("Socket connected to {0}", sender.RemoteEndPoint.ToString()); if (sender.Connected) { isConnected = true; } else { Debug.LogFormat("Could not connect, retry..."); } } // Encode the data string into a byte array. byte[] msg = Encoding.ASCII.GetBytes("Connected from Unity Server."); sendMsg(msg); // ---Where to do this??--- // Release the socket. //sender.Shutdown(SocketShutdown.Both); //sender.Close(); } catch (ArgumentNullException ane) { Debug.LogFormat("ArgumentNullException : {0}", ane.ToString()); } catch (SocketException se) { Debug.LogFormat("SocketException : {0}", se.ToString()); } catch (Exception e) { Debug.LogFormat("Unexpected exception : {0}", e.ToString()); } } catch (Exception e) { Debug.LogFormat(e.ToString()); } }
public override void Bad() { if (IO.StaticReturnsTrueOrFalse()) { TcpListener listener = null; TcpClient tcpConn = null; Stream streamOutput = null; int port = 20000; try { listener = new TcpListener(IPAddress.Parse("10.10.1.10"), port); listener.Start(); tcpConn = listener.AcceptTcpClient(); /* INCIDENTAL: Use of Socket */ /* FLAW: hostname-based Logic */ IPEndPoint endPoint = (IPEndPoint)tcpConn.Client.RemoteEndPoint; IPAddress ipAddress = endPoint.Address; IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); if (hostEntry.HostName.Equals("admin.google.com")) { streamOutput = tcpConn.GetStream(); streamOutput.Write(Encoding.UTF8.GetBytes("Welcome, admin!"), 0, "Welcome, admin!".Length); } else { streamOutput = tcpConn.GetStream(); streamOutput.Write(Encoding.UTF8.GetBytes("Welcome, user."), 0, "Welcome, user.".Length); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Could not connect to port " + port.ToString()); } finally { try { if (streamOutput != null) { streamOutput.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (tcpConn != null) { tcpConn.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (listener != null) { listener.Stop(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } } } else { TcpListener listener = null; TcpClient tcpConn = null; Stream streamOutput = null; int port = 20000; try { listener = new TcpListener(IPAddress.Parse("10.10.1.10"), port); listener.Start(); tcpConn = listener.AcceptTcpClient(); streamOutput = tcpConn.GetStream(); IPEndPoint endPoint = (IPEndPoint)tcpConn.Client.RemoteEndPoint; IPAddress ipAddress = endPoint.Address; IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); /* FIX: No host-based Logic */ streamOutput.Write(Encoding.UTF8.GetBytes(("Welcome, " + hostEntry.ToString())), 0, ("Welcome, " + hostEntry.ToString()).Length); } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Could not connect to port " + port.ToString()); } finally { try { if (streamOutput != null) { streamOutput.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (tcpConn != null) { tcpConn.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (listener != null) { listener.Stop(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } } } }
public void connect() { // Data buffer for incoming data. //byte[] bytes = new byte[1024]; // Connect to a remote device. try { // Establish the remote endpoint for the socket. // The example uses port 11000 on the local computer. //! Obsolete: IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); Debug.Log(String.Format("Connecting from {0}", ipHostInfo.ToString())); IPAddress ipAddress = ipHostInfo.AddressList[0]; byte[] ipBytes = { 169, 254, 152, 39 }; IPAddress ipAddressRemote = new IPAddress(ipBytes); path = ipAddressRemote; port = 20602; Debug.Log(String.Format("Connecting to {0}", path.ToString())); IPEndPoint remoteEP = new IPEndPoint(path, port); // Create a TCP/IP socket. sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect the socket to the remote endpoint. Catch any errors. try { if (isConnected == false) { sender.Connect(remoteEP); Debug.Log(String.Format("Socket connected to {0}", sender.RemoteEndPoint.ToString())); isConnected = true; } // Encode the data string into a byte array. byte[] msg = Encoding.ASCII.GetBytes("Connected from Unity Server."); sendMsg(msg); // ---Where to do this??--- // Release the socket. //sender.Shutdown(SocketShutdown.Both); //sender.Close(); } catch (ArgumentNullException ane) { Debug.Log(String.Format("ArgumentNullException : {0}", ane.ToString())); } catch (SocketException se) { Debug.Log(String.Format("SocketException : {0}", se.ToString())); } catch (Exception e) { Debug.Log(String.Format("Unexpected exception : {0}", e.ToString())); } } catch (Exception e) { Debug.Log(String.Format(e.ToString())); } }