BleepingComputer.com: C# script im trying to decypher

Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

C# script im trying to decypher atleast i think its c#

#1 User is offline   mckooter 

  • Forum Regular
  • PipPipPip
  • Find Topics
  • Group: Members
  • Posts: 211
  • Joined: 29-May 08
  • Gender:Male
  • Location:Maine

Posted 24 September 2009 - 02:13 PM

im trying to examine the data from a script that i believe is written in C#, i need to find out exactly how its communicating with the server and am going to try to replicate it in php, i have what i thought worked, but the server wont send back any data to me.. can anyone look at this and tell me if its doing what i think:

I believe this is taking the hex data thats listed as inputtobesent and sending it to the server via udp and waiting for a response, but when i send the same data in php the server wont respond..

thanks to anyone who might be able to help

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.IO;

namespace FLPing
{
	/// 
	/// Summary description for Class1.
	/// 
	class Class1
	{
		/// 
		/// The main entry point for the application.
		/// 
		[STAThread]
		static void Main(string[] args)
		{
			IPHostEntry lipa;
			if(args.Length < 3)
			{
				Console.WriteLine("Freelancer Server Ping Utility (version 1.0)\n");
				Console.WriteLine("flping	[WEB OUTPUT]");
				return;
			}
			try
			{
				Convert.ToInt32(args[1]);
			}
			catch
			{
				Console.WriteLine("Invalid PORT parameter - must be numeric and less than 65530.");
				return;
			}

			try
			{
				Convert.ToInt32(args[2]);
			}
			catch
			{
				Console.WriteLine("Invalid TIMEOUT parameter - must be a valid integer value.");
				return;
			}
			try
			{
				lipa = Dns.Resolve(args[0]);
			}
			catch
			{
				Console.WriteLine("Could not resolve server name/contact IP.");
				return;
			}
			IPEndPoint lep = new IPEndPoint(lipa.AddressList[0], Convert.ToInt32(args[1]));

			Socket s = new Socket(lep.Address.AddressFamily,
				SocketType.Dgram,
				ProtocolType.Udp);
 
			byte[] inputToBeSent = new byte[21];

			// Create the "special" packet that will return the correct data
			inputToBeSent[0] = 0x00;
			inputToBeSent[1] = 0x02;
			inputToBeSent[2] = 0xF1;
			inputToBeSent[3] = 0x26;
			inputToBeSent[4] = 0x01;
			inputToBeSent[5] = 0x26;
			inputToBeSent[6] = 0xF0;
			inputToBeSent[7] = 0x90;
			inputToBeSent[8] = 0xA6;
			inputToBeSent[9] = 0xF0;
			inputToBeSent[10] = 0x26;
			inputToBeSent[11] = 0x57;
			inputToBeSent[12] = 0x4E;
			inputToBeSent[13] = 0xAC;
			inputToBeSent[14] = 0xA0;
			inputToBeSent[15] = 0xEC;
			inputToBeSent[16] = 0xF8;
			inputToBeSent[17] = 0x68;
			inputToBeSent[18] = 0xE4;
			inputToBeSent[19] = 0x8D;
			inputToBeSent[20] = 0x21;

			try
			{
				DateTime dtStart = DateTime.Now;

				// Sends datagram to the IpEndPoint specified. This call blocks. 
				s.SendTo(inputToBeSent, 0, inputToBeSent.Length, SocketFlags.None, lep);

				// Creates an IpEndPoint to capture the identity of the sending host.
				IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
				EndPoint tempRemoteEP = (EndPoint)sender;

				// Creates a byte buffer to receive the message.
				int iAvailable  = s.Available;
				int iSecCount = 0;

				while(iAvailable < 1 && iSecCount < Convert.ToInt32(args[2]))
				{
					Thread.Sleep(100);
					iAvailable  = s.Available;
					iSecCount++;
					//Console.Write(".");
				}

				byte[] buffer = new byte[iAvailable];

				if(iAvailable > 2)
				{
					DateTime dtEnd = DateTime.Now;

				// Receives datagram from a remote host.  This call blocks.
				s.ReceiveFrom(buffer, 0, iAvailable, SocketFlags.None, ref tempRemoteEP);


					int START  = 92;
					int END = 0;
					int iServerNameLength = Convert.ToInt32(buffer[4]) - START;
					END = iServerNameLength + START + 2;
					
					//TODO: Catch error here - if data is received, but this value does not exist
					byte[] bServerName = new byte[iServerNameLength];
					int j=0;
					for(int i=START;i 0)
						{
							bServerName[j] = buffer[i];
							j++;
						}

					}
					if(args.Length == 3)
					{
						Console.WriteLine("\nTime: " + DateTime.Now);
						Console.WriteLine("Server IP: " + args[0].ToString());
						Console.WriteLine("Server Port: " + args[1].ToString());
						Console.WriteLine("Server Name: " + Encoding.ASCII.GetString(bServerName));

						int iUserCount = Convert.ToInt32(buffer[24])-1;
						int iMaxCount = Convert.ToInt32(buffer[20])-1;
						Console.WriteLine("Players: " + iUserCount.ToString() + "\\" + iMaxCount.ToString()); //.ToString());
						TimeSpan dtDiff = dtEnd - dtStart;
						Console.WriteLine("Response Time: " + dtDiff.Milliseconds);
					}
					else
					{
						int iUserCount = Convert.ToInt32(buffer[24])-1;
						int iMaxCount = Convert.ToInt32(buffer[20])-1;
						TimeSpan dtDiff = dtEnd - dtStart;

						StringBuilder sbWeb = new StringBuilder();
						sbWeb.Append("" + DateTime.Now + "");
						sbWeb.Append("" + Encoding.ASCII.GetString(bServerName) + "");
						sbWeb.Append("" + args[0].ToString() + "");
						sbWeb.Append("" + args[1].ToString() + "");
						sbWeb.Append("" + iUserCount.ToString() + "\\" + iMaxCount.ToString() + "");
						sbWeb.Append("" + dtDiff.Milliseconds + "");
						Console.WriteLine(sbWeb);
					}
				}
				else
				{
					if(args.Length == 3)
						Console.WriteLine("\nCould not find server/port or no data received from the server.");
					else
						Console.WriteLine("" + DateTime.Now + "---" + args[0].ToString() + "" + args[1].ToString() + "------");
				}

			}
			catch(Exception e)
			{
				Console.WriteLine("Could not communicate with server.  Check options and try again.");
				//Console.WriteLine(@"(www.flserver.com)");
				//Console.WriteLine("Exception : " + e.ToString());
				//Console.WriteLine("Stack Trace: " + e.StackTrace);
			}

		}
	}
}



sorry for the long post, i wanted to make sure i have it all in there
You can just call me Chris

Pandy said:

I found out I was Marilyn Monroe in a previous life

#2 User is online   Billy O'Neal 

  • Bleepin Engineer
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,085
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

Posted 24 September 2009 - 02:32 PM

Hello, McKooter :flowers:

You are correct in diagnosing this as C# code. This is the important bit I believe:

Socket s = new Socket(lep.Address.AddressFamily,
SocketType.Dgram,
ProtocolType.Udp);

Open a new UDP socket to the specified host.

I'm not sure PHP allows you to open a UDP socket :thumbsup:

Billy3

#3 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,814
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 24 September 2009 - 11:03 PM

PHP can open sockets using socket_create() function for TCP, UDP or ICMP. http://in.php.net/socket_create

The above code in C# is written to PING a server. The PHP code would be much simpler but for writing a PHP Ping function you need to know the basics of how Ping works in real. What kind of data is to be sent and what to be expected in return.

On the link given for socket_create() above, you would find a PING function written in PHP :thumbsup: But it can be written more compactly if you try.
[url="http://www.avast.com/"]avast! free antivirus[/url]

#4 User is offline   mckooter 

  • Forum Regular
  • PipPipPip
  • Find Topics
  • Group: Members
  • Posts: 211
  • Joined: 29-May 08
  • Gender:Male
  • Location:Maine

Posted 25 September 2009 - 03:41 PM

i have to send that hex data and read the response, and i have tried with socket_create() but am failing on exactly how to send that data specifically and then have a response, also socket_create needs root access from what i understand, so am i correct in thinking this would not be possible for me to code as its a shared hosting and i dont really have that kind of access..

thanks
You can just call me Chris

Pandy said:

I found out I was Marilyn Monroe in a previous life

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users