ejes consulting

Techincal Consulting Design and Automation

Archive for the ‘Commentary’ Category

I call Phoney

leave a comment »

So today I was stumbling around on the internet, and found this kids site:

http://cyberfreax.in/2011/11/15/how-to-create-a-virus-2/

which features “how to create a virus”  Who could help themselves but read?

It turns out that this kid is completely full of it.  He tells you to copy this:

01100110011011110111001001101101011000010111010000
100000011000110011101001011100 0010000000101111010100010010111101011000

into a text file and rename it to something.exe and then run it.

Of course anyone with a bit of understanding on how the binary loader works would know that the loader wouldn’t recognize this as an executable program; ALL executable programs in windows start with either “MZ” or “PE”.  These are the “magic numbers” that tell the binary loader that these are, in fact, executable.

There is a lot going on behind the scenes here so let me explain WHY this won’t work.

Inside of a regular “exe” program is a structure to help the operating system determine how to load this program.  The structure looks like this (in C notation):

(info from: http://www.delorie.com/djgpp/doc/exe/)

struct EXE {
  unsigned short signature; /* == 0x5a4D */
  unsigned short bytes_in_last_block;
  unsigned short blocks_in_file;
  unsigned short num_relocs;
  unsigned short header_paragraphs;
  unsigned short min_extra_paragraphs;
  unsigned short max_extra_paragraphs;
  unsigned short ss;
  unsigned short sp;
  unsigned short checksum;
  unsigned short ip;
  unsigned short cs;
  unsigned short reloc_table_offset;
  unsigned short overlay_number;
};

The first short integer ‘signature’ is always 5a4d in MZ executables (by far less complex than PE executables) this is how the loader knows that this is a valid executable.

The first 16-bit integer is the number of bytes in the last block, unless it’s set to zero, which means the whole last block (152 bytes) is used.

The next 16-bit integer is total number of blocks in the executable file, and if the previous short integer is not zero, that number of the last block is used.

The next short is the number of relocation entries in the header, and the next is the number of “paragraphs” in the header.  Followed by the number of paragraphs of additional memory the program would need (that is, if there isn’t at least this many bytes free the loader will not try to load this program) most programmers know this as the BBS size. And finally, following that, is the maximum number of paragraphs of additional memory.

The next part is the relative value of the stack segment.  This value is added to the segment the program is loaded into, and used to initialize the SS (stack segment) register.

The next value is the initial value of the SP (stack pointer) register.  Then a word which is a checksum, which is usually not used.

The next is the initial value of the IP (instruction pointer) register, and then the CS (code segment) register (which is relative to the segment of the program loaded).  Then the offset of the first relocation item in the file, and finally ending with the overlay number.

If you examine the “binary” that Srivathsan provided, obviously none of this structure “fits.”

So what IS Srivathsan trying to pull?  Let’s take the binary, and bring it to a Binary-to-Ascii conversion site.  I used this one:

http://www.roubaixinteractive.com/PlayGround/Binary_Conversion/Binary_To_Text.asp

I pasted the “binary”, and pressed “To Text” and it comes back with:

format c:\ /Q/X

Oh!!  So he just encoded a “format” command and expected it to run.

This will NOT work.

So, what will work then?

There’s an older format, called “.COM” format that does still run in windows (XP tested).  A Com file (http://en.wikipedia.org/wiki/COM_file) is far less complex, it contains no header information, no relocation and no far jumps.

So it looks to me like you CAN use a .COM file in this way.  So now, to find some executable information you can place in this .com file.

To do this, I did a quick Google for “printable shellcode” and came back with a whole slew of stuff.  I chose this (i got it here(http://r00tsecurity.org/forums/topic/12019-16-bit-printable-shellcode-hello-world/):

X5))%@IP5YI5Y@5P!%PAP[55!5e 5O!54(P^)7CC)7SZBBXPSRABCABCABCABCABCABCABCABCABCZ[XH+H*hello world!$

As you might suspect from the final string, this is simply a “hello world” program; in printable ASCII!!

So, all you have to do is copy the above code, paste it into a text file, and rename the .txt extension to .com and ‘ta-da’ instant executable binary.

Nice try http://cyberfreax.in LOL

Written by ejes

November 17, 2011 at 1:30 pm

Simple Timesharing for ALL ANSI-C programs

leave a comment »

A client of mine asked that I write a simple co-operative timesharing engine to be used in an embedded project.  Timesharing is quite an easy multitasking system and is frequently used in the embedded space because each process must willingly give up cpu control.  This is good if you have a critical task that must not be interrupted before it completes.  Modern, more powerful cpus have the ability to turn off interrupts during execution (the instructions are sti and cli in the x86 world)  but not all processors support this.

Because I cannot be guaranteed that the microcontroller that i’m using has this, i opted to use a software interrupt that i call “swi”.  Realistically, you can turn this into a preemptive multitasking system by assigning the programmable interrupt to my “swi” function and have it execute at a pre-determined time.

anyway, i also wanted this to be somewhat compliant with normal POSIX programming, so I created a “fork” function.

It uses “setjmp” and “longjmp” to create save points in the “swi” and then call the next call on the process stack.  I was going to include a simple prioritizing system, but really it didn’t require it – i might still.

Anyway, the source is posted in my source code area. 

(terms of use) This software is given to you without warrantee and warning that it worked for me, doesn’t mean it’ll work for you.  Feel free to use and modify it, and send me patches, I will gladly post them and of course give you full credit, as I expect you’d give me credit as well.

Written by ejes

August 5, 2010 at 9:47 am

Posted in Commentary, Hacking

Amazing One Line Script

leave a comment »

I was stumbling around on the internet this morning and I found this awesome site… (http://www.centerkey.com/tree/)

This guy posted an amazing one line script that will graphically show your directory tree with a simple one line command:

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

and that’s all!!! It works great!

Written by ejes

March 17, 2010 at 11:42 am

Happy Holidays

leave a comment »

Happy Holidays :)

and have a great new year.

Written by ejes

December 29, 2009 at 4:11 pm

Posted in Commentary

Video Capture Card Driver Woes

leave a comment »

So lately I’ve been working on copying my old VHS movies to digital format so that my NAS can serve them up to my XBMC.

In my stumbles around the internet I found this really great project.

It seems to include EVERY older Video Capture Card for Windows drivers all into 1 beautiful fast and easy to install package.

Since I don’t use windows, I don’t really have much to do with it, but it’s good for those of you who do.

Fun

http://btwincap.sourceforge.net/

Take a look

Written by ejes

November 4, 2009 at 3:29 pm

Happy Thanksgiving

leave a comment »

Happy thanksgiving to my Canadian friends :)

Written by ejes

October 13, 2009 at 4:26 pm

Posted in Commentary

Tagged with

Back from the Dead – Fixing Drives in Linux

with 2 comments

So as you all know I lost my NAS due to some disk errors. 

Sadly, it was actually my flash adapter card (http://www.dealextreme.com/details.dx/sku.711) failed and this caused my FreeNAS to fail.

After much debugging – since this solid state drive seemed like a power supply failing: power turns off a couple seconds after being turned on, turning it on sometimes would do nothing until you unplugged the power supply then plug it back in.  (http://hubpages.com/hub/How-to-Tell-When-Computer-Power-Supply-Is-Failing)

Anyway, after figuring it out, I put in an old unlocked X Box hard disk (15 Gb) and that’s now my boot drive.  I used the newest version of FreeNAS which allows for a “full install” on a hard disk. (simply boot it up, and use the console menu to install)

Now that I’ve got my FreeNAS server up again, I still have a broken 500Gb drive to fix.

I took the 500Gb drive out and put it in my Ubuntu Linux lab server.  I usually use this machine for any experiments that I’m doing and for virtual machines.

Canada computers and a few others have some pretty good deals on 1Tb drives right now.   (I got mine for $90.00. http://www.canadacomputers.com/index.php?do=ShowProduct&cmd=pd&pid=024109&cid=HDD.443.877)  So this is a good time to upgrade my drive.

I put it into my lab server, and dd’ed the drive to make a complete copy onto my new 1Tb drive. 

Now I have a whole bitwise copy of my drive, now the fun part.

I don’t know UFS as well as I know FAT or EXT, so I was hoping to find a utility to help me with the restoration of this drive.

A quick google found me a utility called “testdisk”, (http://www.cgsecurity.org/wiki/TestDisk) and since I have a bitwise copy of my drive, I thought let’s give it a try.

Ran it,  it took literally 1 hour to analyze the drive.  It was so slow that I almost gave up.  However, beer and a night of Simpsons let me relax and let it do its work.

I wish I’d taken screen shots for you, but I was thrilled to find out that it actually worked. 

It recognized the UFS filesystem, GFI partition and all.  It rewrote the partition table, and dropped me to a command prompt.

I installed “ufsutils” with apt-get install, and ran fsck.ufs on it.  fsck did it usual “i found xxx fix?” and the drive was repaired.

I copied the data from the old 500Gb to the new 1Tb, and installed the new 1Tb drive into my FreeNAS server, added the drive, and ta-da it worked.

Back in business.

Now, the new version of FreeNAS has some neat new features that I discovered, the least of which is “/etc/rc.d/transmission blocklist-update” – which makes my old tutorial redundant, and I’ll write an update about that sometime soon :)

This week I’m going to reconfigure it – and I’ll probably write a little tutorial for you all who are interested.

In the meantime, I got my NAS back – and my movies.

Written by ejes

October 5, 2009 at 11:06 am

Alternative, Alternative Operating Systems

leave a comment »

I love operating systems, the heart of any good computer.  Because of my love for the “OS” I have become a sort of collector of Operating Systems.  My virtual machine “LAB” contains nearly one hundred different operating systems. 

Because of this interest I’m going to list a few of the less famous but still noteworthy ones here, sort of top 3 of the unknown OS market.

1. Haiku (http://www.haiku-os.org/)

  • I LOVED BeOS, I still do.  It had a very slick interface, beautiful to look at, and very multimedia friendly.  I heard rumors that this was going to be the next Mac OS (before X) but that it didn’t pan out.  Palm bought BeOS, and grounded the OS.  Hooray for open-source, where teams of guys like me (but not me) went out and decided to build a binary compatible version of BeOS.  That’s the origins of Haiku.

2. ReactOS (http://www.reactos.org/)

  • I hate Windows.  It was poorly designed from the beginning, because of its single user mentality it just hasn’t been able to catch up.  Maybe this will change in Windows 7 (though I doubt it).  Hooray for open-source, where teams of guys like me (but no, not me) went out and decided to build a FREE binary compatible version of Windows.  That’s te origins of ReactOS, which to me looks fairly useable, and actually quite close to Windows binary compatibility.

3. SkyOS (http://www.skyos.org/)

  • SkyOS is an attempt at building a FAST and stable OS from the ground up.  In Assembly.  Quite a project, and it’s quite beautiful.  It has a very quick kernel, and well optimized source.  The problem is that development is very slow, and updates are few and far between.  But quite a nice operating system to watch.

I have personally installed and run each of these with little to no problems on an older machine.  They’re quite nice projects, and (at least in my opinion) nearly user friendly enough for the common desktop market (especially in the cases of Haiku and ReactOS)

Written by ejes

September 15, 2009 at 2:37 pm

Restrict a 14 year old from the internet

leave a comment »

So I’ve taken a bit of time off – to spend with my son who came to stay with me from the far away place called Orillia. 

I’m quite liberal with our computing environment – so he gets his own computer and to be “self regulated” over the Internet.  He knows well enough that I have quite a complex network and know all the traffic that travels through our up link to the Internet.

Giving your 14 year old unrestricted internet access has it’s ups and downs.  One major down was that he managed to eat my entire Rogers High Speed Internet quota in a matter of 4 days.

That’s right 4 days.

So to limit him, I entered his MAC address in my deny list and he isn’t able to attach to the internet.  Easy right?  No.

I also have a Wii, which has an Internet connection, and frequently will download updates for itself.  My son also loves to play the Wii.

I don’t know exactly where he got the idea, but Suddenly I noticed that my Wii was unplugged, and instead the “Wii” was browsing the Internet, Gigabytes at a time on World of Warcraft, Runescape, uTorrent, and Youtube.   A browsing pattern I knew FAR too well.

He went into the Wii’s menu, looked up it’s MAC address, unplugged  the Wii, then changed his own MAC address to the Wii’s easily circumventing my restrictions.

Like father like son, I suppose.  Now I have to physically log into my OpenBSD server from wherever I am and forcibly unload it’s networking modules with a cron job to reload them when he would be allowed to regain access to the internet.

Written by ejes

August 18, 2009 at 1:49 pm

Posted in Commentary

Tagged with

FreeNAS + MediaWiki Match Made In Heaven

with 4 comments

I love my home network; it’s well designed and more importantly secure.

As part of a modern network, Network Attached Storage is a must.  Especially since I like to have all my information centrally accessable for my XBMC and my multitude of computers and remote access sites, not to mention a source repository for my projects and consulting.

I evaluated a whole lot of solutions for Network Attached Storage,  including out of the box NAS appliances and even building the functionality I needed with OpenBSD or Ubuntu Server.  Finally I was turned on to FreeNAS by a colligue.

FreeNAS, out of the box, came with all the functionality I needed.  Web server, Bitttorrent, CIFS stack and NFS.  As well as a bunch I don’t use (yet).

Configuration was a breeze, just boot from CD, and ta-da it worked beautifually.

I started doing a bit of development on the web-server portion of FreeNAS.  It runs a full blown lighthttp server, with a tiny SQLite backend.  This means that MediaWiki can actually work on this tiny embedded platform.

How?  Simple.

In FreeNAS enable the web server, create a directory to serve from and put the latest version of MediaWiki there, configure it up, including a sqlite database (that I put in a non-browseable place for security purposes) and what do you know… home private wiki.

I’m going to start working on scripts and extensions so that my home media wiki will give information on my house, and media contained therein.

If there is enough interest, I’ll post a tutorial for setting up FreeNAS, and the MediaWiki.

Written by ejes

June 23, 2009 at 8:41 am

Posted in Commentary

Follow

Get every new post delivered to your Inbox.