Blue Screen with STOP 0x0000007F: What does it mean?

I recently got a blue screen on a Windows XP machine with the following error code:

STOP 0x0000007F (0x0000000D 0x00000000 0x00000000 0x00000000)

If you’re like me, you want to know what went wrong. This is what Microsoft has to say on the issue:

This error message can occur if either of the following conditions exists:
* Your computer has hardware or software problems (hardware failure is the most common cause).
* You try to over clock the speed of your computer’s processor (for example, you set a 150 MhZ processor to run at 187 MhZ).

[...]

The most important parameter is the first one (0x0000000X) which may have several different values. The cause of this trap can vary, depending on the value of this parameter. All traps that cause a STOP 0x7F can be found in any Intel x86 microprocessor reference manual as they are specific to the x86 platform.

Then follows a short list of common error codes, but 0x0000000D (decimal 13) is not on the list. As mentioned by the document, the full list can be found in the document called Intel® 64 and IA-32 Architectures Software Developer’s Manual, more specifically in the first volume of this 3000+ page behemoth. In Section 6.4.1 on Page 140, you can find the table “Exceptions and Interrupts” with the full list.

So, what is 0xD?

Description: General Protection
Source: Any memory reference and other protection checks.

Ah, it’s the classic General Protection Fault.

Django: Prevent email notification on SuspiciousOperation

Django 1.4.4 introduced the ALLOWED_HOSTS setting as implemented in django/http/__init__.py:

A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent an attacker from poisoning caches and password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header, which is possible even under many seemingly-safe webserver configurations.

If the host header holds an unknown host and DEBUG is set to False, a SuspiciousOperation exception is raised. This results in an HTTP 500 (Internal Server Error) error code which is returned to the client. I believe this was chosen over the HTTP 4xy-class error (Client Error) so that the admins are notified via email (see the Error Reporting docs). This is a good thing if you have misconfigured the ALLOWED_HOSTS setting and forgot to include some host name that should be usable with the site.

If, however, you are constantly spammed by Django error messages because someone is scanning your website and tries to set a fake Host header, things get annoying. I posted a bug report on the Django bug tracker, and it looks like this will be handled either in 1.5.1 or at least in 1.6. (I wish to note at this place that I’m very grateful that Django has such a responsive dev team. The first response came in in less than 3 hours after the bug, and the first proposed patch was posted on the same day. Thank you!)

Until Django is properly fixed, I need some workaround that I implemented as a logging filter that prevents SuspiciousOperation exceptions from being sent via email (it does not change the HTTP 500 into an HTTP 400):

from django.core.exceptions import SuspiciousOperation

def skip_suspicious_operations(record):
  if record.exc_info:
    exc_value = record.exc_info[1]
    if isinstance(exc_value, SuspiciousOperation):
      return False
  return True

To activate this filter, it must be included in your settings.py file just like in the logging docs, where I also got the blueprint for the code that is listed above.

I prepared a minimal example project for your convenience. It comes with the filter enabled.

If you’d like to verify that the filter works, do the following:

  • Check out the example project and make sure that Django is installed (either globally or in a virtualenv).
  • Run the dev server:
    python manage.py runserver
  • On a second terminal, run the SMTP debugging server built into Python:
    sudo python -m smtpd -n -c DebuggingServer localhost:25
    

    (sudo is necessary because port 25 (SMTP default) can only be used by root)

  • On a third terminal, check that the main page works:
    curl http://localhost:8000/

    (should print “Hello, world” to the console)

  • Check that changing the Host name leads to an error message, but that no email is sent (look at the terminal that runs the SMTP server, nothing should be printed there):
    curl -H "Host: asdfasdf" http://localhost:8000/
  • Check that other server errors are sent out as an email (the SMTP debugging server should print the lenghty message):
    curl http://localhost:8000/500

Building the Botan library for Android

Botan is a C++ crypto library with a wide range of supported cryptographic algorithms. In this article, I’ll walk you through building Botan for Android, so that it can be used in applications that are built with the Android NDK.

Preparations

In the following, I use Ubuntu 12.04 LTS (x86_64) with Eclipse as my development platform. If you use another operating system, the commands may differ.

First, we pull in the Java Development Kit (here: OpenJDK 6), some essential build tools and Python which is needed for the configure script:

sudo apt-get install openjdk-6-jdk build-essential python

We need to have the Android SDK and Eclipse with the Android Development Tools (ADT) installed. The easiest way to get both the SDK and Eclipse with ADT preinstalled is to get the ADT Bundle, extract it somewhere (I used /opt/adt-bundle) and run the eclipse/eclipse program from the resulting folder.

Next, we need to get the Android Native Development Kit (NDK) so that we can compile programs written in C or C++ for Android. I extracted it to /opt/android-ndk, but you can freely choose the location.

Generating the botan_all.* files

First, we download and extract the Botan sources. I recommend to get the Stable Series package, which is version 1.10 at the time of writing.

The configure script of Botan offers to put all of the code into one pair of .h/.cpp files, the botan_all.h and botan_all.cpp. This is called amalgamation and makes it easier to build Botan using the NDK, so we open a terminal, change to the Botan directory, and execute the configure script:

./configure.py --gen-amalgamation --cpu=armv5te --os=linux --cc=gcc --with-tr1=none

This works fine if we target ARM-based Android devices, which covers almost all devices out there. If you need to build for x86/Atom- or MIPS-based devices, you will likely need to adjust the argument to the –cpu parameter. The –with-tr1=none parameter seems to be necessary when using STLport instead of GNU STL (see below).

When the configure script is done, you should see the files botan_all.h and botan_all.cpp in the Botan folder.

Including Botan in an Android project

If you have not already started an Android project which should include Botan, create one now: In Eclipse/ADT, choose File -> New -> Android Application Project and follow the instructions.

Now that you created a project, create a subfolder named “jni” in the project folder which will hold the native code. Inside, create “Android.mk” and “Application.mk” files:

# jni/Android.mk:
include $(call all-subdir-makefiles)

# jni/Application.mk:
APP_ABI := armeabi
APP_CPPFLAGS += -fexceptions -frtti
APP_STL := stlport_shared

If you want to know more about these files, you can look it up in the docs folder of the Android NDK (files ANDROID-MK.html and APPLICATION-MK.html, or use the index in documentation.html in the NDK main directory). Basically, Android.mk tells the Android build system to look for makefiles in the subdirectories, while Application.mk introduces some settings that are used for all modules from the subfolders (ARM instruction set, allow C++ exceptions and RTTI, use STLport instead of the extremely restricted default Android STL).

When you have done this, it is time to create the directory “jni/botan”. Put the botan_all.* files in there and create another Android.mk file:

# jni/botan/Android.mk:
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := botan
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := botan_all.cpp
LOCAL_CPPFLAGS := -DBOTAN_USE_GCC_INLINE_ASM=0

include $(BUILD_SHARED_LIBRARY)

Again, detailed information can be found in ANDROID-MK.html. The LOCAL_CPPFLAGS line was necessary because, later on, the compiler complained about wrong assembler syntax when inline assembler was used.

Creating some native code that uses Botan

Now we need to build an interface so that our Java app can talk to our native code which will talk to Botan. We do this by creating a Native class which loads the necessary libraries in its static initializer, and which declares the methods that we intend to implement in C++, for example:

// src/de/tiwoc/botandemo/Native.java
package de.tiwoc.botandemo;

public class Native {
    static {
        System.loadLibrary("stlport_shared");
        System.loadLibrary("botan");
        System.loadLibrary("botandemo");
    }

    public static native String pbkdf2Demo(int iterations);
}

The order of the loadLibrary statements is significant: botandemo uses botan, which uses stlport_shared, so stlport_shared must be loaded first, then botan, then botandemo.

botandemo will hold our glue code, so we need to create the folder “jni/botandemo” and create an Android.mk for this module:

# jni/botandemo/Android.mk
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := botandemo
LOCAL_SRC_FILES := botandemo.cpp
LOCAL_SHARED_LIBRARIES := botan

include $(BUILD_SHARED_LIBRARY)

The one new line in here is the LOCAL_SHARED_LIBRARIES statement which holds a list of the other modules which botandemo will use.

As a next step, we generate a header file corresponding to the Native class. To do this, we use a terminal to change to the bin/classes folder of the app and issue the javah command from the JDK:

javah -o ../../jni/botandemo/native.h de.tiwoc.botandemo.Native

Now, we can write a .cpp file which implements the definitions from the header. The following method will invoke the PBKDF2 key derivation algorithm with some test data:

// snippet from jni/botandemo/botandemo.cpp
JNIEXPORT jstring JNICALL Java_de_tiwoc_botandemo_Native_pbkdf2Demo
    (JNIEnv * env, jclass cls, jint iterations)
{
    try {
        PBKDF* pbkdf = get_pbkdf("PBKDF2(SHA-256)");
        AutoSeeded_RNG rng;

        SecureVector<byte> salt = rng.random_vec(16);
        OctetString aes256_key = pbkdf->derive_key(
                32, "this_is_a_weak_password",
                &salt[0], salt.size(), iterations);
        return env->NewStringUTF(aes256_key.as_string().c_str());

    } catch (...) {
        std::string empty_str = "";
        return env->NewStringUTF(empty_str.c_str());
    }
}

This does nothing particularly useful, but it shows how to bridge the gap between a Java app and the Botan library. A full and working example of this file is part of the example project that can be found on GitHub.

Building the library and testing the app

At this time, all of the native code can be built. We open a terminal, change to the main folder of our project (in this case: BotanDemo) and invoke the Android build system:

# $(NDK) denotes the main folder of the NDK
$(NDK)/ndk-build

This will put all of the native files in the right place inside the project folder, so that the ADT packages all of it into the .apk when building the app.

For the test project on GitHub, I added an Activity that invokes the pbkdf2Demo method:

botan-demo-1

After touching the button:

botan-demo-2

We’re done!

Get the demo project sources from Github!

Resources

The following web sites helped me a lot while I figured out how to do this:

Backup-Erinnerung für Windows

Vor einiger Zeit habe ich ja bereits über eine einfache Backuplösung für Windows mit RdiffBackup (jetzt HardlinkBackup) geschrieben. Diese funktioniert für mehrere Rechner meiner Familie ganz hervorragend. Das verbleibende Problem war jedoch, dass der Benutzer regelmäßig daran erinnert werden sollte, ein Backup anzufertigen. Unter Linux habe ich dafür schon länger eine Lösung: eine Erinnerung nach dem Login mit direkter Möglichkeit, ein Backup zu starten. Ein Artikel dazu, der meinen leicht angestaubten Artikel zu Backup unter Linux aktualisiert, folgt demnächst. Hier widme ich mich zunächst der Windows-Variante (Download am Ende des Artikels).

  • Nach Windows-Systemstart / Login erscheint, wenn das letzte Backup zu alt ist (z.B. nach 7 Tagen), die Bitte, die USB-Backup-Festplatte anzuschließen.
  • Wenn der Benutzer das Laufwerk anschließt und die Meldung bestätigt, startet das Backup-Programm.
  • Wenn allerdings das Backup abgelehnt wird, erscheint die Meldung beim nächsten Login wieder.

Dies wird durch ein in JScript geschriebenes Programm für den Windows Script Host (WSH) erreicht. Das Skript wird zur “Installation” zunächst im Kopfbereich konfiguriert; konkret muss das gewünschte Backup-Intervall und der auszuführende Befehl eingetragen werden. Anschließend kann es einfach im Autostart-Ordner des Startmenüs abgelegt werden, so dass es nach dem Login gestartet wird.

Download:
backup_erinnerung.js

Reporting plagiarism to publishers of Computer Science papers

So you have found plagiarized papers and don’t know who to contact to report your findings? Here are pointers for some of the relevant publishers of Computer Science literature:

If you have anything to add, feel free to add a comment or drop me a message. Thank you!

Facebook: How to hide your online status or disable chat

After signing in to Facebook, your friends can see that you’re online by default. You can open the chat window in the lower right corner of the window and choose to go offline, but after your next login to Facebook, this setting is lost and you’re online, again.

This may be not the way to go for multiple reasons:

  • If I’m logging in to Facebook, this doesn’t necessarily mean that I want to chat. (People who know me probably also know that I don’t use instant messaging at all…)
  • Privacy: I don’t want everyone (of my Facebook friends) to track my use of Facebook.
  • When I use a phone with a Facebook app running in the background, I appear to be online and ready for chatting as long as the phone is connected to the Internet (probably always). This happened at least with the official Facebook app for Android.

So what to do? A friend of mine was so kind to show me a simple procedure to trick Facebook into hiding my status: Continue reading

Clarification concerning the ICQ 7 security issue

Since ICQ seems to spread inaccurate information about the security issue in ICQ7′s update process, I think I need to clarify:

It is not necessary to successfully attack the users machine or his ISP’s network first to use my exploit.

Long version:

Imagine a public hotspot at your favorite café. You have ICQ 7 installed on the laptop that you carry with you to get some work done. You start up your machine and connect to the wireless network.

What you don’t know is that there’s already someone on the café’s hotspot network who wants to harm you or other users of ICQ. He runs the attack code and a simple program to spoof the address of ICQ’s update server on his laptop or even on his mobile phone. The spoofing will affect all clients on the hotspot network, so after your ICQ client starts up, it automatically downloads the malicious update that the attacker wants to run on your computer. Damage done…

I hope this makes it clear why the “theoretical” issue in fact is an issue for people using their computer on networks that are not entirely under their control.

Update on the ICQ 7 update issue

(This is a follow-up to my original posting on a security issue in ICQ 7)

This is what I sent to Bugtraq today after testing the new ICQ 7.4:

UPDATE:

This week, ICQ 7.4 (build 4561) was released. Even though the original
version of my exploit does not work anymore, the vulnerability was not
resolved: ICQ only changed the product ID that is included in the path
to the update file. If every ocurrence of "30009" in both python files
(see original announcement below) is replaced by "30011" and afterwards,
a new update.xml is generated using build_update_files.py, the attack
will still succeed.

Note to ICQ engineers if they're reading this: To really fix the issue,
introduce cryptographically signed update files.

If you’re still using the original ICQ client, I can only urge you to switch to another client such as Pidgin. I wouldn’t trust a company that doesn’t even offer an email address to report security issues and that tries to fix security issues in such an inept way…

Also have a look at the clarification on the security issue’s impact.

ICQ 7 Update Security Issue

Update: ICQ 7.4 is still vulnerable. Also have a look at the clarification on the security issue’s impact.

Since the first news website googled me and found my seldomly used blog, here’s a collection of links:

In the news:

Read on for my original mail to the Bugtraq mailing list:

Continue reading

Adding Playlists to Sansa Fuze using Rhythmbox

I use a Sansa Fuze music player that I’m quite happy with. It supports the USB Mass Storage protocol and thus can be used (and filled with music) just as any other USB flash drive. This means it is fully supported by all operating systems since it doesn’t need proprietary software running on a PC.

However there’s one thing that tools such as Windows Media Player or iTunes are capable of that might be quite useful: managing playlists on the computer and transferring them to the media player. I recently accidentally found out that this can be achieved with Rhytmbox, the music player that comes with Ubuntu and other GNU/Linux distributions:

  • connect player to computer (tested with Sansa Vuze, MSC mode)
  • fire up Rhythmbox
  • left column: under “Devices”, right click on your player
  • choose “New Playlist”
  • enter a name for the playlist
  • drag music files from the player onto the newly created playlist
  • safely remove the player when done

Effect: A new .m3u file is created at the root directory of the player, containing the playlist. It now appears in the list of playlists of your player (Music -> Playlists).